1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://github.com/flipboxfactory/craft-element-lists/LICENSE |
6
|
|
|
* @link https://github.com/flipboxfactory/craft-element-lists/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\craft\element\lists\migrations; |
10
|
|
|
|
11
|
|
|
use craft\db\Migration; |
12
|
|
|
use craft\records\Element; |
13
|
|
|
use craft\records\Field; |
14
|
|
|
use craft\records\Site; |
15
|
|
|
use flipbox\craft\element\lists\records\Association; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Flipbox Factory <[email protected]> |
19
|
|
|
* @since 1.0.0 |
20
|
|
|
*/ |
21
|
|
|
class Install extends Migration |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @inheritdoc |
25
|
|
|
*/ |
26
|
|
|
public function safeUp() |
27
|
|
|
{ |
28
|
|
|
$this->createTable(Association::tableName(), [ |
29
|
|
|
'fieldId' => $this->integer()->notNull(), |
30
|
|
|
'sourceId' => $this->integer()->notNull(), |
31
|
|
|
'targetId' => $this->integer()->notNull(), |
32
|
|
|
'siteId' => $this->integer()->notNull(), |
33
|
|
|
'sortOrder' => $this->integer()->unsigned(), |
34
|
|
|
'dateCreated' => $this->dateTime()->notNull(), |
35
|
|
|
'dateUpdated' => $this->dateTime()->notNull(), |
36
|
|
|
'uid' => $this->uid(), |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
$this->addPrimaryKey( |
40
|
|
|
null, |
41
|
|
|
Association::tableName(), |
42
|
|
|
['fieldId', 'sourceId', 'targetId', 'siteId'] |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$this->addForeignKey( |
46
|
|
|
null, |
47
|
|
|
Association::tableName(), |
48
|
|
|
'fieldId', |
49
|
|
|
Field::tableName(), |
50
|
|
|
'id', |
51
|
|
|
'CASCADE', |
52
|
|
|
null |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$this->addForeignKey( |
56
|
|
|
null, |
57
|
|
|
Association::tableName(), |
58
|
|
|
'sourceId', |
59
|
|
|
Element::tableName(), |
60
|
|
|
'id', |
61
|
|
|
'CASCADE', |
62
|
|
|
null |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$this->addForeignKey( |
66
|
|
|
null, |
67
|
|
|
Association::tableName(), |
68
|
|
|
'targetId', |
69
|
|
|
Element::tableName(), |
70
|
|
|
'id', |
71
|
|
|
'CASCADE', |
72
|
|
|
null |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$this->addForeignKey( |
76
|
|
|
null, |
77
|
|
|
Association::tableName(), |
78
|
|
|
'siteId', |
79
|
|
|
Site::tableName(), |
80
|
|
|
'id', |
81
|
|
|
'CASCADE', |
82
|
|
|
'CASCADE' |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|