1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Phalcon\Db\Column; |
4
|
|
|
use Phalcon\Db\Index; |
5
|
|
|
use Phalcon\Db\Reference; |
6
|
|
|
use Phalcon\Migrations\Mvc\Model\Migration; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class SnapshotMigration_100 |
10
|
|
|
*/ |
11
|
|
|
class SnapshotMigration_100 extends Migration |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Define the table structure |
15
|
|
|
* |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
|
|
public function morph() |
19
|
|
|
{ |
20
|
|
|
$this->morphTable('snapshot', [ |
21
|
|
|
'columns' => [ |
22
|
|
|
new Column( |
23
|
|
|
'id', |
24
|
|
|
[ |
25
|
|
|
'type' => Column::TYPE_INTEGER, |
26
|
|
|
'unsigned' => true, |
27
|
|
|
'notNull' => true, |
28
|
|
|
'autoIncrement' => true, |
29
|
|
|
'size' => 10, |
30
|
|
|
'first' => true |
31
|
|
|
] |
32
|
|
|
), |
33
|
|
|
new Column( |
34
|
|
|
'snapshot_id', |
35
|
|
|
[ |
36
|
|
|
'type' => Column::TYPE_INTEGER, |
37
|
|
|
'unsigned' => true, |
38
|
|
|
'notNull' => false, |
39
|
|
|
'size' => 10, |
40
|
|
|
'after' => 'id' |
41
|
|
|
] |
42
|
|
|
), |
43
|
|
|
new Column( |
44
|
|
|
'project_id', |
45
|
|
|
[ |
46
|
|
|
'type' => Column::TYPE_INTEGER, |
47
|
|
|
'unsigned' => true, |
48
|
|
|
'notNull' => false, |
49
|
|
|
'size' => 10, |
50
|
|
|
'after' => 'snapshot_id' |
51
|
|
|
] |
52
|
|
|
), |
53
|
|
|
new Column( |
54
|
|
|
'channel_id', |
55
|
|
|
[ |
56
|
|
|
'type' => Column::TYPE_INTEGER, |
57
|
|
|
'unsigned' => true, |
58
|
|
|
'notNull' => false, |
59
|
|
|
'size' => 10, |
60
|
|
|
'after' => 'project_id' |
61
|
|
|
] |
62
|
|
|
), |
63
|
|
|
new Column( |
64
|
|
|
'endpoint_id', |
65
|
|
|
[ |
66
|
|
|
'type' => Column::TYPE_INTEGER, |
67
|
|
|
'unsigned' => true, |
68
|
|
|
'notNull' => false, |
69
|
|
|
'size' => 10, |
70
|
|
|
'after' => 'channel_id' |
71
|
|
|
] |
72
|
|
|
), |
73
|
|
|
new Column( |
74
|
|
|
'snapshot', |
75
|
|
|
[ |
76
|
|
|
'type' => Column::TYPE_LONGTEXT, |
77
|
|
|
'notNull' => true, |
78
|
|
|
'after' => 'endpoint_id' |
79
|
|
|
] |
80
|
|
|
), |
81
|
|
|
new Column( |
82
|
|
|
'meta', |
83
|
|
|
[ |
84
|
|
|
'type' => Column::TYPE_LONGTEXT, |
85
|
|
|
'notNull' => false, |
86
|
|
|
'after' => 'snapshot' |
87
|
|
|
] |
88
|
|
|
), |
89
|
|
|
new Column( |
90
|
|
|
'created_at', |
91
|
|
|
[ |
92
|
|
|
'type' => Column::TYPE_DATETIME, |
93
|
|
|
'default' => "current_timestamp()", |
94
|
|
|
'notNull' => true, |
95
|
|
|
'after' => 'meta' |
96
|
|
|
] |
97
|
|
|
), |
98
|
|
|
new Column( |
99
|
|
|
'updated_at', |
100
|
|
|
[ |
101
|
|
|
'type' => Column::TYPE_DATETIME, |
102
|
|
|
'notNull' => false, |
103
|
|
|
'after' => 'created_at' |
104
|
|
|
] |
105
|
|
|
), |
106
|
|
|
new Column( |
107
|
|
|
'deleted_at', |
108
|
|
|
[ |
109
|
|
|
'type' => Column::TYPE_DATETIME, |
110
|
|
|
'notNull' => false, |
111
|
|
|
'after' => 'updated_at' |
112
|
|
|
] |
113
|
|
|
), |
114
|
|
|
new Column( |
115
|
|
|
'deleted', |
116
|
|
|
[ |
117
|
|
|
'type' => Column::TYPE_TINYINTEGER, |
118
|
|
|
'default' => "0", |
119
|
|
|
'unsigned' => true, |
120
|
|
|
'notNull' => true, |
121
|
|
|
'size' => 1, |
122
|
|
|
'after' => 'deleted_at' |
123
|
|
|
] |
124
|
|
|
) |
125
|
|
|
], |
126
|
|
|
'indexes' => [ |
127
|
|
|
new Index('PRIMARY', ['id'], 'PRIMARY'), |
128
|
|
|
new Index('id_UNIQUE', ['id'], 'UNIQUE'), |
129
|
|
|
new Index('snapshot_snapshot_id_fk_idx', ['snapshot_id'], ''), |
130
|
|
|
new Index('snapshot_project_id_fk_idx', ['project_id'], ''), |
131
|
|
|
new Index('snapshot_channel_id_fk_idx', ['channel_id'], ''), |
132
|
|
|
new Index('snapshot_endpoint_id_fk_idx', ['endpoint_id'], '') |
133
|
|
|
], |
134
|
|
|
'references' => [ |
135
|
|
|
new Reference( |
136
|
|
|
'snapshot_channel_id_fk', |
137
|
|
|
[ |
138
|
|
|
'referencedTable' => 'channel', |
139
|
|
|
'referencedSchema' => 'zemit', |
140
|
|
|
'columns' => ['channel_id'], |
141
|
|
|
'referencedColumns' => ['id'], |
142
|
|
|
'onUpdate' => 'CASCADE', |
143
|
|
|
'onDelete' => 'CASCADE' |
144
|
|
|
] |
145
|
|
|
), |
146
|
|
|
new Reference( |
147
|
|
|
'snapshot_endpoint_id_fk', |
148
|
|
|
[ |
149
|
|
|
'referencedTable' => 'endpoint', |
150
|
|
|
'referencedSchema' => 'zemit', |
151
|
|
|
'columns' => ['endpoint_id'], |
152
|
|
|
'referencedColumns' => ['id'], |
153
|
|
|
'onUpdate' => 'CASCADE', |
154
|
|
|
'onDelete' => 'CASCADE' |
155
|
|
|
] |
156
|
|
|
), |
157
|
|
|
new Reference( |
158
|
|
|
'snapshot_project_id_fk', |
159
|
|
|
[ |
160
|
|
|
'referencedTable' => 'project', |
161
|
|
|
'referencedSchema' => 'zemit', |
162
|
|
|
'columns' => ['project_id'], |
163
|
|
|
'referencedColumns' => ['id'], |
164
|
|
|
'onUpdate' => 'CASCADE', |
165
|
|
|
'onDelete' => 'CASCADE' |
166
|
|
|
] |
167
|
|
|
), |
168
|
|
|
new Reference( |
169
|
|
|
'snapshot_snapshot_id_fk', |
170
|
|
|
[ |
171
|
|
|
'referencedTable' => 'snapshot', |
172
|
|
|
'referencedSchema' => 'zemit', |
173
|
|
|
'columns' => ['snapshot_id'], |
174
|
|
|
'referencedColumns' => ['id'], |
175
|
|
|
'onUpdate' => 'CASCADE', |
176
|
|
|
'onDelete' => 'CASCADE' |
177
|
|
|
] |
178
|
|
|
) |
179
|
|
|
], |
180
|
|
|
'options' => [ |
181
|
|
|
'table_type' => 'BASE TABLE', |
182
|
|
|
'auto_increment' => '', |
183
|
|
|
'engine' => 'InnoDB', |
184
|
|
|
'table_collation' => 'utf8mb4_general_ci' |
185
|
|
|
], |
186
|
|
|
] |
187
|
|
|
); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Run the migrations |
192
|
|
|
* |
193
|
|
|
* @return void |
194
|
|
|
*/ |
195
|
|
|
public function up() |
196
|
|
|
{ |
197
|
|
|
|
198
|
|
|
} |
|
|
|
|
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Reverse the migrations |
202
|
|
|
* |
203
|
|
|
* @return void |
204
|
|
|
*/ |
205
|
|
|
public function down() |
206
|
|
|
{ |
207
|
|
|
|
208
|
|
|
} |
|
|
|
|
209
|
|
|
|
210
|
|
|
} |
211
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.