Skip to content

PostgreSQL migration fails on re-execution: missing IF NOT EXISTS for schema creation #45

Description

@Himmelschmidt

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.

Activity

  1. geofmureithi commented on Nov 11, 2025

    @geofmureithi
    Member

    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.

  2. geofmureithi commented on Nov 11, 2025

    @geofmureithi
    Member

    If you feel this was a mistake, please respond with the steps you took, the version you are using and a minimal reproducible example.

  3. Himmelschmidt commented on Nov 11, 2025

    @Himmelschmidt
    ContributorAuthor

    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 ran PostgresStorage::setup got 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.

  4. geofmureithi commented on Nov 11, 2025

    @geofmureithi
    Member

    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.

  5. geofmureithi commented on Nov 12, 2025

    @geofmureithi
    Member

    I will add the solution documented in apalis-dev/apalis#439 to the docs and README.md to help future users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions