Skip to content

Commit

Permalink
Fix base migration to check if table already exists
Browse files Browse the repository at this point in the history
Currently the base schema migration assumes that the "elastic_migrations" table does not exist.

This is problematic when restoring a schema from a schema:dump with prune: `php artisan schema:dump --prune`

When you run `php artisan migrate`, Laravel restores the schema dump in database/schema. However, if you then try to run a migration, the elastic-migrations library attempts to run its migrations, but throws an error because the table already exists via the schema being restored.

`SQLSTATE[42P07]: Duplicate table: 7 ERROR:  relation "elastic_migrations" already exists (SQL: create table "elastic_migrations" ("migration" varchar(255) not null, "batch" integer not null))`
  • Loading branch information
jasonwinn authored May 9, 2024
1 parent c69448e commit 95dac24
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public function __construct()

public function up(): void
{
Schema::create($this->table, static function (Blueprint $table) {
$table->string('migration')->primary();
$table->integer('batch');
});
if (!Schema::hasTable($this->table)) {
Schema::create($this->table, static function (Blueprint $table) {
$table->string('migration')->primary();
$table->integer('batch');
});
}
}

public function down(): void
Expand Down

0 comments on commit 95dac24

Please sign in to comment.