Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
docs(database): describe the schema tree, versions and opening sentences
spacesdrive32ad90b5a991
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 59da0c1..ff11aa7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -28,6 +28,8 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).- When YouTube, Instagram or Reddit fails five times in a row, Twiligent stops calling it for 30 seconds and answers at once that it is not answering, instead of waiting on every request; scheduled posts that meet it are retried (#117, ADR-045)- A unique index on accounts, so adding the same account twice at the same moment stores it once; existing instances run `npm run db:push` (#116)- A shorter README with animated recordings of each main page, made with Flute from the real pages and made-up data, that points to the docs for everything else; the old screenshots are removed (#119)+- `supabase/schemas/`, the schema as it stands with one file per table and function, generated from the database by the new `npm run db:schema`; the migration test checks it names the same objects as the migrations (#122, ADR-046)+- Every migration and rollback opens with one plain sentence that says what it does, and the migration test checks real UTC versions and a verb at the start of each name; only comments changed in the applied files (#122, #124)### Changeddiff --git a/DECISIONS.md b/DECISIONS.mdindex 74c8de9..1b4ed67 100644--- a/DECISIONS.md+++ b/DECISIONS.md@@ -989,3 +989,26 @@ New row ids come from `crypto.randomUUID()` (`newRowId()` in `backend/lib/ids.ts**Trade-offs:**- A paused platform answers "try again in a minute" even if it recovered a few seconds earlier.- Reddit usernames are compared exactly, as the service already did, so a different capitalisation counts as a different account.++## ADR-046: Applied migrations stay as recorded, and a generated schema tree gives the per-object view++**Date:** 2026-10-18+**Status:** Accepted++**Decision:** The 114 migrations production recorded keep their versions and names, and new ones come from `npm run db:new`, which writes the current UTC time as the version (#122). `supabase/schemas/` holds the schema as it stands, generated from the database by `npm run db:schema` (`supabase db schema declarative generate`): one file per table with its checks, indexes, trigger and grants, and one per function. It is committed with each migration and never edited by hand. Migrations stay the source of truth, with their one-entity rule and hand-written rollbacks (ADR-041). Each migration and rollback opens with one plain sentence that says what it does (#124), and the migration test checks the versions, the verbs, the sentences and that the tree names the same tables, indexes, functions and triggers as the migrations.++**Context:** The migrations were numbered by hand in steps of 100, one was squeezed in at `20261016130850`, and 114 files in one folder made it hard to see a table whole. The request was to renumber and rename them and to put them in folders.++**Why not renumber:** The Supabase CLI matches applied migrations by version only. Renumbering would show production and every existing instance 114 new migrations, whose `create` statements fail on objects that exist, unless every owner rewrote their migration history with `supabase migration repair`. GitLab and Rails projects treat an applied migration as fixed for the same reason, and GitLab cleans up old ones by squashing them at planned release stops instead.++**Why not folders under migrations:** The CLI reads only `supabase/migrations/<timestamp>_<name>.sql` and does not look in subfolders; the request for it (supabase/cli#2881) was closed as not planned, with the declarative schema tree as the suggested way to organise by object. The tree is Supabase's own layout and matches GitLab's practice of committing a generated `db/structure.sql` next to the migrations.++**Alternatives considered:**+- Renumbering every file and repairing production's history. It breaks every existing instance and rewrites production records for no change in the schema.+- Squashing into one baseline. It shortens the folder but loses the one-entity history and needs the same history repair on every instance; it can be done later at a release, as GitLab does.+- Declarative schemas as the source of truth, with migrations generated by `supabase db schema declarative sync`. It needs Docker for a shadow database on every change, and the generated files would still have to be split into one entity each with rollbacks written by hand.++**Trade-offs:**+- The tree is a snapshot, so it is right only after `db:push` and `db:schema`; the test catches a missing object, not a changed column.+- The tree is exported from the linked database, so a self-hoster refreshing it needs the CLI linked to their project.+- Changing only the comments of applied files leaves their SQL byte for byte the same, which the CLI does not compare, so production is unaffected.diff --git a/docs/architecture/cloudflare/CI_CD.md b/docs/architecture/cloudflare/CI_CD.mdindex 01051cf..9c6193c 100644--- a/docs/architecture/cloudflare/CI_CD.md+++ b/docs/architecture/cloudflare/CI_CD.md@@ -10,7 +10,7 @@| `deploy-site.yml` | Pushes to `main` that touch the site, manual | Type check and test the public site, then build and deploy it to Pages || `publish-scheduled.yml` | Minutes 7, 22, 37 and 52 of every hour (when GitHub starts them), manual | Publish due Instagram posts (fallback for the Worker cron) |-No workflow runs database migrations. The owner applies `supabase/migrations/` with `npm run db:check` and `npm run db:push` before merging code that needs them (`docs/workflows/DEPLOYMENT.md`), and a change under `supabase/` alone deploys nothing. CI checks the migration files through `npm test` (`backend/tests/database/migrations.test.ts`: names, order, rollback pairs, repeatable baselines, closed functions) without a database. The `supabase` CLI is a root dev dependency, so `npm ci` installs it in every workflow, but no workflow calls it.+No workflow runs database migrations. The owner applies `supabase/migrations/` with `npm run db:check` and `npm run db:push` before merging code that needs them (`docs/workflows/DEPLOYMENT.md`), and a change under `supabase/` alone deploys nothing. CI checks the migration files through `npm test` (`backend/tests/database/migrations.test.ts`: names, real UTC versions, opening sentences, order, rollback pairs, repeatable baselines, closed functions, and a schema tree in `supabase/schemas/` that matches the migrations) without a database. The `supabase` CLI is a root dev dependency, so `npm ci` installs it in every workflow, but no workflow calls it.Nothing compiles TypeScript ahead of time: Wrangler and Vite strip the types while bundling, and Node strips them when it runs tests and `scripts/publish-scheduled.ts`. None of those steps checks types, so each workflow that ships code runs `tsc` first.diff --git a/docs/architecture/database/SCHEMA.md b/docs/architecture/database/SCHEMA.mdindex f56f128..37c973a 100644--- a/docs/architecture/database/SCHEMA.md+++ b/docs/architecture/database/SCHEMA.md@@ -20,9 +20,12 @@ The schema lives in versioned migrations in `supabase/migrations/`, applied with|---|---|| `supabase/migrations/<version>_<name>.sql` | One database entity: a table, its browser access, one trigger, one index or one function. The 14 digit version orders the files || `supabase/rollbacks/<version>_<name>.sql` | The reverse of the migration with the same file name. The CLI has no down migrations, so these are run by hand |+| `supabase/schemas/` | The schema as it stands, one file per object, generated by `npm run db:schema` from the database: `public/tables/<table>.sql` (the table with its checks, indexes, trigger and grants), `public/functions/<function>.sql`, `public/schema.sql` and the default privileges, and `_cluster/extensions/`. Read it to see a table whole; never edit it by hand || `supabase/config.toml` | The CLI's default config, with `major_version = 17` to match the hosted database || `supabase/.gitignore` | Keeps the CLI's `.temp` and `.branches` folders and local env files out of git |+The migrations stay in one flat folder because the Supabase CLI reads no subfolders there, and it matches applied migrations by their version alone, so an applied file is never renamed or given a new version (ADR-046). New files come from `npm run db:new <verb>_<object>`, which puts the current UTC time in the version; the files up to `20261016132100` were numbered by hand in steps of 100 and keep those versions. Each migration and rollback opens with one sentence that says what it does, and its name starts with the verb: `baseline`, `create`, `alter`, `add`, `index`, `revoke`, `check`, `replace`, `drop` or `rename`. `backend/tests/database/migrations.test.ts` checks these rules and that `supabase/schemas/` names the same tables, indexes, functions and triggers as the migrations.+The first four files are baselines. Each recreates one table as it stood before migrations, with `if not exists` everywhere, so they are safe on a database that already has the tables. They also bring older setups to the same starting point: they add `created_at` and the claim columns where missing, replace null `data` and `value` with `{}`, and mark posts stuck in `publishing` with no claim as `failed`. The baselines have no rollback, because undoing them would drop tables with data.| Order | Migrations | What they do |diff --git a/docs/features/NEW_DATABASE_TABLE.md b/docs/features/NEW_DATABASE_TABLE.mdindex c2371d5..58dca74 100644--- a/docs/features/NEW_DATABASE_TABLE.md+++ b/docs/features/NEW_DATABASE_TABLE.md@@ -27,6 +27,8 @@ The schema is versioned in `supabase/migrations/` and applied with the Supabase**Keep every migration as small as possible: one database entity per file.** A table file holds the table with its columns, keys and checks. Its browser access, each trigger, each index and each function get files of their own, and every file gets a rollback of the same size under the same name. A small file is easy to review, fails alone when it fails, and rolls back one thing. `backend/tests/database/migrations.test.ts` refuses a migration that creates more than one entity. Never split or edit a migration production has already recorded; write a new one instead.+Make every file with `npm run db:new <verb>_<object>`. The CLI puts the current UTC time in front of the name, and the CLI matches applied migrations by that version alone, so never type a version by hand or rename a file once it is applied. The name starts with what the file does to its entity: `create`, `alter`, `add`, `index`, `revoke`, `check`, `replace`, `drop` or `rename`. Every migration and rollback opens with one comment line, a plain sentence that says what the file does (`-- adds an index that lists a user's drafts newest first`); comments further down explain why. The migration test checks all three.+A new table is therefore four or more migrations, run in this order:| File | Holds | Rollback |@@ -46,7 +48,7 @@ npm run db:new index_content_drafts_user_id_created_at`create_content_drafts`:```sql--- drafts a user prepares before scheduling them+-- creates content_drafts, which holds the drafts a user prepares before scheduling themcreate table public.content_drafts (id text primary key,user_id uuid not null references auth.users (id) on delete cascade,@@ -82,23 +84,23 @@ create trigger content_drafts_set_updated_at before update on public.content_dra`index_content_drafts_user_id_created_at`:```sql--- contentDrafts.listForUser: where user_id = $1 order by created_at desc+-- adds an index that lists a user's drafts newest firstcreate index content_drafts_user_id_created_at_idx on public.content_drafts (user_id, created_at desc);```Write the reverse of each in `supabase/rollbacks/` with the same file name. `backend/tests/database/migrations.test.ts` fails when a migration has no rollback or an empty one. The table's rollback:```sql--- removes the table and every draft in it+-- removes content_drafts and every draft in itdrop table if exists public.content_drafts;```-The others are one line each: `alter table public.content_drafts disable row level security;`, `drop trigger if exists content_drafts_set_updated_at on public.content_drafts;` and `drop index if exists public.content_drafts_user_id_created_at_idx;`. Roll them back newest first, so the table goes last.+The others are one statement each under their sentence: `alter table public.content_drafts disable row level security;`, `drop trigger if exists content_drafts_set_updated_at on public.content_drafts;` and `drop index if exists public.content_drafts_user_id_created_at_idx;`. Roll them back newest first, so the table goes last. When a rollback deletes data or must run after another one, its sentence says so (`-- removes content_drafts and every draft in it; roll back content_draft_versions first`).If the repository updates `data`, add a merge function in its own migration (`npm run db:new create_merge_content_draft_function`), so an update is one statement and two writers never undo each other. Copy `create_merge_scheduled_post_function.sql`. A function in `public` is exposed through the Data API, so it always revokes execute from the browser roles and grants it only to the service role; the migration test enforces the revoke:```sql--- merges a patch into data in one UPDATE, so two writers never undo each other+-- creates merge_content_draft, which merges changes into a draft in one step so two writers never undo each othercreate or replace function public.merge_content_draft(p_id text, p_user_id uuid, p_patch jsonb, p_status text default null)returns booleanlanguage sql@@ -120,11 +122,12 @@ Its rollback is `drop function if exists public.merge_content_draft(text, uuid,### Step 3: Apply the Migration-1. Run `npm test --workspace backend`. The migration test checks the file names, the rollback pairs and the function grants.+1. Run `npm test --workspace backend`. The migration test checks the file names, versions and opening sentences, the rollback pairs and the function grants. Until step 6 it also reports that the schema tree lacks the new objects.2. Link the CLI to the project once: `npx supabase link --project-ref <ref>`. It needs `SUPABASE_ACCESS_TOKEN` in the environment or `npx supabase login`.3. Run `npm run db:check` and read the list of migrations it would apply.4. Run `npm run db:push` before merging the code that needs the table, because merging deploys the Worker at once.5. Run `npm run db:status` and check that the new version is in both the Local and Remote columns.+6. Run `npm run db:schema` and commit the changed files in `supabase/schemas/` with the migrations. The tree is generated from the database, one file per table (with its checks, indexes, trigger and grants) and per function, so a reviewer sees the table as it now stands. Never edit it by hand.A new instance gets the table from the same `npm run db:push`; there is no setup SQL to update in the README or the docs site. To undo the change, see Rolling Back a Database Change in `docs/workflows/DEPLOYMENT.md`.diff --git a/docs/guidelines/CODE_STYLE.md b/docs/guidelines/CODE_STYLE.mdindex 47017b1..83c1c80 100644--- a/docs/guidelines/CODE_STYLE.md+++ b/docs/guidelines/CODE_STYLE.md@@ -82,7 +82,7 @@ The layers are in `docs/architecture/backend/REQUEST_PIPELINE.md`; the recipes a- Redis code catches every failure and falls back; nothing else swallows errors, with two exceptions that log instead: a job that works through many items (the scheduled publisher, the reply processor, the token refresh) catches one item's failure and moves on, and a secondary step after the main write (subscribing an account when a rule is turned on) is logged with `context.log.warn` so the main result still stands.- A platform call whose every failure leads somewhere different may answer a result union instead of throwing (`sendPrivateReply` returns `{ kind: 'accepted' | 'error' | 'ambiguous' | 'not_sent' }`); the decision table lives in a pure `lib/` helper (`finishPlan` in `lib/automationDelivery.ts`) with its tests.- Work after a response goes through `inBackground(c, label, work)` in `controllers/http.ts`, which gives it its own deadline, never `c.executionCtx.waitUntil()` with the request's services.-- The schema changes only through a migration in `supabase/migrations/` (`npm run db:new <verb>_<object>`) with its reverse in `supabase/rollbacks/` under the same name, one database entity per file: a table (with its columns, keys and checks), its browser access, one trigger, one index or one function (a new table is at least four files; the test in `tests/database/migrations.test.ts` refuses a file that creates more); a repository updates `data` through a merge function with `db.rpc()`, never by reading and writing it back. See `docs/features/NEW_DATABASE_TABLE.md`.+- The schema changes only through a migration in `supabase/migrations/` (`npm run db:new <verb>_<object>`) with its reverse in `supabase/rollbacks/` under the same name, one database entity per file: a table (with its columns, keys and checks), its browser access, one trigger, one index or one function (a new table is at least four files; the test in `tests/database/migrations.test.ts` refuses a file that creates more); each migration and rollback opens with one plain sentence that says what it does (`-- adds an index that lists a user's drafts newest first`), and `supabase/schemas/` is regenerated with `npm run db:schema` after a push, never edited; a repository updates `data` through a merge function with `db.rpc()`, never by reading and writing it back. See `docs/features/NEW_DATABASE_TABLE.md`.- New row ids come from `newRowId()` in `lib/ids.ts`; tests pin them with `mockRowIds()` from `tests/fixtures/rowIds.ts`.- No new runtime dependency in the Worker without approval: call HTTP APIs with `fetch` (Resend is called this way, not through its SDK).diff --git a/docs/workflows/DEPLOYMENT.md b/docs/workflows/DEPLOYMENT.mdindex f11fd45..13d9f33 100644--- a/docs/workflows/DEPLOYMENT.md+++ b/docs/workflows/DEPLOYMENT.md@@ -79,6 +79,7 @@ No workflow migrates Supabase. The schema is versioned in `supabase/migrations/`| `npm run db:status` | `supabase migration list` | Lists each migration as Local, Remote or both || `npm run db:check` | `supabase db push --dry-run` | Shows the migrations a push would apply, without applying them || `npm run db:push` | `supabase db push` | Applies the pending migrations and records them in `supabase_migrations.schema_migrations` |+| `npm run db:schema` | `supabase db schema declarative generate --linked --schema public` | Rewrites `supabase/schemas/` from the linked database, one file per table and function; it only reads the database |### Linking the CLI@@ -97,7 +98,8 @@ The link is stored in `supabase/.temp/`, which git ignores.2. `npm run db:check` and read the list. It must show only the new files.3. `npm run db:push`.4. `npm run db:status`: every migration is in both columns.-5. Merge the pull request with the code that needs the change.+5. `npm run db:schema`, and commit the changed files in `supabase/schemas/` to the pull request; the migration test fails while the tree and the migrations disagree.+6. Merge the pull request with the code that needs the change.A change the old code cannot live with (a dropped column, a renamed function) needs two releases: first the code that works with both shapes, then the migration.diff --git a/docs/workflows/FEATURE_DEVELOPMENT.md b/docs/workflows/FEATURE_DEVELOPMENT.mdindex e06363d..390aba9 100644--- a/docs/workflows/FEATURE_DEVELOPMENT.md+++ b/docs/workflows/FEATURE_DEVELOPMENT.md@@ -113,7 +113,7 @@ npm run dev:site # the public site, when the change touches site/npm run db:check # when the change has a migration: lists what db:push would apply```-A change with a migration is applied with `npm run db:push` before its pull request is merged, and `npm run db:status` must then show every migration applied. CI never touches the database; it only runs `backend/tests/database/migrations.test.ts`, which checks the files. See `docs/workflows/DEPLOYMENT.md` (Database Changes).+A change with a migration is applied with `npm run db:push` before its pull request is merged, and `npm run db:status` must then show every migration applied; `npm run db:schema` then refreshes `supabase/schemas/`, which goes in the same pull request. CI never touches the database; it only runs `backend/tests/database/migrations.test.ts`, which checks the files. See `docs/workflows/DEPLOYMENT.md` (Database Changes).**Step 14 - Lint**```bashdiff --git a/docs/workflows/TESTING.md b/docs/workflows/TESTING.mdindex 94cb566..96d54bf 100644--- a/docs/workflows/TESTING.md+++ b/docs/workflows/TESTING.md@@ -92,7 +92,7 @@ Backend route and cron service tests (`tests/routes/*Routes.test.ts`, `tests/serScheduled publishing recovery has its own tests. `tests/lib/scheduledPublishing.test.ts` covers the shared rules: the 20 minute lease outlasts the 14 minute limit of both schedulers, what a run does for each container status, which Graph API codes count as temporary, when a failure retries or fails, and when the final message says publishing stopped. `tests/repositories/scheduledPostRepository.test.ts` runs the claim against the fake Supabase client: two schedulers claiming the same listed post (only the first gets it, and the claim counts an attempt), which claims are stale and that a takeover must match the expired claim it saw, that a post being published is not deleted, and that an edit only lands while the post is pending. The `scheduled publisher recovery` block in `tests/services/scheduledPublisher.test.ts` runs the whole publisher: a publish reply lost on the way back is checked on Instagram and marked published, an unreadable container status leaves the post claimed, an expired claim is taken over and found published or publishes its ready container, a claim inside its lease is left alone, a passing failure goes back to `pending` and the third fails the post, a run past its deadline claims nothing, and a post taken over after its last attempt is only checked. On the frontend, `tests/features/publishing/scheduleHelpers.test.ts` covers when the overdue alert counts a retried post (from its last claim) and a stuck claim (after the lease and 30 minutes).-The database migrations have their own test. `tests/database/migrations.test.ts` reads `supabase/migrations/` and `supabase/rollbacks/` and checks that every file is named `<14 digit version>_<lowercase name>.sql` with a unique version, that the baseline files come before every change, that every change has a rollback with the same name and every rollback has its migration, that the baselines use only `if not exists` for tables, indexes and columns so they can run again, that every function a migration creates revokes execute from `public, anon, authenticated`, that every migration from version 20261016100000 on creates at most one entity (a table, its access, a trigger, an index or a function) and has a rollback that is not empty, and that no file uses an em or en dash. It does not run the SQL; CI has no database. The migrations themselves were checked once on a local Postgres before the first push (ADR-038). The reply queue migrations (20261016120000 to 20261016122500) were checked the same way on a local Postgres with stub Supabase roles: every migration applies, 60 SQL scenario checks pass (among them eight sessions claiming at once, each job claimed by one), and the rollbacks apply in reverse with data present before the migrations apply again.+The database migrations have their own test. `tests/database/migrations.test.ts` reads `supabase/migrations/` and `supabase/rollbacks/` and checks that every file is named `<14 digit version>_<lowercase name>.sql` with a unique version, that every version is a real UTC date and time as `npm run db:new` writes it, that every name starts with its verb (`baseline`, `create`, `alter`, `add`, `index`, `revoke`, `check`, `replace`, `drop` or `rename`), that every migration and rollback opens with one comment line holding one sentence, that the schema tree in `supabase/schemas/` names the same tables, indexes, functions and triggers as the migrations (replaying every create and drop in order), that the baseline files come before every change, that every change has a rollback with the same name and every rollback has its migration, that the baselines use only `if not exists` for tables, indexes and columns so they can run again, that every function a migration creates revokes execute from `public, anon, authenticated`, that every migration from version 20261016100000 on creates at most one entity (a table, its access, a trigger, an index or a function) and has a rollback that is not empty, and that no file uses an em or en dash. It does not run the SQL; CI has no database. The migrations themselves were checked once on a local Postgres before the first push (ADR-038). The reply queue migrations (20261016120000 to 20261016122500) were checked the same way on a local Postgres with stub Supabase roles: every migration applies, 60 SQL scenario checks pass (among them eight sessions claiming at once, each job claimed by one), and the rollbacks apply in reverse with data present before the migrations apply again.Comment automation has its own tests. `tests/lib/automationMatching.test.ts` covers whole-word and exact matching, case, look-alike characters, literal punctuation in keywords, and that a comment on one reel never triggers a rule for another. `tests/lib/automationDelivery.test.ts` covers the Graph error classes, backoff with jitter, the cooldown from Meta's usage header, and what is recorded for each answer: accepted, rate limited, blocked, temporary errors up to the fifth try, already replied, a refused token (held), not allowed, no answer (needs review), and a request the runtime refused (not sent). `tests/lib/metaWebhookSignature.test.ts` checks signatures with either secret, changed bodies and malformed headers. `tests/fixtures/fakeAutomationQueue.ts` is an in-memory twin of the claim, reserve and finish functions, following the SQL's rules, and `tests/services/automationProcessor.test.ts` runs the processor against it: two comments at once, three reels with their own rules, two runs competing for the same jobs (each reply sent once), a burst over the batch and per-account fairness, a timeout that is never resent, a run that stopped before and during a send, a rate limit cooling one account while another keeps sending, the hourly and per-person limits, five temporary failures, a rule turned off, a deleted reel, an expired comment, a refused token holding the account, the instance pause, a database failure on one job and on the claim, a cancelled run and one without time for a whole send handing their jobs back unstarted, and a run claiming only what its subrequests pay for. `tests/services/automationWebhookService.test.ts` covers intake: per-reel matching, unmatched comments kept without words, own comments, duplicates within and across notifications, accounts without rules, a failed insert, and the verify token. `tests/repositories/automationCommentRepository.test.ts` pages through comments stored in the same instant without skipping or repeating one, and checks the hand-back of unstarted jobs. `tests/routes/instagramWebhookRoutes.test.ts` runs the public route end to end (challenge, signed comment stored then answered, duplicates, either secret, bad signatures, bad bodies, the 1 MB limit, a missing secret, a database failure), and `tests/routes/automationRoutes.test.ts` the user routes, including every route answering 404 for another user's rule, account or item. `tests/fixtures/metaWebhook.ts` signs notifications the way Meta does. `fakeAutomationQueue.ts` also mirrors the turn-taking claim, follow-ups, expiry and review. `tests/services/automationFollowupProcessor.test.ts` covers followers-only replies: a follower gets the link, someone not following gets a reminder and the second ends the wait, nothing is sent when Instagram cannot say, a lost answer needs review and is never sent again, and two runs at once send each follow-up once. `tests/services/automationReconciler.test.ts` covers a lost reply found in the conversation (accepted, nothing sent) or not found (left for a person), and the expiry and health warning. `tests/lib/automationRules.test.ts`, `automationReview.test.ts` and `automationHealth.test.ts` cover the rule checks, matching a lost reply by its digest and time, and the warning line; `tests/services/instagram/instagramMessaging.test.ts` the send, follow check, conversation read and subscription requests; `tests/repositories/automationFollowupRepository.test.ts` the follow-up database calls. Public replies (ADR-044): `tests/lib/automationPublicReply.test.ts` covers the stable wording per comment, the text bounds, what is recorded for each answer (posted only with an id, a lost answer for review, a deleted comment skipped, a public-only cooldown and a day-long block, retries, a held account, expiry) and when a lost reply goes out again. `tests/services/automationPublicReplyProcessor.test.ts` runs the public processor against the fake queue: posting with the stored text while the private reply is left alone, a failed private reply never repeating the public one and a public retry never repeating the private one, a lost answer never posted again by the dispatch, two runs at once posting each reply once, a rate limit cooling public replies only, one public reply per person and post, the account's hourly limit, a public reply turned off, an interrupted run and the instance pause. `tests/services/automationReconciler.test.ts` also covers a lost public reply found on the second page of replies, sent again once after two full reads, never sent again with a page unread or after a second lost answer, and a read Instagram refuses. `tests/services/instagram/instagramComments.test.ts` covers the reply request, answers without an id, refusals and paging; `tests/routes/instagramWebhookRoutes.test.ts` a rule with both replies end to end, where the private reply fails, the public one is posted and a redelivery sends neither again; `tests/routes/automationRoutes.test.ts` the public reply retry, the refused private retry of a public-only comment, and public-only rules. The SQL functions cannot run in Node; they were checked on a local Postgres (PGlite, and Postgres 18 for the public reply functions, including eight claims at once on 10,000 waiting replies with no reply claimed twice) before the first push: deduplication, fair claims and lease recovery, each limit, pause and cooldown, a late answer for an interrupted send, stats, cascades, browser access and every rollback.@@ -234,6 +234,7 @@ Open the app in a browser. For each changed area, test:**Database (if a migration changed):**- [ ] `npm run db:check` lists only the new migrations, and `npm run db:push` applies them without an error- [ ] `npm run db:status` shows every migration in both the Local and Remote columns+- [ ] `npm run db:schema` changes only the files of the objects the migrations touched, and they are committed- [ ] The anon key gets 401 permission denied on every table (including the automation tables and `audit_events`) and on the merge and automation functions: `curl -i "<SUPABASE_URL>/rest/v1/accounts?select=id" -H "apikey: <anon key>"` (repeat for `settings`, `scheduled_posts`, `tracked_posts`) and `curl -i -X POST "<SUPABASE_URL>/rest/v1/rpc/merge_account_data" -H "apikey: <anon key>" -H "Content-Type: application/json" -d '{}'`- [ ] The app still lists accounts, scheduled posts and tracked items, and the row counts in the Table Editor are unchanged