Skip to content

Questions on how to best add a complex index in the context of auto-generating migrations #1202

Discussion options

You must be logged in to vote

So I had a complex index that I didn't know how to model in the sqlAlchemy ORM and I am wondering how to best handle it. I have 2 questions on how to best handle it but first some context.

So in alembic i created a migration and did:

    op.execute(
        """
        CREATE UNIQUE INDEX unique_started_or_finished_per_user
        ON "widget" (user_id)
        WHERE status IN ('started', 'finished');
        """
    )

This worked fine until I auto-generated a new migration in which alembic auto-generated the migration to drop the index I created.

So I guess

1. How do I get auto-generation to ignore my own custom migration?

use the include_object hook: https://alembic.sqlalchemy.org/e…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ekeric13
Comment options

@zzzeek
Comment options

Answer selected by ekeric13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants