mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-08 20:25:19 +02:00
Make migration 24 idempotent
This commit is contained in:
parent
8ed295c053
commit
60a7269ce8
1 changed files with 18 additions and 0 deletions
|
|
@ -7,6 +7,8 @@ Revises: 23
|
||||||
|
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
|
|
@ -16,11 +18,27 @@ branch_labels: str | Sequence[str] | None = None
|
||||||
depends_on: str | Sequence[str] | None = None
|
depends_on: str | Sequence[str] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
def table_exists(table_name: str) -> bool:
|
||||||
|
"""Check if a table exists in the database."""
|
||||||
|
conn = op.get_bind()
|
||||||
|
result = conn.execute(
|
||||||
|
sa.text(
|
||||||
|
"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = :table_name)"
|
||||||
|
),
|
||||||
|
{"table_name": table_name},
|
||||||
|
)
|
||||||
|
return result.scalar()
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
"""
|
"""
|
||||||
Fix any chats with NULL type values by setting them to QNA.
|
Fix any chats with NULL type values by setting them to QNA.
|
||||||
This handles edge cases from previous migrations where type values were not properly migrated.
|
This handles edge cases from previous migrations where type values were not properly migrated.
|
||||||
"""
|
"""
|
||||||
|
# Skip if chats table doesn't exist (fresh database)
|
||||||
|
if not table_exists("chats"):
|
||||||
|
return
|
||||||
|
|
||||||
# Update any NULL type values to QNA (the default chat type)
|
# Update any NULL type values to QNA (the default chat type)
|
||||||
op.execute(
|
op.execute(
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue