Skip to content

ci: migration-only PRs get no database CI, which is how three grant gaps shipped #559

Closed

Description

@thinkclay

A PR that changes only packages/supabase/migrations/** gets no database CI at all.

api-tests.yml — the only workflow that starts Supabase and applies migrations — triggers on:

paths:
  - 'packages/supabase/functions/api/**'
  - 'scripts/test-api-local.ts'
  - 'scripts/deno.json'
  - '.github/workflows/api-tests.yml'

No packages/supabase/migrations/**. So a migration-only PR runs Unit tests and Lint/typecheck/build, neither of which touches a database. Observed on #558: those two ran, everything database-shaped skipped.

Why it matters

This is how the grant-gap bugs keep shipping. Three migrations have now created tables with RLS enabled and no GRANTs, leaving them unreachable by every role including service_role:

Each was found by a human hitting a 403 in unrelated work, sometimes months later. A CI run that applied the migration and touched each new table would have caught all three at the point of authorship.

Suggested fix

  1. Add packages/supabase/migrations/** to the api-tests trigger. Cheapest change; the job already starts Supabase and applies migrations, so a migration that fails to apply becomes a red check immediately.
  2. Consider a smoke assertion after migration apply: for every table in core, assert has_table_privilege('service_role', oid, 'SELECT'). That is the specific defect that has recurred three times, and it is a single query.

Something like:

select c.relname
from pg_class c join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'core' and c.relkind = 'r'
  and not has_table_privilege('service_role', c.oid, 'SELECT');

Non-empty result → fail the job, naming the tables.

Acceptance

  • A PR touching only a migration runs a job that applies it.
  • A new table created without a service_role grant fails CI, naming the table.

Activity

  1. added
    bug
    agent-ready
    on Aug 11, 2026
  2. thinkclay commented on Aug 11, 2026

    @thinkclay
    ContributorAuthor

    Data point for this issue, now that 343 has been promoted.

    343 was merged some days ago and had been applied nowhere — not dev, not preview, not prod. I confirmed that by querying the grants directly rather than trusting the ledger: all seven tables had zero grants in all three environments. So the gap this issue describes is not only "migration-only PRs get no CI"; it is that a merged migration has no mechanism that ever applies it, and nothing surfaces the omission.

    Two things that made this hard to see, both worth designing against:

    1. apply-migration.sh --status reports dev as having 11 unrecorded migrations (331–341, 343). The script says plainly that unrecorded does not mean unapplied — but that means the ledger cannot answer "is this live?" without inspecting the objects each migration touches, one at a time. I had to check information_schema.role_table_grants to establish the truth.
    2. A missing GRANT fails before RLS is evaluated, so the symptom is a flat 42501 permission denied for every role including service_role. It reads like a broken function, not a missing migration — which is why this class has now shipped three times (332, 335, 343).

    Suggestion for the acceptance criteria here: CI should assert that every numbered migration in the repo is recorded in each environment's ledger, and fail when one is not. That is a cheap check and it would have caught all three.

  3. thinkclay commented on Aug 11, 2026

    @thinkclay
    ContributorAuthor

    Dev's ledger is now reconciled: 178/179, up from 168/179. Preview and prod are both 179/179. Worth recording what the nine unrecorded migrations actually turned out to be, because the split is the argument for this issue.

    I resolved each by probing the object it creates rather than trusting the ledger:

    migration ledger said reality
    331 user_profiles_view unrecorded applied — view present
    332 api_keys_grants unrecorded applied — grants present
    333 api_keys_key_prefix_check unrecorded applied — constraint present with the right definition
    335 scheduling_grants unrecorded applied — grants present
    336 fix_validate_oauth_scope unrecorded no-op — the file is SELECT 1 WHERE FALSE;
    337 notification_cron_vault unrecorded not applied, and must not be — see #564
    338 oauth_scope_real_authorization unrecorded not applied — is_self_scoped column and user_has_any_team_permission both missing
    340 fix_profile_completion_certifications unrecorded not applied — view still had the broken JOIN core.certifications
    341 fix_search_path_extension_resolution unrecorded not applied — search_path=onet instead of onet, public, extensions

    So "unrecorded" covered four applied, one no-op, and four genuinely missing. There was no way to tell them apart without inspecting nine different kinds of object — a view definition, three grant sets, a constraint body, a cron table, a column, a function's proconfig. That is the cost this issue is about.

    Two of the four missing ones were silently wrong rather than obviously broken, which is the part I would emphasise in the fix:

    • 340: dev's v_profile_completion_scores joined core.certifications, which is empty and unused — the real FK points at data.certifications. The 15-point certification component scored 0 for every user on dev, and nothing errored.
    • 341: onet.search_occupations had search_path=onet, so extension functions would not resolve.

    Neither would show up as a failure. They just quietly produce wrong answers.

    After applying, dev now matches prod byte-for-byte on all three: identical md5(pg_get_functiondef(...)) for validate_oauth_scope, identical md5(pg_get_viewdef(...)) for the completion view, identical proconfig. And the authz behaviour is verified rather than assumed — validate_oauth_scope(user, ARRAY['fake:scope']) returns [] on both, while a real self-scoped profile:read is granted on both. Default-deny holds.

    Concrete suggestion for this issue's acceptance: the check should not be "is every migration recorded" — that would have passed by hand-inserting nine rows and left four real bugs live on dev. It should be a per-environment schema fingerprint compared against a reference, so drift fails CI, not just bookkeeping.

  4. thinkclay commented on Aug 11, 2026

    @thinkclay
    ContributorAuthor

    Another one for the pile: migration 344 is merged (#570) and applied nowhere but my local database.

    It drops the vestigial core.application_status ENUM. Low risk — verified before writing that no column and no function uses the type — but it is now the fourth migration in this epic that exists in the repo and not in any environment, which is exactly the failure mode this issue describes.

    Running total of what the ledger cannot tell you, from this epic alone:

    migration state when found
    343 (privacy/EEO grants) merged, applied in no environment — including prod
    339 (work_logs.team_id) applied on preview and prod, missing on dev
    340, 341 applied on preview and prod, missing on dev, and both silently wrong rather than broken
    344 (this one) merged, applied nowhere

    343 also turned out to be missing from local, which nothing tracks at all — so a developer running the branch got a 403 on tables that worked in every deployed environment.

    The pattern is consistent: there is no step anywhere that applies a merged migration, and no check that notices. apply-migration.sh --status reports drift but explicitly cannot distinguish "unrecorded" from "unapplied", so it cannot be the check either.

    Reiterating the suggestion from earlier, now with more evidence behind it: the acceptance here should be a per-environment schema fingerprint compared against a reference, not a ledger-row count. A ledger check would have passed on dev while 340 was quietly scoring every candidate's certifications as zero.

  5. thinkclay commented on Aug 12, 2026

    @thinkclay
    ContributorAuthor

    Worked this. The premise needs correcting, and the corrected version is worse.

    A drift audit already existed

    .github/workflows/supabase-drift-audit.yml — nightly, against dev, preview and prod, using supabase db push --dry-run. It is well written: it fails on a non-zero CLI exit rather than falling through, fails on empty output rather than assuming clean, and checks both real drift patterns.

    It had been failing every night, and nobody was acting on it. So the gap was not "there is no check". It was "the check is correct, it has been red for weeks, and that signal reached no one."

    It was red for real reasons

    After applying 343 and 344 to all three environments and 339/340/341 to dev, a dispatched run gives:

    env before now
    preview fail pass
    prod fail pass
    dev fail fail — correctly

    First green preview/prod in at least five days of runs. Dev's remaining failure is accurate:

    Found local migration files to be inserted before the last migration on remote database.
    supabase/migrations/337_notification_cron_vault.sql
    

    337 was deliberately skipped (#564) while 338–345 were applied, which makes it permanently out of order. That is a genuine drift condition.

    What I changed

    #571 — a pull_request trigger scoped to packages/supabase/migrations/**, so migration-only PRs are no longer invisible to database CI. With a nuance: a PR adding a migration is supposed to be unapplied everywhere, so failing on "Would push these migrations" would leave the check permanently red on exactly the PRs it guards. On pull_request it asserts only the two real drift signals and reports the unapplied set as a notice.

    #573 — the exit-code guard runs before the pattern checks, so out-of-order drift was being reported as a generic "investigate before assuming sync". It now names the cause and points at #564.

    I verified the trigger fires by opening a throwaway migrations-only PR (#572) rather than assuming — closed without merging.

    What is still open, and it is the larger half

    Nothing here makes a merged migration get applied. Four migrations from this epic reached main and sat unapplied; 343 was live in no environment including prod. A check that notices is necessary and not sufficient.

    Also worth deciding: every migration PR now shows a red drift-audit (dev) until 337 is applied. That is accurate rather than noisy, and softening it would repeat this epic's central mistake. But it is a real cost, and #564 — two Vault secrets on dev, one human action — clears it.

    Leaving this issue open for the apply-on-merge half.

  6. thinkclay commented on Aug 12, 2026

    @thinkclay
    ContributorAuthor

    Another live instance of this issue, caught by the ledger check within hours of the migration merging.

    345_profile_completion_counts_real_skills.sql (from #601) reached main and was applied nowhere. I applied it to dev and verified the view is now taxonomy-filtered; preview and prod are still unapplied, so the Profile Strength fix that PR describes is not in effect there.

    Current state:

    env unrecorded
    dev 337_notification_cron_vault.sql — correctly blocked on #564
    preview 345_profile_completion_counts_real_skills.sql
    prod 345_profile_completion_counts_real_skills.sql

    I have not promoted 345 beyond dev — it is another session's change and the promotion is their call, not mine.

    This is the fourth time in two days that a merged migration has sat unapplied, and the first where the gap was noticed the same day rather than weeks later. The pull_request trigger added in #571 surfaces it on the PR; what still does not exist is anything that applies a migration on merge. That remains the open half of this issue, and each instance makes the case a bit more concrete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXagent-readybugpriority: high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions