mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-17 18:35:19 +02:00
fix: ensure idempotency in alembic migrations by checking for existing columns and indexes before creation
This commit is contained in:
parent
319923fb40
commit
2c8828f60c
1 changed files with 16 additions and 9 deletions
|
|
@ -36,15 +36,22 @@ depends_on: str | Sequence[str] | None = None
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
op.add_column(
|
bind = op.get_bind()
|
||||||
"new_chat_messages",
|
inspector = sa.inspect(bind)
|
||||||
sa.Column("turn_id", sa.String(length=64), nullable=True),
|
columns = {c["name"] for c in inspector.get_columns("new_chat_messages")}
|
||||||
)
|
indexes = {i["name"] for i in inspector.get_indexes("new_chat_messages")}
|
||||||
op.create_index(
|
|
||||||
"ix_new_chat_messages_turn_id",
|
if "turn_id" not in columns:
|
||||||
"new_chat_messages",
|
op.add_column(
|
||||||
["turn_id"],
|
"new_chat_messages",
|
||||||
)
|
sa.Column("turn_id", sa.String(length=64), nullable=True),
|
||||||
|
)
|
||||||
|
if "ix_new_chat_messages_turn_id" not in indexes:
|
||||||
|
op.create_index(
|
||||||
|
"ix_new_chat_messages_turn_id",
|
||||||
|
"new_chat_messages",
|
||||||
|
["turn_id"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue