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.

refactor(database): split the automation migrations to one entity each

spacesdrive05ad2a792a45
diff --git a/backend/tests/database/migrations.test.ts b/backend/tests/database/migrations.test.ts
index e56d3e3..21b3268 100644
--- a/backend/tests/database/migrations.test.ts
+++ b/backend/tests/database/migrations.test.ts
@@ -8,6 +8,8 @@ const migrations = readdirSync(`${supabase}migrations`).sort();
const rollbacks = readdirSync(`${supabase}rollbacks`).sort();
const read = (folder: string, name: string) => readFileSync(`${supabase}${folder}/${name}`, 'utf8');
const isBaseline = (name: string) => /^\d{14}_baseline_/.test(name);
+// migrations before this version were applied to production before the rule and stay as recorded
+const ONE_ENTITY_FROM = '20261016100000';
describe('database migrations', () => {
test('every migration is named <14 digit version>_<lowercase name>.sql with a unique version', () => {
@@ -45,6 +47,16 @@ describe('database migrations', () => {
}
});
+ test('every migration from the one-entity rule on creates one entity: a table, its access, a trigger, an index or a function', () => {
+ for (const name of migrations.filter(file => file.slice(0, 14) >= ONE_ENTITY_FROM)) {
+ const sql = read('migrations', name);
+ const creates = sql.match(/create (?:table|(?:unique )?index|trigger|or replace function|function|policy|view)/gi) ?? [];
+ const access = /enable row level security|revoke all on table/i.test(sql) ? 1 : 0;
+ assert.ok(creates.length + access <= 1, `${name} creates ${creates.length + access} entities; split it into one file each`);
+ assert.ok(read('rollbacks', name).trim().length > 0, `${name} has an empty rollback`);
+ }
+ });
+
test('no file uses an em or en dash', () => {
for (const name of migrations) assert.doesNotMatch(read('migrations', name), /[–—]/, name);
for (const name of rollbacks) assert.doesNotMatch(read('rollbacks', name), /[–—]/, name);
diff --git a/supabase/migrations/20261016100000_create_automation_accounts.sql b/supabase/migrations/20261016100000_create_automation_accounts.sql
index 9d8c7f7..94c3897 100644
--- a/supabase/migrations/20261016100000_create_automation_accounts.sql
+++ b/supabase/migrations/20261016100000_create_automation_accounts.sql
@@ -15,10 +15,3 @@ create table public.automation_accounts (
constraint automation_accounts_paused_reason_check check (paused_reason is null or char_length(paused_reason) <= 200),
constraint automation_accounts_cooldown_reason_check check (cooldown_reason is null or char_length(cooldown_reason) <= 200)
);
-
--- only the Worker's service role reads the table; the anon key ships in every browser
-alter table public.automation_accounts enable row level security;
-revoke all on table public.automation_accounts from anon, authenticated;
-
-create trigger automation_accounts_set_updated_at before update on public.automation_accounts
- for each row execute function public.set_updated_at();
diff --git a/supabase/migrations/20261016100100_revoke_browser_access_automation_accounts.sql b/supabase/migrations/20261016100100_revoke_browser_access_automation_accounts.sql
new file mode 100644
index 0000000..9543085
--- /dev/null
+++ b/supabase/migrations/20261016100100_revoke_browser_access_automation_accounts.sql
@@ -0,0 +1,3 @@
+-- only the Worker's service role reads automation_accounts; the anon key ships in every browser
+alter table public.automation_accounts enable row level security;
+revoke all on table public.automation_accounts from anon, authenticated;
diff --git a/supabase/migrations/20261016100200_add_automation_accounts_updated_at_trigger.sql b/supabase/migrations/20261016100200_add_automation_accounts_updated_at_trigger.sql
new file mode 100644
index 0000000..0509f21
--- /dev/null
+++ b/supabase/migrations/20261016100200_add_automation_accounts_updated_at_trigger.sql
@@ -0,0 +1,3 @@
+-- set_updated_at() keeps updated_at, so no query has to set it
+create trigger automation_accounts_set_updated_at before update on public.automation_accounts
+ for each row execute function public.set_updated_at();
diff --git a/supabase/migrations/20261016100300_create_automation_attempts.sql b/supabase/migrations/20261016100300_create_automation_attempts.sql
deleted file mode 100644
index dcf7abf..0000000
--- a/supabase/migrations/20261016100300_create_automation_attempts.sql
+++ /dev/null
@@ -1,36 +0,0 @@
--- one row per private reply request sent to Instagram, which is what the sending limits count
-create table public.automation_attempts (
- id text primary key,
- user_id uuid not null references auth.users (id) on delete cascade,
- account_id text not null,
- automation_comment_id text not null references public.automation_comments (id) on delete cascade,
- rule_id text references public.automation_rules (id) on delete set null,
- recipient_id text,
- outcome text not null default 'sending',
- error_code integer,
- error_subcode integer,
- http_status integer,
- started_at timestamptz not null default now(),
- finished_at timestamptz,
- created_at timestamptz not null default now(),
- updated_at timestamptz not null default now(),
- constraint automation_attempts_account_fkey foreign key (account_id, user_id)
- references public.accounts (id, user_id) on delete cascade,
- constraint automation_attempts_outcome_check check (outcome in ('sending', 'accepted', 'rejected', 'rate_limited', 'ambiguous'))
-);
-
--- only the Worker's service role reads the table; the anon key ships in every browser
-alter table public.automation_attempts enable row level security;
-revoke all on table public.automation_attempts from anon, authenticated;
-
-create trigger automation_attempts_set_updated_at before update on public.automation_attempts
- for each row execute function public.set_updated_at();
-
--- reserve_automation_send counts the last hour at each scope, and the last day per recipient
-create index automation_attempts_started_at_idx on public.automation_attempts (started_at);
-create index automation_attempts_user_id_started_at_idx on public.automation_attempts (user_id, started_at);
-create index automation_attempts_account_id_started_at_idx on public.automation_attempts (account_id, started_at);
-create index automation_attempts_rule_id_started_at_idx on public.automation_attempts (rule_id, started_at) where rule_id is not null;
-create index automation_attempts_recipient_idx on public.automation_attempts (account_id, recipient_id, started_at);
--- finish_automation_send and the claim close the attempts of one comment
-create index automation_attempts_comment_idx on public.automation_attempts (automation_comment_id);
diff --git a/supabase/migrations/20261016100100_create_automation_rules.sql b/supabase/migrations/20261016100300_create_automation_rules.sql
similarity index 69%
rename from supabase/migrations/20261016100100_create_automation_rules.sql
rename to supabase/migrations/20261016100300_create_automation_rules.sql
index e629c8b..53d0151 100644
--- a/supabase/migrations/20261016100100_create_automation_rules.sql
+++ b/supabase/migrations/20261016100300_create_automation_rules.sql
@@ -26,15 +26,3 @@ create table public.automation_rules (
-- Instagram allows 750 private replies an hour per account for posts and reels
constraint automation_rules_hourly_limit_check check (hourly_limit is null or hourly_limit between 1 and 750)
);
-
--- only the Worker's service role reads the table; the anon key ships in every browser
-alter table public.automation_rules enable row level security;
-revoke all on table public.automation_rules from anon, authenticated;
-
-create trigger automation_rules_set_updated_at before update on public.automation_rules
- for each row execute function public.set_updated_at();
-
--- automationRules.listForUser: where user_id = $1 order by created_at, id
-create index automation_rules_user_id_created_at_idx on public.automation_rules (user_id, created_at, id);
--- the webhook reads only the enabled rules of an account
-create index automation_rules_enabled_account_idx on public.automation_rules (account_id) where enabled;
diff --git a/supabase/migrations/20261016100400_revoke_browser_access_automation_rules.sql b/supabase/migrations/20261016100400_revoke_browser_access_automation_rules.sql
new file mode 100644
index 0000000..fec75e5
--- /dev/null
+++ b/supabase/migrations/20261016100400_revoke_browser_access_automation_rules.sql
@@ -0,0 +1,3 @@
+-- only the Worker's service role reads automation_rules; the anon key ships in every browser
+alter table public.automation_rules enable row level security;
+revoke all on table public.automation_rules from anon, authenticated;
diff --git a/supabase/migrations/20261016100500_add_automation_rules_updated_at_trigger.sql b/supabase/migrations/20261016100500_add_automation_rules_updated_at_trigger.sql
new file mode 100644
index 0000000..e4e266c
--- /dev/null
+++ b/supabase/migrations/20261016100500_add_automation_rules_updated_at_trigger.sql
@@ -0,0 +1,3 @@
+-- set_updated_at() keeps updated_at, so no query has to set it
+create trigger automation_rules_set_updated_at before update on public.automation_rules
+ for each row execute function public.set_updated_at();
diff --git a/supabase/migrations/20261016100600_index_automation_rules_user_id_created_at.sql b/supabase/migrations/20261016100600_index_automation_rules_user_id_created_at.sql
new file mode 100644
index 0000000..8f0f6ab
--- /dev/null
+++ b/supabase/migrations/20261016100600_index_automation_rules_user_id_created_at.sql
@@ -0,0 +1,2 @@
+-- automationRules.listForUser: where user_id = $1 order by created_at, id
+create index automation_rules_user_id_created_at_idx on public.automation_rules (user_id, created_at, id);
diff --git a/supabase/migrations/20261016100700_index_automation_rules_enabled_account.sql b/supabase/migrations/20261016100700_index_automation_rules_enabled_account.sql
new file mode 100644
index 0000000..66d6427
--- /dev/null
+++ b/supabase/migrations/20261016100700_index_automation_rules_enabled_account.sql
@@ -0,0 +1,2 @@
+-- the webhook reads only the enabled rules of an account
+create index automation_rules_enabled_account_idx on public.automation_rules (account_id) where enabled;
diff --git a/supabase/migrations/20261016100200_create_automation_comments.sql b/supabase/migrations/20261016100800_create_automation_comments.sql
similarity index 63%
rename from supabase/migrations/20261016100200_create_automation_comments.sql
rename to supabase/migrations/20261016100800_create_automation_comments.sql
index 4980a7d..aa022f5 100644
--- a/supabase/migrations/20261016100200_create_automation_comments.sql
+++ b/supabase/migrations/20261016100800_create_automation_comments.sql
@@ -38,21 +38,3 @@ create table public.automation_comments (
constraint automation_comments_text_check check (text is null or char_length(text) <= 2200),
constraint automation_comments_error_message_check check (error_message is null or char_length(error_message) <= 500)
);
-
--- only the Worker's service role reads the table; the anon key ships in every browser
-alter table public.automation_comments enable row level security;
-revoke all on table public.automation_comments from anon, authenticated;
-
-create trigger automation_comments_set_updated_at before update on public.automation_comments
- for each row execute function public.set_updated_at();
-
--- claim_automation_comments: jobs that are due, oldest first
-create index automation_comments_due_idx on public.automation_comments (next_attempt_at) where status in ('queued', 'retry_wait');
--- claim_automation_comments: jobs whose run stopped holding them
-create index automation_comments_claimed_idx on public.automation_comments (claimed_at) where status in ('processing', 'sending');
--- automationComments.listForUser and automation_stats: where user_id = $1 order by created_at desc
-create index automation_comments_user_id_created_at_idx on public.automation_comments (user_id, created_at desc);
--- removing a rule clears rule_id on its comments
-create index automation_comments_rule_id_idx on public.automation_comments (rule_id) where rule_id is not null;
--- the daily retention delete across all users
-create index automation_comments_created_at_idx on public.automation_comments (created_at);
diff --git a/supabase/migrations/20261016100900_revoke_browser_access_automation_comments.sql b/supabase/migrations/20261016100900_revoke_browser_access_automation_comments.sql
new file mode 100644
index 0000000..4ea7344
--- /dev/null
+++ b/supabase/migrations/20261016100900_revoke_browser_access_automation_comments.sql
@@ -0,0 +1,3 @@
+-- only the Worker's service role reads automation_comments; the anon key ships in every browser
+alter table public.automation_comments enable row level security;
+revoke all on table public.automation_comments from anon, authenticated;
diff --git a/supabase/migrations/20261016101000_add_automation_comments_updated_at_trigger.sql b/supabase/migrations/20261016101000_add_automation_comments_updated_at_trigger.sql
new file mode 100644
index 0000000..c872e1b
--- /dev/null
+++ b/supabase/migrations/20261016101000_add_automation_comments_updated_at_trigger.sql
@@ -0,0 +1,3 @@
+-- set_updated_at() keeps updated_at, so no query has to set it
+create trigger automation_comments_set_updated_at before update on public.automation_comments
+ for each row execute function public.set_updated_at();
diff --git a/supabase/migrations/20261016101100_index_automation_comments_due.sql b/supabase/migrations/20261016101100_index_automation_comments_due.sql
new file mode 100644
index 0000000..4958c1c
--- /dev/null
+++ b/supabase/migrations/20261016101100_index_automation_comments_due.sql
@@ -0,0 +1,2 @@
+-- claim_automation_comments: jobs that are due, oldest first; partial, so the history is left out
+create index automation_comments_due_idx on public.automation_comments (next_attempt_at) where status in ('queued', 'retry_wait');
diff --git a/supabase/migrations/20261016101200_index_automation_comments_claimed.sql b/supabase/migrations/20261016101200_index_automation_comments_claimed.sql
new file mode 100644
index 0000000..2819bd2
--- /dev/null
+++ b/supabase/migrations/20261016101200_index_automation_comments_claimed.sql
@@ -0,0 +1,2 @@
+-- claim_automation_comments: jobs whose run stopped holding them
+create index automation_comments_claimed_idx on public.automation_comments (claimed_at) where status in ('processing', 'sending');
diff --git a/supabase/migrations/20261016101300_index_automation_comments_user_id_created_at.sql b/supabase/migrations/20261016101300_index_automation_comments_user_id_created_at.sql
new file mode 100644
index 0000000..f10ee66
--- /dev/null
+++ b/supabase/migrations/20261016101300_index_automation_comments_user_id_created_at.sql
@@ -0,0 +1,2 @@
+-- automationComments.listForUser and automation_stats: where user_id = $1 order by created_at desc
+create index automation_comments_user_id_created_at_idx on public.automation_comments (user_id, created_at desc);
diff --git a/supabase/migrations/20261016101400_index_automation_comments_rule_id.sql b/supabase/migrations/20261016101400_index_automation_comments_rule_id.sql
new file mode 100644
index 0000000..e325e1d
--- /dev/null
+++ b/supabase/migrations/20261016101400_index_automation_comments_rule_id.sql
@@ -0,0 +1,2 @@
+-- removing a rule clears rule_id on its comments, and stats filter by rule
+create index automation_comments_rule_id_idx on public.automation_comments (rule_id) where rule_id is not null;
diff --git a/supabase/migrations/20261016101500_index_automation_comments_created_at.sql b/supabase/migrations/20261016101500_index_automation_comments_created_at.sql
new file mode 100644
index 0000000..e0350a0
--- /dev/null
+++ b/supabase/migrations/20261016101500_index_automation_comments_created_at.sql
@@ -0,0 +1,2 @@
+-- the daily retention delete across all users
+create index automation_comments_created_at_idx on public.automation_comments (created_at);
diff --git a/supabase/migrations/20261016101600_create_automation_attempts.sql b/supabase/migrations/20261016101600_create_automation_attempts.sql
new file mode 100644
index 0000000..a2390da
--- /dev/null
+++ b/supabase/migrations/20261016101600_create_automation_attempts.sql
@@ -0,0 +1,20 @@
+-- one row per private reply request sent to Instagram, which is what the sending limits count
+create table public.automation_attempts (
+ id text primary key,
+ user_id uuid not null references auth.users (id) on delete cascade,
+ account_id text not null,
+ automation_comment_id text not null references public.automation_comments (id) on delete cascade,
+ rule_id text references public.automation_rules (id) on delete set null,
+ recipient_id text,
+ outcome text not null default 'sending',
+ error_code integer,
+ error_subcode integer,
+ http_status integer,
+ started_at timestamptz not null default now(),
+ finished_at timestamptz,
+ created_at timestamptz not null default now(),
+ updated_at timestamptz not null default now(),
+ constraint automation_attempts_account_fkey foreign key (account_id, user_id)
+ references public.accounts (id, user_id) on delete cascade,
+ constraint automation_attempts_outcome_check check (outcome in ('sending', 'accepted', 'rejected', 'rate_limited', 'ambiguous'))
+);
diff --git a/supabase/migrations/20261016101700_revoke_browser_access_automation_attempts.sql b/supabase/migrations/20261016101700_revoke_browser_access_automation_attempts.sql
new file mode 100644
index 0000000..da3e8c5
--- /dev/null
+++ b/supabase/migrations/20261016101700_revoke_browser_access_automation_attempts.sql
@@ -0,0 +1,3 @@
+-- only the Worker's service role reads automation_attempts; the anon key ships in every browser
+alter table public.automation_attempts enable row level security;
+revoke all on table public.automation_attempts from anon, authenticated;
diff --git a/supabase/migrations/20261016101800_add_automation_attempts_updated_at_trigger.sql b/supabase/migrations/20261016101800_add_automation_attempts_updated_at_trigger.sql
new file mode 100644
index 0000000..bc463a2
--- /dev/null
+++ b/supabase/migrations/20261016101800_add_automation_attempts_updated_at_trigger.sql
@@ -0,0 +1,3 @@
+-- set_updated_at() keeps updated_at, so no query has to set it
+create trigger automation_attempts_set_updated_at before update on public.automation_attempts
+ for each row execute function public.set_updated_at();
diff --git a/supabase/migrations/20261016101900_index_automation_attempts_started_at.sql b/supabase/migrations/20261016101900_index_automation_attempts_started_at.sql
new file mode 100644
index 0000000..68e0eb4
--- /dev/null
+++ b/supabase/migrations/20261016101900_index_automation_attempts_started_at.sql
@@ -0,0 +1,2 @@
+-- reserve_automation_send: sends in the last hour across the instance
+create index automation_attempts_started_at_idx on public.automation_attempts (started_at);
diff --git a/supabase/migrations/20261016102000_index_automation_attempts_user_id_started_at.sql b/supabase/migrations/20261016102000_index_automation_attempts_user_id_started_at.sql
new file mode 100644
index 0000000..0e28c82
--- /dev/null
+++ b/supabase/migrations/20261016102000_index_automation_attempts_user_id_started_at.sql
@@ -0,0 +1,2 @@
+-- reserve_automation_send: sends in the last hour for one member
+create index automation_attempts_user_id_started_at_idx on public.automation_attempts (user_id, started_at);
diff --git a/supabase/migrations/20261016102100_index_automation_attempts_account_id_started_at.sql b/supabase/migrations/20261016102100_index_automation_attempts_account_id_started_at.sql
new file mode 100644
index 0000000..6a69b22
--- /dev/null
+++ b/supabase/migrations/20261016102100_index_automation_attempts_account_id_started_at.sql
@@ -0,0 +1,2 @@
+-- reserve_automation_send: sends in the last hour for one Instagram account
+create index automation_attempts_account_id_started_at_idx on public.automation_attempts (account_id, started_at);
diff --git a/supabase/migrations/20261016102200_index_automation_attempts_rule_id_started_at.sql b/supabase/migrations/20261016102200_index_automation_attempts_rule_id_started_at.sql
new file mode 100644
index 0000000..2e97fde
--- /dev/null
+++ b/supabase/migrations/20261016102200_index_automation_attempts_rule_id_started_at.sql
@@ -0,0 +1,2 @@
+-- reserve_automation_send: sends in the last hour for one rule
+create index automation_attempts_rule_id_started_at_idx on public.automation_attempts (rule_id, started_at) where rule_id is not null;
diff --git a/supabase/migrations/20261016102300_index_automation_attempts_recipient.sql b/supabase/migrations/20261016102300_index_automation_attempts_recipient.sql
new file mode 100644
index 0000000..63857fa
--- /dev/null
+++ b/supabase/migrations/20261016102300_index_automation_attempts_recipient.sql
@@ -0,0 +1,2 @@
+-- reserve_automation_send: replies to one person from one account in the last day
+create index automation_attempts_recipient_idx on public.automation_attempts (account_id, recipient_id, started_at);
diff --git a/supabase/migrations/20261016102400_index_automation_attempts_comment.sql b/supabase/migrations/20261016102400_index_automation_attempts_comment.sql
new file mode 100644
index 0000000..9f92a40
--- /dev/null
+++ b/supabase/migrations/20261016102400_index_automation_attempts_comment.sql
@@ -0,0 +1,2 @@
+-- finish_automation_send and the claim close the attempts of one comment; the cascade from a comment
+create index automation_attempts_comment_idx on public.automation_attempts (automation_comment_id);
diff --git a/supabase/migrations/20261016100400_create_audit_events.sql b/supabase/migrations/20261016102500_create_audit_events.sql
similarity index 54%
rename from supabase/migrations/20261016100400_create_audit_events.sql
rename to supabase/migrations/20261016102500_create_audit_events.sql
index 90699c4..f2c4173 100644
--- a/supabase/migrations/20261016100400_create_audit_events.sql
+++ b/supabase/migrations/20261016102500_create_audit_events.sql
@@ -12,15 +12,3 @@ create table public.audit_events (
constraint audit_events_subject_type_check check (subject_type in ('account', 'automation_rule', 'automation_account', 'automation_comment')),
constraint audit_events_details_check check (jsonb_typeof(details) = 'object')
);
-
--- only the Worker's service role reads the table; the anon key ships in every browser
-alter table public.audit_events enable row level security;
-revoke all on table public.audit_events from anon, authenticated;
-
-create trigger audit_events_set_updated_at before update on public.audit_events
- for each row execute function public.set_updated_at();
-
--- auditEvents.listForUser: where user_id = $1 order by created_at desc
-create index audit_events_user_id_created_at_idx on public.audit_events (user_id, created_at desc);
--- the daily retention delete across all users
-create index audit_events_created_at_idx on public.audit_events (created_at);
diff --git a/supabase/migrations/20261016102600_revoke_browser_access_audit_events.sql b/supabase/migrations/20261016102600_revoke_browser_access_audit_events.sql
new file mode 100644
index 0000000..8bbb742
--- /dev/null
+++ b/supabase/migrations/20261016102600_revoke_browser_access_audit_events.sql
@@ -0,0 +1,3 @@
+-- only the Worker's service role reads audit_events; the anon key ships in every browser
+alter table public.audit_events enable row level security;
+revoke all on table public.audit_events from anon, authenticated;
diff --git a/supabase/migrations/20261016102700_add_audit_events_updated_at_trigger.sql b/supabase/migrations/20261016102700_add_audit_events_updated_at_trigger.sql
new file mode 100644
index 0000000..2f7cc48
--- /dev/null
+++ b/supabase/migrations/20261016102700_add_audit_events_updated_at_trigger.sql
@@ -0,0 +1,3 @@
+-- set_updated_at() keeps updated_at, so no query has to set it
+create trigger audit_events_set_updated_at before update on public.audit_events
+ for each row execute function public.set_updated_at();
diff --git a/supabase/migrations/20261016102800_index_audit_events_user_id_created_at.sql b/supabase/migrations/20261016102800_index_audit_events_user_id_created_at.sql
new file mode 100644
index 0000000..86855db
--- /dev/null
+++ b/supabase/migrations/20261016102800_index_audit_events_user_id_created_at.sql
@@ -0,0 +1,2 @@
+-- auditEvents.listForUser: where user_id = $1 order by created_at desc
+create index audit_events_user_id_created_at_idx on public.audit_events (user_id, created_at desc);
diff --git a/supabase/migrations/20261016102900_index_audit_events_created_at.sql b/supabase/migrations/20261016102900_index_audit_events_created_at.sql
new file mode 100644
index 0000000..f00688d
--- /dev/null
+++ b/supabase/migrations/20261016102900_index_audit_events_created_at.sql
@@ -0,0 +1,2 @@
+-- the daily retention delete across all users
+create index audit_events_created_at_idx on public.audit_events (created_at);
diff --git a/supabase/migrations/20261016100500_index_accounts_instagram_user.sql b/supabase/migrations/20261016103000_index_accounts_instagram_user.sql
similarity index 100%
rename from supabase/migrations/20261016100500_index_accounts_instagram_user.sql
rename to supabase/migrations/20261016103000_index_accounts_instagram_user.sql
diff --git a/supabase/migrations/20261016100600_create_automation_rules_for_ig_user_function.sql b/supabase/migrations/20261016103100_create_automation_rules_for_ig_user_function.sql
similarity index 100%
rename from supabase/migrations/20261016100600_create_automation_rules_for_ig_user_function.sql
rename to supabase/migrations/20261016103100_create_automation_rules_for_ig_user_function.sql
diff --git a/supabase/migrations/20261016100700_create_claim_automation_comments_function.sql b/supabase/migrations/20261016103200_create_claim_automation_comments_function.sql
similarity index 100%
rename from supabase/migrations/20261016100700_create_claim_automation_comments_function.sql
rename to supabase/migrations/20261016103200_create_claim_automation_comments_function.sql
diff --git a/supabase/migrations/20261016100800_create_reserve_automation_send_function.sql b/supabase/migrations/20261016103300_create_reserve_automation_send_function.sql
similarity index 100%
rename from supabase/migrations/20261016100800_create_reserve_automation_send_function.sql
rename to supabase/migrations/20261016103300_create_reserve_automation_send_function.sql
diff --git a/supabase/migrations/20261016100900_create_finish_automation_send_function.sql b/supabase/migrations/20261016103400_create_finish_automation_send_function.sql
similarity index 100%
rename from supabase/migrations/20261016100900_create_finish_automation_send_function.sql
rename to supabase/migrations/20261016103400_create_finish_automation_send_function.sql
diff --git a/supabase/migrations/20261016101000_create_automation_stats_function.sql b/supabase/migrations/20261016103500_create_automation_stats_function.sql
similarity index 100%
rename from supabase/migrations/20261016101000_create_automation_stats_function.sql
rename to supabase/migrations/20261016103500_create_automation_stats_function.sql
diff --git a/supabase/rollbacks/20261016100100_revoke_browser_access_automation_accounts.sql b/supabase/rollbacks/20261016100100_revoke_browser_access_automation_accounts.sql
new file mode 100644
index 0000000..dd7df68
--- /dev/null
+++ b/supabase/rollbacks/20261016100100_revoke_browser_access_automation_accounts.sql
@@ -0,0 +1,2 @@
+-- the table had no browser grants before, because new tables in public start without them
+alter table public.automation_accounts disable row level security;
diff --git a/supabase/rollbacks/20261016100200_add_automation_accounts_updated_at_trigger.sql b/supabase/rollbacks/20261016100200_add_automation_accounts_updated_at_trigger.sql
new file mode 100644
index 0000000..0f9112f
--- /dev/null
+++ b/supabase/rollbacks/20261016100200_add_automation_accounts_updated_at_trigger.sql
@@ -0,0 +1 @@
+drop trigger if exists automation_accounts_set_updated_at on public.automation_accounts;
diff --git a/supabase/rollbacks/20261016100100_create_automation_rules.sql b/supabase/rollbacks/20261016100300_create_automation_rules.sql
similarity index 100%
rename from supabase/rollbacks/20261016100100_create_automation_rules.sql
rename to supabase/rollbacks/20261016100300_create_automation_rules.sql
diff --git a/supabase/rollbacks/20261016100400_revoke_browser_access_automation_rules.sql b/supabase/rollbacks/20261016100400_revoke_browser_access_automation_rules.sql
new file mode 100644
index 0000000..0faaf90
--- /dev/null
+++ b/supabase/rollbacks/20261016100400_revoke_browser_access_automation_rules.sql
@@ -0,0 +1,2 @@
+-- the table had no browser grants before, because new tables in public start without them
+alter table public.automation_rules disable row level security;
diff --git a/supabase/rollbacks/20261016100500_add_automation_rules_updated_at_trigger.sql b/supabase/rollbacks/20261016100500_add_automation_rules_updated_at_trigger.sql
new file mode 100644
index 0000000..85df30c
--- /dev/null
+++ b/supabase/rollbacks/20261016100500_add_automation_rules_updated_at_trigger.sql
@@ -0,0 +1 @@
+drop trigger if exists automation_rules_set_updated_at on public.automation_rules;
diff --git a/supabase/rollbacks/20261016100600_index_automation_rules_user_id_created_at.sql b/supabase/rollbacks/20261016100600_index_automation_rules_user_id_created_at.sql
new file mode 100644
index 0000000..fb63ece
--- /dev/null
+++ b/supabase/rollbacks/20261016100600_index_automation_rules_user_id_created_at.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_rules_user_id_created_at_idx;
diff --git a/supabase/rollbacks/20261016100700_index_automation_rules_enabled_account.sql b/supabase/rollbacks/20261016100700_index_automation_rules_enabled_account.sql
new file mode 100644
index 0000000..b0ffd87
--- /dev/null
+++ b/supabase/rollbacks/20261016100700_index_automation_rules_enabled_account.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_rules_enabled_account_idx;
diff --git a/supabase/rollbacks/20261016100200_create_automation_comments.sql b/supabase/rollbacks/20261016100800_create_automation_comments.sql
similarity index 100%
rename from supabase/rollbacks/20261016100200_create_automation_comments.sql
rename to supabase/rollbacks/20261016100800_create_automation_comments.sql
diff --git a/supabase/rollbacks/20261016100900_revoke_browser_access_automation_comments.sql b/supabase/rollbacks/20261016100900_revoke_browser_access_automation_comments.sql
new file mode 100644
index 0000000..f4b7259
--- /dev/null
+++ b/supabase/rollbacks/20261016100900_revoke_browser_access_automation_comments.sql
@@ -0,0 +1,2 @@
+-- the table had no browser grants before, because new tables in public start without them
+alter table public.automation_comments disable row level security;
diff --git a/supabase/rollbacks/20261016101000_add_automation_comments_updated_at_trigger.sql b/supabase/rollbacks/20261016101000_add_automation_comments_updated_at_trigger.sql
new file mode 100644
index 0000000..0f9b3f5
--- /dev/null
+++ b/supabase/rollbacks/20261016101000_add_automation_comments_updated_at_trigger.sql
@@ -0,0 +1 @@
+drop trigger if exists automation_comments_set_updated_at on public.automation_comments;
diff --git a/supabase/rollbacks/20261016101100_index_automation_comments_due.sql b/supabase/rollbacks/20261016101100_index_automation_comments_due.sql
new file mode 100644
index 0000000..f2d6fac
--- /dev/null
+++ b/supabase/rollbacks/20261016101100_index_automation_comments_due.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_comments_due_idx;
diff --git a/supabase/rollbacks/20261016101200_index_automation_comments_claimed.sql b/supabase/rollbacks/20261016101200_index_automation_comments_claimed.sql
new file mode 100644
index 0000000..cb29b89
--- /dev/null
+++ b/supabase/rollbacks/20261016101200_index_automation_comments_claimed.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_comments_claimed_idx;
diff --git a/supabase/rollbacks/20261016101300_index_automation_comments_user_id_created_at.sql b/supabase/rollbacks/20261016101300_index_automation_comments_user_id_created_at.sql
new file mode 100644
index 0000000..9f30994
--- /dev/null
+++ b/supabase/rollbacks/20261016101300_index_automation_comments_user_id_created_at.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_comments_user_id_created_at_idx;
diff --git a/supabase/rollbacks/20261016101400_index_automation_comments_rule_id.sql b/supabase/rollbacks/20261016101400_index_automation_comments_rule_id.sql
new file mode 100644
index 0000000..5c68358
--- /dev/null
+++ b/supabase/rollbacks/20261016101400_index_automation_comments_rule_id.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_comments_rule_id_idx;
diff --git a/supabase/rollbacks/20261016101500_index_automation_comments_created_at.sql b/supabase/rollbacks/20261016101500_index_automation_comments_created_at.sql
new file mode 100644
index 0000000..a18a09d
--- /dev/null
+++ b/supabase/rollbacks/20261016101500_index_automation_comments_created_at.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_comments_created_at_idx;
diff --git a/supabase/rollbacks/20261016100300_create_automation_attempts.sql b/supabase/rollbacks/20261016101600_create_automation_attempts.sql
similarity index 100%
rename from supabase/rollbacks/20261016100300_create_automation_attempts.sql
rename to supabase/rollbacks/20261016101600_create_automation_attempts.sql
diff --git a/supabase/rollbacks/20261016101700_revoke_browser_access_automation_attempts.sql b/supabase/rollbacks/20261016101700_revoke_browser_access_automation_attempts.sql
new file mode 100644
index 0000000..b9b9826
--- /dev/null
+++ b/supabase/rollbacks/20261016101700_revoke_browser_access_automation_attempts.sql
@@ -0,0 +1,2 @@
+-- the table had no browser grants before, because new tables in public start without them
+alter table public.automation_attempts disable row level security;
diff --git a/supabase/rollbacks/20261016101800_add_automation_attempts_updated_at_trigger.sql b/supabase/rollbacks/20261016101800_add_automation_attempts_updated_at_trigger.sql
new file mode 100644
index 0000000..47dc20d
--- /dev/null
+++ b/supabase/rollbacks/20261016101800_add_automation_attempts_updated_at_trigger.sql
@@ -0,0 +1 @@
+drop trigger if exists automation_attempts_set_updated_at on public.automation_attempts;
diff --git a/supabase/rollbacks/20261016101900_index_automation_attempts_started_at.sql b/supabase/rollbacks/20261016101900_index_automation_attempts_started_at.sql
new file mode 100644
index 0000000..85bb1eb
--- /dev/null
+++ b/supabase/rollbacks/20261016101900_index_automation_attempts_started_at.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_attempts_started_at_idx;
diff --git a/supabase/rollbacks/20261016102000_index_automation_attempts_user_id_started_at.sql b/supabase/rollbacks/20261016102000_index_automation_attempts_user_id_started_at.sql
new file mode 100644
index 0000000..3d1f216
--- /dev/null
+++ b/supabase/rollbacks/20261016102000_index_automation_attempts_user_id_started_at.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_attempts_user_id_started_at_idx;
diff --git a/supabase/rollbacks/20261016102100_index_automation_attempts_account_id_started_at.sql b/supabase/rollbacks/20261016102100_index_automation_attempts_account_id_started_at.sql
new file mode 100644
index 0000000..e97f9b5
--- /dev/null
+++ b/supabase/rollbacks/20261016102100_index_automation_attempts_account_id_started_at.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_attempts_account_id_started_at_idx;
diff --git a/supabase/rollbacks/20261016102200_index_automation_attempts_rule_id_started_at.sql b/supabase/rollbacks/20261016102200_index_automation_attempts_rule_id_started_at.sql
new file mode 100644
index 0000000..a857e8b
--- /dev/null
+++ b/supabase/rollbacks/20261016102200_index_automation_attempts_rule_id_started_at.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_attempts_rule_id_started_at_idx;
diff --git a/supabase/rollbacks/20261016102300_index_automation_attempts_recipient.sql b/supabase/rollbacks/20261016102300_index_automation_attempts_recipient.sql
new file mode 100644
index 0000000..7c72c15
--- /dev/null
+++ b/supabase/rollbacks/20261016102300_index_automation_attempts_recipient.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_attempts_recipient_idx;
diff --git a/supabase/rollbacks/20261016102400_index_automation_attempts_comment.sql b/supabase/rollbacks/20261016102400_index_automation_attempts_comment.sql
new file mode 100644
index 0000000..d0e9f6e
--- /dev/null
+++ b/supabase/rollbacks/20261016102400_index_automation_attempts_comment.sql
@@ -0,0 +1 @@
+drop index if exists public.automation_attempts_comment_idx;
diff --git a/supabase/rollbacks/20261016100400_create_audit_events.sql b/supabase/rollbacks/20261016102500_create_audit_events.sql
similarity index 100%
rename from supabase/rollbacks/20261016100400_create_audit_events.sql
rename to supabase/rollbacks/20261016102500_create_audit_events.sql
diff --git a/supabase/rollbacks/20261016102600_revoke_browser_access_audit_events.sql b/supabase/rollbacks/20261016102600_revoke_browser_access_audit_events.sql
new file mode 100644
index 0000000..c3f3c5d
--- /dev/null
+++ b/supabase/rollbacks/20261016102600_revoke_browser_access_audit_events.sql
@@ -0,0 +1,2 @@
+-- the table had no browser grants before, because new tables in public start without them
+alter table public.audit_events disable row level security;
diff --git a/supabase/rollbacks/20261016102700_add_audit_events_updated_at_trigger.sql b/supabase/rollbacks/20261016102700_add_audit_events_updated_at_trigger.sql
new file mode 100644
index 0000000..b0d9ba6
--- /dev/null
+++ b/supabase/rollbacks/20261016102700_add_audit_events_updated_at_trigger.sql
@@ -0,0 +1 @@
+drop trigger if exists audit_events_set_updated_at on public.audit_events;
diff --git a/supabase/rollbacks/20261016102800_index_audit_events_user_id_created_at.sql b/supabase/rollbacks/20261016102800_index_audit_events_user_id_created_at.sql
new file mode 100644
index 0000000..781cebe
--- /dev/null
+++ b/supabase/rollbacks/20261016102800_index_audit_events_user_id_created_at.sql
@@ -0,0 +1 @@
+drop index if exists public.audit_events_user_id_created_at_idx;
diff --git a/supabase/rollbacks/20261016102900_index_audit_events_created_at.sql b/supabase/rollbacks/20261016102900_index_audit_events_created_at.sql
new file mode 100644
index 0000000..cd59465
--- /dev/null
+++ b/supabase/rollbacks/20261016102900_index_audit_events_created_at.sql
@@ -0,0 +1 @@
+drop index if exists public.audit_events_created_at_idx;
diff --git a/supabase/rollbacks/20261016100500_index_accounts_instagram_user.sql b/supabase/rollbacks/20261016103000_index_accounts_instagram_user.sql
similarity index 100%
rename from supabase/rollbacks/20261016100500_index_accounts_instagram_user.sql
rename to supabase/rollbacks/20261016103000_index_accounts_instagram_user.sql
diff --git a/supabase/rollbacks/20261016100600_create_automation_rules_for_ig_user_function.sql b/supabase/rollbacks/20261016103100_create_automation_rules_for_ig_user_function.sql
similarity index 100%
rename from supabase/rollbacks/20261016100600_create_automation_rules_for_ig_user_function.sql
rename to supabase/rollbacks/20261016103100_create_automation_rules_for_ig_user_function.sql
diff --git a/supabase/rollbacks/20261016100700_create_claim_automation_comments_function.sql b/supabase/rollbacks/20261016103200_create_claim_automation_comments_function.sql
similarity index 100%
rename from supabase/rollbacks/20261016100700_create_claim_automation_comments_function.sql
rename to supabase/rollbacks/20261016103200_create_claim_automation_comments_function.sql
diff --git a/supabase/rollbacks/20261016100800_create_reserve_automation_send_function.sql b/supabase/rollbacks/20261016103300_create_reserve_automation_send_function.sql
similarity index 100%
rename from supabase/rollbacks/20261016100800_create_reserve_automation_send_function.sql
rename to supabase/rollbacks/20261016103300_create_reserve_automation_send_function.sql
diff --git a/supabase/rollbacks/20261016100900_create_finish_automation_send_function.sql b/supabase/rollbacks/20261016103400_create_finish_automation_send_function.sql
similarity index 100%
rename from supabase/rollbacks/20261016100900_create_finish_automation_send_function.sql
rename to supabase/rollbacks/20261016103400_create_finish_automation_send_function.sql
diff --git a/supabase/rollbacks/20261016101000_create_automation_stats_function.sql b/supabase/rollbacks/20261016103500_create_automation_stats_function.sql
similarity index 100%
rename from supabase/rollbacks/20261016101000_create_automation_stats_function.sql
rename to supabase/rollbacks/20261016103500_create_automation_stats_function.sql