You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve migration between projects to include super user role update #1416
It took me quite a while to understand it but when I was doing a migration from a project to another one replication disappeared and even though my data was correctly imported into the new project, all foreign keys weirdly brought bugs.
After a couple of tests, I found out that the problem was that the user postgres was not a super user.
I fixed the issue by temporarily set the postgres user as super user with ALTER USER postgres WITH SUPERUSER;
I could now see way less errors and the import worked correctly.
I switch the user postgres back to not being a super user with ALTER USER postgres WITH NOSUPERUSER;
Describe the improvement
I'm not 100% sure this is the right approach but it worked for me. If it is then perhaps this could be added to the doc. In the doc, you're saying "You may see some errors". But in my case, I saw a lot of errors due to lack of permissions and I thought it was ok.
I get a long list of results in the console including these errors:
ERROR: must be owner of table objects
ERROR: relation "public.searchUpdates" does not exist
ERROR: must be owner of index name_prefix_search
ERROR: must be owner of table objects
ERROR: cannot drop constraint users_pkey on table auth.users because other objects depend on it
DETAIL: constraint buckets_owner_fkey on table storage.buckets depends on index auth.users_pkey
constraint objects_owner_fkey on table storage.objects depends on index auth.users_pkey
HINT: Use DROP ... CASCADE to drop the dependent objects too.
ERROR: permission denied to create extension "pgcrypto"
HINT: Must be superuser to create this extension.
ERROR: extension "pgcrypto" does not exist
ERROR: required extension "pgcrypto" is not installed
HINT: Use CREATE EXTENSION ... CASCADE to install required extensions too.
ERROR: extension "pgjwt" does not exist
CREATE EXTENSION
COMMENT
CREATE TYPE
ERROR: must be member of role "supabase_admin"
CREATE FUNCTION
ERROR: must be member of role "supabase_admin"
ERROR: function "extension" already exists with same argument types
CREATE TABLE
ERROR: must be member of role "supabase_admin"
ERROR: must be member of role "supabase_admin"
ERROR: must be member of role "supabase_admin"
ERROR: must be member of role "supabase_admin"
ERROR: must be member of role "supabase_admin"
ERROR: must be member of role "supabase_admin"
ERROR: permission denied to create event trigger "api_restart"
HINT: Must be superuser to create an event trigger.
ERROR: event trigger "api_restart" does not exist
These are just snippets. If you want the full log please let me know.
On the new project I also couldn't delete a user from the dashboard. I could only do that if postgres is a super user. Not sure what's the right approach here.
@AWaselnuk Yes that seems to be the same issue. If you use the workaround I described in the problem it should do the trick. @kiwicopple also talked about it in your tweet.
@AWaselnuk Hm. Could you send me your project ref(https://app.supabase.io/project/<project_ref>/editor/sql) to [email protected]?
I think the main problem with the current procedure in the docs is that it dumps the fulll db, and that includes internal schemas, such as auth, storage, extensions - those require high privileges to set up.
If we restrict to just dump the public schema(which is where users store their app schema), it's possible to restore without a SUPERUSER. Like this:
@steve-chavez Ah I'll try it out. That would make sense. Perhaps it would be great to document the 2 approaches as in my case I actually wanted to move auth users as well.
Activity
steve-chavez commentedon May 5, 2021
Can you share what were the errors?
We're tightening security and SUPERUSER privilege won't be available soon(ish).
cdedreuille commentedon May 5, 2021
Thanks for your reply @steve-chavez. To reproduce the issue:
These are just snippets. If you want the full log please let me know.
On the new project I also couldn't delete a user from the dashboard. I could only do that if
postgresis a super user. Not sure what's the right approach here.AWaselnuk commentedon May 6, 2021
I'm struggling with foreign keys after a project migration. I wonder if this is the cause.
Details here: https://twitter.com/AWaselnuk/status/1390307727583371264?s=20
cdedreuille commentedon May 6, 2021
@AWaselnuk Yes that seems to be the same issue. If you use the workaround I described in the problem it should do the trick. @kiwicopple also talked about it in your tweet.
steve-chavez commentedon May 6, 2021
@AWaselnuk Can you try creating/dropping a fake table on your db, and then retry the failing requests?
Do:
steve-chavez commentedon May 6, 2021
@cdedreuille Yes, that would be really helpful. Thank you.
AWaselnuk commentedon May 6, 2021
@cdedreuille thanks for the assist :)
@steve-chavez I tried the table create/drop and still seeing same error from query.
Steps I took:
create table sample(); drop table sample;Error message same as before:
'Could not find foreign keys between these entities. No relationship found between purchases and stripe_product_id'I need a way to fix these keys without running a second import because I shipped with a workaround so I now have actual user data coming in on PROD.
steve-chavez commentedon May 6, 2021
@AWaselnuk Hm. Could you send me your project ref(
https://app.supabase.io/project/<project_ref>/editor/sql) to [email protected]?cdedreuille commentedon May 6, 2021
@steve-chavez I sent the logs by email.
AWaselnuk commentedon May 7, 2021
@steve-chavez sent. Thanks very much 🙏
steve-chavez commentedon May 7, 2021
I think the main problem with the current procedure in the docs is that it dumps the fulll db, and that includes internal schemas, such as
auth,storage,extensions- those require high privileges to set up.If we restrict to just dump the
publicschema(which is where users store their app schema), it's possible to restore without a SUPERUSER. Like this:pg_dump \ -h db.ref.supabase.co \ -U postgres --schema-only \ --clean --if-exists --schema=public \ > supabase_schema.sqlThe restore command stays the same, I've tried it on a new project and it's working.
@cdedreuille Perhaps you can confirm the above works without a superuser?
cdedreuille commentedon May 10, 2021
@steve-chavez Ah I'll try it out. That would make sense. Perhaps it would be great to document the 2 approaches as in my case I actually wanted to move auth users as well.
GaryAustin1 commentedon Feb 8, 2023
Closing this issue as stale and likely impacted by the new security patch removing super user role.
#9314