From 0f441b60416d9e0ae769a6505ee056d5535fcceb Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 20 Apr 2026 17:48:25 +0200 Subject: [PATCH] feat(06-01): add migration 007 setup_completed column and backfill - ALTER TABLE profiles ADD COLUMN setup_completed boolean NOT NULL DEFAULT false - Backfill existing users with categories OR template items to true - UNION covers edge case users with template items but no categories --- supabase/migrations/007_setup_completed.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 supabase/migrations/007_setup_completed.sql diff --git a/supabase/migrations/007_setup_completed.sql b/supabase/migrations/007_setup_completed.sql new file mode 100644 index 0000000..7980ec2 --- /dev/null +++ b/supabase/migrations/007_setup_completed.sql @@ -0,0 +1,18 @@ +-- Migration 007: Add setup_completed to profiles +-- New signups default to false (not set up). +-- Existing users who have any categories are backfilled to true (already set up). +-- Wider backfill also includes users with template items to protect against +-- edge case where user created template items but skipped category creation. + +ALTER TABLE profiles + ADD COLUMN setup_completed boolean NOT NULL DEFAULT false; + +-- Backfill: users with categories OR template items are considered set up +UPDATE profiles +SET setup_completed = true +WHERE id IN ( + SELECT DISTINCT user_id FROM categories + UNION + SELECT t.user_id FROM templates t + INNER JOIN template_items ti ON ti.template_id = t.id +);