Skip to content

BE-M0-29 · First push to staging: migrations, then the seed

ID BE-M0-29 · Level L0 · Pack Pack F · Staging · Run order row 32 · Issue #22

Staging holds main's 13 migrations and the seed: schema V13 with RLS on every table, the system rows, the four buckets and the sealed E2E organization. This is the only db push staging gets. After it, migration files edited in place under D11 reach staging by a rebuild, BE-M0-33, never by another push. The seed goes to local and staging only, never to production. This step changes no file in the repository.

  • BE-M0-28 is Done: the CLI is linked to staging, and its check printed "linked to staging".
  • The checks on main's latest commit are green, the database job included (TL-M0-18). So every migration applies to an empty database and every pgTAP test passes.
  • Staging is empty: nothing has been pushed to it since TL-M0-20 made it.
  • The password manager is open on the "Opleet v2 staging" entry.

1 · From main, clean, and linked to staging

Section titled “1 · From main, clean, and linked to staging”
Terminal window
cd ~/opleet-v2/opleet
git switch main && git pull
git status --short
ref="$(cat supabase/.temp/project-ref)"; want="$(sed -n 's/^STAGING_PROJECT_REF=//p' .env.staging)"; [ -n "$ref" ] && [ "$ref" = "$want" ] && echo "linked to staging" || echo "STOP: not linked to staging"
gh run list --branch main --limit 3

Go on only if git status --short printed nothing, the test printed "linked to staging", and the newest runs show ✓.

2 · Preview: what would be pushed, and the seed

Section titled “2 · Preview: what would be pushed, and the seed”

Nothing is written. If the CLI asks for the database password, paste <STAGING_DB_PASSWORD> at the prompt. This applies to every block below.

Terminal window
pnpm supabase db push --linked --include-seed --dry-run

The CLI lists them again and asks before it applies anything. Answer y.

Terminal window
pnpm supabase db push --linked

4 · The seed: staging only, never production

Section titled “4 · The seed: staging only, never production”

The same command with --include-seed finds no migration left to push, and applies supabase/seed.sql once.

Terminal window
pnpm supabase db push --linked --include-seed

5 · Note the commit staging was built from

Section titled “5 · Note the commit staging was built from”
Terminal window
git rev-parse --short HEAD

Put this in your run comment. BE-M0-33 compares later commits with it to tell when staging needs a rebuild.

  • Block 1: git status --short prints nothing; then "linked to staging"; then three runs on main, the newest with ✓.
  • Block 2: a line saying this is a dry run, then the 13 migration files in order, from 20261006000100_foundation.sql to 20261006001300_storage.sql, then supabase/seed.sql as the seed it would apply.
  • Block 3: the same 13 files and a "[Y/n]" question. After y, one "Applying migration …" line per file, then "Finished supabase db push."
  • Block 4: no migration to apply; a line about seeding from supabase/seed.sql, then "Finished supabase db push."
  • Block 5: a seven-character commit, the same as git log -1 --oneline on main.
Terminal window
pnpm supabase migration list --linked
(
set -a; . ./.env.staging; set +a
h=(-H "apikey: $SUPABASE_SECRET_KEY" -H "Authorization: Bearer $SUPABASE_SECRET_KEY")
curl -s "$SUPABASE_URL/rest/v1/organizations?select=slug" "${h[@]}"; echo
curl -s "$SUPABASE_URL/rest/v1/roles?organization_id=is.null&select=code" "${h[@]}" | python3 -c 'import json, sys; print(len(json.load(sys.stdin)), "system roles")'
curl -s "$SUPABASE_URL/storage/v1/bucket" "${h[@]}" | python3 -c 'import json, sys; print(sorted(b["id"] for b in json.load(sys.stdin)))'
)

The parentheses keep .env.staging's values in a subshell: they're gone when it ends, and nothing prints them.

  • migration list: 13 rows, each with the same version under Local and Remote, and no row with only one of them.
  • organizations: [{"slug":"e2e"}]. The sealed E2E organization is the only one on staging.
  • roles: 11 system roles.
  • buckets: ['documents', 'inspections', 'payments', 'screening'].
  • Block 1 doesn't print "linked to staging", or a run on main isn't green: stop. Don't push.
  • Block 2 lists fewer than 13 files, or says "Remote migration versions not found in local migrations directory": staging isn't empty. Stop, and paste the output into #22.
  • Block 3 stops at a file with an error: the files before it are applied; the one that failed and those after it aren't. Paste the error with its file name, and stop. Don't edit anything on staging by hand. The fix lands on main through a pull request, and staging is then rebuilt with BE-M0-33.
  • "must be owner of table objects", or another permission error naming storage: the Storage migration couldn't create its policies on the hosted project. Paste the error; it needs a change to 20261006001300_storage.sql, not a workaround on staging.
  • "password authentication failed": paste the password again from the password manager. A pooler error ("Tenant or user not found") usually means the project is still starting: wait a minute and run the block again.
  • The check prints [] for organizations, or a count below 11 for roles: the seed didn't apply. Paste the output of block 4.
  • The check prints an error object instead of a list: paste it. It names a key or a URL problem in .env.staging, never the key itself.

Not reversible by a command here. To start staging again from main, run BE-M0-33, which wipes it and rebuilds it. Staging holds only the seed and test logins now, so a rebuild loses nothing real. Never run either against production.

Log each run as a comment on #22: the date, the commit from block 5, the last lines of blocks 3 and 4, and the check's output. Never paste the database password or the secret key.