@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | EnvironmentInterface $env, |
45 | 45 | FinalizerInterface $finalizer, |
46 | 46 | ContainerInterface $container |
47 | - ) { |
|
47 | + ){ |
|
48 | 48 | $this->env = $env; |
49 | 49 | $this->finalizer = $finalizer; |
50 | 50 | $this->container = $container; |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | /** @var Console $console */ |
74 | 74 | $console = $this->container->get(Console::class); |
75 | 75 | |
76 | - try { |
|
76 | + try{ |
|
77 | 77 | $console->start($input ?? new ArgvInput(), $output); |
78 | - } catch (\Throwable $e) { |
|
78 | + }catch (\Throwable $e){ |
|
79 | 79 | $this->handleException($e, $output); |
80 | - } finally { |
|
80 | + }finally{ |
|
81 | 81 | $listener->disable(); |
82 | 82 | $this->finalizer->finalize(false); |
83 | 83 | } |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | */ |
90 | 90 | protected function handleException(\Throwable $e, OutputInterface $output) |
91 | 91 | { |
92 | - try { |
|
92 | + try{ |
|
93 | 93 | $this->container->get(SnapshotterInterface::class)->register($e); |
94 | - } catch (\Throwable|ContainerExceptionInterface $se) { |
|
94 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
95 | 95 | // no need to notify when unable to register an exception |
96 | 96 | } |
97 | 97 | |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | */ |
107 | 107 | private function mapVerbosity(OutputInterface $output): int |
108 | 108 | { |
109 | - if ($output->isDebug()) { |
|
109 | + if ($output->isDebug()){ |
|
110 | 110 | return ConsoleHandler::VERBOSITY_DEBUG; |
111 | 111 | } |
112 | 112 | |
113 | - if ($output->isVeryVerbose()) { |
|
113 | + if ($output->isVeryVerbose()){ |
|
114 | 114 | return ConsoleHandler::VERBOSITY_VERBOSE; |
115 | 115 | } |
116 | 116 |
@@ -73,11 +73,16 @@ discard block |
||
73 | 73 | /** @var Console $console */ |
74 | 74 | $console = $this->container->get(Console::class); |
75 | 75 | |
76 | - try { |
|
76 | + try |
|
77 | + { |
|
77 | 78 | $console->start($input ?? new ArgvInput(), $output); |
78 | - } catch (\Throwable $e) { |
|
79 | + } |
|
80 | + catch (\Throwable $e) |
|
81 | + { |
|
79 | 82 | $this->handleException($e, $output); |
80 | - } finally { |
|
83 | + } |
|
84 | + finally |
|
85 | + { |
|
81 | 86 | $listener->disable(); |
82 | 87 | $this->finalizer->finalize(false); |
83 | 88 | } |
@@ -89,9 +94,12 @@ discard block |
||
89 | 94 | */ |
90 | 95 | protected function handleException(\Throwable $e, OutputInterface $output) |
91 | 96 | { |
92 | - try { |
|
97 | + try |
|
98 | + { |
|
93 | 99 | $this->container->get(SnapshotterInterface::class)->register($e); |
94 | - } catch (\Throwable|ContainerExceptionInterface $se) { |
|
100 | + } |
|
101 | + catch (\Throwable|ContainerExceptionInterface $se) |
|
102 | + { |
|
95 | 103 | // no need to notify when unable to register an exception |
96 | 104 | } |
97 | 105 | |
@@ -106,11 +114,13 @@ discard block |
||
106 | 114 | */ |
107 | 115 | private function mapVerbosity(OutputInterface $output): int |
108 | 116 | { |
109 | - if ($output->isDebug()) { |
|
117 | + if ($output->isDebug()) |
|
118 | + { |
|
110 | 119 | return ConsoleHandler::VERBOSITY_DEBUG; |
111 | 120 | } |
112 | 121 | |
113 | - if ($output->isVeryVerbose()) { |
|
122 | + if ($output->isVeryVerbose()) |
|
123 | + { |
|
114 | 124 | return ConsoleHandler::VERBOSITY_VERBOSE; |
115 | 125 | } |
116 | 126 |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | $this->output->writeln("<info>Detecting schema changes:</info>"); |
41 | 41 | |
42 | 42 | $this->changes = []; |
43 | - foreach ($registry->getIterator() as $e) { |
|
44 | - if ($registry->hasTable($e)) { |
|
43 | + foreach ($registry->getIterator() as $e){ |
|
44 | + if ($registry->hasTable($e)){ |
|
45 | 45 | $table = $registry->getTableSchema($e); |
46 | 46 | |
47 | - if ($table->getComparator()->hasChanges()) { |
|
47 | + if ($table->getComparator()->hasChanges()){ |
|
48 | 48 | $this->changes[] = [ |
49 | 49 | 'database' => $registry->getDatabase($e), |
50 | 50 | 'table' => $registry->getTable($e), |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | - if ($this->changes === []) { |
|
57 | + if ($this->changes === []){ |
|
58 | 58 | $this->output->writeln("<fg=yellow>no database changes has been detected</fg=yellow>"); |
59 | 59 | |
60 | 60 | return $registry; |
61 | 61 | } |
62 | 62 | |
63 | - foreach ($this->changes as $change) { |
|
63 | + foreach ($this->changes as $change){ |
|
64 | 64 | $this->output->write(sprintf("• <fg=cyan>%s.%s</fg=cyan>", $change['database'], $change['table'])); |
65 | 65 | $this->describeChanges($change['schema']); |
66 | 66 | } |
@@ -73,22 +73,22 @@ discard block |
||
73 | 73 | */ |
74 | 74 | protected function describeChanges(AbstractTable $table) |
75 | 75 | { |
76 | - if (!$this->output->isVerbose()) { |
|
76 | + if (!$this->output->isVerbose()){ |
|
77 | 77 | $this->output->writeln(sprintf( |
78 | 78 | ": <fg=green>%s</fg=green> change(s) detected", |
79 | 79 | $this->numChanges($table) |
80 | 80 | )); |
81 | 81 | |
82 | 82 | return; |
83 | - } else { |
|
83 | + }else{ |
|
84 | 84 | $this->output->write("\n"); |
85 | 85 | } |
86 | 86 | |
87 | - if (!$table->exists()) { |
|
87 | + if (!$table->exists()){ |
|
88 | 88 | $this->output->writeln(" - create table"); |
89 | 89 | } |
90 | 90 | |
91 | - if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) { |
|
91 | + if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED){ |
|
92 | 92 | $this->output->writeln(" - drop table"); |
93 | 93 | return; |
94 | 94 | } |
@@ -105,15 +105,15 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function describeColumns(Comparator $cmp) |
107 | 107 | { |
108 | - foreach ($cmp->addedColumns() as $column) { |
|
108 | + foreach ($cmp->addedColumns() as $column){ |
|
109 | 109 | $this->output->writeln(" - add column <fg=yellow>{$column->getName()}</fg=yellow>"); |
110 | 110 | } |
111 | 111 | |
112 | - foreach ($cmp->droppedColumns() as $column) { |
|
112 | + foreach ($cmp->droppedColumns() as $column){ |
|
113 | 113 | $this->output->writeln(" - drop column <fg=yellow>{$column->getName()}</fg=yellow>"); |
114 | 114 | } |
115 | 115 | |
116 | - foreach ($cmp->alteredColumns() as $column) { |
|
116 | + foreach ($cmp->alteredColumns() as $column){ |
|
117 | 117 | $column = $column[0]; |
118 | 118 | $this->output->writeln(" - alter column <fg=yellow>{$column->getName()}</fg=yellow>"); |
119 | 119 | } |
@@ -124,17 +124,17 @@ discard block |
||
124 | 124 | */ |
125 | 125 | protected function describeIndexes(Comparator $cmp) |
126 | 126 | { |
127 | - foreach ($cmp->addedIndexes() as $index) { |
|
127 | + foreach ($cmp->addedIndexes() as $index){ |
|
128 | 128 | $index = join(', ', $index->getColumns()); |
129 | 129 | $this->output->writeln(" - add index on <fg=yellow>[{$index}]</fg=yellow>"); |
130 | 130 | } |
131 | 131 | |
132 | - foreach ($cmp->droppedIndexes() as $index) { |
|
132 | + foreach ($cmp->droppedIndexes() as $index){ |
|
133 | 133 | $index = join(', ', $index->getColumns()); |
134 | 134 | $this->output->writeln(" - drop index on <fg=yellow>[{$index}]</fg=yellow>"); |
135 | 135 | } |
136 | 136 | |
137 | - foreach ($cmp->alteredIndexes() as $index) { |
|
137 | + foreach ($cmp->alteredIndexes() as $index){ |
|
138 | 138 | $index = $index[0]; |
139 | 139 | $index = join(', ', $index->getColumns()); |
140 | 140 | $this->output->writeln(" - alter index on <fg=yellow>[{$index}]</fg=yellow>"); |
@@ -146,17 +146,17 @@ discard block |
||
146 | 146 | */ |
147 | 147 | protected function describeFKs(Comparator $cmp) |
148 | 148 | { |
149 | - foreach ($cmp->addedForeignKeys() as $fk) { |
|
149 | + foreach ($cmp->addedForeignKeys() as $fk){ |
|
150 | 150 | $fkColumns = join(', ', $fk->getColumns()); |
151 | 151 | $this->output->writeln(" - add foreign key on <fg=yellow>{$fkColumns}</fg=yellow>"); |
152 | 152 | } |
153 | 153 | |
154 | - foreach ($cmp->droppedForeignKeys() as $fk) { |
|
154 | + foreach ($cmp->droppedForeignKeys() as $fk){ |
|
155 | 155 | $fkColumns = join(', ', $fk->getColumns()); |
156 | 156 | $this->output->writeln(" - drop foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
157 | 157 | } |
158 | 158 | |
159 | - foreach ($cmp->alteredForeignKeys() as $fk) { |
|
159 | + foreach ($cmp->alteredForeignKeys() as $fk){ |
|
160 | 160 | $fk = $fk[0]; |
161 | 161 | $fkColumns = join(', ', $fk->getColumns()); |
162 | 162 | $this->output->writeln(" - alter foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
@@ -40,11 +40,14 @@ discard block |
||
40 | 40 | $this->output->writeln("<info>Detecting schema changes:</info>"); |
41 | 41 | |
42 | 42 | $this->changes = []; |
43 | - foreach ($registry->getIterator() as $e) { |
|
44 | - if ($registry->hasTable($e)) { |
|
43 | + foreach ($registry->getIterator() as $e) |
|
44 | + { |
|
45 | + if ($registry->hasTable($e)) |
|
46 | + { |
|
45 | 47 | $table = $registry->getTableSchema($e); |
46 | 48 | |
47 | - if ($table->getComparator()->hasChanges()) { |
|
49 | + if ($table->getComparator()->hasChanges()) |
|
50 | + { |
|
48 | 51 | $this->changes[] = [ |
49 | 52 | 'database' => $registry->getDatabase($e), |
50 | 53 | 'table' => $registry->getTable($e), |
@@ -54,13 +57,15 @@ discard block |
||
54 | 57 | } |
55 | 58 | } |
56 | 59 | |
57 | - if ($this->changes === []) { |
|
60 | + if ($this->changes === []) |
|
61 | + { |
|
58 | 62 | $this->output->writeln("<fg=yellow>no database changes has been detected</fg=yellow>"); |
59 | 63 | |
60 | 64 | return $registry; |
61 | 65 | } |
62 | 66 | |
63 | - foreach ($this->changes as $change) { |
|
67 | + foreach ($this->changes as $change) |
|
68 | + { |
|
64 | 69 | $this->output->write(sprintf("• <fg=cyan>%s.%s</fg=cyan>", $change['database'], $change['table'])); |
65 | 70 | $this->describeChanges($change['schema']); |
66 | 71 | } |
@@ -73,22 +78,27 @@ discard block |
||
73 | 78 | */ |
74 | 79 | protected function describeChanges(AbstractTable $table) |
75 | 80 | { |
76 | - if (!$this->output->isVerbose()) { |
|
81 | + if (!$this->output->isVerbose()) |
|
82 | + { |
|
77 | 83 | $this->output->writeln(sprintf( |
78 | 84 | ": <fg=green>%s</fg=green> change(s) detected", |
79 | 85 | $this->numChanges($table) |
80 | 86 | )); |
81 | 87 | |
82 | 88 | return; |
83 | - } else { |
|
89 | + } |
|
90 | + else |
|
91 | + { |
|
84 | 92 | $this->output->write("\n"); |
85 | 93 | } |
86 | 94 | |
87 | - if (!$table->exists()) { |
|
95 | + if (!$table->exists()) |
|
96 | + { |
|
88 | 97 | $this->output->writeln(" - create table"); |
89 | 98 | } |
90 | 99 | |
91 | - if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) { |
|
100 | + if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) |
|
101 | + { |
|
92 | 102 | $this->output->writeln(" - drop table"); |
93 | 103 | return; |
94 | 104 | } |
@@ -105,15 +115,18 @@ discard block |
||
105 | 115 | */ |
106 | 116 | protected function describeColumns(Comparator $cmp) |
107 | 117 | { |
108 | - foreach ($cmp->addedColumns() as $column) { |
|
118 | + foreach ($cmp->addedColumns() as $column) |
|
119 | + { |
|
109 | 120 | $this->output->writeln(" - add column <fg=yellow>{$column->getName()}</fg=yellow>"); |
110 | 121 | } |
111 | 122 | |
112 | - foreach ($cmp->droppedColumns() as $column) { |
|
123 | + foreach ($cmp->droppedColumns() as $column) |
|
124 | + { |
|
113 | 125 | $this->output->writeln(" - drop column <fg=yellow>{$column->getName()}</fg=yellow>"); |
114 | 126 | } |
115 | 127 | |
116 | - foreach ($cmp->alteredColumns() as $column) { |
|
128 | + foreach ($cmp->alteredColumns() as $column) |
|
129 | + { |
|
117 | 130 | $column = $column[0]; |
118 | 131 | $this->output->writeln(" - alter column <fg=yellow>{$column->getName()}</fg=yellow>"); |
119 | 132 | } |
@@ -124,17 +137,20 @@ discard block |
||
124 | 137 | */ |
125 | 138 | protected function describeIndexes(Comparator $cmp) |
126 | 139 | { |
127 | - foreach ($cmp->addedIndexes() as $index) { |
|
140 | + foreach ($cmp->addedIndexes() as $index) |
|
141 | + { |
|
128 | 142 | $index = join(', ', $index->getColumns()); |
129 | 143 | $this->output->writeln(" - add index on <fg=yellow>[{$index}]</fg=yellow>"); |
130 | 144 | } |
131 | 145 | |
132 | - foreach ($cmp->droppedIndexes() as $index) { |
|
146 | + foreach ($cmp->droppedIndexes() as $index) |
|
147 | + { |
|
133 | 148 | $index = join(', ', $index->getColumns()); |
134 | 149 | $this->output->writeln(" - drop index on <fg=yellow>[{$index}]</fg=yellow>"); |
135 | 150 | } |
136 | 151 | |
137 | - foreach ($cmp->alteredIndexes() as $index) { |
|
152 | + foreach ($cmp->alteredIndexes() as $index) |
|
153 | + { |
|
138 | 154 | $index = $index[0]; |
139 | 155 | $index = join(', ', $index->getColumns()); |
140 | 156 | $this->output->writeln(" - alter index on <fg=yellow>[{$index}]</fg=yellow>"); |
@@ -146,17 +162,20 @@ discard block |
||
146 | 162 | */ |
147 | 163 | protected function describeFKs(Comparator $cmp) |
148 | 164 | { |
149 | - foreach ($cmp->addedForeignKeys() as $fk) { |
|
165 | + foreach ($cmp->addedForeignKeys() as $fk) |
|
166 | + { |
|
150 | 167 | $fkColumns = join(', ', $fk->getColumns()); |
151 | 168 | $this->output->writeln(" - add foreign key on <fg=yellow>{$fkColumns}</fg=yellow>"); |
152 | 169 | } |
153 | 170 | |
154 | - foreach ($cmp->droppedForeignKeys() as $fk) { |
|
171 | + foreach ($cmp->droppedForeignKeys() as $fk) |
|
172 | + { |
|
155 | 173 | $fkColumns = join(', ', $fk->getColumns()); |
156 | 174 | $this->output->writeln(" - drop foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
157 | 175 | } |
158 | 176 | |
159 | - foreach ($cmp->alteredForeignKeys() as $fk) { |
|
177 | + foreach ($cmp->alteredForeignKeys() as $fk) |
|
178 | + { |
|
160 | 179 | $fk = $fk[0]; |
161 | 180 | $fkColumns = join(', ', $fk->getColumns()); |
162 | 181 | $this->output->writeln(" - alter foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |