cli icon indicating copy to clipboard operation
cli copied to clipboard

Pulling migrations from fresh project errors on running migrations

Open ncrmro opened this issue 9 months ago • 6 comments

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Create new project on supabase
  2. Try to pull migrations to local project. Get the following errro
Seeding globals from roles.sql...
Applying migration 20250523033515_remote_schema.sql...
Applying migration 20250523033836_remote_schema.sql...
Stopping containers...
ERROR: must be owner of relation prefixes (SQLSTATE 42501)                
At statement: 4                                                           
drop trigger if exists "prefixes_create_hierarchy" on "storage"."prefixes"
Try rerunning the command with --debug to troubleshoot the error.

Expected behavior A clear and concise description of what you expected to happen.

Migrations complete

Screenshots If applicable, add screenshots to help explain your problem.

System information Rerun the failing command with --create-ticket flag.

  • Ticket ID: [e.g. ab1ac733e31e4f928a4d7c8402543712]
  • Version of OS: Ubuntu 24.04
  • Version of CLI: 2.23.5/2.23.4
  • Version of Docker: Docker version 26.1.3, build b72abbb
  • Versions of services: [output from supabase services command]
  
   SERVICE IMAGE          | LOCAL                  | LINKED     
  ------------------------|------------------------|------------
   supabase/postgres      | 15.8.1.091             | 15.8.1.091 
   supabase/gotrue        | v2.173.0               | v2.173.0   
   postgrest/postgrest    | v12.2.3                | v12.2.3    
   supabase/realtime      | v2.35.3                | -          
   supabase/storage-api   | v1.22.17               | -          
   supabase/edge-runtime  | v1.67.4                | -          
   supabase/studio        | 2025.05.19-sha-3487831 | -          
   supabase/postgres-meta | v0.89.1                | -          
   supabase/logflare      | 1.12.0                 | -          
   supabase/supavisor     | 2.5.1                  | -     

Additional context

 realtime            | schema_migrations          | table             | supabase_admin
 realtime            | subscription               | table             | supabase_admin
 storage             | buckets                    | table             | supabase_storage_admin
 storage             | migrations                 | table             | supabase_storage_admin
 storage             | objects                    | table             | supabase_storage_admin
 storage             | prefixes                   | table             | supabase_storage_admin
 storage             | s3_multipart_uploads       | table             | supabase_storage_admin
 storage             | s3_multipart_uploads_parts | table             | supabase_storage_admin

ncrmro avatar May 23 '25 04:05 ncrmro

I guess i'm a bit confused, was I supposed to run this supabase db pull --schema auth,storage?

ncrmro avatar May 23 '25 04:05 ncrmro

Same issue, I think it gets fixed if you revert back to the old CLI version but this keeps popping up with the new CLI version

reyanshgupta avatar May 24 '25 08:05 reyanshgupta

I guess this is related to a similar issue I had all of the sudden.

I was creating a new migration the day after upgrading to newest cli (2.23.4), and got this error: "supabase diff ERROR: permission denied for schema "storage" (SQLSTATE 42501)". (The migrations worked fine the day before, before I upgraded, don't remember the cli version that was sorry).

This is my command: supabase db diff --schema public,storage,extensions,auth,util,pgmq --file

The problem was a very old migration that was doing this:

CREATE OR REPLACE FUNCTION storage.extension(name text)
...rest of function...
;

I could not find anything to fix this so wound up commenting out the errorous statements in the migration files locally so I could create my new migration, which worked for now.

Hope this helps.

iamgoddog avatar May 25 '25 14:05 iamgoddog

Almost same issue here. I just upgraded supabase-cli from 2.22.6-1 to 2.23.4-1 and after supabase db reset I get these migration errors.

nietsmmar avatar May 26 '25 16:05 nietsmmar

Facing the same issue on version 2.26.9.

Stopping containers...
ERROR: must be owner of relation prefixes (SQLSTATE 42501)                
At statement: 4                                                           
drop trigger if exists "prefixes_create_hierarchy" on "storage"."prefixes"
Try rerunning the command with --debug to troubleshoot the error.
Error: Process completed with exit code 1.

farzadali3 avatar Jun 22 '25 09:06 farzadali3

@farzadali3 check this out: https://github.com/orgs/supabase/discussions/34270

nietsmmar avatar Jun 22 '25 14:06 nietsmmar

I get the same issue with the cli on 2.45.5 and after i updated 2.48.3

ERROR: must be owner of relation prefixes (SQLSTATE 42501)              
At statement: 775                                                       
drop trigger if exists "prefixes_delete_cleanup" on "storage"."prefixes"

I run the queries to check if i've changed auth, storage, and realtime (https://github.com/orgs/supabase/discussions/34270) referenced by @nietsmmar

SET search_path = '';
SELECT oid::regclass AS table_name
FROM pg_class  
WHERE  
    (relnamespace = 'auth'::regnamespace AND relowner != 'supabase_auth_admin'::regrole)  
    OR (relnamespace = 'storage'::regnamespace AND relowner != 'supabase_storage_admin'::regrole)  
    OR (  
        relnamespace = 'realtime'::regnamespace
        AND relowner NOT IN (  
            SELECT oid  
            FROM pg_roles  
            WHERE rolname IN ('supabase_admin', 'supabase_realtime_admin')  
        )  
    );

SET search_path = '';
SELECT pg_catalog.format('%s(%s)', oid::regproc, pg_get_function_identity_arguments(oid::regproc)) AS function_name
FROM pg_proc  
WHERE  
   (pronamespace = 'auth'::regnamespace AND proowner != 'supabase_auth_admin'::regrole)  
   OR (pronamespace = 'storage'::regnamespace AND proowner != 'supabase_storage_admin'::regrole)  
   OR (  
       pronamespace = 'realtime'::regnamespace  
       AND proowner NOT IN (  
           SELECT oid  
           FROM pg_roles  
           WHERE rolname IN ('supabase_admin', 'supabase_realtime_admin')  
       )  
   );

but it returns nothing as well

EDIT: unsure but seems that after updating docker new images were downloaded for supabase cli (even though i had updated the version prior already) and everything essentially works

saadiahmadx avatar Oct 02 '25 15:10 saadiahmadx