File tree Expand file tree Collapse file tree 2 files changed +23
-21
lines changed
Expand file tree Collapse file tree 2 files changed +23
-21
lines changed Original file line number Diff line number Diff line change 99use Tempest \Container \Container ;
1010use Tempest \Core \Installer ;
1111use Tempest \Core \PublishesFiles ;
12+ use Tempest \Database \Database ;
13+ use Tempest \Database \Migrations \CreateMigrationsTable ;
1214use Tempest \Database \Migrations \MigrationManager ;
1315
1416use function Tempest \root_path ;
@@ -36,6 +38,10 @@ public function install(): void
3638 $ this ->publishImports ();
3739
3840 if ($ migration && $ this ->shouldMigrate ()) {
41+ if (! $ this ->migrationManager ->doesMigrationsTableExist ()) {
42+ $ this ->migrationManager ->executeUp (new CreateMigrationsTable ());
43+ }
44+
3945 $ this ->migrationManager ->executeUp (
4046 migration: $ this ->container ->get (to_fqcn ($ migration , root: root_path ())),
4147 );
Original file line number Diff line number Diff line change @@ -188,11 +188,6 @@ public function validate(): void
188188
189189 public function executeUp (MigratesUp $ migration ): void
190190 {
191-
192- if (! $ migration instanceof CreateMigrationsTable) {
193- $ this ->ensureMigrationsTableExists ();
194- }
195-
196191 if ($ migration instanceof ShouldMigrate && $ migration ->shouldMigrate ($ this ->database ) === false ) {
197192 return ;
198193 }
@@ -292,6 +287,23 @@ public function executeDown(MigratesDown $migration): void
292287 event (new MigrationRolledBack ($ migration ->name ));
293288 }
294289
290+ public function doesMigrationsTableExist (): bool
291+ {
292+ try {
293+ Migration::select ()
294+ ->onDatabase ($ this ->onDatabase )
295+ ->limit (1 )
296+ ->all ();
297+ } catch (QueryWasInvalid $ exception ) {
298+ if ($ this ->dialect ->isTableNotFoundError ($ exception )) {
299+ return false ;
300+ } else {
301+ throw $ exception ;
302+ }
303+ }
304+ return true ;
305+ }
306+
295307 /**
296308 * @return \Tempest\Database\Migrations\TableMigrationDefinition[]
297309 */
@@ -339,20 +351,4 @@ private function getMinifiedSqlFromStatement(?QueryStatement $statement): string
339351
340352 return $ sql ;
341353 }
342-
343- private function ensureMigrationsTableExists (): void
344- {
345- try {
346- Migration::select ()
347- ->onDatabase ($ this ->onDatabase )
348- ->limit (1 )
349- ->all ();
350- } catch (QueryWasInvalid $ exception ) {
351- if ($ this ->dialect ->isTableNotFoundError ($ exception )) {
352- $ this ->executeUp (new CreateMigrationsTable ());
353- } else {
354- throw $ exception ;
355- }
356- }
357- }
358354}
You can’t perform that action at this time.
0 commit comments