diff --git a/backend/alembic/versions/057_project_collab_prep.py b/backend/alembic/versions/057_project_collab_prep.py index 7b2263b..d3755bf 100644 --- a/backend/alembic/versions/057_project_collab_prep.py +++ b/backend/alembic/versions/057_project_collab_prep.py @@ -17,27 +17,11 @@ depends_on = None def upgrade() -> None: # 1a. Performance indexes for project_tasks - op.create_index( - "ix_project_tasks_project_id", - "project_tasks", - ["project_id"], - ) - op.create_index( - "ix_project_tasks_parent_task_id", - "project_tasks", - ["parent_task_id"], - postgresql_where=sa.text("parent_task_id IS NOT NULL"), - ) - op.create_index( - "ix_project_tasks_project_updated", - "project_tasks", - ["project_id", sa.text("updated_at DESC")], - ) - op.create_index( - "ix_projects_user_updated", - "projects", - ["user_id", sa.text("updated_at DESC")], - ) + # Use IF NOT EXISTS to handle indexes that may already exist on the DB + op.execute("CREATE INDEX IF NOT EXISTS ix_project_tasks_project_id ON project_tasks (project_id)") + op.execute("CREATE INDEX IF NOT EXISTS ix_project_tasks_parent_task_id ON project_tasks (parent_task_id) WHERE parent_task_id IS NOT NULL") + op.execute("CREATE INDEX IF NOT EXISTS ix_project_tasks_project_updated ON project_tasks (project_id, updated_at DESC)") + op.execute("CREATE INDEX IF NOT EXISTS ix_projects_user_updated ON projects (user_id, updated_at DESC)") # 1b. Add user_id to task_comments for multi-user attribution op.add_column( @@ -52,11 +36,7 @@ def upgrade() -> None: ) # Calendar delta polling index (Phase 4 prep) - op.create_index( - "ix_events_calendar_updated", - "calendar_events", - ["calendar_id", sa.text("updated_at DESC")], - ) + op.execute("CREATE INDEX IF NOT EXISTS ix_events_calendar_updated ON calendar_events (calendar_id, updated_at DESC)") def downgrade() -> None: