m160411_143038_create_portfolio_gallery.php
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
use yii\db\Migration;
/**
* Handles the creation for table `portfolio_gallery`.
*/
class m160411_143038_create_portfolio_gallery extends Migration
{
/**
* @inheritdoc
*/
public function up()
{
$this->createTable('portfolio_gallery', [
'portfolio_gallery_id' => $this->primaryKey(),
'gallery_id' => $this->integer()
->notNull(),
'portfolio_id' => $this->integer()
->notNull(),
'user_id' => $this->integer()
->notNull(),
'caption' => $this->string(),
'visible' => $this->smallInteger()
->defaultValue(1),
]);
$this->addForeignKey('portfolio_gallery_gallery', '{{%portfolio_gallery}}', 'gallery_id', '{{%gallery}}', 'gallery_id', 'CASCADE', 'CASCADE');
$this->addForeignKey('portfolio_gallery_portfolio', '{{%portfolio_gallery}}', 'portfolio_id', '{{%portfolio}}', 'portfolio_id', 'CASCADE', 'CASCADE');
$this->addForeignKey('portfolio_gallery_user', '{{%portfolio_gallery}}', 'user_id', '{{%user}}', 'id', 'CASCADE', 'CASCADE');
}
/**
* @inheritdoc
*/
public function down()
{
$this->dropForeignKey('portfolio_gallery_user', '{{%portfolio_gallery}}');
$this->dropForeignKey('portfolio_gallery_gallery', '{{%portfolio_gallery}}');
$this->dropForeignKey('portfolio_gallery_portfolio', '{{%portfolio_gallery}}');
$this->dropTable('portfolio_gallery');
}
}