@@ -2,17 +2,17 @@ |
||
2 | 2 | |
3 | 3 | class m170731_173719_comments_and_relationships_fix extends CDbMigration |
4 | 4 | { |
5 | - public function up() |
|
6 | - { |
|
7 | - } |
|
5 | + public function up() |
|
6 | + { |
|
7 | + } |
|
8 | 8 | |
9 | - public function down() |
|
10 | - { |
|
11 | - $this->addForeignKey('user_roles_fk', 'users', 'user_role', 'user_roles', 'id', 'CASCADE', 'NO ACTION'); |
|
12 | - $this->execute('ALTER TABLE `comments` MODIFY comment TEXT NOT NULL'); |
|
13 | - } |
|
9 | + public function down() |
|
10 | + { |
|
11 | + $this->addForeignKey('user_roles_fk', 'users', 'user_role', 'user_roles', 'id', 'CASCADE', 'NO ACTION'); |
|
12 | + $this->execute('ALTER TABLE `comments` MODIFY comment TEXT NOT NULL'); |
|
13 | + } |
|
14 | 14 | |
15 | - /* |
|
15 | + /* |
|
16 | 16 | // Use safeUp/safeDown to do migration with transaction |
17 | 17 | public function safeUp() |
18 | 18 | { |
@@ -2,14 +2,14 @@ |
||
2 | 2 | |
3 | 3 | class m170731_173719_comments_and_relationships_fix extends CDbMigration |
4 | 4 | { |
5 | - public function up() |
|
5 | + public function up () |
|
6 | 6 | { |
7 | 7 | } |
8 | 8 | |
9 | - public function down() |
|
9 | + public function down () |
|
10 | 10 | { |
11 | - $this->addForeignKey('user_roles_fk', 'users', 'user_role', 'user_roles', 'id', 'CASCADE', 'NO ACTION'); |
|
12 | - $this->execute('ALTER TABLE `comments` MODIFY comment TEXT NOT NULL'); |
|
11 | + $this->addForeignKey ('user_roles_fk', 'users', 'user_role', 'user_roles', 'id', 'CASCADE', 'NO ACTION'); |
|
12 | + $this->execute ('ALTER TABLE `comments` MODIFY comment TEXT NOT NULL'); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /* |
@@ -3,286 +3,286 @@ |
||
3 | 3 | class m141001_145619_init extends CDbMigration |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * For data insertions, this is the current time. |
|
8 | - * @var integer |
|
9 | - */ |
|
10 | - private $_moment = 0; |
|
11 | - |
|
12 | - public function safeUp() |
|
13 | - { |
|
14 | - $this->_moment = time(); |
|
15 | - |
|
16 | - // Try to get the table names, if we get something back, do not run this migration |
|
17 | - try |
|
18 | - { |
|
19 | - $test = Yii::app()->db->schema->getTables(); |
|
20 | - if (count($test) <= 1) |
|
21 | - throw new Exception('CiiMS doesn\'t exist. Applying base migration'); |
|
22 | - return true; |
|
23 | - } |
|
24 | - catch (Exception $e) |
|
25 | - { |
|
26 | - // Yii will throw an exception if Yii::app()->db->schema is undefined (which is should be if we're doing this for the first time) |
|
27 | - // This SHOULD throw an error if we're running this for the first time - it's the only way to check if we have a valid db or not. |
|
28 | - } |
|
29 | - |
|
30 | - // Otherwise, run the install migration |
|
31 | - $this->createUserTables(); |
|
32 | - |
|
33 | - $this->createCategories(); |
|
34 | - |
|
35 | - $this->createContent(); |
|
36 | - |
|
37 | - $this->createConfiguration(); |
|
38 | - } |
|
39 | - |
|
40 | - public function safeDown() |
|
41 | - { |
|
42 | - echo "m141001_145619_init does not support migration down.\n"; |
|
43 | - return false; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Creates the tables, indexes, and relations for users |
|
48 | - */ |
|
49 | - private function createUserTables() |
|
50 | - { |
|
51 | - $this->createTable('users', array( |
|
52 | - 'id' => 'pk', |
|
53 | - 'email' => 'string NOT NULL', |
|
54 | - 'password' => 'string NOT NULL', |
|
55 | - 'username' => 'string NOT NULL', |
|
56 | - 'user_role' => 'integer DEFAULT 1', |
|
57 | - 'status' => 'integer DEFAULT 1', |
|
58 | - 'created' => 'integer', |
|
59 | - 'updated' => 'integer' |
|
60 | - )); |
|
61 | - |
|
62 | - $this->createTable('user_roles', array( |
|
63 | - 'id' => 'pk', |
|
64 | - 'name' => 'string NOT NULL', |
|
65 | - 'created' => 'integer', |
|
66 | - 'updated' => 'integer' |
|
67 | - )); |
|
68 | - |
|
69 | - $this->createTable('user_metadata', array( |
|
70 | - 'user_id' => 'integer', |
|
71 | - 'key' => 'string NOT NULL', |
|
72 | - 'value' => 'text NOT NULL', |
|
73 | - 'entity_type' => 'integer', |
|
74 | - 'created' => 'integer', |
|
75 | - 'updated' => 'integer' |
|
76 | - )); |
|
77 | - |
|
78 | - // Create the necessary indexes on the columns |
|
79 | - $this->createIndex('user_email', 'users', 'email', true); |
|
80 | - $this->createIndex('user_username', 'users', 'username', true); |
|
81 | - $this->createIndex('user_metadata', 'user_metadata', 'user_id, key', false); |
|
82 | - |
|
83 | - $this->addPrimaryKey('user_metadata_composite', 'user_metadata', 'user_id,key'); |
|
84 | - |
|
85 | - // Setup the foreign key constraints |
|
86 | - $this->addForeignKey('user_metadata_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
87 | - |
|
88 | - // Insert data into the tables |
|
89 | - $this->insert('user_roles', array( |
|
90 | - 'id' => 1, |
|
91 | - 'name' => 'User', |
|
92 | - 'created' => $this->_moment, |
|
93 | - 'updated' => $this->_moment |
|
94 | - )); |
|
95 | - |
|
96 | - $this->insert('user_roles', array( |
|
97 | - 'id' => 2, |
|
98 | - 'name' => 'Pending', |
|
99 | - 'created' => $this->_moment, |
|
100 | - 'updated' => $this->_moment |
|
101 | - )); |
|
102 | - |
|
103 | - $this->insert('user_roles', array( |
|
104 | - 'id' => 3, |
|
105 | - 'name' => 'Suspended', |
|
106 | - 'created' => $this->_moment, |
|
107 | - 'updated' => $this->_moment |
|
108 | - )); |
|
109 | - |
|
110 | - $this->insert('user_roles', array( |
|
111 | - 'id' => 5, |
|
112 | - 'name' => 'Collaborator', |
|
113 | - 'created' => $this->_moment, |
|
114 | - 'updated' => $this->_moment |
|
115 | - )); |
|
116 | - |
|
117 | - $this->insert('user_roles', array( |
|
118 | - 'id' => 6, |
|
119 | - 'name' => 'Author', |
|
120 | - 'created' => $this->_moment, |
|
121 | - 'updated' => $this->_moment |
|
122 | - )); |
|
123 | - |
|
124 | - $this->insert('user_roles', array( |
|
125 | - 'id' => 7, |
|
126 | - 'name' => 'User', |
|
127 | - 'created' => $this->_moment, |
|
128 | - 'updated' => $this->_moment |
|
129 | - )); |
|
130 | - |
|
131 | - $this->insert('user_roles', array( |
|
132 | - 'id' => 8, |
|
133 | - 'name' => 'Publisher', |
|
134 | - 'created' => $this->_moment, |
|
135 | - 'updated' => $this->_moment |
|
136 | - )); |
|
137 | - |
|
138 | - $this->insert('user_roles', array( |
|
139 | - 'id' => 9, |
|
140 | - 'name' => 'Administrator', |
|
141 | - 'created' => $this->_moment, |
|
142 | - 'updated' => $this->_moment |
|
143 | - )); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Create the categories and relations |
|
148 | - */ |
|
149 | - private function createCategories() |
|
150 | - { |
|
151 | - // Categories |
|
152 | - $this->createTable('categories', array( |
|
153 | - 'id' => 'pk', |
|
154 | - 'parent_id' => 'integer DEFAULT 1', |
|
155 | - 'name' => 'string NOT NULL', |
|
156 | - 'slug' => 'string NOT NULL', |
|
157 | - 'created' => 'integer', |
|
158 | - 'updated' => 'integer' |
|
159 | - )); |
|
160 | - |
|
161 | - $this->createTable('categories_metadata', array( |
|
162 | - 'category_id' => 'integer', |
|
163 | - 'key' => 'string NOT NULL', |
|
164 | - 'value' => 'text NOT NULL', |
|
165 | - 'created' => 'integer', |
|
166 | - 'updated' => 'integer' |
|
167 | - )); |
|
168 | - |
|
169 | - // Insert the first record into the categories table |
|
170 | - $this->insert('categories', array( |
|
171 | - 'id' => 1, |
|
172 | - 'name' => 'Uncategorized', |
|
173 | - 'slug' => 'uncategorized', |
|
174 | - 'created' => $this->_moment, |
|
175 | - 'updated' => $this->_moment |
|
176 | - )); |
|
177 | - |
|
178 | - $this->addPrimaryKey('categories_metadata_composite', 'categories_metadata', 'category_id,key'); |
|
179 | - $this->addForeignKey('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
180 | - $this->addForeignKey('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Creates the content, comemnts, and necessary relations |
|
185 | - */ |
|
186 | - private function createContent() |
|
187 | - { |
|
188 | - $this->createTable('content', array( |
|
189 | - 'id' => 'integer NOT NULL', |
|
190 | - 'vid' => 'integer NOT NULL DEFAULT 1', |
|
191 | - 'title' => 'string NOT NULL', |
|
192 | - 'content' => 'text NOT NULL', |
|
193 | - 'excerpt' => 'text NOT NULL', |
|
194 | - 'slug' => 'string NOT NULL', |
|
195 | - 'category_id' => 'integer DEFAULT 1', |
|
196 | - 'author_id' => 'integer DEFAULT 1', |
|
197 | - 'type_id' => 'integer DEFAULT 2', |
|
198 | - 'commentable' => 'integer DEFAULT 1', |
|
199 | - 'password' => 'string DEFAULT NULL', |
|
200 | - 'status' => 'integer DEFAULT 0', |
|
201 | - 'like_count' => 'integer DEFAULT 0', |
|
202 | - 'published' => 'integer', |
|
203 | - 'created' => 'integer', |
|
204 | - 'updated' => 'integer' |
|
205 | - )); |
|
206 | - |
|
207 | - $this->createTable('content_types', array( |
|
208 | - 'id' => 'pk', |
|
209 | - 'name' => 'string NOT NULL', |
|
210 | - 'created' => 'integer', |
|
211 | - 'updated' => 'integer' |
|
212 | - )); |
|
213 | - |
|
214 | - $this->createTable('content_metadata', array( |
|
215 | - 'content_id' => 'integer', |
|
216 | - 'key' => 'string NOT NULL', |
|
217 | - 'value' => 'text NOT NULL', |
|
218 | - 'created' => 'integer', |
|
219 | - 'updated' => 'integer' |
|
220 | - )); |
|
221 | - |
|
222 | - $this->createTable('comments', array( |
|
223 | - 'id' => 'pk', |
|
224 | - 'content_id' => 'integer', |
|
225 | - 'author_id' => 'integer', |
|
226 | - 'comment' => 'integer', |
|
227 | - 'created' => 'integer', |
|
228 | - 'updated' => 'integer' |
|
229 | - )); |
|
230 | - |
|
231 | - $this->insert('content_types', array( |
|
232 | - 'id' => 1, |
|
233 | - 'name' => 'Static Page', |
|
234 | - 'created' => $this->_moment, |
|
235 | - 'updated' => $this->_moment |
|
236 | - )); |
|
237 | - |
|
238 | - $this->insert('content_types', array( |
|
239 | - 'id' => 2, |
|
240 | - 'name' => 'Blog Post', |
|
241 | - 'created' => $this->_moment, |
|
242 | - 'updated' => $this->_moment |
|
243 | - )); |
|
244 | - |
|
245 | - $this->addPrimaryKey('content_composite', 'content', 'id, vid'); |
|
246 | - |
|
247 | - $this->execute('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT'); |
|
248 | - |
|
249 | - $this->addPrimaryKey('content_metadata_composite', 'content_metadata', 'content_id,key'); |
|
250 | - |
|
251 | - $this->createIndex('content_author', 'content', 'author_id', false); |
|
252 | - $this->createIndex('content_category', 'content', 'category_id', false); |
|
253 | - $this->createIndex('content_type', 'content', 'type_id', false); |
|
254 | - $this->createIndex('comment_content', 'comments', 'content_id', false); |
|
255 | - $this->createIndex('comment_author', 'comments', 'author_id', false); |
|
256 | - |
|
257 | - $this->addForeignKey('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
258 | - $this->addForeignKey('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
259 | - $this->addForeignKey('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION'); |
|
260 | - |
|
261 | - $this->addForeignKey('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION'); |
|
262 | - $this->addForeignKey('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Creates the configuration and events tables |
|
267 | - */ |
|
268 | - private function createConfiguration() |
|
269 | - { |
|
270 | - $this->createTable('configuration', array( |
|
271 | - 'key' => 'string', |
|
272 | - 'value' => 'text NOT NULL', |
|
273 | - 'created' => 'integer', |
|
274 | - 'updated' => 'integer' |
|
275 | - )); |
|
276 | - |
|
277 | - $this->createTable('events', array( |
|
278 | - 'id' => 'pk', |
|
279 | - 'event' => 'string NOT NULL', |
|
280 | - 'event_data' => 'text DEFAULT NULL', |
|
281 | - 'uri' => 'string DEFAULT NULL', |
|
282 | - 'content_id' => 'integer DEFAULT NULL', |
|
283 | - 'created' => 'integer' |
|
284 | - )); |
|
285 | - |
|
286 | - $this->addPrimaryKey('configuration_pk', 'configuration', 'key'); |
|
287 | - } |
|
6 | + /** |
|
7 | + * For data insertions, this is the current time. |
|
8 | + * @var integer |
|
9 | + */ |
|
10 | + private $_moment = 0; |
|
11 | + |
|
12 | + public function safeUp() |
|
13 | + { |
|
14 | + $this->_moment = time(); |
|
15 | + |
|
16 | + // Try to get the table names, if we get something back, do not run this migration |
|
17 | + try |
|
18 | + { |
|
19 | + $test = Yii::app()->db->schema->getTables(); |
|
20 | + if (count($test) <= 1) |
|
21 | + throw new Exception('CiiMS doesn\'t exist. Applying base migration'); |
|
22 | + return true; |
|
23 | + } |
|
24 | + catch (Exception $e) |
|
25 | + { |
|
26 | + // Yii will throw an exception if Yii::app()->db->schema is undefined (which is should be if we're doing this for the first time) |
|
27 | + // This SHOULD throw an error if we're running this for the first time - it's the only way to check if we have a valid db or not. |
|
28 | + } |
|
29 | + |
|
30 | + // Otherwise, run the install migration |
|
31 | + $this->createUserTables(); |
|
32 | + |
|
33 | + $this->createCategories(); |
|
34 | + |
|
35 | + $this->createContent(); |
|
36 | + |
|
37 | + $this->createConfiguration(); |
|
38 | + } |
|
39 | + |
|
40 | + public function safeDown() |
|
41 | + { |
|
42 | + echo "m141001_145619_init does not support migration down.\n"; |
|
43 | + return false; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Creates the tables, indexes, and relations for users |
|
48 | + */ |
|
49 | + private function createUserTables() |
|
50 | + { |
|
51 | + $this->createTable('users', array( |
|
52 | + 'id' => 'pk', |
|
53 | + 'email' => 'string NOT NULL', |
|
54 | + 'password' => 'string NOT NULL', |
|
55 | + 'username' => 'string NOT NULL', |
|
56 | + 'user_role' => 'integer DEFAULT 1', |
|
57 | + 'status' => 'integer DEFAULT 1', |
|
58 | + 'created' => 'integer', |
|
59 | + 'updated' => 'integer' |
|
60 | + )); |
|
61 | + |
|
62 | + $this->createTable('user_roles', array( |
|
63 | + 'id' => 'pk', |
|
64 | + 'name' => 'string NOT NULL', |
|
65 | + 'created' => 'integer', |
|
66 | + 'updated' => 'integer' |
|
67 | + )); |
|
68 | + |
|
69 | + $this->createTable('user_metadata', array( |
|
70 | + 'user_id' => 'integer', |
|
71 | + 'key' => 'string NOT NULL', |
|
72 | + 'value' => 'text NOT NULL', |
|
73 | + 'entity_type' => 'integer', |
|
74 | + 'created' => 'integer', |
|
75 | + 'updated' => 'integer' |
|
76 | + )); |
|
77 | + |
|
78 | + // Create the necessary indexes on the columns |
|
79 | + $this->createIndex('user_email', 'users', 'email', true); |
|
80 | + $this->createIndex('user_username', 'users', 'username', true); |
|
81 | + $this->createIndex('user_metadata', 'user_metadata', 'user_id, key', false); |
|
82 | + |
|
83 | + $this->addPrimaryKey('user_metadata_composite', 'user_metadata', 'user_id,key'); |
|
84 | + |
|
85 | + // Setup the foreign key constraints |
|
86 | + $this->addForeignKey('user_metadata_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
87 | + |
|
88 | + // Insert data into the tables |
|
89 | + $this->insert('user_roles', array( |
|
90 | + 'id' => 1, |
|
91 | + 'name' => 'User', |
|
92 | + 'created' => $this->_moment, |
|
93 | + 'updated' => $this->_moment |
|
94 | + )); |
|
95 | + |
|
96 | + $this->insert('user_roles', array( |
|
97 | + 'id' => 2, |
|
98 | + 'name' => 'Pending', |
|
99 | + 'created' => $this->_moment, |
|
100 | + 'updated' => $this->_moment |
|
101 | + )); |
|
102 | + |
|
103 | + $this->insert('user_roles', array( |
|
104 | + 'id' => 3, |
|
105 | + 'name' => 'Suspended', |
|
106 | + 'created' => $this->_moment, |
|
107 | + 'updated' => $this->_moment |
|
108 | + )); |
|
109 | + |
|
110 | + $this->insert('user_roles', array( |
|
111 | + 'id' => 5, |
|
112 | + 'name' => 'Collaborator', |
|
113 | + 'created' => $this->_moment, |
|
114 | + 'updated' => $this->_moment |
|
115 | + )); |
|
116 | + |
|
117 | + $this->insert('user_roles', array( |
|
118 | + 'id' => 6, |
|
119 | + 'name' => 'Author', |
|
120 | + 'created' => $this->_moment, |
|
121 | + 'updated' => $this->_moment |
|
122 | + )); |
|
123 | + |
|
124 | + $this->insert('user_roles', array( |
|
125 | + 'id' => 7, |
|
126 | + 'name' => 'User', |
|
127 | + 'created' => $this->_moment, |
|
128 | + 'updated' => $this->_moment |
|
129 | + )); |
|
130 | + |
|
131 | + $this->insert('user_roles', array( |
|
132 | + 'id' => 8, |
|
133 | + 'name' => 'Publisher', |
|
134 | + 'created' => $this->_moment, |
|
135 | + 'updated' => $this->_moment |
|
136 | + )); |
|
137 | + |
|
138 | + $this->insert('user_roles', array( |
|
139 | + 'id' => 9, |
|
140 | + 'name' => 'Administrator', |
|
141 | + 'created' => $this->_moment, |
|
142 | + 'updated' => $this->_moment |
|
143 | + )); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Create the categories and relations |
|
148 | + */ |
|
149 | + private function createCategories() |
|
150 | + { |
|
151 | + // Categories |
|
152 | + $this->createTable('categories', array( |
|
153 | + 'id' => 'pk', |
|
154 | + 'parent_id' => 'integer DEFAULT 1', |
|
155 | + 'name' => 'string NOT NULL', |
|
156 | + 'slug' => 'string NOT NULL', |
|
157 | + 'created' => 'integer', |
|
158 | + 'updated' => 'integer' |
|
159 | + )); |
|
160 | + |
|
161 | + $this->createTable('categories_metadata', array( |
|
162 | + 'category_id' => 'integer', |
|
163 | + 'key' => 'string NOT NULL', |
|
164 | + 'value' => 'text NOT NULL', |
|
165 | + 'created' => 'integer', |
|
166 | + 'updated' => 'integer' |
|
167 | + )); |
|
168 | + |
|
169 | + // Insert the first record into the categories table |
|
170 | + $this->insert('categories', array( |
|
171 | + 'id' => 1, |
|
172 | + 'name' => 'Uncategorized', |
|
173 | + 'slug' => 'uncategorized', |
|
174 | + 'created' => $this->_moment, |
|
175 | + 'updated' => $this->_moment |
|
176 | + )); |
|
177 | + |
|
178 | + $this->addPrimaryKey('categories_metadata_composite', 'categories_metadata', 'category_id,key'); |
|
179 | + $this->addForeignKey('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
180 | + $this->addForeignKey('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Creates the content, comemnts, and necessary relations |
|
185 | + */ |
|
186 | + private function createContent() |
|
187 | + { |
|
188 | + $this->createTable('content', array( |
|
189 | + 'id' => 'integer NOT NULL', |
|
190 | + 'vid' => 'integer NOT NULL DEFAULT 1', |
|
191 | + 'title' => 'string NOT NULL', |
|
192 | + 'content' => 'text NOT NULL', |
|
193 | + 'excerpt' => 'text NOT NULL', |
|
194 | + 'slug' => 'string NOT NULL', |
|
195 | + 'category_id' => 'integer DEFAULT 1', |
|
196 | + 'author_id' => 'integer DEFAULT 1', |
|
197 | + 'type_id' => 'integer DEFAULT 2', |
|
198 | + 'commentable' => 'integer DEFAULT 1', |
|
199 | + 'password' => 'string DEFAULT NULL', |
|
200 | + 'status' => 'integer DEFAULT 0', |
|
201 | + 'like_count' => 'integer DEFAULT 0', |
|
202 | + 'published' => 'integer', |
|
203 | + 'created' => 'integer', |
|
204 | + 'updated' => 'integer' |
|
205 | + )); |
|
206 | + |
|
207 | + $this->createTable('content_types', array( |
|
208 | + 'id' => 'pk', |
|
209 | + 'name' => 'string NOT NULL', |
|
210 | + 'created' => 'integer', |
|
211 | + 'updated' => 'integer' |
|
212 | + )); |
|
213 | + |
|
214 | + $this->createTable('content_metadata', array( |
|
215 | + 'content_id' => 'integer', |
|
216 | + 'key' => 'string NOT NULL', |
|
217 | + 'value' => 'text NOT NULL', |
|
218 | + 'created' => 'integer', |
|
219 | + 'updated' => 'integer' |
|
220 | + )); |
|
221 | + |
|
222 | + $this->createTable('comments', array( |
|
223 | + 'id' => 'pk', |
|
224 | + 'content_id' => 'integer', |
|
225 | + 'author_id' => 'integer', |
|
226 | + 'comment' => 'integer', |
|
227 | + 'created' => 'integer', |
|
228 | + 'updated' => 'integer' |
|
229 | + )); |
|
230 | + |
|
231 | + $this->insert('content_types', array( |
|
232 | + 'id' => 1, |
|
233 | + 'name' => 'Static Page', |
|
234 | + 'created' => $this->_moment, |
|
235 | + 'updated' => $this->_moment |
|
236 | + )); |
|
237 | + |
|
238 | + $this->insert('content_types', array( |
|
239 | + 'id' => 2, |
|
240 | + 'name' => 'Blog Post', |
|
241 | + 'created' => $this->_moment, |
|
242 | + 'updated' => $this->_moment |
|
243 | + )); |
|
244 | + |
|
245 | + $this->addPrimaryKey('content_composite', 'content', 'id, vid'); |
|
246 | + |
|
247 | + $this->execute('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT'); |
|
248 | + |
|
249 | + $this->addPrimaryKey('content_metadata_composite', 'content_metadata', 'content_id,key'); |
|
250 | + |
|
251 | + $this->createIndex('content_author', 'content', 'author_id', false); |
|
252 | + $this->createIndex('content_category', 'content', 'category_id', false); |
|
253 | + $this->createIndex('content_type', 'content', 'type_id', false); |
|
254 | + $this->createIndex('comment_content', 'comments', 'content_id', false); |
|
255 | + $this->createIndex('comment_author', 'comments', 'author_id', false); |
|
256 | + |
|
257 | + $this->addForeignKey('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
258 | + $this->addForeignKey('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
259 | + $this->addForeignKey('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION'); |
|
260 | + |
|
261 | + $this->addForeignKey('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION'); |
|
262 | + $this->addForeignKey('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Creates the configuration and events tables |
|
267 | + */ |
|
268 | + private function createConfiguration() |
|
269 | + { |
|
270 | + $this->createTable('configuration', array( |
|
271 | + 'key' => 'string', |
|
272 | + 'value' => 'text NOT NULL', |
|
273 | + 'created' => 'integer', |
|
274 | + 'updated' => 'integer' |
|
275 | + )); |
|
276 | + |
|
277 | + $this->createTable('events', array( |
|
278 | + 'id' => 'pk', |
|
279 | + 'event' => 'string NOT NULL', |
|
280 | + 'event_data' => 'text DEFAULT NULL', |
|
281 | + 'uri' => 'string DEFAULT NULL', |
|
282 | + 'content_id' => 'integer DEFAULT NULL', |
|
283 | + 'created' => 'integer' |
|
284 | + )); |
|
285 | + |
|
286 | + $this->addPrimaryKey('configuration_pk', 'configuration', 'key'); |
|
287 | + } |
|
288 | 288 | } |
289 | 289 | \ No newline at end of file |
@@ -9,16 +9,16 @@ discard block |
||
9 | 9 | */ |
10 | 10 | private $_moment = 0; |
11 | 11 | |
12 | - public function safeUp() |
|
12 | + public function safeUp () |
|
13 | 13 | { |
14 | - $this->_moment = time(); |
|
14 | + $this->_moment = time (); |
|
15 | 15 | |
16 | 16 | // Try to get the table names, if we get something back, do not run this migration |
17 | 17 | try |
18 | 18 | { |
19 | - $test = Yii::app()->db->schema->getTables(); |
|
20 | - if (count($test) <= 1) |
|
21 | - throw new Exception('CiiMS doesn\'t exist. Applying base migration'); |
|
19 | + $test = Yii::app ()->db->schema->getTables (); |
|
20 | + if (count ($test) <= 1) |
|
21 | + throw new Exception ('CiiMS doesn\'t exist. Applying base migration'); |
|
22 | 22 | return true; |
23 | 23 | } |
24 | 24 | catch (Exception $e) |
@@ -28,16 +28,16 @@ discard block |
||
28 | 28 | } |
29 | 29 | |
30 | 30 | // Otherwise, run the install migration |
31 | - $this->createUserTables(); |
|
31 | + $this->createUserTables (); |
|
32 | 32 | |
33 | - $this->createCategories(); |
|
33 | + $this->createCategories (); |
|
34 | 34 | |
35 | - $this->createContent(); |
|
35 | + $this->createContent (); |
|
36 | 36 | |
37 | - $this->createConfiguration(); |
|
37 | + $this->createConfiguration (); |
|
38 | 38 | } |
39 | 39 | |
40 | - public function safeDown() |
|
40 | + public function safeDown () |
|
41 | 41 | { |
42 | 42 | echo "m141001_145619_init does not support migration down.\n"; |
43 | 43 | return false; |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * Creates the tables, indexes, and relations for users |
48 | 48 | */ |
49 | - private function createUserTables() |
|
49 | + private function createUserTables () |
|
50 | 50 | { |
51 | - $this->createTable('users', array( |
|
51 | + $this->createTable ('users', array( |
|
52 | 52 | 'id' => 'pk', |
53 | 53 | 'email' => 'string NOT NULL', |
54 | 54 | 'password' => 'string NOT NULL', |
@@ -59,14 +59,14 @@ discard block |
||
59 | 59 | 'updated' => 'integer' |
60 | 60 | )); |
61 | 61 | |
62 | - $this->createTable('user_roles', array( |
|
62 | + $this->createTable ('user_roles', array( |
|
63 | 63 | 'id' => 'pk', |
64 | 64 | 'name' => 'string NOT NULL', |
65 | 65 | 'created' => 'integer', |
66 | 66 | 'updated' => 'integer' |
67 | 67 | )); |
68 | 68 | |
69 | - $this->createTable('user_metadata', array( |
|
69 | + $this->createTable ('user_metadata', array( |
|
70 | 70 | 'user_id' => 'integer', |
71 | 71 | 'key' => 'string NOT NULL', |
72 | 72 | 'value' => 'text NOT NULL', |
@@ -76,66 +76,66 @@ discard block |
||
76 | 76 | )); |
77 | 77 | |
78 | 78 | // Create the necessary indexes on the columns |
79 | - $this->createIndex('user_email', 'users', 'email', true); |
|
80 | - $this->createIndex('user_username', 'users', 'username', true); |
|
81 | - $this->createIndex('user_metadata', 'user_metadata', 'user_id, key', false); |
|
79 | + $this->createIndex ('user_email', 'users', 'email', true); |
|
80 | + $this->createIndex ('user_username', 'users', 'username', true); |
|
81 | + $this->createIndex ('user_metadata', 'user_metadata', 'user_id, key', false); |
|
82 | 82 | |
83 | - $this->addPrimaryKey('user_metadata_composite', 'user_metadata', 'user_id,key'); |
|
83 | + $this->addPrimaryKey ('user_metadata_composite', 'user_metadata', 'user_id,key'); |
|
84 | 84 | |
85 | 85 | // Setup the foreign key constraints |
86 | - $this->addForeignKey('user_metadata_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
86 | + $this->addForeignKey ('user_metadata_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
87 | 87 | |
88 | 88 | // Insert data into the tables |
89 | - $this->insert('user_roles', array( |
|
89 | + $this->insert ('user_roles', array( |
|
90 | 90 | 'id' => 1, |
91 | 91 | 'name' => 'User', |
92 | 92 | 'created' => $this->_moment, |
93 | 93 | 'updated' => $this->_moment |
94 | 94 | )); |
95 | 95 | |
96 | - $this->insert('user_roles', array( |
|
96 | + $this->insert ('user_roles', array( |
|
97 | 97 | 'id' => 2, |
98 | 98 | 'name' => 'Pending', |
99 | 99 | 'created' => $this->_moment, |
100 | 100 | 'updated' => $this->_moment |
101 | 101 | )); |
102 | 102 | |
103 | - $this->insert('user_roles', array( |
|
103 | + $this->insert ('user_roles', array( |
|
104 | 104 | 'id' => 3, |
105 | 105 | 'name' => 'Suspended', |
106 | 106 | 'created' => $this->_moment, |
107 | 107 | 'updated' => $this->_moment |
108 | 108 | )); |
109 | 109 | |
110 | - $this->insert('user_roles', array( |
|
110 | + $this->insert ('user_roles', array( |
|
111 | 111 | 'id' => 5, |
112 | 112 | 'name' => 'Collaborator', |
113 | 113 | 'created' => $this->_moment, |
114 | 114 | 'updated' => $this->_moment |
115 | 115 | )); |
116 | 116 | |
117 | - $this->insert('user_roles', array( |
|
117 | + $this->insert ('user_roles', array( |
|
118 | 118 | 'id' => 6, |
119 | 119 | 'name' => 'Author', |
120 | 120 | 'created' => $this->_moment, |
121 | 121 | 'updated' => $this->_moment |
122 | 122 | )); |
123 | 123 | |
124 | - $this->insert('user_roles', array( |
|
124 | + $this->insert ('user_roles', array( |
|
125 | 125 | 'id' => 7, |
126 | 126 | 'name' => 'User', |
127 | 127 | 'created' => $this->_moment, |
128 | 128 | 'updated' => $this->_moment |
129 | 129 | )); |
130 | 130 | |
131 | - $this->insert('user_roles', array( |
|
131 | + $this->insert ('user_roles', array( |
|
132 | 132 | 'id' => 8, |
133 | 133 | 'name' => 'Publisher', |
134 | 134 | 'created' => $this->_moment, |
135 | 135 | 'updated' => $this->_moment |
136 | 136 | )); |
137 | 137 | |
138 | - $this->insert('user_roles', array( |
|
138 | + $this->insert ('user_roles', array( |
|
139 | 139 | 'id' => 9, |
140 | 140 | 'name' => 'Administrator', |
141 | 141 | 'created' => $this->_moment, |
@@ -146,10 +146,10 @@ discard block |
||
146 | 146 | /** |
147 | 147 | * Create the categories and relations |
148 | 148 | */ |
149 | - private function createCategories() |
|
149 | + private function createCategories () |
|
150 | 150 | { |
151 | 151 | // Categories |
152 | - $this->createTable('categories', array( |
|
152 | + $this->createTable ('categories', array( |
|
153 | 153 | 'id' => 'pk', |
154 | 154 | 'parent_id' => 'integer DEFAULT 1', |
155 | 155 | 'name' => 'string NOT NULL', |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | 'updated' => 'integer' |
159 | 159 | )); |
160 | 160 | |
161 | - $this->createTable('categories_metadata', array( |
|
161 | + $this->createTable ('categories_metadata', array( |
|
162 | 162 | 'category_id' => 'integer', |
163 | 163 | 'key' => 'string NOT NULL', |
164 | 164 | 'value' => 'text NOT NULL', |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | )); |
168 | 168 | |
169 | 169 | // Insert the first record into the categories table |
170 | - $this->insert('categories', array( |
|
170 | + $this->insert ('categories', array( |
|
171 | 171 | 'id' => 1, |
172 | 172 | 'name' => 'Uncategorized', |
173 | 173 | 'slug' => 'uncategorized', |
@@ -175,17 +175,17 @@ discard block |
||
175 | 175 | 'updated' => $this->_moment |
176 | 176 | )); |
177 | 177 | |
178 | - $this->addPrimaryKey('categories_metadata_composite', 'categories_metadata', 'category_id,key'); |
|
179 | - $this->addForeignKey('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
180 | - $this->addForeignKey('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
178 | + $this->addPrimaryKey ('categories_metadata_composite', 'categories_metadata', 'category_id,key'); |
|
179 | + $this->addForeignKey ('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
180 | + $this->addForeignKey ('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
184 | 184 | * Creates the content, comemnts, and necessary relations |
185 | 185 | */ |
186 | - private function createContent() |
|
186 | + private function createContent () |
|
187 | 187 | { |
188 | - $this->createTable('content', array( |
|
188 | + $this->createTable ('content', array( |
|
189 | 189 | 'id' => 'integer NOT NULL', |
190 | 190 | 'vid' => 'integer NOT NULL DEFAULT 1', |
191 | 191 | 'title' => 'string NOT NULL', |
@@ -204,14 +204,14 @@ discard block |
||
204 | 204 | 'updated' => 'integer' |
205 | 205 | )); |
206 | 206 | |
207 | - $this->createTable('content_types', array( |
|
207 | + $this->createTable ('content_types', array( |
|
208 | 208 | 'id' => 'pk', |
209 | 209 | 'name' => 'string NOT NULL', |
210 | 210 | 'created' => 'integer', |
211 | 211 | 'updated' => 'integer' |
212 | 212 | )); |
213 | 213 | |
214 | - $this->createTable('content_metadata', array( |
|
214 | + $this->createTable ('content_metadata', array( |
|
215 | 215 | 'content_id' => 'integer', |
216 | 216 | 'key' => 'string NOT NULL', |
217 | 217 | 'value' => 'text NOT NULL', |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | 'updated' => 'integer' |
220 | 220 | )); |
221 | 221 | |
222 | - $this->createTable('comments', array( |
|
222 | + $this->createTable ('comments', array( |
|
223 | 223 | 'id' => 'pk', |
224 | 224 | 'content_id' => 'integer', |
225 | 225 | 'author_id' => 'integer', |
@@ -228,53 +228,53 @@ discard block |
||
228 | 228 | 'updated' => 'integer' |
229 | 229 | )); |
230 | 230 | |
231 | - $this->insert('content_types', array( |
|
231 | + $this->insert ('content_types', array( |
|
232 | 232 | 'id' => 1, |
233 | 233 | 'name' => 'Static Page', |
234 | 234 | 'created' => $this->_moment, |
235 | 235 | 'updated' => $this->_moment |
236 | 236 | )); |
237 | 237 | |
238 | - $this->insert('content_types', array( |
|
238 | + $this->insert ('content_types', array( |
|
239 | 239 | 'id' => 2, |
240 | 240 | 'name' => 'Blog Post', |
241 | 241 | 'created' => $this->_moment, |
242 | 242 | 'updated' => $this->_moment |
243 | 243 | )); |
244 | 244 | |
245 | - $this->addPrimaryKey('content_composite', 'content', 'id, vid'); |
|
245 | + $this->addPrimaryKey ('content_composite', 'content', 'id, vid'); |
|
246 | 246 | |
247 | - $this->execute('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT'); |
|
247 | + $this->execute ('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT'); |
|
248 | 248 | |
249 | - $this->addPrimaryKey('content_metadata_composite', 'content_metadata', 'content_id,key'); |
|
249 | + $this->addPrimaryKey ('content_metadata_composite', 'content_metadata', 'content_id,key'); |
|
250 | 250 | |
251 | - $this->createIndex('content_author', 'content', 'author_id', false); |
|
252 | - $this->createIndex('content_category', 'content', 'category_id', false); |
|
253 | - $this->createIndex('content_type', 'content', 'type_id', false); |
|
254 | - $this->createIndex('comment_content', 'comments', 'content_id', false); |
|
255 | - $this->createIndex('comment_author', 'comments', 'author_id', false); |
|
251 | + $this->createIndex ('content_author', 'content', 'author_id', false); |
|
252 | + $this->createIndex ('content_category', 'content', 'category_id', false); |
|
253 | + $this->createIndex ('content_type', 'content', 'type_id', false); |
|
254 | + $this->createIndex ('comment_content', 'comments', 'content_id', false); |
|
255 | + $this->createIndex ('comment_author', 'comments', 'author_id', false); |
|
256 | 256 | |
257 | - $this->addForeignKey('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
258 | - $this->addForeignKey('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
259 | - $this->addForeignKey('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION'); |
|
257 | + $this->addForeignKey ('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION'); |
|
258 | + $this->addForeignKey ('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
259 | + $this->addForeignKey ('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION'); |
|
260 | 260 | |
261 | - $this->addForeignKey('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION'); |
|
262 | - $this->addForeignKey('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
261 | + $this->addForeignKey ('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION'); |
|
262 | + $this->addForeignKey ('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
266 | 266 | * Creates the configuration and events tables |
267 | 267 | */ |
268 | - private function createConfiguration() |
|
268 | + private function createConfiguration () |
|
269 | 269 | { |
270 | - $this->createTable('configuration', array( |
|
270 | + $this->createTable ('configuration', array( |
|
271 | 271 | 'key' => 'string', |
272 | 272 | 'value' => 'text NOT NULL', |
273 | 273 | 'created' => 'integer', |
274 | 274 | 'updated' => 'integer' |
275 | 275 | )); |
276 | 276 | |
277 | - $this->createTable('events', array( |
|
277 | + $this->createTable ('events', array( |
|
278 | 278 | 'id' => 'pk', |
279 | 279 | 'event' => 'string NOT NULL', |
280 | 280 | 'event_data' => 'text DEFAULT NULL', |
@@ -283,6 +283,6 @@ discard block |
||
283 | 283 | 'created' => 'integer' |
284 | 284 | )); |
285 | 285 | |
286 | - $this->addPrimaryKey('configuration_pk', 'configuration', 'key'); |
|
286 | + $this->addPrimaryKey ('configuration_pk', 'configuration', 'key'); |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | \ No newline at end of file |