Skip to content

Commit 7671ff6

Browse files
fix: missing migrations table when installing auth
1 parent dbca8f3 commit 7671ff6

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

packages/auth/src/Installer/AuthenticationInstaller.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Tempest\Container\Container;
1010
use Tempest\Core\Installer;
1111
use Tempest\Core\PublishesFiles;
12+
use Tempest\Database\Database;
13+
use Tempest\Database\Migrations\CreateMigrationsTable;
1214
use Tempest\Database\Migrations\MigrationManager;
1315

1416
use 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
);

packages/database/src/Migrations/MigrationManager.php

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)