refactor: use SQLAlchemy inspector for database-agnostic table existence check

Replace PostgreSQL-specific information_schema query with SQLAlchemy's
inspector API that works across all supported database types.
This commit is contained in:
-LAN- 2025-09-03 10:22:20 +08:00
parent 4e8e53c579
commit 62f2288460
No known key found for this signature in database
GPG Key ID: 6BA0D108DED011FF
1 changed files with 6 additions and 8 deletions

View File

@ -8,6 +8,7 @@ Create Date: 2025-09-02 20:12:37.311318
from alembic import op
import models as models
import sqlalchemy as sa
from sqlalchemy import inspect
# revision identifiers, used by Alembic.
@ -51,15 +52,12 @@ def downgrade():
# Restore soft-deleted conversations from backup table if it exists
# Check if backup table exists
result = op.get_bind().execute(sa.text(f"""
SELECT EXISTS (
SELECT FROM information_schema.tables
WHERE table_name = '{backup_table_name}'
)
"""))
# Check if backup table exists using inspector (works for all database types)
bind = op.get_bind()
inspector = inspect(bind)
existing_tables = inspector.get_table_names()
if result.scalar():
if backup_table_name in existing_tables:
# Restore the soft-deleted conversations
op.execute(sa.text(f"""
INSERT INTO conversations