cli: Error on 'npx supabase start' When Linking New Local Project to Existing Remote Supabase Project

Describe the bug When running npx supabase start in a new local project and attempting to link to an existing Supabase project, the process fails with the error: “Migration failed. Reason: An error occurred running ‘storage-schema’”. This is particularly interesting because I don’t have any migrations in my project.

To Reproduce Steps to reproduce the behavior:

  1. Initialize a fresh Supabase folder by running npx supabase init.
  2. Log in to your Supabase account by running npx supabase login.
  3. Link your remote Supabase project by executing npx supabase link --project-ref PROJECT_REF.
  4. Enter your database password.
  5. Run npx supabase start.
  6. Observe the error as shown in the screenshot.

Expected behavior I expect that all containers would successfully run, allowing me access to the local Supabase Studio.

Screenshots Screenshot of error Project Structure

Desktop:

  • OS: MacOS 14.0 (23A344)
  • Docker Client: OrbStack
  • Version of CLI: 1.136.2
  • Version of Node.js: v18.17.0

Additional context I’ve successfully run npx supabase start in another project I am working on, which makes it surprising that this issue occurs in a fresh project that I am trying to link to an existing remote Supabase project.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 19 (6 by maintainers)

Most upvoted comments

I can confirm there is an incompatibility with the latest version of storage which starts managing roles in a non-idempotent way https://github.com/supabase/storage/blame/master/migrations/tenant/0002-storage-schema.sql#L21.

The temporary workaround is to revert to an old version of storage by rm supabase/.temp/storage-version.

I will also make a patch release after discussing with the storage team on what’s the intended behaviour.

Hello mine worked after doing these steps

  1. supabase link
  2. supabase start

just did supabase link before doing supabase start

I have the same issue, with or without migrations present, even on a clean project with no prior configuration. Supabase CLI v1.137.0 (beta) is also affected.

/app/dist/database/migrate.js:104
            const error = new Error(`Migration failed. Reason: ${e.message}`);
                          ^

Error: Migration failed. Reason: An error occurred running 'storage-schema'. Rolled back this migration. No further migrations were run. Reason: role "anon" already exists
    at /app/dist/database/migrate.js:104:27
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /app/dist/database/migrate.js:149:28
    ... 2 lines matching cause stack trace ...
    at async /app/dist/server.js:23:9 {
  cause: Error: An error occurred running 'storage-schema'. Rolled back this migration. No further migrations were run. Reason: role "anon" already exists
      at /app/node_modules/postgres-migrations/dist/run-migration.js:36:15
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /app/dist/database/migrate.js:98:32
      at async /app/dist/database/migrate.js:149:28
      at async connectAndMigrate (/app/dist/database/migrate.js:48:9)
      at async runMigrationsOnTenant (/app/dist/database/migrate.js:35:5)
      at async /app/dist/server.js:23:9
}

Node.js v18.19.0

Supabase Services:

        SERVICE IMAGE      │        LOCAL         │  LINKED
  ─────────────────────────┼──────────────────────┼────────────
    supabase/postgres      │ 15.1.0.44            │ 15.1.0.44
    supabase/gotrue        │ v2.132.3             │ v2.132.3
    postgrest/postgrest    │ v10.2.0              │ v10.2.0
    supabase/realtime      │ v2.25.50             │ -
    supabase/storage-api   │ v0.46.3              │ v0.46.3
    supabase/edge-runtime  │ v1.32.0              │ -
    supabase/studio        │ 20240101-8e4a094     │ -
    supabase/postgres-meta │ v0.75.0              │ -
    supabase/logflare      │ 1.4.0                │ -
    bitnami/pgbouncer      │ 1.20.1-debian-11-r39 │ -
    darthsim/imgproxy      │ v3.8.0               │ -

A note about the supabase/postgres version: this is due to my remote running still this version (haven’t upgraded), tut this happens with the latest version as well.

That’s a separate error tracked here https://github.com/supabase/cli/issues/1892

Great! That did the trick for me, even without upgrading the remote Postgres version. I’ll do that later. Thanks so much for your quick actions, @sweatybridge!

So the earliest version of pg15 that is compatible with cli for local development is 15.1.0.55. I’ve updated the beta release of cli to ignore versions before that. You can try it out with

npx supabase@beta start

There’s likely a conflict with this version of postgres image with realtime migrations. One way to fix it is to delete supabase/.temp/postgres-version file so it uses the latest pinned version. I will also make a patch to cli to ignore these incompatible versions.

Alternatively you may want to update your hosted project to the latest postgres version.

Hey, @sweatybridge! Thanks for figuring it out. It seems to have solved the specific error I mentioned earlier. However, I’m now encountering a new error. After removing the .temp folder, re-linking with my remote project, and running npx supabase start again, this issue surfaced. I did update to CLI version 1.136.3.

New error log:

realtime-dev.supabase_realtime_PROJECT_NAME container logs:
08:55:40.926 [error] Could not create schema migrations table. This error usually happens due to the following:

  * The database does not exist
  * The "schema_migrations" table, which Ecto uses for managing
    migrations, was defined by another library
  * There is a deadlock while migrating (such as using concurrent
    indexes with a migration_lock)

To fix the first issue, run "mix ecto.create".

To address the second, you can run "mix ecto.drop" followed by
"mix ecto.create". Alternatively you may configure Ecto to use
another table and/or repository for managing migrations:

    config :realtime, Realtime.Repo,
      migration_source: "some_other_table_for_schema_migrations",
      migration_repo: AnotherRepoForSchemaMigrations

The full error report is shown below.

** (Postgrex.Error) ERROR 3F000 (invalid_schema_name) no schema has been selected to create in
    (ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:932: Ecto.Adapters.SQL.raise_sql_call_error/1
    (elixir 1.14.3) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
    (ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:1024: Ecto.Adapters.SQL.execute_ddl/4
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:696: Ecto.Migrator.verbose_schema_migration/3
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:510: Ecto.Migrator.lock_for_migrations/4
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:422: Ecto.Migrator.run/4
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:146: Ecto.Migrator.with_repo/3
    nofile:1: (file)

Output of npx supabase services:

SERVICE IMAGE LOCAL LINKED
supabase/postgres 15.1.0.49 15.1.0.49
supabase/gotrue v2.132.3 v2.132.3
postgrest/postgrest v10.2.0 v10.2.0
supabase/realtime v2.25.50 -
supabase/storage-api v0.46.3 v0.46.3
supabase/edge-runtime v1.32.0 -
supabase/studio 20240101-8e4a094 -
supabase/postgres-meta v0.75.0 -
supabase/logflare 1.4.0 -
bitnami/pgbouncer 1.20.1-debian-11-r39 -
darthsim/imgproxy v3.8.0 -