@@ -10,8 +10,7 @@ discard block |
||
| 10 | 10 | use yii\helpers\Console; |
| 11 | 11 | use yii\helpers\FileHelper; |
| 12 | 12 | |
| 13 | -class MigrationController extends MigrateController |
|
| 14 | -{ |
|
| 13 | +class MigrationController extends MigrateController { |
|
| 15 | 14 | use \tmukherjee13\migration\console\components\Formatter; |
| 16 | 15 | |
| 17 | 16 | /** |
@@ -60,16 +59,14 @@ discard block |
||
| 60 | 59 | /** |
| 61 | 60 | * @inheritdoc |
| 62 | 61 | */ |
| 63 | - public function options($actionID) |
|
| 64 | - { |
|
| 62 | + public function options($actionID) { |
|
| 65 | 63 | return array_merge(parent::options($actionID), ['migrationTable', 'db']); |
| 66 | 64 | } |
| 67 | 65 | |
| 68 | 66 | /** |
| 69 | 67 | * @inheritdoc |
| 70 | 68 | */ |
| 71 | - public function beforeAction($action) |
|
| 72 | - { |
|
| 69 | + public function beforeAction($action) { |
|
| 73 | 70 | |
| 74 | 71 | if (parent::beforeAction($action)) { |
| 75 | 72 | if (is_string($this->db)) { |
@@ -103,8 +100,7 @@ discard block |
||
| 103 | 100 | * Collects the foreign key column details for the given table. |
| 104 | 101 | * @param TableSchema $table the table metadata |
| 105 | 102 | */ |
| 106 | - protected function findConstraints($table) |
|
| 107 | - { |
|
| 103 | + protected function findConstraints($table) { |
|
| 108 | 104 | $sql = <<<SQL |
| 109 | 105 | SELECT |
| 110 | 106 | kcu.constraint_name, |
@@ -172,20 +168,19 @@ discard block |
||
| 172 | 168 | * @param TableSchema $table the table metadata |
| 173 | 169 | * @return string $sql the result of 'SHOW CREATE TABLE' |
| 174 | 170 | */ |
| 175 | - protected function getCreateTableSql($table) |
|
| 176 | - { |
|
| 171 | + protected function getCreateTableSql($table) { |
|
| 177 | 172 | $row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->quoteTableName($table->fullName))->queryOne(); |
| 178 | 173 | if (isset($row['Create Table'])) { |
| 179 | 174 | $sql = $row['Create Table']; |
| 180 | - } else { |
|
| 175 | + } |
|
| 176 | + else { |
|
| 181 | 177 | $row = array_values($row); |
| 182 | 178 | $sql = $row[1]; |
| 183 | 179 | } |
| 184 | 180 | return $sql; |
| 185 | 181 | } |
| 186 | 182 | |
| 187 | - public function quoteTableName($name) |
|
| 188 | - { |
|
| 183 | + public function quoteTableName($name) { |
|
| 189 | 184 | return strpos($name, '`') !== false ? $name : "`$name`"; |
| 190 | 185 | } |
| 191 | 186 | |
@@ -197,8 +192,7 @@ discard block |
||
| 197 | 192 | * @author Tarun Mukherjee (https://github.com/tmukherjee13) |
| 198 | 193 | */ |
| 199 | 194 | |
| 200 | - public function actionTable(array $tables) |
|
| 201 | - { |
|
| 195 | + public function actionTable(array $tables) { |
|
| 202 | 196 | |
| 203 | 197 | if ($this->confirm('Create the migration ' . "?")) { |
| 204 | 198 | |
@@ -276,8 +270,7 @@ discard block |
||
| 276 | 270 | * @param array $tables the list of tables |
| 277 | 271 | * @return integer|null |
| 278 | 272 | */ |
| 279 | - public function actionData(array $tables) |
|
| 280 | - { |
|
| 273 | + public function actionData(array $tables) { |
|
| 281 | 274 | |
| 282 | 275 | if ($this->confirm('Create the migration ' . "?", true)) { |
| 283 | 276 | foreach ($tables as $key => $args) { |
@@ -319,7 +312,8 @@ discard block |
||
| 319 | 312 | |
| 320 | 313 | if (empty($prepared_data)) { |
| 321 | 314 | $this->stdout("\nTable '{$table->name}' doesn't contain any data.\n\n", Console::FG_RED); |
| 322 | - } else { |
|
| 315 | + } |
|
| 316 | + else { |
|
| 323 | 317 | $pcolumns = $this->prepareColumns($pcolumns); |
| 324 | 318 | $prows = $this->prepareData($prepared_data); |
| 325 | 319 | |
@@ -339,8 +333,7 @@ discard block |
||
| 339 | 333 | * @param string $args the schema name |
| 340 | 334 | * @return integer |
| 341 | 335 | */ |
| 342 | - public function actionSchema($args) |
|
| 343 | - { |
|
| 336 | + public function actionSchema($args) { |
|
| 344 | 337 | |
| 345 | 338 | $schema = $args; |
| 346 | 339 | $this->class = 'dump_database_' . $schema; |
@@ -368,18 +361,15 @@ discard block |
||
| 368 | 361 | |
| 369 | 362 | } |
| 370 | 363 | |
| 371 | - public function getFileName() |
|
| 372 | - { |
|
| 364 | + public function getFileName() { |
|
| 373 | 365 | return 'm' . gmdate('ymd_His') . '_' . $this->class; |
| 374 | 366 | } |
| 375 | 367 | |
| 376 | - public function setFileName() |
|
| 377 | - { |
|
| 368 | + public function setFileName() { |
|
| 378 | 369 | $this->fileName = $this->getFileName(); |
| 379 | 370 | } |
| 380 | 371 | |
| 381 | - public function prepareFile($data) |
|
| 382 | - { |
|
| 372 | + public function prepareFile($data) { |
|
| 383 | 373 | $file = $this->migrationPath . DIRECTORY_SEPARATOR . $this->getFileName() . '.php'; |
| 384 | 374 | try { |
| 385 | 375 | |
@@ -399,8 +389,7 @@ discard block |
||
| 399 | 389 | /** |
| 400 | 390 | * @inheritdoc |
| 401 | 391 | */ |
| 402 | - protected function getMigrationHistory($limit) |
|
| 403 | - { |
|
| 392 | + protected function getMigrationHistory($limit) { |
|
| 404 | 393 | if ($this->db->schema->getTableSchema($this->migrationTable, true) === null) { |
| 405 | 394 | $this->createMigrationHistoryTable(); |
| 406 | 395 | } |
@@ -420,8 +409,7 @@ discard block |
||
| 420 | 409 | /** |
| 421 | 410 | * @inheritdoc |
| 422 | 411 | */ |
| 423 | - protected function addMigrationHistory($version) |
|
| 424 | - { |
|
| 412 | + protected function addMigrationHistory($version) { |
|
| 425 | 413 | $command = $this->db->createCommand(); |
| 426 | 414 | $command->insert($this->migrationTable, [ |
| 427 | 415 | 'version' => $version, |
@@ -432,8 +420,7 @@ discard block |
||
| 432 | 420 | /** |
| 433 | 421 | * @inheritdoc |
| 434 | 422 | */ |
| 435 | - protected function removeMigrationHistory($version) |
|
| 436 | - { |
|
| 423 | + protected function removeMigrationHistory($version) { |
|
| 437 | 424 | $command = $this->db->createCommand(); |
| 438 | 425 | $command->delete($this->migrationTable, [ |
| 439 | 426 | 'version' => $version, |
@@ -443,8 +430,7 @@ discard block |
||
| 443 | 430 | /** |
| 444 | 431 | * @inheritdoc |
| 445 | 432 | */ |
| 446 | - protected function parseFields() |
|
| 447 | - { |
|
| 433 | + protected function parseFields() { |
|
| 448 | 434 | $fields = []; |
| 449 | 435 | |
| 450 | 436 | foreach ($this->fields as $column => $schema) { |