1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use yii\db\Migration; |
4
|
|
|
use app\modules\shop\models\Wishlist; |
5
|
|
|
use app\modules\shop\models\WishlistProduct; |
6
|
|
|
use app\modules\user\models\User; |
7
|
|
|
use app\modules\shop\models\Product; |
8
|
|
|
|
9
|
|
|
class m160316_102050_create_wish_table extends Migration |
10
|
|
|
{ |
11
|
|
|
public function safeUp() |
12
|
|
|
{ |
13
|
|
|
$this->createTable(Wishlist::tableName(), [ |
14
|
|
|
'id' => $this->primaryKey(), |
15
|
|
|
'user_id' => $this->integer()->unsigned()->notNull(), |
16
|
|
|
'title' => $this->string()->notNull(), |
17
|
|
|
'default' => $this->boolean()->notNull()->defaultValue(true), |
18
|
|
|
]); |
19
|
|
|
|
20
|
|
|
$this->createTable(WishlistProduct::tableName(), [ |
21
|
|
|
'id' => $this->primaryKey(), |
22
|
|
|
'wishlist_id' => $this->integer()->notNull(), |
23
|
|
|
'product_id' => $this->integer()->unsigned()->notNull(), |
24
|
|
|
'UNIQUE KEY `ix-wishlist_id-product_id` (`wishlist_id`, `product_id`)', |
25
|
|
|
]); |
26
|
|
|
$this->addForeignKey('wishlist_product_wishlist_id', WishlistProduct::tableName(), 'wishlist_id', Wishlist::tableName(), 'id', 'CASCADE'); |
|
|
|
|
27
|
|
|
$this->addForeignKey('wishlist_product_product_id', WishlistProduct::tableName(), 'product_id', Product::tableName(), 'id', 'CASCADE'); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function safeDown() |
31
|
|
|
{ |
32
|
|
|
$this->dropTable(WishlistProduct::tableName()); |
33
|
|
|
$this->dropTable(Wishlist::tableName()); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.