@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function actionUpData($limit = 0) |
104 | 104 | { |
105 | - $this->migrationPath .= DIRECTORY_SEPARATOR . $this->dataMigrationFolder; |
|
105 | + $this->migrationPath .= DIRECTORY_SEPARATOR.$this->dataMigrationFolder; |
|
106 | 106 | return parent::actionUp($limit); |
107 | 107 | } |
108 | 108 | |
@@ -118,11 +118,11 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function actionData(array $tables) |
120 | 120 | { |
121 | - if ($this->confirm('Create the migration ' . "?", TRUE)) { |
|
121 | + if ($this->confirm('Create the migration '."?", TRUE)) { |
|
122 | 122 | foreach ($tables as $key => $args) { |
123 | 123 | |
124 | 124 | $table = $args; |
125 | - $this->class = 'insert_data_into_' . $table; |
|
125 | + $this->class = 'insert_data_into_'.$table; |
|
126 | 126 | $this->table = $table; |
127 | 127 | $this->templateFile = '@tmukherjee13/migration/views/dataTemplate.php'; |
128 | 128 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | |
151 | 151 | $pcolumns = ''; |
152 | 152 | foreach ($columns->columns as $column) { |
153 | - $pcolumns .= "'" . $column->name . "',"; |
|
153 | + $pcolumns .= "'".$column->name."',"; |
|
154 | 154 | } |
155 | 155 | foreach ($data as $row) { |
156 | 156 | array_push($prepared_data, $row); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $prows = $this->prepareData($prepared_data); |
164 | 164 | |
165 | 165 | if ($this->useDataMigrationFolder) { |
166 | - $path = $this->migrationPath . DIRECTORY_SEPARATOR . $this->dataMigrationFolder; |
|
166 | + $path = $this->migrationPath.DIRECTORY_SEPARATOR.$this->dataMigrationFolder; |
|
167 | 167 | FileHelper::createDirectory($path); |
168 | 168 | $this->migrationPath = $path; |
169 | 169 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function getFileName() |
183 | 183 | { |
184 | - return 'm' . gmdate('ymd_His') . '_' . $this->class; |
|
184 | + return 'm'.gmdate('ymd_His').'_'.$this->class; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public function prepareFile($data) |
202 | 202 | { |
203 | - $file = $this->migrationPath . DIRECTORY_SEPARATOR . $this->getFileName() . '.php'; |
|
203 | + $file = $this->migrationPath.DIRECTORY_SEPARATOR.$this->getFileName().'.php'; |
|
204 | 204 | try { |
205 | 205 | |
206 | 206 | $data['table'] = $this->table; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | { |
227 | 227 | |
228 | 228 | $schema = $args; |
229 | - $this->class = 'dump_database_' . $schema; |
|
229 | + $this->class = 'dump_database_'.$schema; |
|
230 | 230 | $tables = $this->db->schema->getTableSchemas($schema); |
231 | 231 | $addForeignKeys = ''; |
232 | 232 | $dropForeignKeys = ''; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | $generateTables = []; |
239 | 239 | |
240 | 240 | foreach ($tables as $table) { |
241 | - if ($table->name === $this->db->tablePrefix . $this->migrationTable) { |
|
241 | + if ($table->name === $this->db->tablePrefix.$this->migrationTable) { |
|
242 | 242 | continue; |
243 | 243 | } |
244 | 244 | $generateTables[] = $table->name; |
@@ -260,13 +260,13 @@ discard block |
||
260 | 260 | public function actionTable(array $tables) |
261 | 261 | { |
262 | 262 | |
263 | - if (!$this->confirm('Create the migration ' . "?")) { |
|
263 | + if (!$this->confirm('Create the migration '."?")) { |
|
264 | 264 | return; |
265 | 265 | } |
266 | 266 | |
267 | 267 | foreach ($tables as $key => $tableName) { |
268 | 268 | |
269 | - $this->class = 'create_table_' . $tableName; |
|
269 | + $this->class = 'create_table_'.$tableName; |
|
270 | 270 | |
271 | 271 | try { |
272 | 272 | |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | $this->table = $this->getTableName($table); |
293 | 293 | |
294 | 294 | foreach ($table->columns as $col) { |
295 | - $up .= "\t\t\t" . '\'' . $col->name . '\'=>"' . $this->getColType($col) . '",' . "\n"; |
|
295 | + $up .= "\t\t\t".'\''.$col->name.'\'=>"'.$this->getColType($col).'",'."\n"; |
|
296 | 296 | if ($col->isPrimaryKey) { |
297 | 297 | // Add column to composite primary key array |
298 | 298 | $compositePrimaryKeyCols[] = $col->name; |
@@ -309,15 +309,15 @@ discard block |
||
309 | 309 | } |
310 | 310 | } |
311 | 311 | $indexStr = implode(',', $indexArr); |
312 | - $up .= "\t\t" . '$this->createIndex(\'idx_' . $indexKey . "', '" . $this->getTableName($table) . "', '$indexStr', TRUE);\n"; |
|
312 | + $up .= "\t\t".'$this->createIndex(\'idx_'.$indexKey."', '".$this->getTableName($table)."', '$indexStr', TRUE);\n"; |
|
313 | 313 | |
314 | 314 | } |
315 | 315 | |
316 | 316 | if (!empty($table->foreignKeys)): |
317 | 317 | |
318 | 318 | foreach ($table->foreignKeys as $fkName => $fk) { |
319 | - $addForeignKeys .= "\t\t" . '$this->addForeignKey("' . $fkName . '", "' . $table->name . '", "' . $fk['column'] . '","' . $fk['table'] . '","' . $fk['ref_column'] . '", "' . $fk['delete'] . '", "' . $fk['update'] . '");' . "\n"; |
|
320 | - $dropForeignKeys .= '$this->dropForeignKey(' . "'$fkName', '$table->name');"; |
|
319 | + $addForeignKeys .= "\t\t".'$this->addForeignKey("'.$fkName.'", "'.$table->name.'", "'.$fk['column'].'","'.$fk['table'].'","'.$fk['ref_column'].'", "'.$fk['delete'].'", "'.$fk['update'].'");'."\n"; |
|
320 | + $dropForeignKeys .= '$this->dropForeignKey('."'$fkName', '$table->name');"; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | endif; |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | 'foreignKeys' => $table->foreignKeys, |
333 | 333 | 'fields' => $fields, |
334 | 334 | 'indexes' => $this->findIndexes($table), |
335 | - ]) . "\n\n"; |
|
335 | + ])."\n\n"; |
|
336 | 336 | |
337 | 337 | } |
338 | 338 | } |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | */ |
418 | 418 | protected function getCreateTableSql(TableSchema $table) |
419 | 419 | { |
420 | - $row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->quoteTableName($table->fullName))->queryOne(); |
|
420 | + $row = $this->db->createCommand('SHOW CREATE TABLE '.$this->quoteTableName($table->fullName))->queryOne(); |
|
421 | 421 | if (isset($row['Create Table'])) { |
422 | 422 | $sql = $row['Create Table']; |
423 | 423 | } else { |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | use yii\console\controllers\MigrateController; |
13 | 13 | |
14 | 14 | |
15 | -class MigrationController extends MigrateController |
|
16 | -{ |
|
15 | +class MigrationController extends MigrateController { |
|
17 | 16 | use \tmukherjee13\migration\console\components\Formatter; |
18 | 17 | |
19 | 18 | /** |
@@ -54,16 +53,14 @@ discard block |
||
54 | 53 | /** |
55 | 54 | * @inheritdoc |
56 | 55 | */ |
57 | - public function options($actionID) |
|
58 | - { |
|
56 | + public function options($actionID) { |
|
59 | 57 | return array_merge(parent::options($actionID), ['migrationTable', 'db']); |
60 | 58 | } |
61 | 59 | |
62 | 60 | /** |
63 | 61 | * @inheritdoc |
64 | 62 | */ |
65 | - public function beforeAction($action) |
|
66 | - { |
|
63 | + public function beforeAction($action) { |
|
67 | 64 | |
68 | 65 | if (parent::beforeAction($action)) { |
69 | 66 | if (is_string($this->db)) { |
@@ -100,8 +97,7 @@ discard block |
||
100 | 97 | * |
101 | 98 | * @return int |
102 | 99 | */ |
103 | - public function actionUpData($limit = 0) |
|
104 | - { |
|
100 | + public function actionUpData($limit = 0) { |
|
105 | 101 | $this->migrationPath .= DIRECTORY_SEPARATOR . $this->dataMigrationFolder; |
106 | 102 | return parent::actionUp($limit); |
107 | 103 | } |
@@ -116,8 +112,7 @@ discard block |
||
116 | 112 | * @throws \yii\console\Exception |
117 | 113 | * @throws \yii\db\Exception |
118 | 114 | */ |
119 | - public function actionData(array $tables) |
|
120 | - { |
|
115 | + public function actionData(array $tables) { |
|
121 | 116 | if ($this->confirm('Create the migration ' . "?", TRUE)) { |
122 | 117 | foreach ($tables as $key => $args) { |
123 | 118 | |
@@ -158,7 +153,8 @@ discard block |
||
158 | 153 | |
159 | 154 | if (empty($prepared_data)) { |
160 | 155 | $this->stdout("\nTable '{$table->name}' doesn't contain any data.\n\n", Console::FG_RED); |
161 | - } else { |
|
156 | + } |
|
157 | + else { |
|
162 | 158 | $pcolumns = $this->prepareColumns($pcolumns); |
163 | 159 | $prows = $this->prepareData($prepared_data); |
164 | 160 | |
@@ -179,16 +175,14 @@ discard block |
||
179 | 175 | /** |
180 | 176 | * @return string |
181 | 177 | */ |
182 | - public function getFileName() |
|
183 | - { |
|
178 | + public function getFileName() { |
|
184 | 179 | return 'm' . gmdate('ymd_His') . '_' . $this->class; |
185 | 180 | } |
186 | 181 | |
187 | 182 | /** |
188 | 183 | * |
189 | 184 | */ |
190 | - public function setFileName() |
|
191 | - { |
|
185 | + public function setFileName() { |
|
192 | 186 | $this->fileName = $this->getFileName(); |
193 | 187 | } |
194 | 188 | |
@@ -198,8 +192,7 @@ discard block |
||
198 | 192 | * @return string |
199 | 193 | * @throws \yii\console\Exception |
200 | 194 | */ |
201 | - public function prepareFile($data) |
|
202 | - { |
|
195 | + public function prepareFile($data) { |
|
203 | 196 | $file = $this->migrationPath . DIRECTORY_SEPARATOR . $this->getFileName() . '.php'; |
204 | 197 | try { |
205 | 198 | |
@@ -222,8 +215,7 @@ discard block |
||
222 | 215 | * @return int |
223 | 216 | * @throws \yii\console\Exception |
224 | 217 | */ |
225 | - public function actionSchema($args) |
|
226 | - { |
|
218 | + public function actionSchema($args) { |
|
227 | 219 | |
228 | 220 | $schema = $args; |
229 | 221 | $this->class = 'dump_database_' . $schema; |
@@ -257,8 +249,7 @@ discard block |
||
257 | 249 | * @return mixed |
258 | 250 | * @author Tarun Mukherjee (https://github.com/tmukherjee13) |
259 | 251 | */ |
260 | - public function actionTable(array $tables) |
|
261 | - { |
|
252 | + public function actionTable(array $tables) { |
|
262 | 253 | |
263 | 254 | if (!$this->confirm('Create the migration ' . "?")) { |
264 | 255 | return; |
@@ -343,8 +334,7 @@ discard block |
||
343 | 334 | * @return array |
344 | 335 | * @throws \yii\db\Exception |
345 | 336 | */ |
346 | - protected function findConstraints($table) |
|
347 | - { |
|
337 | + protected function findConstraints($table) { |
|
348 | 338 | $sql = <<<SQL |
349 | 339 | SELECT |
350 | 340 | kcu.constraint_name, |
@@ -415,12 +405,12 @@ discard block |
||
415 | 405 | * @return mixed |
416 | 406 | * @throws \yii\db\Exception |
417 | 407 | */ |
418 | - protected function getCreateTableSql(TableSchema $table) |
|
419 | - { |
|
408 | + protected function getCreateTableSql(TableSchema $table) { |
|
420 | 409 | $row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->quoteTableName($table->fullName))->queryOne(); |
421 | 410 | if (isset($row['Create Table'])) { |
422 | 411 | $sql = $row['Create Table']; |
423 | - } else { |
|
412 | + } |
|
413 | + else { |
|
424 | 414 | $row = array_values($row); |
425 | 415 | $sql = $row[1]; |
426 | 416 | } |
@@ -432,16 +422,14 @@ discard block |
||
432 | 422 | * |
433 | 423 | * @return string |
434 | 424 | */ |
435 | - public function quoteTableName($name) |
|
436 | - { |
|
425 | + public function quoteTableName($name) { |
|
437 | 426 | return strpos($name, '`') !== FALSE ? $name : "`$name`"; |
438 | 427 | } |
439 | 428 | |
440 | 429 | /** |
441 | 430 | * @inheritdoc |
442 | 431 | */ |
443 | - protected function parseFields() |
|
444 | - { |
|
432 | + protected function parseFields() { |
|
445 | 433 | $fields = []; |
446 | 434 | |
447 | 435 | foreach ($this->fields as $column => $schema) { |
@@ -480,8 +468,7 @@ discard block |
||
480 | 468 | * |
481 | 469 | * @return array|void |
482 | 470 | */ |
483 | - protected function findIndexes(TableSchema $table) |
|
484 | - { |
|
471 | + protected function findIndexes(TableSchema $table) { |
|
485 | 472 | $sql = "SHOW INDEX FROM `{$table->name}`"; |
486 | 473 | |
487 | 474 | try { |
@@ -506,8 +493,7 @@ discard block |
||
506 | 493 | * |
507 | 494 | * @return array |
508 | 495 | */ |
509 | - public function filterKeyIndex($table, array $rows = []) |
|
510 | - { |
|
496 | + public function filterKeyIndex($table, array $rows = []) { |
|
511 | 497 | $return = []; |
512 | 498 | foreach ($rows as $row) { |
513 | 499 | |
@@ -542,8 +528,7 @@ discard block |
||
542 | 528 | /** |
543 | 529 | * @inheritdoc |
544 | 530 | */ |
545 | - protected function getMigrationHistory($limit) |
|
546 | - { |
|
531 | + protected function getMigrationHistory($limit) { |
|
547 | 532 | if ($this->db->schema->getTableSchema($this->migrationTable, TRUE) === NULL) { |
548 | 533 | $this->createMigrationHistoryTable(); |
549 | 534 | } |
@@ -563,8 +548,7 @@ discard block |
||
563 | 548 | /** |
564 | 549 | * @inheritdoc |
565 | 550 | */ |
566 | - protected function addMigrationHistory($version) |
|
567 | - { |
|
551 | + protected function addMigrationHistory($version) { |
|
568 | 552 | $command = $this->db->createCommand(); |
569 | 553 | $command->insert($this->migrationTable, [ |
570 | 554 | 'version' => $version, |
@@ -575,8 +559,7 @@ discard block |
||
575 | 559 | /** |
576 | 560 | * @inheritdoc |
577 | 561 | */ |
578 | - protected function removeMigrationHistory($version) |
|
579 | - { |
|
562 | + protected function removeMigrationHistory($version) { |
|
580 | 563 | $command = $this->db->createCommand(); |
581 | 564 | $command->delete($this->migrationTable, [ |
582 | 565 | 'version' => $version, |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function getTableName($table) |
47 | 47 | { |
48 | - return '{{%' . str_replace($this->db->tablePrefix, '', $table->name) . '}}'; |
|
48 | + return '{{%'.str_replace($this->db->tablePrefix, '', $table->name).'}}'; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function prepareInsert($rows, $columns) |
58 | 58 | { |
59 | - return '$this->batchInsert("{{%test}}", ' . $rows . ', ' . $columns . ');'; |
|
59 | + return '$this->batchInsert("{{%test}}", '.$rows.', '.$columns.');'; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $data = rtrim($data, $trim); |
85 | 85 | } |
86 | 86 | |
87 | - return self::$columnEncloser[0] . rtrim($data, $trim) . self::$columnEncloser[1]; |
|
87 | + return self::$columnEncloser[0].rtrim($data, $trim).self::$columnEncloser[1]; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | foreach ($data as $row) { |
101 | 101 | $rows = ''; |
102 | 102 | foreach ($row as $value) { |
103 | - $rows .= "'" . addslashes($value) . "',"; |
|
103 | + $rows .= "'".addslashes($value)."',"; |
|
104 | 104 | } |
105 | - self::$rows .= "\n\t\t\t" . self::dataFormat($rows) . ","; |
|
105 | + self::$rows .= "\n\t\t\t".self::dataFormat($rows).","; |
|
106 | 106 | } |
107 | 107 | if (!empty(self::$rows)) { |
108 | 108 | return self::dataFormat(self::$rows); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | if (NULL !== $trim) { |
123 | 123 | $data = rtrim($data, $trim); |
124 | 124 | } |
125 | - return self::$dataEncloser[0] . $data . self::$dataEncloser[1]; |
|
125 | + return self::$dataEncloser[0].$data.self::$dataEncloser[1]; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Table class |
9 | 9 | */ |
10 | -trait Formatter |
|
11 | -{ |
|
10 | +trait Formatter { |
|
12 | 11 | /** |
13 | 12 | * @var array column enclosing literal |
14 | 13 | */ |
@@ -43,8 +42,7 @@ discard block |
||
43 | 42 | * @return string |
44 | 43 | * @author Tarun Mukherjee (https://github.com/tmukherjee13) |
45 | 44 | */ |
46 | - public function getTableName($table) |
|
47 | - { |
|
45 | + public function getTableName($table) { |
|
48 | 46 | return '{{%' . str_replace($this->db->tablePrefix, '', $table->name) . '}}'; |
49 | 47 | } |
50 | 48 | |
@@ -54,8 +52,7 @@ discard block |
||
54 | 52 | * |
55 | 53 | * @return string |
56 | 54 | */ |
57 | - public function prepareInsert($rows, $columns) |
|
58 | - { |
|
55 | + public function prepareInsert($rows, $columns) { |
|
59 | 56 | return '$this->batchInsert("{{%test}}", ' . $rows . ', ' . $columns . ');'; |
60 | 57 | } |
61 | 58 | |
@@ -66,8 +63,7 @@ discard block |
||
66 | 63 | * |
67 | 64 | * @return string |
68 | 65 | */ |
69 | - public function prepareColumns($data, $trim = ',') |
|
70 | - { |
|
66 | + public function prepareColumns($data, $trim = ',') { |
|
71 | 67 | return self::columnFormat($data, $trim); |
72 | 68 | } |
73 | 69 | |
@@ -78,8 +74,7 @@ discard block |
||
78 | 74 | * |
79 | 75 | * @return string |
80 | 76 | */ |
81 | - public function columnFormat($data, $trim = ',') |
|
82 | - { |
|
77 | + public function columnFormat($data, $trim = ',') { |
|
83 | 78 | if (NULL !== $trim) { |
84 | 79 | $data = rtrim($data, $trim); |
85 | 80 | } |
@@ -94,8 +89,7 @@ discard block |
||
94 | 89 | * |
95 | 90 | * @return string |
96 | 91 | */ |
97 | - public function prepareData($data = []) |
|
98 | - { |
|
92 | + public function prepareData($data = []) { |
|
99 | 93 | self::$rows = ''; |
100 | 94 | foreach ($data as $row) { |
101 | 95 | $rows = ''; |
@@ -117,8 +111,7 @@ discard block |
||
117 | 111 | * |
118 | 112 | * @return string |
119 | 113 | */ |
120 | - public function dataFormat($data, $trim = ',') |
|
121 | - { |
|
114 | + public function dataFormat($data, $trim = ',') { |
|
122 | 115 | if (NULL !== $trim) { |
123 | 116 | $data = rtrim($data, $trim); |
124 | 117 | } |
@@ -135,8 +128,7 @@ discard block |
||
135 | 128 | * @author Tarun Mukherjee (https://github.com/tmukherjee13) |
136 | 129 | */ |
137 | 130 | |
138 | - public function formatCol($col) |
|
139 | - { |
|
131 | + public function formatCol($col) { |
|
140 | 132 | if (!empty($col->enumValues)) { |
141 | 133 | return $this->getColType($col); |
142 | 134 | } |
@@ -144,14 +136,18 @@ discard block |
||
144 | 136 | $decorator = []; |
145 | 137 | if ($col->isPrimaryKey && $col->autoIncrement) { |
146 | 138 | $decorator[] = 'primaryKey'; |
147 | - } elseif (in_array($col->type, self::$colTypes)) { |
|
139 | + } |
|
140 | + elseif (in_array($col->type, self::$colTypes)) { |
|
148 | 141 | $decorator[] = "{$this->modifyColType($col->dbType)}"; |
149 | - } elseif ($col->type == 'decimal') { |
|
142 | + } |
|
143 | + elseif ($col->type == 'decimal') { |
|
150 | 144 | $decorator[] = "{$col->dbType}"; |
151 | - } else { |
|
145 | + } |
|
146 | + else { |
|
152 | 147 | if (!empty($col->size) && $col->size == 1 && $col->type != 'char') { |
153 | 148 | $column = "boolean"; |
154 | - } else { |
|
149 | + } |
|
150 | + else { |
|
155 | 151 | $column = "{$col->type}"; |
156 | 152 | if (!empty($col->size)) { |
157 | 153 | $column .= "({$col->size})"; |
@@ -171,9 +167,11 @@ discard block |
||
171 | 167 | // default value. |
172 | 168 | if (is_a($col->defaultValue, Expression::class)) { |
173 | 169 | $decorator[] = "defaultExpression('{$col->defaultValue}')"; |
174 | - } elseif (is_numeric($col->defaultValue)) { |
|
170 | + } |
|
171 | + elseif (is_numeric($col->defaultValue)) { |
|
175 | 172 | $decorator[] = "defaultValue({$col->defaultValue})"; |
176 | - } elseif (!empty($col->defaultValue)) { |
|
173 | + } |
|
174 | + elseif (!empty($col->defaultValue)) { |
|
177 | 175 | $decorator[] = "defaultValue('{$col->defaultValue}')"; |
178 | 176 | } |
179 | 177 | |
@@ -193,8 +191,7 @@ discard block |
||
193 | 191 | * @return string |
194 | 192 | * @author Tarun Mukherjee (https://github.com/tmukherjee13) |
195 | 193 | */ |
196 | - public function getColType($col) |
|
197 | - { |
|
194 | + public function getColType($col) { |
|
198 | 195 | if ($col->isPrimaryKey && $col->autoIncrement) { |
199 | 196 | return 'pk'; |
200 | 197 | } |
@@ -205,11 +202,14 @@ discard block |
||
205 | 202 | } |
206 | 203 | if ($col->defaultValue != NULL && 'timestamp' != $col->dbType) { |
207 | 204 | $result .= " DEFAULT '{$col->defaultValue}'"; |
208 | - } elseif ($col->defaultValue == 'CURRENT_TIMESTAMP' && 'timestamp' == $col->dbType) { |
|
205 | + } |
|
206 | + elseif ($col->defaultValue == 'CURRENT_TIMESTAMP' && 'timestamp' == $col->dbType) { |
|
209 | 207 | $result .= " DEFAULT {$col->defaultValue}"; |
210 | - } elseif ($col->defaultValue != NULL && 'timestamp' == $col->dbType) { |
|
208 | + } |
|
209 | + elseif ($col->defaultValue != NULL && 'timestamp' == $col->dbType) { |
|
211 | 210 | $result .= " DEFAULT '{$col->defaultValue}'"; |
212 | - } elseif ($col->allowNull) { |
|
211 | + } |
|
212 | + elseif ($col->allowNull) { |
|
213 | 213 | $result .= ' DEFAULT NULL'; |
214 | 214 | } |
215 | 215 | return $result; |
@@ -2,7 +2,7 @@ |
||
2 | 2 | /* @var $table string the name table */ |
3 | 3 | /* @var $indexes array the foreign keys */ |
4 | 4 | |
5 | -if($indexes){ |
|
5 | +if ($indexes) { |
|
6 | 6 | foreach ($indexes as $key => $index): ?> |
7 | 7 | $this->dropIndex('<?= $key ?>', $this->tableName); |
8 | 8 | <?php endforeach; |
@@ -2,7 +2,7 @@ |
||
2 | 2 | /* @var $table string the name table */ |
3 | 3 | /* @var $indexes array the foreign keys */ |
4 | 4 | |
5 | -if($indexes){ |
|
5 | +if($indexes) { |
|
6 | 6 | foreach ($indexes as $key => $index): ?> |
7 | 7 | $this->dropIndex('<?= $key ?>', $this->tableName); |
8 | 8 | <?php endforeach; |
@@ -8,16 +8,16 @@ |
||
8 | 8 | |
9 | 9 | //dd( $indexes ); |
10 | 10 | |
11 | -if($indexes){ |
|
11 | +if ($indexes) { |
|
12 | 12 | foreach ($indexes as $index): |
13 | - if(is_string($index['Column_name'])): ?> |
|
14 | - <?php if($index['Non_unique'] == 0): ?> |
|
13 | + if (is_string($index['Column_name'])): ?> |
|
14 | + <?php if ($index['Non_unique'] == 0): ?> |
|
15 | 15 | $this->createIndex('<?= str_replace('_UNIQUE', '', $index['Key_name'])?>', $this->tableName, '<?= $index['Column_name'] ?>', true); |
16 | 16 | <?php else: ?> |
17 | 17 | $this->createIndex('<?= $index['Key_name'] ?>', $this->tableName, '<?= $index['Column_name'] ?>'); |
18 | 18 | <?php endif; ?> |
19 | 19 | <?php else: ?> |
20 | - $this->createIndex('<?= $index['Key_name'] ?>', $this->tableName, ['<?= implode("','",$index['Column_name']) ?>']); |
|
20 | + $this->createIndex('<?= $index['Key_name'] ?>', $this->tableName, ['<?= implode("','", $index['Column_name']) ?>']); |
|
21 | 21 | <?php endif; ?> |
22 | 22 | <?php endforeach; |
23 | 23 | } |
@@ -8,16 +8,22 @@ |
||
8 | 8 | |
9 | 9 | //dd( $indexes ); |
10 | 10 | |
11 | -if($indexes){ |
|
11 | +if($indexes) { |
|
12 | 12 | foreach ($indexes as $index): |
13 | 13 | if(is_string($index['Column_name'])): ?> |
14 | 14 | <?php if($index['Non_unique'] == 0): ?> |
15 | 15 | $this->createIndex('<?= str_replace('_UNIQUE', '', $index['Key_name'])?>', $this->tableName, '<?= $index['Column_name'] ?>', true); |
16 | - <?php else: ?> |
|
16 | + <?php else { |
|
17 | + : ?> |
|
17 | 18 | $this->createIndex('<?= $index['Key_name'] ?>', $this->tableName, '<?= $index['Column_name'] ?>'); |
18 | - <?php endif; ?> |
|
19 | - <?php else: ?> |
|
19 | + <?php endif; |
|
20 | +} |
|
21 | +?> |
|
22 | + <?php else { |
|
23 | + : ?> |
|
20 | 24 | $this->createIndex('<?= $index['Key_name'] ?>', $this->tableName, ['<?= implode("','",$index['Column_name']) ?>']); |
21 | - <?php endif; ?> |
|
25 | + <?php endif; |
|
26 | +} |
|
27 | +?> |
|
22 | 28 | <?php endforeach; |
23 | 29 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | <?php foreach ($fields as $field): |
14 | 14 | if (!empty($field['decorators'])): ?> |
15 | 15 | <?= "'{$field['property']}' => \$this->{$field['decorators']}" ?>, |
16 | - <?php elseif(!empty('raw')): ?> |
|
16 | + <?php elseif (!empty('raw')): ?> |
|
17 | 17 | <?=$field['raw'] ?>, |
18 | 18 | <?php else: ?> |
19 | 19 | '<?= $field['property'] ?>', |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | <?= $this->render('_addForeignKeys', [ |
25 | 25 | 'table' => $table, |
26 | 26 | 'foreignKeys' => $foreignKeys, |
27 | -]);?> |
|
27 | +]); ?> |
|
28 | 28 | |
29 | 29 | <?= $this->render('_addIndexes', [ |
30 | 30 | 'table' => $table, |
@@ -15,9 +15,11 @@ |
||
15 | 15 | <?= "'{$field['property']}' => \$this->{$field['decorators']}" ?>, |
16 | 16 | <?php elseif(!empty('raw')): ?> |
17 | 17 | <?=$field['raw'] ?>, |
18 | - <?php else: ?> |
|
18 | + <?php else { |
|
19 | + : ?> |
|
19 | 20 | '<?= $field['property'] ?>', |
20 | 21 | <?php endif; |
22 | +} |
|
21 | 23 | endforeach; ?> |
22 | 24 | ], $collation); |
23 | 25 |