From 6fed283e4c126ca3ce1d74354fbf7e2b64601269 Mon Sep 17 00:00:00 2001 From: "DESKTOP-JKIE562\\PC" <1013397054@qq.com> Date: Thu, 4 Jun 2026 13:49:46 +0800 Subject: [PATCH] add --- ...a3b4c5_repair_schema_drift_indexes_and_.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 backend/migrations/versions/d0e1f2a3b4c5_repair_schema_drift_indexes_and_.py diff --git a/backend/migrations/versions/d0e1f2a3b4c5_repair_schema_drift_indexes_and_.py b/backend/migrations/versions/d0e1f2a3b4c5_repair_schema_drift_indexes_and_.py new file mode 100644 index 00000000..42ff33e8 --- /dev/null +++ b/backend/migrations/versions/d0e1f2a3b4c5_repair_schema_drift_indexes_and_.py @@ -0,0 +1,52 @@ +"""repair schema drift indexes and constraints + +Revision ID: d0e1f2a3b4c5 +Revises: c9d8e7f6a5b4 +Create Date: 2026-06-03 12:00:00.000000 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'd0e1f2a3b4c5' +down_revision = 'c9d8e7f6a5b4' +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_index('ix_kb_documents_group_id', 'kb_documents', ['group_id'], unique=False) + op.create_index( + 'ix_kb_document_versions_document_id', + 'kb_document_versions', + ['document_id'], + unique=False, + ) + op.create_index('ix_schedule_tasks_last_run_at', 'schedule_tasks', ['last_run_at'], unique=False) + op.create_index('ix_schedule_tasks_created_at', 'schedule_tasks', ['created_at'], unique=False) + + op.execute("UPDATE schedule_runs SET wecom_notified = false WHERE wecom_notified IS NULL") + op.alter_column( + 'schedule_runs', + 'wecom_notified', + existing_type=sa.Boolean(), + nullable=False, + existing_server_default=sa.text('false'), + ) + + +def downgrade(): + op.alter_column( + 'schedule_runs', + 'wecom_notified', + existing_type=sa.Boolean(), + nullable=True, + existing_server_default=sa.text('false'), + ) + + op.drop_index('ix_schedule_tasks_created_at', table_name='schedule_tasks') + op.drop_index('ix_schedule_tasks_last_run_at', table_name='schedule_tasks') + op.drop_index('ix_kb_document_versions_document_id', table_name='kb_document_versions') + op.drop_index('ix_kb_documents_group_id', table_name='kb_documents')