Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

feat(database): add a unique index on each account's identity

spacesdrive3e2827d47190
diff --git a/supabase/migrations/20261017171632_index_accounts_identity.sql b/supabase/migrations/20261017171632_index_accounts_identity.sql
new file mode 100644
index 0000000..71f9ad0
--- /dev/null
+++ b/supabase/migrations/20261017171632_index_accounts_identity.sql
@@ -0,0 +1,7 @@
+-- one row per user, platform and account, so two adds at the same moment cannot store the same account twice; the
+-- identity is the field each platform's account is matched by in accountService
+create unique index if not exists accounts_identity_key on public.accounts (
+ user_id,
+ platform,
+ (case platform when 'youtube' then data ->> 'channelId' when 'reddit' then data ->> 'username' when 'instagram' then data ->> 'igUserId' end)
+);
diff --git a/supabase/rollbacks/20261017171632_index_accounts_identity.sql b/supabase/rollbacks/20261017171632_index_accounts_identity.sql
new file mode 100644
index 0000000..9fb227c
--- /dev/null
+++ b/supabase/rollbacks/20261017171632_index_accounts_identity.sql
@@ -0,0 +1 @@
+drop index if exists public.accounts_identity_key;