mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-14 20:55:15 +02:00
fix migrations
This commit is contained in:
parent
5c22238c10
commit
16f79aa88b
3 changed files with 74 additions and 33 deletions
|
|
@ -7,6 +7,8 @@ Create Date: 2026-01-13 12:23:31.481643
|
|||
"""
|
||||
from collections.abc import Sequence
|
||||
|
||||
from sqlalchemy import text
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
|
|
@ -18,33 +20,77 @@ depends_on: str | Sequence[str] | None = None
|
|||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# Drop the old unique constraint
|
||||
op.drop_constraint(
|
||||
'uq_searchspace_user_connector_type',
|
||||
'search_source_connectors',
|
||||
type_='unique'
|
||||
)
|
||||
connection = op.get_bind()
|
||||
|
||||
# Create new unique constraint that includes name
|
||||
op.create_unique_constraint(
|
||||
'uq_searchspace_user_connector_type_name',
|
||||
'search_source_connectors',
|
||||
['search_space_id', 'user_id', 'connector_type', 'name']
|
||||
)
|
||||
# Check if old constraint exists before trying to drop it
|
||||
old_constraint_exists = connection.execute(
|
||||
text("""
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE table_name='search_source_connectors'
|
||||
AND constraint_type='UNIQUE'
|
||||
AND constraint_name='uq_searchspace_user_connector_type'
|
||||
""")
|
||||
).scalar()
|
||||
|
||||
if old_constraint_exists:
|
||||
op.drop_constraint(
|
||||
'uq_searchspace_user_connector_type',
|
||||
'search_source_connectors',
|
||||
type_='unique'
|
||||
)
|
||||
|
||||
# Check if new constraint already exists before creating
|
||||
new_constraint_exists = connection.execute(
|
||||
text("""
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE table_name='search_source_connectors'
|
||||
AND constraint_type='UNIQUE'
|
||||
AND constraint_name='uq_searchspace_user_connector_type_name'
|
||||
""")
|
||||
).scalar()
|
||||
|
||||
if not new_constraint_exists:
|
||||
op.create_unique_constraint(
|
||||
'uq_searchspace_user_connector_type_name',
|
||||
'search_source_connectors',
|
||||
['search_space_id', 'user_id', 'connector_type', 'name']
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# Drop the new constraint
|
||||
op.drop_constraint(
|
||||
'uq_searchspace_user_connector_type_name',
|
||||
'search_source_connectors',
|
||||
type_='unique'
|
||||
)
|
||||
connection = op.get_bind()
|
||||
|
||||
# Restore the old constraint
|
||||
op.create_unique_constraint(
|
||||
'uq_searchspace_user_connector_type',
|
||||
'search_source_connectors',
|
||||
['search_space_id', 'user_id', 'connector_type']
|
||||
)
|
||||
# Check if new constraint exists before dropping
|
||||
new_constraint_exists = connection.execute(
|
||||
text("""
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE table_name='search_source_connectors'
|
||||
AND constraint_type='UNIQUE'
|
||||
AND constraint_name='uq_searchspace_user_connector_type_name'
|
||||
""")
|
||||
).scalar()
|
||||
|
||||
if new_constraint_exists:
|
||||
op.drop_constraint(
|
||||
'uq_searchspace_user_connector_type_name',
|
||||
'search_source_connectors',
|
||||
type_='unique'
|
||||
)
|
||||
|
||||
# Only restore old constraint if it doesn't exist
|
||||
old_constraint_exists = connection.execute(
|
||||
text("""
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE table_name='search_source_connectors'
|
||||
AND constraint_type='UNIQUE'
|
||||
AND constraint_name='uq_searchspace_user_connector_type'
|
||||
""")
|
||||
).scalar()
|
||||
|
||||
if not old_constraint_exists:
|
||||
op.create_unique_constraint(
|
||||
'uq_searchspace_user_connector_type',
|
||||
'search_source_connectors',
|
||||
['search_space_id', 'user_id', 'connector_type']
|
||||
)
|
||||
|
|
|
|||
|
|
@ -37,11 +37,6 @@ def upgrade() -> None:
|
|||
|
||||
def downgrade() -> None:
|
||||
"""Remove author_id column from new_chat_messages table."""
|
||||
op.execute(
|
||||
"""
|
||||
DROP INDEX IF EXISTS ix_new_chat_messages_author_id;
|
||||
ALTER TABLE new_chat_messages
|
||||
DROP COLUMN IF EXISTS author_id;
|
||||
"""
|
||||
)
|
||||
op.execute("DROP INDEX IF EXISTS ix_new_chat_messages_author_id")
|
||||
op.execute("ALTER TABLE new_chat_messages DROP COLUMN IF EXISTS author_id")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""Add MCP connector type
|
||||
|
||||
Revision ID: a1b2c3d4e5f6
|
||||
Revises: 61
|
||||
Revises: 63
|
||||
Create Date: 2026-01-09 15:19:51.827647
|
||||
|
||||
"""
|
||||
|
|
@ -11,7 +11,7 @@ from alembic import op
|
|||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'a1b2c3d4e5f6'
|
||||
down_revision: str | None = '61'
|
||||
down_revision: str | None = '63'
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue