fix: Migration 0104 — check table existence before ALTER, remove companies table
This commit is contained in:
@@ -35,12 +35,17 @@ def upgrade() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# 2. Add embedding columns to other tables (from plugin migration 0002)
|
# 2. Add embedding columns to other tables (from plugin migration 0002)
|
||||||
for table in ["mails", "companies", "files", "calendar_entries"]:
|
for table in ["mails", "files", "calendar_entries"]:
|
||||||
result = conn.execute(sa.text(
|
result = conn.execute(sa.text(
|
||||||
f"SELECT column_name FROM information_schema.columns "
|
f"SELECT column_name FROM information_schema.columns "
|
||||||
f"WHERE table_name = '{table}' AND column_name = 'embedding'"
|
f"WHERE table_name = '{table}' AND column_name = 'embedding'"
|
||||||
))
|
))
|
||||||
if result.fetchone() is None:
|
if result.fetchone() is None:
|
||||||
|
# Check if table exists
|
||||||
|
table_exists = conn.execute(sa.text(
|
||||||
|
f"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = '{table}')"
|
||||||
|
)).scalar()
|
||||||
|
if table_exists:
|
||||||
op.execute(f"ALTER TABLE {table} ADD COLUMN embedding vector(768)")
|
op.execute(f"ALTER TABLE {table} ADD COLUMN embedding vector(768)")
|
||||||
op.execute(
|
op.execute(
|
||||||
f"CREATE INDEX IF NOT EXISTS ix_{table}_embedding "
|
f"CREATE INDEX IF NOT EXISTS ix_{table}_embedding "
|
||||||
@@ -53,6 +58,10 @@ def upgrade() -> None:
|
|||||||
"WHERE table_name = 'tags' AND column_name = 'embedding'"
|
"WHERE table_name = 'tags' AND column_name = 'embedding'"
|
||||||
))
|
))
|
||||||
if result.fetchone() is None:
|
if result.fetchone() is None:
|
||||||
|
table_exists = conn.execute(sa.text(
|
||||||
|
"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'tags')"
|
||||||
|
)).scalar()
|
||||||
|
if table_exists:
|
||||||
op.execute("ALTER TABLE tags ADD COLUMN embedding vector(384)")
|
op.execute("ALTER TABLE tags ADD COLUMN embedding vector(384)")
|
||||||
op.execute(
|
op.execute(
|
||||||
"CREATE INDEX IF NOT EXISTS ix_tags_embedding "
|
"CREATE INDEX IF NOT EXISTS ix_tags_embedding "
|
||||||
|
|||||||
Reference in New Issue
Block a user