mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-05 23:42:21 +00:00
refactor migration to use op.execute pattern
This commit is contained in:
parent
68dc7723af
commit
3a8a9734d6
1 changed files with 17 additions and 18 deletions
|
|
@ -10,8 +10,6 @@ public sharing of chat threads via secure tokenized URLs.
|
|||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
|
|
@ -24,20 +22,19 @@ depends_on: str | Sequence[str] | None = None
|
|||
def upgrade() -> None:
|
||||
"""Add public sharing columns to new_chat_threads."""
|
||||
# Add public_share_token column
|
||||
op.add_column(
|
||||
"new_chat_threads",
|
||||
sa.Column("public_share_token", sa.String(64), nullable=True),
|
||||
op.execute(
|
||||
"""
|
||||
ALTER TABLE new_chat_threads
|
||||
ADD COLUMN IF NOT EXISTS public_share_token VARCHAR(64);
|
||||
"""
|
||||
)
|
||||
|
||||
# Add public_share_enabled column
|
||||
op.add_column(
|
||||
"new_chat_threads",
|
||||
sa.Column(
|
||||
"public_share_enabled",
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
server_default="false",
|
||||
),
|
||||
# Add public_share_enabled column with default false
|
||||
op.execute(
|
||||
"""
|
||||
ALTER TABLE new_chat_threads
|
||||
ADD COLUMN IF NOT EXISTS public_share_enabled BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
"""
|
||||
)
|
||||
|
||||
# Add unique partial index on public_share_token (only non-null values)
|
||||
|
|
@ -45,7 +42,7 @@ def upgrade() -> None:
|
|||
"""
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ix_new_chat_threads_public_share_token
|
||||
ON new_chat_threads(public_share_token)
|
||||
WHERE public_share_token IS NOT NULL
|
||||
WHERE public_share_token IS NOT NULL;
|
||||
"""
|
||||
)
|
||||
|
||||
|
|
@ -54,7 +51,7 @@ def upgrade() -> None:
|
|||
"""
|
||||
CREATE INDEX IF NOT EXISTS ix_new_chat_threads_public_share_enabled
|
||||
ON new_chat_threads(public_share_enabled)
|
||||
WHERE public_share_enabled = TRUE
|
||||
WHERE public_share_enabled = TRUE;
|
||||
"""
|
||||
)
|
||||
|
||||
|
|
@ -63,5 +60,7 @@ def downgrade() -> None:
|
|||
"""Remove public sharing columns from new_chat_threads."""
|
||||
op.execute("DROP INDEX IF EXISTS ix_new_chat_threads_public_share_enabled")
|
||||
op.execute("DROP INDEX IF EXISTS ix_new_chat_threads_public_share_token")
|
||||
op.drop_column("new_chat_threads", "public_share_enabled")
|
||||
op.drop_column("new_chat_threads", "public_share_token")
|
||||
op.execute(
|
||||
"ALTER TABLE new_chat_threads DROP COLUMN IF EXISTS public_share_enabled"
|
||||
)
|
||||
op.execute("ALTER TABLE new_chat_threads DROP COLUMN IF EXISTS public_share_token")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue