1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/hubspot/license |
6
|
|
|
* @link https://www.flipboxfactory.com/software/hubspot/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\hubspot\migrations; |
10
|
|
|
|
11
|
|
|
use craft\db\Migration; |
12
|
|
|
use craft\records\Element as ElementRecord; |
13
|
|
|
use craft\records\Field as FieldRecord; |
14
|
|
|
use craft\records\Site as SiteRecord; |
15
|
|
|
use flipbox\hubspot\records\ObjectAssociation as ObjectAssociationRecord; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Flipbox Factory <[email protected]> |
19
|
|
|
* @since 1.0.0 |
20
|
|
|
*/ |
21
|
|
|
class ObjectAssociation extends Migration |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @inheritdoc |
25
|
|
|
*/ |
26
|
3 |
|
public function safeUp() |
27
|
|
|
{ |
28
|
3 |
|
$this->createTables(); |
29
|
3 |
|
$this->createIndexes(); |
30
|
3 |
|
$this->addForeignKeys(); |
31
|
|
|
|
32
|
|
|
return true; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritdoc |
37
|
|
|
*/ |
38
|
|
|
public function safeDown() |
39
|
|
|
{ |
40
|
|
|
$this->dropTableIfExists(ObjectAssociationRecord::tableName()); |
41
|
|
|
return true; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Creates the tables. |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
3 |
|
protected function createTables() |
50
|
|
|
{ |
51
|
3 |
|
$this->createTable(ObjectAssociationRecord::tableName(), [ |
52
|
3 |
|
'objectId' => $this->integer()->notNull(), |
53
|
3 |
|
'elementId' => $this->integer()->notNull(), |
54
|
3 |
|
'fieldId' => $this->integer()->notNull(), |
55
|
3 |
|
'siteId' => $this->integer()->notNull(), |
56
|
3 |
|
'sortOrder' => $this->smallInteger()->unsigned(), |
57
|
3 |
|
'dateCreated' => $this->dateTime()->notNull(), |
58
|
3 |
|
'dateUpdated' => $this->dateTime()->notNull(), |
59
|
3 |
|
'uid' => $this->uid() |
60
|
|
|
]); |
61
|
3 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Creates the indexes. |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
3 |
|
protected function createIndexes() |
69
|
|
|
{ |
70
|
3 |
|
$this->addPrimaryKey( |
71
|
3 |
|
null, |
72
|
3 |
|
ObjectAssociationRecord::tableName(), |
73
|
|
|
[ |
74
|
3 |
|
'elementId', |
75
|
|
|
'objectId', |
76
|
|
|
'fieldId', |
77
|
|
|
'siteId' |
78
|
|
|
] |
79
|
|
|
); |
80
|
3 |
|
$this->createIndex( |
81
|
3 |
|
null, |
82
|
3 |
|
ObjectAssociationRecord::tableName(), |
83
|
3 |
|
'objectId', |
84
|
3 |
|
false |
85
|
|
|
); |
86
|
3 |
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Adds the foreign keys. |
90
|
|
|
* |
91
|
|
|
* @return void |
92
|
|
|
*/ |
93
|
3 |
|
protected function addForeignKeys() |
94
|
|
|
{ |
95
|
3 |
|
$this->addForeignKey( |
96
|
3 |
|
null, |
97
|
3 |
|
ObjectAssociationRecord::tableName(), |
98
|
3 |
|
'elementId', |
99
|
3 |
|
ElementRecord::tableName(), |
100
|
3 |
|
'id', |
101
|
3 |
|
'CASCADE', |
102
|
3 |
|
null |
103
|
|
|
); |
104
|
|
|
$this->addForeignKey( |
105
|
|
|
null, |
106
|
|
|
ObjectAssociationRecord::tableName(), |
107
|
|
|
'siteId', |
108
|
|
|
SiteRecord::tableName(), |
109
|
|
|
'id', |
110
|
|
|
'CASCADE', |
111
|
|
|
'CASCADE' |
112
|
|
|
); |
113
|
|
|
$this->addForeignKey( |
114
|
|
|
null, |
115
|
|
|
ObjectAssociationRecord::tableName(), |
116
|
|
|
'fieldId', |
117
|
|
|
FieldRecord::tableName(), |
118
|
|
|
'id', |
119
|
|
|
'CASCADE', |
120
|
|
|
'CASCADE' |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|