mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-21 18:55:16 +02:00
fix migration version 45 | upgrade
This commit is contained in:
parent
88eb557161
commit
181df4237e
1 changed files with 22 additions and 12 deletions
|
|
@ -12,6 +12,7 @@ for efficient time-based filtering.
|
|||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import inspect
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
|
@ -24,6 +25,11 @@ depends_on: str | Sequence[str] | None = None
|
|||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema - Add updated_at field with index to documents."""
|
||||
connection = op.get_bind()
|
||||
inspector = inspect(connection)
|
||||
columns = [col["name"] for col in inspector.get_columns("documents")]
|
||||
|
||||
if "updated_at" not in columns:
|
||||
op.add_column(
|
||||
"documents",
|
||||
sa.Column("updated_at", sa.TIMESTAMP(timezone=True), nullable=True),
|
||||
|
|
@ -37,6 +43,10 @@ def upgrade() -> None:
|
|||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema - Remove updated_at field and index."""
|
||||
# Use if_exists to handle cases where index wasn't created (migration modified after apply)
|
||||
connection = op.get_bind()
|
||||
inspector = inspect(connection)
|
||||
columns = [col["name"] for col in inspector.get_columns("documents")]
|
||||
|
||||
if "updated_at" in columns:
|
||||
op.drop_index("ix_documents_updated_at", table_name="documents", if_exists=True)
|
||||
op.drop_column("documents", "updated_at")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue