From b7ccd9e6c3d8be51d2b930ecb4117df1fbcc7d6c Mon Sep 17 00:00:00 2001 From: Agent Zero Date: Wed, 29 Jul 2026 02:35:32 +0200 Subject: [PATCH] =?UTF-8?q?sprint8:=20fix=20migration=200054=20=E2=80=94?= =?UTF-8?q?=20skip=20existing=20owner=5Fid=20columns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alembic/versions/0054_plugin_owner_id.py | 43 +++++++++++++++--------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/alembic/versions/0054_plugin_owner_id.py b/alembic/versions/0054_plugin_owner_id.py index 4274dba..a0c802b 100644 --- a/alembic/versions/0054_plugin_owner_id.py +++ b/alembic/versions/0054_plugin_owner_id.py @@ -3,10 +3,6 @@ Revision ID: 0054 Revises: 0053 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 @@ -18,7 +14,7 @@ down_revision = "0053" branch_labels = None depends_on = None -# Plugin entity tables that need owner_id +# Tables that need owner_id TABLES = [ "files", "folders", @@ -30,20 +26,37 @@ TABLES = [ def upgrade() -> None: + # Check which columns already exist before adding + conn = op.get_bind() for table in TABLES: - op.add_column( - table, - sa.Column( - "owner_id", - PGUUID(as_uuid=True), - sa.ForeignKey("users.id", ondelete="SET NULL"), - nullable=True, + # 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}, ) - op.create_index(f"ix_{table}_owner", table, ["owner_id"]) + if result.fetchone() is None: + op.add_column( + table, + sa.Column( + "owner_id", + PGUUID(as_uuid=True), + sa.ForeignKey("users.id", ondelete="SET NULL"), + nullable=True, + ), + ) + op.create_index(f"ix_{table}_owner", table, ["owner_id"]) def downgrade() -> None: for table in TABLES: - op.drop_index(f"ix_{table}_owner", table_name=table) - op.drop_column(table, "owner_id") + try: + op.drop_index(f"ix_{table}_owner", table_name=table) + except Exception: + pass + try: + op.drop_column(table, "owner_id") + except Exception: + pass