Repository navigation
PostgreSQL migration fails on re-execution: missing IF NOT EXISTS for schema creation #45
Description
Activity
- added a commit that references this issue
on Nov 11, 2025 Please do not AI generate issues, This is not a valid issue if you are actually using this library. The migration in question was created in 2022 so whatever you are experiencing is an issue on your specific setup, (As the current CI passes). But again the description sounds generic and vague, as if you just asked an LLM what change could be done.
The solution in apalis-dev/apalis#621 is not a valid solution either as it would actually break anyone with later migrations. You CANNOT edit migrations directly.
If you feel this was a mistake, please respond with the steps you took, the version you are using and a minimal reproducible example.
I am using v0.7.3.
I use SeaOrm with Postgres in my project, along with their migrator cli. I was consistently getting this error after completely wiping my app DB for testing with their "fresh" command (which drops all types and tables).
Any app startup after in which I ranPostgresStorage::setupgot this error unless I manually deleted the Apalis schema.I thought that an easy fix would be to add the
IF NOT EXISTS. I'm aware that you can't usually directly modify migration files (for obvious reasons), I had figured that this case is different as it wouldn't be modifying any existing structures, only the check when we should create the schema.Regarding the LLM sounding description, I do use LLMs to help write commit messages and I did not see any contributing guidelines that would suggest I shouldn't use it.
You need to use the sqlx migrator. You are possibly facing an issue similar to this apalis-dev/apalis#439.
Regarding AI, its not an issue of using in but rather the lack of enough context. You are using SeaORM on top of the default migrations. Let me know if the issue linked works. If not please create a tiny repo with your use case and approach.I'm aware that you can't usually directly modify migration files (for obvious reasons). I had figured that this case is different as it wouldn't be modifying any existing structures, only the check when we should create the schema.
Sqlx indexes migrations by file hash so changing a file means its a different migration.
Reacted by HimmelschmidtI will add the solution documented in apalis-dev/apalis#439 to the docs and README.md to help future users.
Migration 20220530084123 creates the apalis schema without the IF NOT EXISTS clause. This causes the migration to fail with 'schema apalis already exists' error when re-executed. All tables and indexes in the same migration properly use IF NOT EXISTS. The schema creation should follow the same pattern for idempotency.