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
|
from collections.abc import Sequence
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy import inspect
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
|
|
@ -24,19 +25,28 @@ depends_on: str | Sequence[str] | None = None
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
"""Upgrade schema - Add updated_at field with index to documents."""
|
"""Upgrade schema - Add updated_at field with index to documents."""
|
||||||
op.add_column(
|
connection = op.get_bind()
|
||||||
"documents",
|
inspector = inspect(connection)
|
||||||
sa.Column("updated_at", sa.TIMESTAMP(timezone=True), nullable=True),
|
columns = [col["name"] for col in inspector.get_columns("documents")]
|
||||||
)
|
|
||||||
op.create_index(
|
if "updated_at" not in columns:
|
||||||
"ix_documents_updated_at",
|
op.add_column(
|
||||||
"documents",
|
"documents",
|
||||||
["updated_at"],
|
sa.Column("updated_at", sa.TIMESTAMP(timezone=True), nullable=True),
|
||||||
)
|
)
|
||||||
|
op.create_index(
|
||||||
|
"ix_documents_updated_at",
|
||||||
|
"documents",
|
||||||
|
["updated_at"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
"""Downgrade schema - Remove updated_at field and index."""
|
"""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()
|
||||||
op.drop_index("ix_documents_updated_at", table_name="documents", if_exists=True)
|
inspector = inspect(connection)
|
||||||
op.drop_column("documents", "updated_at")
|
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