feat: Phase 1 tenant isolation — add account_id to all tenant tables #133

Merged
chihlasm merged 37 commits from feat/tenant-isolation-phase-1 into main 2026-04-10 04:57:53 +00:00
Showing only changes of commit d2ebc4f182 - Show all commits

View File

@@ -51,16 +51,26 @@ def upgrade() -> None:
op.create_index('ix_platform_steps_step_type', 'platform_steps', ['step_type']) op.create_index('ix_platform_steps_step_type', 'platform_steps', ['step_type'])
# ── Copy is_default=TRUE trees → template_trees ───────────────────────── # ── Copy is_default=TRUE trees → template_trees ─────────────────────────
# Note: trees.tags is a relationship via tree_tags join table — no direct column.
# Aggregate tag names via a correlated subquery.
op.execute(""" op.execute("""
INSERT INTO template_trees INSERT INTO template_trees
(id, name, description, category, tree_type, tree_structure, (id, name, description, category, tree_type, tree_structure,
tags, is_active, created_at, updated_at, source_tree_id) tags, is_active, created_at, updated_at, source_tree_id)
SELECT SELECT
gen_random_uuid(), name, description, category, tree_type, gen_random_uuid(), t.name, t.description, t.category, t.tree_type,
tree_structure, COALESCE(tags, '[]'::jsonb), is_active, t.tree_structure,
COALESCE(created_at, NOW()), COALESCE(updated_at, NOW()), id COALESCE(
FROM trees (SELECT jsonb_agg(tt.name ORDER BY tt.name)
WHERE is_default = TRUE FROM tree_tag_assignments ta
JOIN tree_tags tt ON tt.id = ta.tag_id
WHERE ta.tree_id = t.id),
'[]'::jsonb
),
t.is_active,
COALESCE(t.created_at, NOW()), COALESCE(t.updated_at, NOW()), t.id
FROM trees t
WHERE t.is_default = TRUE
""") """)
# ── Copy visibility='public' steps → platform_steps ───────────────────── # ── Copy visibility='public' steps → platform_steps ─────────────────────