Skip to content

Commit 2911795

Browse files
PLyncharislam
andauthored
Docs: overhaul Migrating within Supabase page(supabase#31049)
* Overhaul of Migrate within Supabase * Added sub menus for overhaul of Migrate within supabase * Re-structuring of content and pages * Re-organize flow of the guide * Prettier fix and small additions to dashboard restore guide * update CLI guide to have dummy data for now * Add structure for Windows specific instructions * Add Postgres installation as partial * Full first draft * fix headings in main page * Fix vale issues * Proofread #1 * Small fixes * Editing pass * More edits after first tests. * Final editting pass after testing * Add common issues I ran into while testing and fixed installation instructions for MacOS * Editing pass after more testing and proofreading * Grammar fixes * attempt at vale fixes * Add tip for windows installation * edits * Fix dashboard restore hyperlink --------- Co-authored-by: Charis Lam <[email protected]>
1 parent fc5ef8b commit 2911795

File tree

10 files changed

+590
-146
lines changed

10 files changed

+590
-146
lines changed

apps/docs/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ const HomePage = () => (
251251
</div>
252252

253253
<ul className="grid col-span-8 grid-cols-12 gap-6 not-prose">
254-
{MIGRATION_PAGES.map((guide) => {
254+
{MIGRATION_PAGES.sort((a, b) => a.name.localeCompare(b.name)).map((guide) => {
255255
return (
256256
<li key={guide.name} className="col-span-6 md:col-span-4">
257257
<Link href={guide.url} passHref>

apps/docs/components/MDX/partials.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import QuickstartDbSetup from './quickstart_db_setup.mdx'
1414
import QuickstartIntro from './quickstart_intro.mdx'
1515
import SocialProviderSettingsSupabase from './social_provider_settings_supabase.mdx'
1616
import SocialProviderSetup from './social_provider_setup.mdx'
17+
import PostgresInstallation from './postgres_installation.mdx'
1718

1819
export {
1920
AuthErrorCodesTable,
@@ -30,4 +31,5 @@ export {
3031
QuickstartIntro,
3132
SocialProviderSettingsSupabase,
3233
SocialProviderSetup,
34+
PostgresInstallation,
3335
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<Tabs
2+
scrollable
3+
size="small"
4+
type="underlined"
5+
defaultActiveId="windows"
6+
>
7+
8+
<TabPanel id="windows" label="Windows">
9+
10+
<StepHikeCompact>
11+
12+
<StepHikeCompact.Step step={1}>
13+
14+
<StepHikeCompact.Details title="Install Postgres" fullWidth>
15+
16+
Download and run the installation file for the latest version from the [PostgreSQL installer download page](https://www.postgresql.org/download/windows/).
17+
18+
</StepHikeCompact.Details>
19+
20+
</StepHikeCompact.Step>
21+
22+
<StepHikeCompact.Step step={2}>
23+
24+
<StepHikeCompact.Details title="Add Postgres to your system PATH" fullWidth>
25+
26+
Add the Postgres binary to your system PATH.
27+
28+
In Control Panel, under the Advanced tab of System Properties, click Environment Variables. Edit the Path variable by adding the path the SQL binary you just installed.
29+
30+
The path will look something like this, though it may differ slightly depending on your installed version:
31+
32+
```
33+
C:\Program Files\PostgreSQL\17\bin
34+
```
35+
36+
</StepHikeCompact.Details>
37+
38+
</StepHikeCompact.Step>
39+
40+
<StepHikeCompact.Step step={3}>
41+
42+
<StepHikeCompact.Details title="Verify that psql is working" fullWidth>
43+
44+
Open your terminal and run the following command:
45+
46+
```sh
47+
psql --version
48+
```
49+
50+
<Admonition type="tip">
51+
52+
If you get an error that psql is not available or cannot be found, check that you have correctly added the binary to your system PATH. Also try restarting your terminal.
53+
54+
</Admonition>
55+
56+
</StepHikeCompact.Details>
57+
58+
</StepHikeCompact.Step>
59+
60+
</StepHikeCompact>
61+
62+
</TabPanel>
63+
64+
<TabPanel id="mac" label="MacOS">
65+
66+
<StepHikeCompact>
67+
68+
<StepHikeCompact.Step step={1}>
69+
70+
<StepHikeCompact.Details title="Install Homebrew" fullWidth>
71+
72+
Install [Homebrew](https://brew.sh/).
73+
74+
</StepHikeCompact.Details>
75+
76+
</StepHikeCompact.Step>
77+
78+
<StepHikeCompact.Step step={2}>
79+
80+
<StepHikeCompact.Details title="Install Postgres" fullWidth>
81+
82+
Install Postgres via Homebrew by running the following command in your terminal:
83+
84+
```sh
85+
brew install postgresql@17
86+
```
87+
88+
</StepHikeCompact.Details>
89+
90+
</StepHikeCompact.Step>
91+
92+
<StepHikeCompact.Step step={3}>
93+
94+
<StepHikeCompact.Details title="Verify that psql is working" fullWidth>
95+
96+
Restart your terminal and run the following command:
97+
98+
```sh
99+
psql --version
100+
```
101+
102+
If you get an error that psql is not available or cannot be found then the PATH variable is likely either not correctly set or you need to restart your terminal.
103+
104+
You can add the Postgres installation path to your PATH variable by running the following command:
105+
106+
```sh
107+
brew info postgresql@17
108+
```
109+
110+
The above command will give an output like this:
111+
112+
```sh
113+
If you need to have postgresql@17 first in your PATH, run:
114+
115+
echo 'export PATH="/opt/homebrew/opt/postgresql@17/bin:$PATH"' >> ~/.zshrc
116+
```
117+
118+
Run the command mentioned and restart the terminal.
119+
120+
</StepHikeCompact.Details>
121+
122+
</StepHikeCompact.Step>
123+
124+
</StepHikeCompact>
125+
126+
</TabPanel>
127+
128+
</Tabs>

apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,16 @@ export const platform: NavMenuConstant = {
20032003
{
20042004
name: 'Migrating within Supabase',
20052005
url: '/guides/platform/migrating-within-supabase',
2006+
items: [
2007+
{
2008+
name: 'Restore Dashboard backup',
2009+
url: '/guides/platform/migrating-within-supabase/dashboard-restore',
2010+
},
2011+
{
2012+
name: 'Backup and restore using CLI',
2013+
url: '/guides/platform/migrating-within-supabase/backup-restore',
2014+
},
2015+
],
20062016
},
20072017
{
20082018
name: 'Migrating to Supabase',

apps/docs/components/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import ProjectSetup from './MDX/project_setup.mdx'
4848
import QuickstartIntro from './MDX/quickstart_intro.mdx'
4949
import SocialProviderSettingsSupabase from './MDX/social_provider_settings_supabase.mdx'
5050
import SocialProviderSetup from './MDX/social_provider_setup.mdx'
51+
import PostgresInstallation from './MDX/postgres_installation.mdx'
5152

5253
// Icons
5354
import {
@@ -162,6 +163,7 @@ const components = {
162163
SharedData,
163164
SocialProviderSettingsSupabase,
164165
SocialProviderSetup,
166+
PostgresInstallation,
165167
SqlToRest,
166168
StepHikeCompact,
167169
table: Table,
Lines changed: 11 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,23 @@
11
---
22
title: Migrating within Supabase
3-
subtitle: Migrate from one Supabase project to another
3+
subtitle: Learn how to migrate from one Supabase project to another
44
---
55

6-
Migrating projects can be achieved using the Supabase CLI. This is particularly useful for older projects (for example to use a newer Postgres version).
6+
If you are on a Paid Plan and have physical backups enabled, you should instead use the [Restore
7+
to another project feature](/docs/guides/platform/backups#restore-to-a-new-project)
78

8-
### Before you begin
9+
## Database migration guides
910

10-
- Install [Postgres](https://www.postgresql.org/download/) so you can run `psql` and `pg_dump`.
11-
- Install the latest version of [Supabase CLI](/docs/guides/cli#installation).
12-
- Create a new [Supabase project](https://supabase.com/dashboard).
13-
- Install [Docker Desktop](https://www.docker.com) for your platform.
14-
- Set environment variables for the old project's database URL as `$OLD_DB_URL` and the new project's as `$NEW_DB_URL`.
15-
To find the database URL for a project, go to the project's dashboard page [Project Settings/Database](https://supabase.com/dashboard/project/_/settings/database) and look under `Connection string`. If your network provider supports IPv6, you can disable `Use connection pooling`. Otherwise, enable `Use connection pooling`. For the pooler mode, `Transaction` will work.
11+
If you need to migrate from one Supabase project to another, choose the appropriate guide below:
1612

17-
### Backup your old database
13+
### Backup file from the dashboard (\*.backup)
1814

19-
1. Run the following command from your terminal:
15+
Follow the [Restore dashboard backup guide](/docs/guides/platform/migrating-within-supabase/dashboard-restore)
2016

21-
```bash
22-
supabase db dump --db-url "$OLD_DB_URL" -f roles.sql --role-only
23-
supabase db dump --db-url "$OLD_DB_URL" -f schema.sql
24-
supabase db dump --db-url "$OLD_DB_URL" -f data.sql --use-copy --data-only
25-
```
17+
### SQL backup files (\*.sql)
2618

27-
### Restore to your new project
19+
Follow the [Backup and Restore using the CLI guide](/docs/guides/platform/migrating-within-supabase/backup-restore)
2820

29-
In your new project:
21+
## Transfer my project to a different organization
3022

31-
1. Enable [Database Webhooks](https://supabase.com/dashboard/project/_/database/hooks) if you enabled them in your old project.
32-
2. Enable any [extensions](https://supabase.com/dashboard/project/_/database/extensions) that were enabled in your old project.
33-
34-
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).
35-
36-
```bash
37-
export OLD_PROJECT_REF="<old_project_ref>"
38-
export NEW_PROJECT_REF="<new_project_ref>"
39-
export SUPABASE_ACCESS_TOKEN="<personal_access_token>"
40-
41-
curl "https://api.supabase.com/v1/projects/$OLD_PROJECT_REF/pgsodium" \
42-
-H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" |
43-
curl "https://api.supabase.com/v1/projects/$NEW_PROJECT_REF/pgsodium" \
44-
-H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \
45-
-X PUT --json @-
46-
```
47-
48-
Then run the following command from your terminal:
49-
50-
```bash
51-
psql \
52-
--single-transaction \
53-
--variable ON_ERROR_STOP=1 \
54-
--file roles.sql \
55-
--file schema.sql \
56-
--command 'SET session_replication_role = replica' \
57-
--file data.sql \
58-
--dbname "$NEW_DB_URL"
59-
```
60-
61-
Setting the `session_replication_role` to `replica` disables all triggers so that columns are not double encrypted.
62-
63-
Troubleshooting notes:
64-
65-
- 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.
66-
- 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"`.
67-
68-
### Preserving migration history
69-
70-
If you were using Supabase CLI for managing migrations on your old database and would like to preserve the migration history in your newly restored project, you need to insert the migration records separately using the following commands.
71-
72-
```bash
73-
supabase db dump --db-url "$OLD_DB_URL" -f history_schema.sql --schema supabase_migrations
74-
supabase db dump --db-url "$OLD_DB_URL" -f history_data.sql --use-copy --data-only --schema supabase_migrations
75-
psql \
76-
--single-transaction \
77-
--variable ON_ERROR_STOP=1 \
78-
--file history_schema.sql \
79-
--file history_data.sql \
80-
--dbname "$NEW_DB_URL"
81-
```
82-
83-
### Schema changes to `auth` and `storage`
84-
85-
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.
86-
87-
```bash
88-
supabase link --project-ref "$OLD_PROJECT_REF"
89-
supabase db diff --linked --schema auth,storage > changes.sql
90-
```
91-
92-
### Enable publication on tables
93-
94-
Replication for Realtime is disabled for all tables in your new project. On the [Publications](https://supabase.com/dashboard/project/_/database/publications) page in the Dashboard, select your new project and enable replication for tables that were enabled in your old project.
95-
96-
### Migrate storage objects
97-
98-
The new project has the old project's Storage buckets, but the Storage objects need to be migrated manually. Use this script to move storage objects from one project to another.
99-
100-
```js
101-
// npm install @supabase/supabase-js@1
102-
const { createClient } = require('@supabase/supabase-js')
103-
104-
const OLD_PROJECT_URL = 'https://xxx.supabase.co'
105-
const OLD_PROJECT_SERVICE_KEY = 'old-project-service-key-xxx'
106-
107-
const NEW_PROJECT_URL = 'https://yyy.supabase.co'
108-
const NEW_PROJECT_SERVICE_KEY = 'new-project-service-key-yyy'
109-
110-
;(async () => {
111-
const oldSupabaseRestClient = createClient(OLD_PROJECT_URL, OLD_PROJECT_SERVICE_KEY, {
112-
db: {
113-
schema: 'storage',
114-
},
115-
})
116-
const oldSupabaseClient = createClient(OLD_PROJECT_URL, OLD_PROJECT_SERVICE_KEY)
117-
const newSupabaseClient = createClient(NEW_PROJECT_URL, NEW_PROJECT_SERVICE_KEY)
118-
119-
// make sure you update max_rows in postgrest settings if you have a lot of objects
120-
// or paginate here
121-
const { data: oldObjects, error } = await oldSupabaseRestClient.from('objects').select()
122-
if (error) {
123-
console.log('error getting objects from old bucket')
124-
throw error
125-
}
126-
127-
for (const objectData of oldObjects) {
128-
console.log(`moving ${objectData.id}`)
129-
try {
130-
const { data, error: downloadObjectError } = await oldSupabaseClient.storage
131-
.from(objectData.bucket_id)
132-
.download(objectData.name)
133-
if (downloadObjectError) {
134-
throw downloadObjectError
135-
}
136-
137-
const { _, error: uploadObjectError } = await newSupabaseClient.storage
138-
.from(objectData.bucket_id)
139-
.upload(objectData.name, data, {
140-
upsert: true,
141-
contentType: objectData.metadata.mimetype,
142-
cacheControl: objectData.metadata.cacheControl,
143-
})
144-
if (uploadObjectError) {
145-
throw uploadObjectError
146-
}
147-
} catch (err) {
148-
console.log('error moving ', objectData)
149-
console.log(err)
150-
}
151-
}
152-
})()
153-
```
154-
155-
### Transfer to a different organization
156-
157-
Note that project migration is for transferring your projects to different regions. If you need to move your project to a different organization without touching the infrastructure, see [project transfers](/docs/guides/platform/project-transfer).
23+
Project migration is primarily for changing regions or upgrading to new major versions of the platform in some scenarios. If you need to move your project to a different organization without touching the infrastructure, see [project transfers](/docs/guides/platform/project-transfer).

0 commit comments

Comments
 (0)