@@ -42,11 +42,14 @@ discard block |
||
| 42 | 42 | $this->output->writeln('<info>Detecting schema changes:</info>'); |
| 43 | 43 | |
| 44 | 44 | $this->changes = []; |
| 45 | - foreach ($registry->getIterator() as $e) { |
|
| 46 | - if ($registry->hasTable($e)) { |
|
| 45 | + foreach ($registry->getIterator() as $e) |
|
| 46 | + { |
|
| 47 | + if ($registry->hasTable($e)) |
|
| 48 | + { |
|
| 47 | 49 | $table = $registry->getTableSchema($e); |
| 48 | 50 | |
| 49 | - if ($table->getComparator()->hasChanges()) { |
|
| 51 | + if ($table->getComparator()->hasChanges()) |
|
| 52 | + { |
|
| 50 | 53 | $key = $registry->getDatabase($e) . ':' . $registry->getTable($e); |
| 51 | 54 | $this->changes[$key] = [ |
| 52 | 55 | 'database' => $registry->getDatabase($e), |
@@ -57,13 +60,15 @@ discard block |
||
| 57 | 60 | } |
| 58 | 61 | } |
| 59 | 62 | |
| 60 | - if ($this->changes === []) { |
|
| 63 | + if ($this->changes === []) |
|
| 64 | + { |
|
| 61 | 65 | $this->output->writeln('<fg=yellow>no database changes has been detected</fg=yellow>'); |
| 62 | 66 | |
| 63 | 67 | return $registry; |
| 64 | 68 | } |
| 65 | 69 | |
| 66 | - foreach ($this->changes as $change) { |
|
| 70 | + foreach ($this->changes as $change) |
|
| 71 | + { |
|
| 67 | 72 | $this->output->write(sprintf('• <fg=cyan>%s.%s</fg=cyan>', $change['database'], $change['table'])); |
| 68 | 73 | $this->describeChanges($change['schema']); |
| 69 | 74 | } |
@@ -84,7 +89,8 @@ discard block |
||
| 84 | 89 | */ |
| 85 | 90 | protected function describeChanges(AbstractTable $table): void |
| 86 | 91 | { |
| 87 | - if (!$this->output->isVerbose()) { |
|
| 92 | + if (!$this->output->isVerbose()) |
|
| 93 | + { |
|
| 88 | 94 | $this->output->writeln( |
| 89 | 95 | sprintf( |
| 90 | 96 | ': <fg=green>%s</fg=green> change(s) detected', |
@@ -97,11 +103,13 @@ discard block |
||
| 97 | 103 | $this->output->write("\n"); |
| 98 | 104 | |
| 99 | 105 | |
| 100 | - if (!$table->exists()) { |
|
| 106 | + if (!$table->exists()) |
|
| 107 | + { |
|
| 101 | 108 | $this->output->writeln(' - create table'); |
| 102 | 109 | } |
| 103 | 110 | |
| 104 | - if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) { |
|
| 111 | + if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) |
|
| 112 | + { |
|
| 105 | 113 | $this->output->writeln(' - drop table'); |
| 106 | 114 | return; |
| 107 | 115 | } |
@@ -118,15 +126,18 @@ discard block |
||
| 118 | 126 | */ |
| 119 | 127 | protected function describeColumns(Comparator $cmp): void |
| 120 | 128 | { |
| 121 | - foreach ($cmp->addedColumns() as $column) { |
|
| 129 | + foreach ($cmp->addedColumns() as $column) |
|
| 130 | + { |
|
| 122 | 131 | $this->output->writeln(" - add column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 123 | 132 | } |
| 124 | 133 | |
| 125 | - foreach ($cmp->droppedColumns() as $column) { |
|
| 134 | + foreach ($cmp->droppedColumns() as $column) |
|
| 135 | + { |
|
| 126 | 136 | $this->output->writeln(" - drop column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 127 | 137 | } |
| 128 | 138 | |
| 129 | - foreach ($cmp->alteredColumns() as $column) { |
|
| 139 | + foreach ($cmp->alteredColumns() as $column) |
|
| 140 | + { |
|
| 130 | 141 | $column = $column[0]; |
| 131 | 142 | $this->output->writeln(" - alter column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 132 | 143 | } |
@@ -137,17 +148,20 @@ discard block |
||
| 137 | 148 | */ |
| 138 | 149 | protected function describeIndexes(Comparator $cmp): void |
| 139 | 150 | { |
| 140 | - foreach ($cmp->addedIndexes() as $index) { |
|
| 151 | + foreach ($cmp->addedIndexes() as $index) |
|
| 152 | + { |
|
| 141 | 153 | $index = implode(', ', $index->getColumns()); |
| 142 | 154 | $this->output->writeln(" - add index on <fg=yellow>[{$index}]</fg=yellow>"); |
| 143 | 155 | } |
| 144 | 156 | |
| 145 | - foreach ($cmp->droppedIndexes() as $index) { |
|
| 157 | + foreach ($cmp->droppedIndexes() as $index) |
|
| 158 | + { |
|
| 146 | 159 | $index = implode(', ', $index->getColumns()); |
| 147 | 160 | $this->output->writeln(" - drop index on <fg=yellow>[{$index}]</fg=yellow>"); |
| 148 | 161 | } |
| 149 | 162 | |
| 150 | - foreach ($cmp->alteredIndexes() as $index) { |
|
| 163 | + foreach ($cmp->alteredIndexes() as $index) |
|
| 164 | + { |
|
| 151 | 165 | $index = $index[0]; |
| 152 | 166 | $index = implode(', ', $index->getColumns()); |
| 153 | 167 | $this->output->writeln(" - alter index on <fg=yellow>[{$index}]</fg=yellow>"); |
@@ -159,17 +173,20 @@ discard block |
||
| 159 | 173 | */ |
| 160 | 174 | protected function describeFKs(Comparator $cmp): void |
| 161 | 175 | { |
| 162 | - foreach ($cmp->addedForeignKeys() as $fk) { |
|
| 176 | + foreach ($cmp->addedForeignKeys() as $fk) |
|
| 177 | + { |
|
| 163 | 178 | $fkColumns = implode(', ', $fk->getColumns()); |
| 164 | 179 | $this->output->writeln(" - add foreign key on <fg=yellow>{$fkColumns}</fg=yellow>"); |
| 165 | 180 | } |
| 166 | 181 | |
| 167 | - foreach ($cmp->droppedForeignKeys() as $fk) { |
|
| 182 | + foreach ($cmp->droppedForeignKeys() as $fk) |
|
| 183 | + { |
|
| 168 | 184 | $fkColumns = implode(', ', $fk->getColumns()); |
| 169 | 185 | $this->output->writeln(" - drop foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
| 170 | 186 | } |
| 171 | 187 | |
| 172 | - foreach ($cmp->alteredForeignKeys() as $fk) { |
|
| 188 | + foreach ($cmp->alteredForeignKeys() as $fk) |
|
| 189 | + { |
|
| 173 | 190 | $fk = $fk[0]; |
| 174 | 191 | $fkColumns = implode(', ', $fk->getColumns()); |
| 175 | 192 | $this->output->writeln(" - alter foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |