sprint8: fix migration 0054 — skip existing owner_id columns
This commit is contained in:
@@ -3,10 +3,6 @@
|
|||||||
Revision ID: 0054
|
Revision ID: 0054
|
||||||
Revises: 0053
|
Revises: 0053
|
||||||
Create Date: 2026-07-29
|
Create Date: 2026-07-29
|
||||||
|
|
||||||
This migration adds owner_id to plugin entity tables (files, folders,
|
|
||||||
calendar_entries, calendars, tasks, subtasks) so that the universal
|
|
||||||
visibility/permission system can be used for plugin entities.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
@@ -18,7 +14,7 @@ down_revision = "0053"
|
|||||||
branch_labels = None
|
branch_labels = None
|
||||||
depends_on = None
|
depends_on = None
|
||||||
|
|
||||||
# Plugin entity tables that need owner_id
|
# Tables that need owner_id
|
||||||
TABLES = [
|
TABLES = [
|
||||||
"files",
|
"files",
|
||||||
"folders",
|
"folders",
|
||||||
@@ -30,7 +26,18 @@ TABLES = [
|
|||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
|
# Check which columns already exist before adding
|
||||||
|
conn = op.get_bind()
|
||||||
for table in TABLES:
|
for table in TABLES:
|
||||||
|
# Check if column already exists
|
||||||
|
result = conn.execute(
|
||||||
|
sa.text(
|
||||||
|
"SELECT column_name FROM information_schema.columns "
|
||||||
|
"WHERE table_name = :table AND column_name = 'owner_id'"
|
||||||
|
),
|
||||||
|
{"table": table},
|
||||||
|
)
|
||||||
|
if result.fetchone() is None:
|
||||||
op.add_column(
|
op.add_column(
|
||||||
table,
|
table,
|
||||||
sa.Column(
|
sa.Column(
|
||||||
@@ -45,5 +52,11 @@ def upgrade() -> None:
|
|||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
for table in TABLES:
|
for table in TABLES:
|
||||||
|
try:
|
||||||
op.drop_index(f"ix_{table}_owner", table_name=table)
|
op.drop_index(f"ix_{table}_owner", table_name=table)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
op.drop_column(table, "owner_id")
|
op.drop_column(table, "owner_id")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user