sqlalchemy / sqlalchemy/alembic

if/when SQLAlchemy provides truncation for naming convention names, need to do that same truncation on the name comparison side

Open
#438 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autogenerate - detection bug low priority naming convention issues
Dominant language
Python
Stars
4.4k
Forks
375
PR merge metrics
No merged PRs in 30d

Description

Migrated issue, originally created by Danny Milosavljevic

Hi,

postgresql automatically truncates too-long index names (for the limit see "SELECT max_identifier_length - 1 FROM pg_control_init()") but alembic does not truncate index names in this manner.

That means that if an index name is too long then alembic will always generate a spurious migration where it tries to create the index with the long name and drop the index with the short name.

The bug is not that bad because for cases where the sqlalchemy naming convention generates index names that are too long you can just override it in the model by specifying a non-autogenerated index name ("name=...").

But in the long run it would be nice if alembic would also auto-truncate index names like postgres does.

It is apparently not possible to disable autotruncation in postgresql 9.6.1, so it might be a bit difficult to find these cases.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how Alembic compares and generates index names when SQLAlchemy naming conventions produce identifiers longer than PostgreSQL allows. Reproduce the case with a long convention-generated index name and inspect the resulting migration. Done means comparison recognizes PostgreSQL's truncated name and no longer produces a spurious create-and-drop migration.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python, sqlalchemy
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.