From 8292e6ec655f3577e15fb3ee45b1e4f9f436f270 Mon Sep 17 00:00:00 2001 From: chihlasm Date: Fri, 10 Apr 2026 05:21:18 +0000 Subject: [PATCH] fix: handle non-default, no-team trees in global content migration Migration 019 only backfills trees with team_id IS NOT NULL. Migration 3a40fe11b427 only covered is_default=TRUE trees. Trees with team_id=NULL and is_default=FALSE (e.g. inactive test trees, pre-team-system content) fell through both passes and triggered the NULL guard. Add two new UPDATE steps after the is_default pass: 1. Assign remaining trees to their author's account (if author has one) 2. Final fallback to PLATFORM_ACCOUNT_ID for any still-NULL rows Co-Authored-By: Claude Sonnet 4.6 --- ...40fe11b427_create_global_content_tables.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/backend/alembic/versions/3a40fe11b427_create_global_content_tables.py b/backend/alembic/versions/3a40fe11b427_create_global_content_tables.py index 01dbac47..0eafb7da 100644 --- a/backend/alembic/versions/3a40fe11b427_create_global_content_tables.py +++ b/backend/alembic/versions/3a40fe11b427_create_global_content_tables.py @@ -105,6 +105,26 @@ def upgrade() -> None: AND account_id IS NULL """) + # ── Assign remaining trees to their author's account ───────────────────── + # Handles trees with no team_id that aren't is_default (e.g. inactive test + # trees, trees created before the team system existed). + op.execute(""" + UPDATE trees + SET account_id = u.account_id + FROM users u + WHERE trees.author_id = u.id + AND trees.account_id IS NULL + AND u.account_id IS NOT NULL + """) + + # ── Final fallback: any still-NULL trees go to platform account ─────────── + # Covers trees whose author has no account (seeded content, system rows). + op.execute(""" + UPDATE trees + SET account_id = '00000000-0000-0000-0000-000000000001' + WHERE account_id IS NULL + """) + # ── Assign global categories/tags/steps to platform account ───────────── op.execute(""" UPDATE tree_categories