feat(db): add migration chain CI validation, pre-commit hook, script template, docs, and tests

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-17 09:18:11 +00:00
parent 935e8a626e
commit aa49fa3ae6
7 changed files with 641 additions and 8 deletions
+40
View File
@@ -0,0 +1,40 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from typing import Union
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, None] = ${repr(down_revision)}
depends_on: Union[str, None] = None
def upgrade() -> None:
"""${message}."""
# Use ``op.batch_alter_table()`` for SQLite compatibility.
# Always check whether the table/column already exists before altering
# to keep migrations idempotent (safe to re-run).
#
# Example add a column only if it is missing:
#
# conn = op.get_bind()
# inspector = sa.inspect(conn)
# if "my_table" in inspector.get_table_names():
# existing = {c["name"] for c in inspector.get_columns("my_table")}
# if "new_col" not in existing:
# with op.batch_alter_table("my_table") as batch_op:
# batch_op.add_column(sa.Column("new_col", sa.String(128), nullable=True))
${upgrades if upgrades else "pass"}
def downgrade() -> None:
"""Reverse ${message}."""
${downgrades if downgrades else "pass"}