Home > Back-end >  alembic.command.check (version: 1.9.0) does not detect difference regarding names of constraints
alembic.command.check (version: 1.9.0) does not detect difference regarding names of constraints

Time:12-21

I have been working on a project including SQLite, SQLAlchemy, and Alembic.

My current task is to write a test to ensure that our migrations and the SQLAlchemy models are in sync.

I happily found that there was introduced a new built-in command just for that in Alembic==1.9.0. https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/ /4295 https://alembic.sqlalchemy.org/en/latest/api/commands.html#alembic.command.check

from alembic.command import check, upgrade
from alembic.config import Config

# pytest
def test_migrations_and_sqlalchelmy_models_are_in_sync():
  config = Config(CONFIG_PATH)
  upgrade(config, "head")
  check(config)

It's nice. And it works fine until it comes to the names of constraints (tried with sqlalchemy.UniqueConstraint and sqlalchemy.ForeignKeyConstraint). For some reason, which is unknown to me, it does not detect difference between the names of a constraint.

Is it intented to detect the difference in the name of a constraint? Is there any way to fix this?

Versions:
python==3.10.6
sqlalchemy==1.4.23
alembic==1.9.0

CodePudding user response:

It lists "Anonymously named constraints" as something that doesn't detect. It might help to set The template for naming foreign keys and constraints. As mentioned in that section under what it does not detect. Also various dialects have different support so I don't think it is intended at all to detect everything.

https://alembic.sqlalchemy.org/en/latest/naming.html

https://alembic.sqlalchemy.org/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect

  • Related