mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-19 18:45:15 +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,10 +36,17 @@ depends_on: str | Sequence[str] | None = None
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
|
bind = op.get_bind()
|
||||||
|
inspector = sa.inspect(bind)
|
||||||
|
columns = {c["name"] for c in inspector.get_columns("new_chat_messages")}
|
||||||
|
indexes = {i["name"] for i in inspector.get_indexes("new_chat_messages")}
|
||||||
|
|
||||||
|
if "turn_id" not in columns:
|
||||||
op.add_column(
|
op.add_column(
|
||||||
"new_chat_messages",
|
"new_chat_messages",
|
||||||
sa.Column("turn_id", sa.String(length=64), nullable=True),
|
sa.Column("turn_id", sa.String(length=64), nullable=True),
|
||||||
)
|
)
|
||||||
|
if "ix_new_chat_messages_turn_id" not in indexes:
|
||||||
op.create_index(
|
op.create_index(
|
||||||
"ix_new_chat_messages_turn_id",
|
"ix_new_chat_messages_turn_id",
|
||||||
"new_chat_messages",
|
"new_chat_messages",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue