m170512_092259_create_wishlist_table.php
1.57 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
44
45
46
47
48
49
50
51
52
53
54
55
<?php
use yii\db\Migration;
/**
* Handles the creation of table `wishlist`.
*/
class m170512_092259_create_wishlist_table extends Migration
{
/**
* @inheritdoc
*/
public function up()
{
$this->createTable(
'wishlist',
[
'user_id' => $this->integer(),
'product_id' => $this->integer(),
'variant_id' => $this->integer(),
]
);
$this->addForeignKey('user_fk', 'wishlist', 'user_id', 'customer', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('product_fk', 'wishlist', 'product_id', 'product', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('variant_fk', 'wishlist', 'variant_id', 'variant', 'id', 'CASCADE', 'CASCADE');
$this->createIndex(
'user_variant_fk',
'wishlist',
[
'user_id',
'variant_id',
],
true
);
}
/**
* @inheritdoc
*/
public function down()
{
$this->dropIndex(
'user_variant_fk',
'wishlist'
);
$this->dropForeignKey('variant_fk', 'wishlist');
$this->dropForeignKey('product_fk', 'wishlist');
$this->dropForeignKey('user_fk', 'wishlist');
$this->dropTable('wishlist');
}
}