2026-10-09 06:46:36 -04:00
|
|
|
|
"""${message}
|
|
|
|
|
|
|
|
|
|
|
|
Revision ID: ${up_revision}
|
|
|
|
|
|
Revises: ${down_revision | comma,n}
|
|
|
|
|
|
Create Date: ${create_date}
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
2026-10-09 22:44:05 -04:00
|
|
|
|
from collections.abc import Sequence
|
2026-10-09 06:46:36 -04:00
|
|
|
|
|
|
|
|
|
|
from alembic import op
|
|
|
|
|
|
import sqlalchemy as sa
|
|
|
|
|
|
${imports if imports else ""}
|
|
|
|
|
|
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
|
|
|
|
revision: str = ${repr(up_revision)}
|
2026-10-09 22:44:05 -04:00
|
|
|
|
down_revision: str | Sequence[str] | None = ${repr(down_revision)}
|
|
|
|
|
|
branch_labels: str | Sequence[str] | None = ${repr(branch_labels)}
|
|
|
|
|
|
depends_on: str | Sequence[str] | None = ${repr(depends_on)}
|
2026-10-09 06:46:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade() -> None:
|
2026-10-09 22:44:05 -04:00
|
|
|
|
"""应用迁移。"""
|
2026-10-09 06:46:36 -04:00
|
|
|
|
${upgrades if upgrades else "pass"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade() -> None:
|
2026-10-09 22:44:05 -04:00
|
|
|
|
"""回滚迁移。
|
|
|
|
|
|
|
|
|
|
|
|
**注意(autogenerate 不会替你处理)**:生成的 `op.drop_index` 与
|
|
|
|
|
|
`op.drop_table` 顺序需人工检查 —— 若某索引是外键的唯一支撑索引,
|
|
|
|
|
|
单独 drop_index 会报 MySQL 1553(needed in a foreign key constraint)。
|
|
|
|
|
|
**整表回滚应只保留 `op.drop_table`**,DROP TABLE 会连带删除索引与外键。
|
|
|
|
|
|
"""
|
2026-10-09 06:46:36 -04:00
|
|
|
|
${downgrades if downgrades else "pass"}
|