babenkoivan / elastic-migrations

Elasticsearch migrations for Laravel
MIT License
187 stars 32 forks source link

Update base migration file to check if table elastic_migrations table already exists #56

Closed jasonwinn closed 4 months ago

jasonwinn commented 4 months ago

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 which recreates tables like elastic_migrations.

It follows that the migrations table exists and is empty. Additionally, the elastic_migrations table exists and is empty.

Therefore, if you try to create and run a new migration, this library sees that 2019_15_12_112000_create_elastic_migrations_table.php does not exist in the migrations table and tries to create the elastic_migrations table. This causes an error because the table actually does exist. This is the error that is thrown:

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))
babenkoivan commented 4 months ago

Hey @jasonwinn, thank you for your PR! I've merged it and released a new version v3.4.1 🎉

jasonwinn commented 4 months ago

You are welcome @babenkoivan, thanks for the great libraries!