Skip to content

Align Alembic metadata with models - #43

Merged
AlexKitipov merged 1 commit into
mainfrom
codex/ensure-alembic-metadata-consistency
Jun 9, 2026
Merged

Align Alembic metadata with models#43
AlexKitipov merged 1 commit into
mainfrom
codex/ensure-alembic-metadata-consistency

Conversation

@AlexKitipov

Copy link
Copy Markdown
Owner

Motivation

  • Ensure Alembic autogeneration sees the full SQLAlchemy metadata and that model definitions match migrations so future alembic revision --autogenerate yields no unexpected drift.
  • Consolidate all models on a single shared Base to avoid inconsistent metadata and type/index mismatches.

Description

  • Import every model class in migrations/env.py so target_metadata = Base.metadata is fully populated during autogenerate and keep compare_type=True enabled.
  • Point all model modules to the single declarative base by importing Base from app.database.base instead of app.database.
  • Update the initial migration migrations/versions/0001_initial_schema.py to match the models (change links.click_count to BigInteger, make indexes/unique constraints match the model-generated names and uniqueness, and add/remove indexes so names and properties align).
  • Chose to edit the initial migration (rather than add a corrective migration) because this repo only contains the initial schema migration, and aligning it removes drift for a clean autogenerate.

Testing

  • Ran an SQLite upgrade + autogenerate drift check with DATABASE_URL=sqlite:///$tmp/test.db alembic upgrade head && DATABASE_URL=sqlite:///$tmp/test.db alembic check, and alembic check reported "No new upgrade operations detected" indicating no drift.
  • Generated an autogenerate revision after the changes and confirmed the produced revision was empty (pass) for both attempts, indicating metadata/migration alignment.
  • Compiled code with python -m compileall app migrations and ran the test suite with pytest, where all tests passed (8 passed).

Codex Task

@AlexKitipov
AlexKitipov merged commit 48d7738 into main Jun 9, 2026
2 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4be036c519

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

sa.Column("title", sa.String(length=255), nullable=True),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("click_count", sa.Integer(), nullable=False, server_default="0"),
sa.Column("click_count", sa.BigInteger(), nullable=False, server_default="0"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add a forward migration for the BigInteger change

In any database that has already run revision 0001_initial_schema, Alembic will see the revision as applied and will not re-run this edited initial migration. Those environments therefore keep the old links.click_count INTEGER column while the model now expects BigInteger, so high-traffic links can still overflow at the 32-bit integer limit and Alembic drift checks will continue reporting the type mismatch. Please add a new migration that alters existing schemas instead of relying only on the rewritten initial revision.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant