Skip to content

Commit 6ff45d6

Browse files
authored
chore(docs): update project migration guide with vault instructions (supabase#17841)
* chore(docs): update project migration guide with vault instructions * chore(docs): add troubleshooting notes for auth and storage schemas
1 parent 19746b1 commit 6ff45d6

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

apps/docs/pages/guides/platform/migrating-and-upgrading-projects.mdx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Migrating projects can be achieved using the Supabase CLI. This is particularly
7373
### Before you begin
7474

7575
- Install [Postgres](https://www.postgresql.org/download/) so you can run `psql` and `pg_dump`.
76-
- Install [Supabase CLI](https://supabase.com/docs/guides/cli#installation).
76+
- Install [Supabase CLI](/docs/guides/cli#installation).
7777
- Create a new [Supabase project](https://supabase.com/dashboard).
7878
- Install [Docker Desktop](https://www.docker.com) for your platform.
7979
- Set environment variables for the old project's database URL as `$OLD_DB_URL` and the new project's as `$NEW_DB_URL`.
@@ -96,6 +96,20 @@ In your new project:
9696
1. Enable [Database Webhooks](https://supabase.com/dashboard/project/_/database/hooks) if you enabled them in your old project.
9797
2. Enable any [extensions](https://supabase.com/dashboard/project/_/database/extensions) that were enabled in your old project.
9898

99+
If you use [column encryption](/docs/guides/database/column-encryption), first copy the root encryption key to your new project using your [Personal Access Token](https://supabase.com/dashboard/account/tokens).
100+
101+
```bash
102+
export OLD_PROJECT_REF="<old_project_ref>"
103+
export NEW_PROJECT_REF="<new_project_ref>"
104+
export SUPABASE_ACCESS_TOKEN="<personal_access_token>"
105+
106+
curl "https://api.supabase.com/v1/projects/$OLD_PROJECT_REF/pgsodium" \
107+
-H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" |
108+
curl "https://api.supabase.com/v1/projects/$NEW_PROJECT_REF/pgsodium" \
109+
-H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \
110+
-X PUT --json @-
111+
```
112+
99113
Then run the following command from your terminal:
100114

101115
```bash
@@ -104,14 +118,26 @@ psql \
104118
--variable ON_ERROR_STOP=1 \
105119
--file roles.sql \
106120
--file schema.sql \
121+
--command 'SET session_replication_role = replica' \
107122
--file data.sql \
108123
--dbname "$NEW_DB_URL"
109124
```
110125

111-
Notes:
126+
Setting the `session_replication_role` to `replica` disables all triggers so that columns are not double encrypted.
127+
128+
Troubleshooting notes:
112129

113130
- If you have created any [custom roles](https://supabase.com/dashboard/project/_/database/roles) with `login` attribute, you have to manually set their passwords in the new project.
114-
- If you receive any permission errors when running `supabase db dump --db-url "$OLD_DB_URL" -f schema.sql`, you may need to edit the `schema.sql` file and change any lines saying `OWNER TO "supabase_admin"` to `OWNER TO "postgres"`.
131+
- If you run into any permission errors related to `supabase_admin` during restore, edit the `schema.sql` file and comment out any lines containing `ALTER ... OWNER TO "supabase_admin"`.
132+
133+
### Schema changes to `auth` and `storage`
134+
135+
If you have modified the `auth` and `storage` schemas in your old project, such as adding triggers or RLS policies, you have to restore them separately. The Supabase CLI can help you diff the changes to these schemas using the following commands.
136+
137+
```bash
138+
supabase link --project-ref "$OLD_PROJECT_REF"
139+
supabase db diff --linked --schema auth,storage > changes.sql
140+
```
115141

116142
### Enable publication on tables
117143

0 commit comments

Comments
 (0)