sqlalchemy / sqlalchemy/alembic

batch_alter_table forgets unchanged Enum CHECK constraint

Open
#400 19 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

autogenerate for enums batch migrations bug documentation
Dominant language
Python
Stars
4.4k
Forks
375
PR merge metrics
No merged PRs in 30d

Description

Migrated issue, originally created by Jeremy Field (@jdf-id-au)

Using batch_alter_table to change an Enum in sqlite causes CHECK constraint for another Enum to be lost.

Working example at repo.

The documentation makes it look like this shouldn't happen.

When trying to reinstate lost Enum constraints on other columns, only the last batch_op.alter_column call seems to result in a CHECK constraint being created.

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 with the batch_alter_table documentation section on changing Boolean, Enum, and other implicit CHECK datatypes, then reproduce the behavior using the linked working example. Trace how multiple batch_op.alter_column calls handle unchanged Enum constraints; done means existing CHECK constraints are preserved and each intended Enum constraint is recreated.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.