Skip to content

Wrong index detection on cockroachdb #1356

@OndrejIT

Description

@OndrejIT

Hi, I'm trying to make a migration on my cockroachdb DB + sqlmodel.
when I first init alembic and create DB everything works, if I scan again (alembic revision --autogenerate) for possible changes, alembic prints "Detected changed index 'ix_file_bucket' on 'file': expression ('INDEX', 'bucket nulls first') to ('INDEX', 'bucket')" (I didn't change anything in code and database)
and alembic creates the following migrations:

op.drop_index(op.f('ix_file_bucket'), table_name='file')
op.create_index('ix_file_bucket', 'file', [sa.text('bucket NULLS FIRST')], unique=False, postgresql_using='prefix')

the next time the alembic is triggered, it fails.
with the message:
sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions.ObjectNotInPrerequisiteStateError'>: index "ix_file_bucket" is cancelled, try again later

is there any way to solve this? currently I have to manually delete bad migrations line every time.

Versions.

  • OS: Docker
  • Python: docker.io/python:3.12-alpine
  • Alembic: 1.12.1
  • SQLAlchemy: 1.4.41 + sqlmodel==0.0.11
  • Database: cockroachdb v23.1.11
  • DBAPI: sqlalchemy-cockroachdb==2.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    external driver issuesthe issue involves a misbehavior on the part of the DBAPI itself, probably not SQLAlchemy or Alembicindex expressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions