1 | <?php namespace Limoncello\Application\Data; |
||
40 | abstract class BaseMigrationRunner |
||
41 | { |
||
42 | /** Migrations table name */ |
||
43 | const MIGRATIONS_TABLE = '_migrations'; |
||
44 | |||
45 | /** Migration column name */ |
||
46 | const MIGRATIONS_COLUMN_ID = 'id'; |
||
47 | |||
48 | /** Migration column name */ |
||
49 | const MIGRATIONS_COLUMN_CLASS = 'class'; |
||
50 | |||
51 | /** Migration column name */ |
||
52 | const MIGRATIONS_COLUMN_MIGRATED_AT = 'migrated_at'; |
||
53 | |||
54 | /** Seeds table name */ |
||
55 | const SEEDS_TABLE = '_seeds'; |
||
56 | |||
57 | /** |
||
58 | * @var IoInterface |
||
59 | */ |
||
60 | private $inOut; |
||
61 | |||
62 | /** |
||
63 | * @return string[] |
||
64 | */ |
||
65 | abstract protected function getMigrationClasses(): array; |
||
66 | |||
67 | /** |
||
68 | * @param IoInterface $inOut |
||
69 | */ |
||
70 | 2 | public function __construct(IoInterface $inOut) |
|
74 | |||
75 | /** |
||
76 | * @param ContainerInterface $container |
||
77 | * |
||
78 | * @return void |
||
79 | * |
||
80 | * @throws ContainerExceptionInterface |
||
81 | * @throws NotFoundExceptionInterface |
||
82 | * @throws DBALException |
||
83 | */ |
||
84 | 1 | public function migrate(ContainerInterface $container): void |
|
95 | |||
96 | /** |
||
97 | * @param ContainerInterface $container |
||
98 | * |
||
99 | * @return void |
||
100 | * |
||
101 | * @throws ContainerExceptionInterface |
||
102 | * @throws InvalidArgumentException |
||
103 | * @throws NotFoundExceptionInterface |
||
104 | * @throws DBALException |
||
105 | */ |
||
106 | 1 | public function rollback(ContainerInterface $container): void |
|
125 | |||
126 | /** |
||
127 | * @return IoInterface |
||
128 | */ |
||
129 | 2 | protected function getIO(): IoInterface |
|
133 | |||
134 | /** |
||
135 | * @param IoInterface $inOut |
||
136 | * |
||
137 | * @return self |
||
138 | */ |
||
139 | 3 | private function setIO(IoInterface $inOut): self |
|
145 | |||
146 | /** |
||
147 | * @param ContainerInterface $container |
||
148 | * |
||
149 | * @return Generator |
||
150 | * |
||
151 | * @throws ContainerExceptionInterface |
||
152 | * @throws NotFoundExceptionInterface |
||
153 | * |
||
154 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
155 | * @throws DBALException |
||
156 | */ |
||
157 | 1 | private function getMigrations(ContainerInterface $container): Generator |
|
176 | |||
177 | /** |
||
178 | * @param ContainerInterface $container |
||
179 | * |
||
180 | * @return Generator |
||
181 | * |
||
182 | * @throws ContainerExceptionInterface |
||
183 | * @throws NotFoundExceptionInterface |
||
184 | * @throws InvalidArgumentException |
||
185 | * @throws DBALException |
||
186 | */ |
||
187 | 1 | private function getRollbacks(ContainerInterface $container): Generator |
|
197 | |||
198 | /** |
||
199 | * @param ContainerInterface $container |
||
200 | * |
||
201 | * @return Connection |
||
202 | * |
||
203 | * @throws ContainerExceptionInterface |
||
204 | * @throws NotFoundExceptionInterface |
||
205 | */ |
||
206 | 1 | private function getConnection(ContainerInterface $container): Connection |
|
210 | |||
211 | /** |
||
212 | * @param AbstractSchemaManager $manager |
||
213 | * |
||
214 | * @return void |
||
215 | * |
||
216 | * @throws DBALException |
||
217 | */ |
||
218 | 1 | private function createMigrationsTable(AbstractSchemaManager $manager): void |
|
237 | |||
238 | /** |
||
239 | * @param Connection $connection |
||
240 | * |
||
241 | * @return array |
||
242 | */ |
||
243 | 1 | private function readMigrated(Connection $connection): array |
|
264 | |||
265 | /** |
||
266 | * @param Connection $connection |
||
267 | * @param string $class |
||
268 | * |
||
269 | * @return void |
||
270 | * |
||
271 | * @throws DBALException |
||
272 | * @throws Exception |
||
273 | */ |
||
274 | 1 | private function saveMigration(Connection $connection, string $class): void |
|
283 | |||
284 | /** |
||
285 | * @param Connection $connection |
||
286 | * @param int $index |
||
287 | * |
||
288 | * @return void |
||
289 | * |
||
290 | * @throws InvalidArgumentException |
||
291 | * |
||
292 | * @throws DBALException |
||
293 | */ |
||
294 | 1 | private function removeMigration(Connection $connection, int $index): void |
|
298 | |||
299 | /** |
||
300 | * @param string $class |
||
301 | * @param ContainerInterface $container |
||
302 | * |
||
303 | * @return MigrationInterface|null |
||
304 | */ |
||
305 | 2 | private function createMigration(string $class, ContainerInterface $container): ?MigrationInterface |
|
318 | } |
||
319 |