The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Docs: overhaul Migrating within Supabase page(#31049)
Peter29117959b14a
diff --git a/apps/docs/app/page.tsx b/apps/docs/app/page.tsxindex 66911206162..9286d1a2f20 100644--- a/apps/docs/app/page.tsx+++ b/apps/docs/app/page.tsx@@ -251,7 +251,7 @@ const HomePage = () => (</div><ul className="grid col-span-8 grid-cols-12 gap-6 not-prose">- {MIGRATION_PAGES.map((guide) => {+ {MIGRATION_PAGES.sort((a, b) => a.name.localeCompare(b.name)).map((guide) => {return (<li key={guide.name} className="col-span-6 md:col-span-4"><Link href={guide.url} passHref>diff --git a/apps/docs/components/MDX/partials.tsx b/apps/docs/components/MDX/partials.tsxindex 1f6133c6e4f..a931fcf5877 100644--- a/apps/docs/components/MDX/partials.tsx+++ b/apps/docs/components/MDX/partials.tsx@@ -14,6 +14,7 @@ import QuickstartDbSetup from './quickstart_db_setup.mdx'import QuickstartIntro from './quickstart_intro.mdx'import SocialProviderSettingsSupabase from './social_provider_settings_supabase.mdx'import SocialProviderSetup from './social_provider_setup.mdx'+import PostgresInstallation from './postgres_installation.mdx'export {AuthErrorCodesTable,@@ -30,4 +31,5 @@ export {QuickstartIntro,SocialProviderSettingsSupabase,SocialProviderSetup,+ PostgresInstallation,}diff --git a/apps/docs/components/MDX/postgres_installation.mdx b/apps/docs/components/MDX/postgres_installation.mdxnew file mode 100644index 00000000000..46f440e9d8b--- /dev/null+++ b/apps/docs/components/MDX/postgres_installation.mdx@@ -0,0 +1,128 @@+<Tabs+ scrollable+ size="small"+ type="underlined"+ defaultActiveId="windows"+>++<TabPanel id="windows" label="Windows">++<StepHikeCompact>++ <StepHikeCompact.Step step={1}>++ <StepHikeCompact.Details title="Install Postgres" fullWidth>++ Download and run the installation file for the latest version from the [PostgreSQL installer download page](https://www.postgresql.org/download/windows/).++ </StepHikeCompact.Details>++ </StepHikeCompact.Step>++ <StepHikeCompact.Step step={2}>++ <StepHikeCompact.Details title="Add Postgres to your system PATH" fullWidth>++ Add the Postgres binary to your system PATH.++ 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.++ The path will look something like this, though it may differ slightly depending on your installed version:++ ```+ C:\Program Files\PostgreSQL\17\bin+ ```++ </StepHikeCompact.Details>++ </StepHikeCompact.Step>++ <StepHikeCompact.Step step={3}>++ <StepHikeCompact.Details title="Verify that psql is working" fullWidth>++ Open your terminal and run the following command:++ ```sh+ psql --version+ ```++ <Admonition type="tip">++ 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.++ </Admonition>++ </StepHikeCompact.Details>++ </StepHikeCompact.Step>++</StepHikeCompact>++</TabPanel>++<TabPanel id="mac" label="MacOS">++<StepHikeCompact>++ <StepHikeCompact.Step step={1}>++ <StepHikeCompact.Details title="Install Homebrew" fullWidth>++ Install [Homebrew](https://brew.sh/).++ </StepHikeCompact.Details>++ </StepHikeCompact.Step>++ <StepHikeCompact.Step step={2}>++ <StepHikeCompact.Details title="Install Postgres" fullWidth>++ Install Postgres via Homebrew by running the following command in your terminal:++ ```sh+ brew install postgresql@17+ ```++ </StepHikeCompact.Details>++ </StepHikeCompact.Step>++ <StepHikeCompact.Step step={3}>++ <StepHikeCompact.Details title="Verify that psql is working" fullWidth>++ Restart your terminal and run the following command:++ ```sh+ psql --version+ ```++ 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.++ You can add the Postgres installation path to your PATH variable by running the following command:++ ```sh+ brew info postgresql@17+ ```++ The above command will give an output like this:++ ```sh+ If you need to have postgresql@17 first in your PATH, run:++ echo 'export PATH="/opt/homebrew/opt/postgresql@17/bin:$PATH"' >> ~/.zshrc+ ```++ Run the command mentioned and restart the terminal.++ </StepHikeCompact.Details>++ </StepHikeCompact.Step>++</StepHikeCompact>++</TabPanel>++</Tabs>diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.tsindex 26b092a7509..2dcc7059145 100644--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts@@ -2003,6 +2003,16 @@ export const platform: NavMenuConstant = {{name: 'Migrating within Supabase',url: '/guides/platform/migrating-within-supabase',+ items: [+ {+ name: 'Restore Dashboard backup',+ url: '/guides/platform/migrating-within-supabase/dashboard-restore',+ },+ {+ name: 'Backup and restore using CLI',+ url: '/guides/platform/migrating-within-supabase/backup-restore',+ },+ ],},{name: 'Migrating to Supabase',diff --git a/apps/docs/components/index.tsx b/apps/docs/components/index.tsxindex 990db346ea6..78be0f2c7b2 100644--- a/apps/docs/components/index.tsx+++ b/apps/docs/components/index.tsx@@ -48,6 +48,7 @@ import ProjectSetup from './MDX/project_setup.mdx'import QuickstartIntro from './MDX/quickstart_intro.mdx'import SocialProviderSettingsSupabase from './MDX/social_provider_settings_supabase.mdx'import SocialProviderSetup from './MDX/social_provider_setup.mdx'+import PostgresInstallation from './MDX/postgres_installation.mdx'// Iconsimport {@@ -162,6 +163,7 @@ const components = {SharedData,SocialProviderSettingsSupabase,SocialProviderSetup,+ PostgresInstallation,SqlToRest,StepHikeCompact,table: Table,diff --git a/apps/docs/content/guides/platform/migrating-within-supabase.mdx b/apps/docs/content/guides/platform/migrating-within-supabase.mdxindex 0c33c3a7015..7c646a5f6f7 100644--- a/apps/docs/content/guides/platform/migrating-within-supabase.mdx+++ b/apps/docs/content/guides/platform/migrating-within-supabase.mdx@@ -1,157 +1,23 @@---title: Migrating within Supabase-subtitle: Migrate from one Supabase project to another+subtitle: Learn how to migrate from one Supabase project to another----Migrating projects can be achieved using the Supabase CLI. This is particularly useful for older projects (for example to use a newer Postgres version).+If you are on a Paid Plan and have physical backups enabled, you should instead use the [Restore+to another project feature](/docs/guides/platform/backups#restore-to-a-new-project)-### Before you begin+## Database migration guides-- Install [Postgres](https://www.postgresql.org/download/) so you can run `psql` and `pg_dump`.-- Install the latest version of [Supabase CLI](/docs/guides/cli#installation).-- Create a new [Supabase project](https://supabase.com/dashboard).-- Install [Docker Desktop](https://www.docker.com) for your platform.-- Set environment variables for the old project's database URL as `$OLD_DB_URL` and the new project's as `$NEW_DB_URL`.- 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.+If you need to migrate from one Supabase project to another, choose the appropriate guide below:-### Backup your old database+### Backup file from the dashboard (\*.backup)-1. Run the following command from your terminal:+Follow the [Restore dashboard backup guide](/docs/guides/platform/migrating-within-supabase/dashboard-restore)-```bash-supabase db dump --db-url "$OLD_DB_URL" -f roles.sql --role-only-supabase db dump --db-url "$OLD_DB_URL" -f schema.sql-supabase db dump --db-url "$OLD_DB_URL" -f data.sql --use-copy --data-only-```+### SQL backup files (\*.sql)-### Restore to your new project+Follow the [Backup and Restore using the CLI guide](/docs/guides/platform/migrating-within-supabase/backup-restore)-In your new project:+## Transfer my project to a different organization-1. Enable [Database Webhooks](https://supabase.com/dashboard/project/_/database/hooks) if you enabled them in your old project.-2. Enable any [extensions](https://supabase.com/dashboard/project/_/database/extensions) that were enabled in your old project.--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).--```bash-export OLD_PROJECT_REF="<old_project_ref>"-export NEW_PROJECT_REF="<new_project_ref>"-export SUPABASE_ACCESS_TOKEN="<personal_access_token>"--curl "https://api.supabase.com/v1/projects/$OLD_PROJECT_REF/pgsodium" \- -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" |-curl "https://api.supabase.com/v1/projects/$NEW_PROJECT_REF/pgsodium" \- -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \- -X PUT --json @--```--Then run the following command from your terminal:--```bash-psql \- --single-transaction \- --variable ON_ERROR_STOP=1 \- --file roles.sql \- --file schema.sql \- --command 'SET session_replication_role = replica' \- --file data.sql \- --dbname "$NEW_DB_URL"-```--Setting the `session_replication_role` to `replica` disables all triggers so that columns are not double encrypted.--Troubleshooting notes:--- 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.-- 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"`.--### Preserving migration history--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.--```bash-supabase db dump --db-url "$OLD_DB_URL" -f history_schema.sql --schema supabase_migrations-supabase db dump --db-url "$OLD_DB_URL" -f history_data.sql --use-copy --data-only --schema supabase_migrations-psql \- --single-transaction \- --variable ON_ERROR_STOP=1 \- --file history_schema.sql \- --file history_data.sql \- --dbname "$NEW_DB_URL"-```--### Schema changes to `auth` and `storage`--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.--```bash-supabase link --project-ref "$OLD_PROJECT_REF"-supabase db diff --linked --schema auth,storage > changes.sql-```--### Enable publication on tables--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.--### Migrate storage objects--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.--```js-// npm install @supabase/supabase-js@1-const { createClient } = require('@supabase/supabase-js')--const OLD_PROJECT_URL = 'https://xxx.supabase.co'-const OLD_PROJECT_SERVICE_KEY = 'old-project-service-key-xxx'--const NEW_PROJECT_URL = 'https://yyy.supabase.co'-const NEW_PROJECT_SERVICE_KEY = 'new-project-service-key-yyy'--;(async () => {- const oldSupabaseRestClient = createClient(OLD_PROJECT_URL, OLD_PROJECT_SERVICE_KEY, {- db: {- schema: 'storage',- },- })- const oldSupabaseClient = createClient(OLD_PROJECT_URL, OLD_PROJECT_SERVICE_KEY)- const newSupabaseClient = createClient(NEW_PROJECT_URL, NEW_PROJECT_SERVICE_KEY)-- // make sure you update max_rows in postgrest settings if you have a lot of objects- // or paginate here- const { data: oldObjects, error } = await oldSupabaseRestClient.from('objects').select()- if (error) {- console.log('error getting objects from old bucket')- throw error- }-- for (const objectData of oldObjects) {- console.log(`moving ${objectData.id}`)- try {- const { data, error: downloadObjectError } = await oldSupabaseClient.storage- .from(objectData.bucket_id)- .download(objectData.name)- if (downloadObjectError) {- throw downloadObjectError- }-- const { _, error: uploadObjectError } = await newSupabaseClient.storage- .from(objectData.bucket_id)- .upload(objectData.name, data, {- upsert: true,- contentType: objectData.metadata.mimetype,- cacheControl: objectData.metadata.cacheControl,- })- if (uploadObjectError) {- throw uploadObjectError- }- } catch (err) {- console.log('error moving ', objectData)- console.log(err)- }- }-})()-```--### Transfer to a different organization--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).+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).diff --git a/apps/docs/content/guides/platform/migrating-within-supabase/backup-restore.mdx b/apps/docs/content/guides/platform/migrating-within-supabase/backup-restore.mdxnew file mode 100644index 00000000000..c7c24c8d30e--- /dev/null+++ b/apps/docs/content/guides/platform/migrating-within-supabase/backup-restore.mdx@@ -0,0 +1,278 @@+---+title: 'Backup and Restore using the CLI'+subtitle: 'Learn how to backup and restore projects using the Supabase CLI'+breadcrumb: 'Migrations'+---++## Before you begin++<Accordion+ type="default"+ openBehaviour="multiple"+ chevronAlign="right"+ justified+ size="medium"+ className="text-foreground-light mt-8 mb-6"+>+ <div className="border-b mt-3 pb-3">+ <AccordionItem header="Install Postgres and psql" id="install-postgres">+ <PostgresInstallation />+ </AccordionItem>+ </div>+</Accordion>++## Backup database using the CLI++<StepHikeCompact>+ <StepHikeCompact.Step step={1}>+ <StepHikeCompact.Details title="Install the Supabase CLI" fullWidth>+ Install the [Supabase CLI](/docs/guides/local-development/cli/getting-started).+ </StepHikeCompact.Details>+ </StepHikeCompact.Step>++<StepHikeCompact.Step step={2}>+ <StepHikeCompact.Details title="Install Docker Desktop" fullWidth>+ Install [Docker Desktop](https://www.docker.com) for your platform.+ </StepHikeCompact.Details>+</StepHikeCompact.Step>++ <StepHikeCompact.Step step={3}>+ <StepHikeCompact.Details title="Get the new database connection string" fullWidth>+ Go to the [project page](/dashboard/project/_/) and click the "**Connect**" button at the top of the page for the connection string.++ <Admonition type="info">+ Use the Session pooler connection string by default. If your ISP supports IPv6, use the direct connection string.+ </Admonition>++ Session pooler connection string:+ ```bash+ postgresql://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@aws-0-us-east-1.pooler.supabase.com:5432/postgres+ ```++ Direct connection string:+ ```bash+ postgresql://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@db.[PROJECT-REF].supabase.com:5432/postgres+ ```+ </StepHikeCompact.Details>++ </StepHikeCompact.Step>++ <StepHikeCompact.Step step={4}>+ <StepHikeCompact.Details title="Get the database password" fullWidth>+ Reset the password in the [Database Settings](/dashboard/project/_/settings/database).++ Replace ```[YOUR-PASSWORD]``` in the connection string with the database password.++ </StepHikeCompact.Details>++ </StepHikeCompact.Step>++ <StepHikeCompact.Step step={5}>+ <StepHikeCompact.Details title="Backup database" fullWidth>+ Run these commands after replacing ```[CONNECTION_STRING]``` with your connection string from the previous steps:++ ```bash+ supabase db dump --db-url [CONNECTION_STRING] -f roles.sql --role-only+ ```++ ```bash+ supabase db dump --db-url [CONNECTION_STRING] -f schema.sql+ ```++ ```bash+ supabase db dump --db-url [CONNECTION_STRING] -f data.sql --use-copy --data-only+ ```+ </StepHikeCompact.Details>+ </StepHikeCompact.Step>++</StepHikeCompact>++## Restore backup using CLI++<StepHikeCompact>+ <StepHikeCompact.Step step={1}>+ <StepHikeCompact.Details title="Create project" fullWidth>+ Create a [new project](https://database.new)+ </StepHikeCompact.Details>+ </StepHikeCompact.Step>++ <StepHikeCompact.Step step={2}>+ <StepHikeCompact.Details title="Configure newly created project" fullWidth>+ In the new project:++ - If Webhooks were used in the old database, enable [Database Webhooks](/dashboard/project/_/database/hooks).+ - If any non-default extensions were used in the old database, enable the [Extensions](/dashboard/project/_/database/extensions).+ - If Replication for Realtime was used in the old database, enable [Publication](/dashboard/project/_/database/publications) on the tables necessary+ </StepHikeCompact.Details>++ </StepHikeCompact.Step>++ <StepHikeCompact.Step step={3}>+ <StepHikeCompact.Details title="Get the new database connection string" fullWidth>+ Go to the [project page](/dashboard/project/_/) and click the "**Connect**" button at the top of the page for the connection string.++ <Admonition type="info">+ Use the Session pooler connection string by default. If your ISP supports IPv6, use the direct connection string.+ </Admonition>++ Session pooler connection string:+ ```bash+ postgresql://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@aws-0-us-east-1.pooler.supabase.com:5432/postgres+ ```++ Direct connection string:+ ```bash+ postgresql://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@db.[PROJECT-REF].supabase.com:5432/postgres+ ```+ </StepHikeCompact.Details>++ </StepHikeCompact.Step>++ <StepHikeCompact.Step step={4}>++ <StepHikeCompact.Details title="Get the database password" fullWidth>+ Reset the password in the [Database Settings](/dashboard/project/_/settings/database).++ Replace ```[YOUR-PASSWORD]``` in the connection string with the database password.++ </StepHikeCompact.Details>+ </StepHikeCompact.Step>++ <StepHikeCompact.Step step={5}>+ <StepHikeCompact.Details title="Restore your Project with the CLI" fullWidth>+ <Tabs+ scrollable+ size="small"+ type="underlined"+ defaultActiveId="no-column-encryption"+ >+ <TabPanel id="no-column-encryption" label="Column encryption disabled">++ Run these commands after replacing ```[CONNECTION_STRING]``` with your connection string from the previous steps:++ ```bash+ psql \+ --single-transaction \+ --variable ON_ERROR_STOP=1 \+ --file roles.sql \+ --file schema.sql \+ --command 'SET session_replication_role = replica' \+ --file data.sql \+ --dbname [CONNECTION_STRING]+ ```++ </TabPanel>+ <TabPanel id="column-encryption" label="Column encryption enabled">+ If you use [column encryption](/docs/guides/database/column-encryption), copy the root encryption key to your new project using your [Personal Access Token](/dashboard/account/tokens).++ You can restore the project using both the old and new project ref (the project ref is the value between "https://" and ".supabase.co" in the URL) instead of the URL.++ ```bash+ export OLD_PROJECT_REF="<old_project_ref>"+ export NEW_PROJECT_REF="<new_project_ref>"+ export SUPABASE_ACCESS_TOKEN="<personal_access_token>"++ curl "https://api.supabase.com/v1/projects/$OLD_PROJECT_REF/pgsodium" \+ -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" |+ curl "https://api.supabase.com/v1/projects/$NEW_PROJECT_REF/pgsodium" \+ -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \+ -X PUT --json @-+ ```+ </TabPanel>+ </Tabs>+ </StepHikeCompact.Details>++ </StepHikeCompact.Step>++</StepHikeCompact>++## Important project restoration notes++### Troubleshooting notes++- Setting the `session_replication_role` to `replica` disables all triggers so that columns are not double encrypted.+- If you have created any [custom roles](/dashboard/project/_/database/roles) with `login` attribute, you have to manually set their passwords in the new project.+- 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"`.++### Preserving migration history++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.++```bash+supabase db dump --db-url "$OLD_DB_URL" -f history_schema.sql --schema supabase_migrations+supabase db dump --db-url "$OLD_DB_URL" -f history_data.sql --use-copy --data-only --schema supabase_migrations+psql \+ --single-transaction \+ --variable ON_ERROR_STOP=1 \+ --file history_schema.sql \+ --file history_data.sql \+ --dbname "$NEW_DB_URL"+```++### Schema changes to `auth` and `storage`++If you have modified the `auth` and `storage` schemas in your old project, such as adding triggers or Row Level Security(RLS) policies, you have to restore them separately. The Supabase CLI can help you diff the changes to these schemas using the following commands.++```bash+supabase link --project-ref "$OLD_PROJECT_REF"+supabase db diff --linked --schema auth,storage > changes.sql+```++### Migrate storage objects++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.++```js+// npm install @supabase/supabase-js@1+const { createClient } = require('@supabase/supabase-js')++const OLD_PROJECT_URL = 'https://xxx.supabase.co'+const OLD_PROJECT_SERVICE_KEY = 'old-project-service-key-xxx'++const NEW_PROJECT_URL = 'https://yyy.supabase.co'+const NEW_PROJECT_SERVICE_KEY = 'new-project-service-key-yyy'++;(async () => {+ const oldSupabaseRestClient = createClient(OLD_PROJECT_URL, OLD_PROJECT_SERVICE_KEY, {+ db: {+ schema: 'storage',+ },+ })+ const oldSupabaseClient = createClient(OLD_PROJECT_URL, OLD_PROJECT_SERVICE_KEY)+ const newSupabaseClient = createClient(NEW_PROJECT_URL, NEW_PROJECT_SERVICE_KEY)++ // make sure you update max_rows in postgrest settings if you have a lot of objects+ // or paginate here+ const { data: oldObjects, error } = await oldSupabaseRestClient.from('objects').select()+ if (error) {+ console.log('error getting objects from old bucket')+ throw error+ }++ for (const objectData of oldObjects) {+ console.log(`moving ${objectData.id}`)+ try {+ const { data, error: downloadObjectError } = await oldSupabaseClient.storage+ .from(objectData.bucket_id)+ .download(objectData.name)+ if (downloadObjectError) {+ throw downloadObjectError+ }++ const { _, error: uploadObjectError } = await newSupabaseClient.storage+ .from(objectData.bucket_id)+ .upload(objectData.name, data, {+ upsert: true,+ contentType: objectData.metadata.mimetype,+ cacheControl: objectData.metadata.cacheControl,+ })+ if (uploadObjectError) {+ throw uploadObjectError+ }+ } catch (err) {+ console.log('error moving ', objectData)+ console.log(err)+ }+ }+})()+```diff --git a/apps/docs/content/guides/platform/migrating-within-supabase/dashboard-restore.mdx b/apps/docs/content/guides/platform/migrating-within-supabase/dashboard-restore.mdxnew file mode 100644index 00000000000..cf39b0324e8--- /dev/null+++ b/apps/docs/content/guides/platform/migrating-within-supabase/dashboard-restore.mdx@@ -0,0 +1,151 @@+---+title: 'Restore Dashboard backup'+subtitle: 'Learn how to restore your dashboard backup to a new Supabase project'+breadcrumb: 'Migrations'+---++## Before you begin++<Accordion+ type="default"+ openBehaviour="multiple"+ chevronAlign="right"+ justified+ size="medium"+ className="text-foreground-light mt-8 mb-6"+>+ <div className="border-b mt-3 pb-3">+ <AccordionItem+ header="Install Postgres and psql"+ id="install-postgres"+ >+ <PostgresInstallation />+ </AccordionItem>++ </div>+ <div className="border-b mt-3 pb-3">+ <AccordionItem+ header="Create and configure a new project"+ id="create-project"+ >+ <StepHikeCompact>+ <StepHikeCompact.Step step={1}>+ <StepHikeCompact.Details title="Create New project" fullWidth>+ Create a new [Supabase project](https://database.new)+ </StepHikeCompact.Details>+ </StepHikeCompact.Step>+ <StepHikeCompact.Step step={2}>+ <StepHikeCompact.Details title="Configure your new project" fullWidth>+ In your new project:++ - If you were using Webhooks, enable [Database Webhooks](/dashboard/project/_/database/hooks).+ - If you were using any extensions, enable the [Extensions](/dashboard/project/_/database/extensions).+ - If you were using Replication for Realtime, enable [Publication](/dashboard/project/_/database/publications) where needed.+ </StepHikeCompact.Details>+ </StepHikeCompact.Step>+ </StepHikeCompact>+ </AccordionItem>++ </div>+</Accordion>++## Restore backup++<StepHikeCompact>+ <StepHikeCompact.Step step={1}>+ <StepHikeCompact.Details title="Get the new database connection string" fullWidth>+ Go to the [project page](/dashboard/project/_/) and click the "**Connect**" button at the top of the page for the connection string.++ <Admonition type="info">+ Use the Session pooler connection string by default. If your ISP supports IPv6, use the direct connection string.+ </Admonition>++ Session pooler connection string:+ ```bash+ postgresql://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@aws-0-us-east-1.pooler.supabase.com:5432/postgres+ ```++ Direct connection string:+ ```bash+ postgresql://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@db.[PROJECT-REF].supabase.com:5432/postgres+ ```+ </StepHikeCompact.Details>++ </StepHikeCompact.Step>+<StepHikeCompact.Step step={2}>+ <StepHikeCompact.Details title="Get the database password" fullWidth>+ Reset the password in the [Database Settings](https://supabase.com/dashboard/project/_/settings/database).++ Replace ```[YOUR-PASSWORD]``` in the connection string with the database password.++ </StepHikeCompact.Details>+</StepHikeCompact.Step>++<StepHikeCompact.Step step={3}>+ <StepHikeCompact.Details title="Get the backup file path" fullWidth>+ Get the relative file path of the downloaded backup file.++ If the restore is done in the same directory as the downloaded backup, the file path would look like this:++ ```./backup_name.backup```++ </StepHikeCompact.Details>+</StepHikeCompact.Step>++<StepHikeCompact.Step step={4}>+ <StepHikeCompact.Details title="Verify the backup file format" fullWidth>+ The backup file will be gzipped with a .gz extension. You will need to unzip the file to look like this:++ `backup_name.backup`++ </StepHikeCompact.Details>+</StepHikeCompact.Step>++<StepHikeCompact.Step step={5}>+ <StepHikeCompact.Details title="Restore your backup" fullWidth>+ <StepHikeCompact.Code>+ ```sql+ psql -d [CONNECTION_STRING] -f /file/path+ ```+ </StepHikeCompact.Code>++ Replace ```[CONNECTION_STRING]``` with connection string from Steps 1 & 2.++ Replace ```/file/path``` with the file path from Step 3.++ Run the command with the replaced values to restore the backup to your new project.+ </StepHikeCompact.Details>++ </StepHikeCompact.Step>+</StepHikeCompact>++## Migrate storage objects to new project's S3 storage++After restoring the backup, the buckets and files metadata will show up in the dashboard of the new project.+However, the storage files stored in the S3 buckets would not be present.++Use the following Google Colab script provided below to migrate your downloaded storage objects to your new project's S3 buckets.++[](https://colab.research.google.com/github/PLyn/supabase-storage-migrate/blob/main/Supabase_Storage_migration.ipynb)++This method requires uploading to Google Colab and then to the S3 buckets. This could add significant upload time if there are large storage objects.++## Common errors with the backup restore process++"**object already exists**"+"**constraint x for relation y already exists**"+"**Many other variations of errors**"++These errors are expected when restoring to a new Supabase project. The backup from the dashboard is a full dump which contains the CREATE commands for all schemas. This is by design as the full dump allows you to rebuild the entire database from scratch even outside of Supabase.++One side effect of this method is that a new Supabase project has these commands already applied to schemas like storage and auth. The errors from this are not an issue because it skips to the next command to run. Another side effect of this is that all triggers will run during the restoration process which is not ideal but generally is not a problem.++There are circumstances where this method can fail and if it does, you should reach out to Supabase support for help.++"**psql: error: connection to server at "aws-0-us-east-1.pooler.supabase.com" (44.216.29.125), port 5432 failed: received invalid response to GSSAPI negotiation:**"++You are possibly using psql and postgres version 15 or lower. Completely remove the Postgresql installation and install the latest version as per the instructions above to resolve this issue.++"**psql: error: connection to server at "aws-0-us-east-1.pooler.supabase.com" (44.216.29.125), port 5432 failed: error received from server in SCRAM exchange: Wrong password**"++If you reset your password for your project, it may take a few minutes for it to reflect. Try again after a few minutes if you did a password reset.diff --git a/apps/docs/content/guides/platform/upgrading.mdx b/apps/docs/content/guides/platform/upgrading.mdxindex b7ab96b76a3..36fb163e15e 100644--- a/apps/docs/content/guides/platform/upgrading.mdx+++ b/apps/docs/content/guides/platform/upgrading.mdx@@ -102,6 +102,11 @@ If you upgrade to a paid plan while your project is paused, any expired one-clic#### Restoring a downloaded backup locally+<Admonition type="caution">+ If you want to restore your backup to a hosted Supabase project, you will need to use the+ [Migrating within Supabase guide](/docs/guides/platform/migrating-within-supabase)+</Admonition>+If the 90 day project restore window has expired but you need to access data contained within your project using SQL, you can attempt to restore the project into a local Postgres instance. Supabase publishes tooling that can be used for that purpose. Be aware that this workflow does not produce a complete Supabase environment with REST/Auth/Storage. Instead, it creates a standalone Postgres instance that is maximally compatible with your project's backup file to assist with recovering your data.Downloaded backups are plain text SQL files that can be executed in Postgres to restore your project's schema and data. If you need to access data within a backup we recommend restoring into a Postgres instance built using the Supabase open source build tooling to ensure that the local instance is as similar to the original project as possible. Here are the steps to start Supabase Postgres locally and restore the backup:diff --git a/apps/docs/features/docs/MdxBase.shared.tsx b/apps/docs/features/docs/MdxBase.shared.tsxindex f10680b392c..7b0fb4b1c99 100644--- a/apps/docs/features/docs/MdxBase.shared.tsx+++ b/apps/docs/features/docs/MdxBase.shared.tsx@@ -28,6 +28,7 @@ import {QuickstartIntro,SocialProviderSettingsSupabase,SocialProviderSetup,+ PostgresInstallation,} from '~/components/MDX/partials'import { NavData } from '~/components/NavData'import { ProjectConfigVariables } from '~/components/ProjectConfigVariables'@@ -83,6 +84,7 @@ const components = {ShowUntil,SocialProviderSettingsSupabase,SocialProviderSetup,+ PostgresInstallation,SqlToRest,StepHikeCompact,Tabs,