Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

supabase db reset intermittently fails: temporary Realtime init job races with the running Realtime service on "schema_migrations_pkey"

Open
#6,915 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@7ttp is already working on this.

Since Sep 30, 2026.

Assessment

This issue has not been assessed yet.

Description

🐛 Bug supabase/cli

CLI version: 2.118.0 (Linux, Docker Engine, self-hosted GitHub Actions runner), Postgres 17 local stack.

Describe the bug

supabase db reset (local) fails intermittently at the "Initialising schema" stage with error running container: exit 1. It happens mostly on the second reset of a CI job, when the stack has been running for a while. With --debug, the output of the temporary Realtime init container shows:

Resetting local database...
Recreating database...
Initialising schema...
+ echo 'Running migrations'
+ sudo -E -u nobody /app/bin/migrate
** (Ecto.ConstraintError) constraint error when attempting to insert struct:

    * "schema_migrations_pkey" (unique_constraint)
...
    (ecto_sql 3.14.0) lib/ecto/migrator.ex:337: anonymous fn/6 in Ecto.Migrator.async_migrate_maybe_in_transaction/7
error running container: exit 1

Why it happens (reading internal/db/reset/reset.go and internal/db/start/start.go at v2.118.0)

resetDatabase15:

  1. removes and recreates the db container and volume;
  2. runs SetupLocalDatabase → initSchema15, which runs one-off containers for Realtime (/app/bin/migrate, seeds, health_check), Storage (migrate-call.js) and GoTrue (gotrue migrate);
  3. only then calls restartServices (storage, gotrue, realtime, pooler).

During step 2, the persistent supabase_realtime_<project> container is still running against the freshly recreated database. When it restarts itself (it loses its DB connection while the db container is recreated), its entrypoint runs the same Realtime migrations concurrently with the one-off init job. Both insert the same version into _realtime.schema_migrations, and the one-off job crashes on schema_migrations_pkey.

Workaround

Stop the persistent Realtime container before supabase db reset (docker stop supabase_realtime_<project>). restartServices starts it again at the end.

Suggested fix

In resetDatabase15, stop the service containers that run their own migrations (at least Realtime; probably Storage and GoTrue too) before recreating the database, and start them again in restartServices. Alternatively, run the one-off init jobs only while those services are stopped.

To reproduce

  1. supabase start with Realtime enabled (default config).
  2. Run supabase db reset --debug and, as soon as it prints Initialising schema..., run docker restart supabase_realtime_<project>. This simulates the service restarting on its own after losing the database.
  3. The reset fails with the error above. The same sequence with the Realtime container stopped beforehand succeeds.

Observed locally (CLI 2.118.0, 2026-09-30):

  • Realtime running and restarted at Initialising schema...: 1 of 3 resets failed with the exact error above; the one-off Realtime container was the only one that exited 1.
  • Realtime stopped before the reset: 3 of 3 succeeded, and restartServices left it running.
  • Plain resets (control): 2 of 2 succeeded.
Dominant language
TypeScript
Stars
2.4k
Forks
531
Avg merge
1d 2h
Merged PRs (30d)
323

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from supabase/cli

All issues in supabase/cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.