The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Chore/update branching doc (#19116)
Terry Sutton38dfd14c314a
diff --git a/apps/docs/pages/guides/platform/branching.mdx b/apps/docs/pages/guides/platform/branching.mdxindex ddfb5b894c2..7cd9416151b 100644--- a/apps/docs/pages/guides/platform/branching.mdx+++ b/apps/docs/pages/guides/platform/branching.mdx@@ -3,122 +3,126 @@ import { Admonition } from 'ui'export const meta = {title: 'Branching',- description: 'Use Supabase branches to test and preview changes.',+ description: 'Use Supabase Branches to test and preview changes.',+ subtitle: 'Use Supabase Branches to test and preview changes',}-<Admonition type="note">+ <Admonition type="note">+-Branching is only available on the Pro Plan and above.-</Admonition>+ </Admonition>-Branching lets you safely and easily experiment with changes to your Supabase project.+Use branching to safely and easily experiment with changes to your Supabase project.-Supabase branches work similarly to Git branches. You can create a new branch for each set of related changes, such as new configurations, new database schemas, or new features. A temporary Supabase instance is created with your changes, so you can examine and test them without affecting your production instance.+Supabase branches work like Git branches. They let you create and test changes like new configurations, database schemas, or features in a separate, temporary instance without affecting your production setup.-When you’re ready to ship your changes, merge your branch. Your production instance updates to reflect the new changes.+When you're ready to ship your changes, merge your branch to update your production instance with the new changes.-<Admonition type="caution">+If you understand Git, you already understand Supabase Branching.-It is not recommended to use Branching in a production environment.+ <Admonition type="caution" label="Branching is in Alpha">-Branching is an alpha feature. To try out branching for non-production experiments, [request access here](https://forms.supabase.com/branching-request).+ It is not recommended to use Branching in a production environment.-</Admonition>+Branching is an Alpha feature. To try out branching for non-production experiments, [request access here](https://forms.supabase.com/branching-request).++ </Admonition>## How branching works-Each Supabase project can consist of multiple Preview Branches. Each Preview Branch is backed by an isolated Supabase instance. Each instance contains all Supabase features, and has its own API credentials.+Supabase projects can consist of multiple Preview Branches. All Preview Branches are backed by an isolated Supabase instance. Each instance contains all Supabase features, and has its own API credentials.++ <figure className="max-w-[700px] mx-auto">+ <Image+ className="hidden dark:block"+ alt="Each branch has a separate Supabase instance."+ src="/docs/img/guides/platform/branching/github-workflow-without-branching.jpg"+ />-<figure className="max-w-[700px] mx-auto">- <Image- className="hidden dark:block"- alt="Each branch has a separate Supabase instance."- src="/docs/img/guides/platform/branching/github-workflow-without-branching.jpg"- /><Image- className="dark:hidden"- alt="Each branch has a separate Supabase instance."- src="/docs/img/guides/platform/branching/github-workflow-without-branching--light.jpg"- />+ className="dark:hidden"+ alt="Each branch has a separate Supabase instance."+ src="/docs/img/guides/platform/branching/github-workflow-without-branching--light.jpg"+ /><figcaption>Each branch has a separate Supabase instance.</figcaption>-</figure>+ </figure>-Conceptually, Supabase Branching works like Git branching, in which you usually have a designated branch for Production, and then you use other branches to propose changes that will be merged into your Production branch.+Supabase branching works like Git branching, with one main Production branch. Preview Branches branch off your Production branch and contain proposed changes. These changes can then be merged into Production.-When you create a Preview Branch (which will be merged off from your Production branch), the SQL migration files from your Production branch are run on the new Preview Branch. The Preview Branch then reflects your current Production branch schema.+When you create a Preview Branch, the SQL migration files from your Production branch are run on the new Preview Branch. The Preview Branch then reflects your current Production branch schema.The Preview Branch will also be [seeded with sample data](#seeding-behaviour) if a seed file exists.-By creating new SQL migrations in a Preview Branch to propose schema changes, those changes can then be merged into your Production branch, which then runs the new migrations on your Supabase Production branch.+By creating new SQL migrations in a Preview Branch to propose schema changes, those changes can then be merged into your Production branch. These changes then run the new migrations on your Supabase Production branch. This is exactly how Git branches work: experiment on a feature branch and merge back into Production when you're finished.-<Admonition type="note">+ <Admonition type="note" label="Schema-only changes">-Only schema changes are captured in preview branches.+ Only *schema* changes are captured in preview branches.-Preview instances contain no data by default. You can include a seed file to seed your preview instance with sample data when the Preview Branch is created. Future versions of branching may allow for automated data seeding and cloning.+Preview Branch instances contain no data by default. You must include a seed file to seed your preview instance with sample data when the Preview Branch is created. Future versions of Branching may allow for automated data seeding and cloning.-</Admonition>+ </Admonition>## Git providersTo facilitate Supabase Branching, your Supabase project will be connected to a Git repository via an integration.-Supabase Branching works with [GitHub](#branching-with-github). Future iterations may support other Git providers, such as GitLab and BitBucket.+Supabase Branching works with [GitHub](#branching-with-github). Future iterations may support other Git providers. If you are interested in other Git providers or a non-Git-based workflow, join the discussions for [GitLab Branching, BitBucket Branching, and non-Git based Branching](https://github.com/orgs/supabase/discussions/18936).### Branching with GitHubSupabase Branching uses the Supabase GitHub integration to read files from your GitHub repository. With this integration, Supabase watches all commits, branches, and pull requests of your GitHub repository.-One of your Git branches is your Production Branch. This should also be your Supabase project's Production Branch.+In Git, you have a Production Branch (typically this is `main`, `master`, `prod`, etc). This should also be your Supabase project's Production Branch.-For every Git Branch in your GitHub repository, you may have a corresponding Preview Branch. Each time a new Preview Branch is created, the migrations in the Git branch of that Preview Branch are run on the Preview Branch.+You can create a corresponding Preview Branch for any Git branch in your repository. Each time a new Preview Branch is created, the migrations in the Git branch of that Preview Branch are run on the Preview Branch.The Preview Branch is also seeded with sample data based on `./supabase/seed.sql`, if that file exists.-<figure className="max-w-[700px] mx-auto">- <Image- className="hidden dark:block"- alt="Each GitHub branch can have its own Supabase preview branch."- src="/docs/img/guides/platform/branching/github-workflow.jpg"- />+ <figure className="max-w-[700px] mx-auto">+ <Image+ className="hidden dark:block"+ alt="Each GitHub branch can have its own Supabase preview branch."+ src="/docs/img/guides/platform/branching/github-workflow.jpg"+ />+<Image- className="dark:hidden"- alt="Each GitHub branch can have its own Supabase preview branch."- src="/docs/img/guides/platform/branching/github-workflow--light.jpg"- />+ className="dark:hidden"+ alt="Each GitHub branch can have its own Supabase preview branch."+ src="/docs/img/guides/platform/branching/github-workflow--light.jpg"+ /><figcaption>Each GitHub branch can have its own Supabase preview branch.</figcaption>-</figure>+ </figure>Each time a commit is pushed with new migrations in the `./supabase/migrations` directory, the migrations are run on the matching preview instance.-<figure className="max-w-[700px] mx-auto">- <Image- className="hidden dark:block"- alt="New migration files trigger migrations on the preview instance."- src="/docs/img/guides/platform/branching/github-workflow-commit-migration.jpg"- />+ <figure className="max-w-[700px] mx-auto">+ <Image+ className="hidden dark:block"+ alt="New migration files trigger migrations on the preview instance."+ src="/docs/img/guides/platform/branching/github-workflow-commit-migration.jpg"+ />+<Image- className="dark:hidden"- alt="New migration files trigger migrations on the preview instance."- src="/docs/img/guides/platform/branching/github-workflow-commit-migration--light.jpg"- />+ className="dark:hidden"+ alt="New migration files trigger migrations on the preview instance."+ src="/docs/img/guides/platform/branching/github-workflow-commit-migration--light.jpg"+ /><figcaption>New migration files trigger migrations on the preview instance.</figcaption>-</figure>--Only GitHub is currently supported (as a beta release). If you’re interested in other Git providers or a non-Git-based workflow, join the discussions for [GitLab Branching, BitBucket Branching, and non-Git based Branching](https://github.com/orgs/supabase/discussions/18936).+ </figure>## Alternatives to branching-If you don’t turn on branching, your Supabase project continues to work as always. You have a single set of API keys for each project, and no preview instances are created.+If you don’t turn on branching, your Supabase project continues to work as a single branch, on a single instance. You have a single set of API keys for each project, and no preview instances are created. It's the Git equivalent of working directly on the `main` branch.If you prefer not to use branching, you can manage your environments and tests in other ways:-1. ##### Host a project per environment, and run tests against a staging project+1. ##### Host a project per environment, and test against a staging projectCreate multiple projects on Supabase with the same schema. Use one project as a staging environment to test any changes. Then migrate tested changes to the production project.-2. ##### Host a single production project, and run tests locally+2. ##### Host a single production project, and test locallyCreate a single project to host your production instance. Test any changes locally, then run the migrations against your hosted production project.@@ -126,11 +130,11 @@ You can also combine both strategies to perform both local and staging tests.## How to use Supabase Branching-<Admonition type="note">+ <Admonition type="note" label="Github integration required">-Supabase branching requires the GitHub integration. Your application must be developed in a GitHub repository.-</Admonition>++ </Admonition>### Preparing your GitHub repository@@ -138,12 +142,12 @@ You need a GitHub repository to use Supabase branching. The `./supabase` directoTo start:-- If you don’t have a new project, [set one up using the example template](#set-up-a-new-project-with-the-example-template).-- If you have a project, [make sure your database-related files are up to date](#set-up-an-existing-project-for-branching).+- If you don't have a new project, [set one up using the example template](#set-up-a-new-project-with-the-example-template).+- If you have an existing project, [make sure your database-related files are up to date](#set-up-an-existing-project-for-branching).#### Set up a new project with the example template-Use the NextJS example template to try out branching. This template includes sample migration and seed files to get you started.+Use the Next.js example template to try out branching. This template includes sample migration and seed files to get you started.Run the following command in your terminal to clone the example:@@ -155,21 +159,21 @@ Push your new project to a GitHub repo. For more information, see the GitHub gui#### Set up an existing project for branching-Before enabling branching on an existing project, make sure your database-related files are up to date. You need a correct snapshot of your existing database, so newer migration files have a foundation to run on top of.+Before enabling branching on an existing project, make sure your database-related files are up to date. You need a current snapshot of your existing database, so newer migration files have a foundation to run on top of.-<Admonition type="caution">+ <Admonition type="caution" label="Get set up before turning on branching">-Setting up the initial state incorrectly can cause migrations to be wrongly applied.+ Setting up the initial state incorrectly can cause migrations to be wrongly applied.Follow the instructions below **before turning on Supabase branching**.-</Admonition>+ </Admonition>##### If your migration files are already in GitHub, under `./supabase/migrations`:If your migration files are up to date with your production database, you don’t need to do anything. You can now turn on branching.-##### If you don’t have migration files in GitHub:+##### If you don't have migration files in GitHub:You need to take a snapshot of your database. Log into Supabase from the [command line client](/docs/guides/cli) and pull the relevant files. Then commit them to GitHub:@@ -179,7 +183,7 @@ You need to take a snapshot of your database. Log into Supabase from the [commansupabase init```-2. Pull down database-related files. You can find your database URL in your [database settings](https://supabase.com/dashboard/project/_/settings/database).+2. Pull down database-related files. You can find your database URL in your [database settings](https://supabase.com/dashboard/project/_/settings/database), under the URI tab of the Connection String settings panel. It will look something like `postgresql://username:[email protected]:5432/postgres````bashsupabase db pull --db-url <db_url>@@ -197,35 +201,36 @@ You need to take a snapshot of your database. Log into Supabase from the [commanOnce your repository is [correctly prepared](#set-up-an-existing-project-for-branching), you can enable branching from the Supabase dashboard.-<Admonition type="caution">+ <Admonition type="caution" label="Prepare your repo before enabling Branching">++-Before turning on branching, make sure your [GitHub repository is prepared](#set-up-an-existing-project-for-branching). If your repository doesn’t have all the migration files, your production branch could run an incomplete set of migrations.+ </Admonition>-</Admonition>+ <Admonition type="note" label="Branching is invite-only">-<Admonition type="note">+ Branching is only available to alpha testers.-Branching is only available to alpha testers.If you’re not in the alpha testing group, you can join the waitlist.-</Admonition>+ </Admonition>1. Select the project you want to use, then click `Enable branching`.- If you’re prompted to join the waitlist, click `Join waitlist`. Access to branching will be expanded as branching graduates from alpha testing.+ If you’re prompted to join the waitlist, click `Join waitlist`. Access will be expanded as branching graduates from alpha testing.<figure className="max-w-[520px]">- <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-opt-in-popover.jpg"/>+ <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-opt-in-popover.jpg" />- </figure>+ </figure>2. If you see the following dialog, you’re in the alpha testing group.<figure className="max-w-[520px]">- <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-opt-in-install-github.jpg"/>+ <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-opt-in-install-github.jpg" />- </figure>+ </figure>If you don’t have the GitHub integration installed, click `Install GitHub Integration`. The integration is required to run migration files and the optional database seed file.@@ -233,17 +238,17 @@ If you’re not in the alpha testing group, you can join the waitlist.<figure className="max-w-[520px]">- <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-opt-in-install-github-permissions.jpg"/>+ <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-opt-in-install-github-permissions.jpg" />- </figure>+ </figure>Follow the instructions to link your Supabase project to its GitHub repository.<figure className="max-w-[520px]">- <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-opt-in-install-github-integration-link.jpg"/>+ <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-opt-in-install-github-integration-link.jpg" />- </figure>+ </figure>Return to your project and re-click `Enable branching`.@@ -253,16 +258,16 @@ If you’re not in the alpha testing group, you can join the waitlist.<Admonition type="caution">- Your production branch can’t be changed while branching is enabled.+ Your production branch can’t be changed while branching is enabled.To change your production branch, you need to disable branching and re-enable it with a different branch.- </Admonition>+ </Admonition><figure className="max-w-[520px]">- <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-opt-in-install-production-branch.jpg"/>+ <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-opt-in-install-production-branch.jpg" />- </figure>+ </figure>4. Click `I understand, enable branching`. Branching is now enabled for your project.@@ -276,13 +281,13 @@ Preview branches are automatically created for each pull request, but you can al<figure className="max-w-[520px]">- <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-first-preview-branch-github.jpg"/>+ <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-first-preview-branch-github.jpg" /><figcaption>- You can use the GitHub dashboard or command line to create a new branch. In this example, the new branch is called `feat/add-members`.- </figcaption>- </figure>+ </figcaption>++ </figure>You can use the GitHub dashboard or command line to create a new branch. In this example, the new branch is called `feat/add-members`.@@ -292,9 +297,9 @@ Preview branches are automatically created for each pull request, but you can al<figure className="max-w-[520px]">- <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-first-preview-branch-branch-dropdown.jpg" />+ <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-first-preview-branch-branch-dropdown.jpg" />- </figure>+ </figure>3. ##### Create a Supabase preview branch@@ -302,28 +307,29 @@ Preview branches are automatically created for each pull request, but you can al<figure className="max-w-[520px]">- <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-first-preview-branch-branch-action.jpg" />+ <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-first-preview-branch-branch-action.jpg" />- </figure>+ </figure>Type in the branch name you want to add. Click `Create branch` to confirm.<Admonition type="note">- **Only branches from the repository can be used to create a Preview Branch**- Git Branches from external contributors currently can’t support a Preview Branch+ **Only branches from the repository can be used to create a Preview Branch**- </Admonition>+ Git branches from external contributors currently can’t support a Preview Branch++ </Admonition><figure className="max-w-[520px]">- <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-first-preview-branch-choose-branch.jpg" />+ <Image src="/docs/img/guides/platform/branching/enable-supabase-branching-first-preview-branch-choose-branch.jpg" />- </figure>+ </figure>### Develop your app with Supabase branches-Supabase branching uses the state of your GitHub repository to apply migrations and seed preview instances. It checks the directory `supabase` at the top level of your repository.+Supabase branching uses the state of your GitHub repository to apply migrations and seed preview instances. It checks the `supabase` directory at the top level of your repository.The `supabase` directory should include:@@ -381,13 +387,13 @@ If you need to reset your database to a clean state (that is, discard any changeAs an alternative to developing locally, you can make changes on your remote Supabase dashboard. You can then pull these changes to your local machine and commit them to GitHub.-<Admonition type="note">+ <Admonition type="note">-Changes must be locally pulled and committed to keep your GitHub repository state in sync.+ Changes must be locally pulled and committed to keep your GitHub repository state in sync.Dashboard changes aren’t automatically reflected in your repository. If you’d like to see automatic syncing in a future release, [join the discussion](https://github.com/orgs/supabase/discussions/18937).-</Admonition>+ </Admonition>1. Click on the active branch in the top bar to open the dropdown menu. Select the branch you want to use.@@ -411,13 +417,14 @@ When you open a pull request on GitHub, the Supabase integration automatically cA comment is added to your PR with the deployment status of your preview branch. Statuses are shown separately for Database, Services, and APIs.-<figure className="max-w-[700px] mx-auto">- <Image src="/docs/img/guides/platform/branching/develop-your-app-open-pull-request-github.jpg" />- {/* prettier-ignore */}+ <figure className="max-w-[700px] mx-auto">+ <Image src="/docs/img/guides/platform/branching/develop-your-app-open-pull-request-github.jpg" />++{/* prettier-ignore */}<figcaption>- Supabase GitHub integration will comment on your PR with the status of your Preview Branch, including whether migrations have successfully run.- </figcaption>-</figure>++ </figcaption>+ </figure>Every time a new commit is pushed that changes the migration files in `./supabase/migrations`, the new migrations are run against the preview branch. You can check the status of these runs in the comment’s Tasks table.@@ -427,13 +434,14 @@ We highly recommend turning on a ‘required check’ for the Supabase integratiThis prevents PRs from being merged when migration checks fail, and stops invalid migrations from being merged into your production branch.-<figure className="max-w-[700px] mx-auto">- <Image src="/docs/img/guides/platform/branching/github-required-check.jpg" />- {/* prettier-ignore */}+ <figure className="max-w-[700px] mx-auto">+ <Image src="/docs/img/guides/platform/branching/github-required-check.jpg" />++{/* prettier-ignore */}<figcaption>- Check the "Require status checks to pass before merging" option.- </figcaption>-</figure>++ </figcaption>+ </figure>### Disable branching@@ -441,21 +449,21 @@ You can disable branching at any time. Navigate to the [Branches](https://supaba## Migration and seeding behavior-Migrations are run in sequential order. Each migration builds upon the previous ones.+Migrations are run in sequential order. Each migration builds upon the previous one.The preview branch has a record of which migrations have been applied, and only applies new migrations for each commit. This can create an issue when rolling back migrations.### Rolling back migrations-In some circumstances, you might want to roll back changes you’ve made in an earlier migration change. For example, you might’ve pushed a migration file containing schema changes you no longer want.+You might want to roll back changes you’ve made in an earlier migration change. For example, you may have pushed a migration file containing schema changes you no longer want.-To fix this, push your latest changes, then delete the preview branch and reopen it.+To fix this, push your latest changes, then delete the preview branch in Supabase and reopen it.The new preview branch is reseeded from your `./supabase/seed.sql` file. Any additional data changes you made on the old preview branch are lost. This is equivalent to running `supabase db reset` locally. All migrations are rerun in sequential order.### Seeding behavior-Your Preview Branches are seeded with sample data based on the file `./supabase/seed.sql`.+Your Preview Branches are seeded with sample data from the file `./supabase/seed.sql`.The database is only seeded once, when the preview branch is created. To rerun seeding, delete the preview branch and recreate it.@@ -475,7 +483,7 @@ If you have multiple preview branches, each preview branch might contain differeWhen a preview branch is merged into the production branch, it creates a schema drift between the production branch and the preview branches you haven’t merged yet.-To solve this conflict, merge or rebase from your production Git branch to your preview Git branch. Since migrations are applied sequentially, ensure that migration files are timestamped correctly after the rebase. Changes that build on top of earlier changes should always have later timestamps.+You can solve thse conflicts the way you would solve normal Git Conflicts: merge or rebase from your production Git branch to your preview Git branch. Since migrations are applied sequentially, ensure that migration files are timestamped correctly after the rebase. Changes that build on top of earlier changes should always have later timestamps.### Changing Production Branch@@ -489,24 +497,22 @@ With the Supabase branching integration, you can sync the Git branch used by the### Vercel-<Admonition type="note">+ <Admonition type="note">-Vercel Branching support is in development+ Vercel Branching support is in developmentThe Vercel Integration for Supabase branching is under development. To express your interest, [join the discussion on GitHub discussions](https://github.com/orgs/supabase/discussions/18938).-</Admonition>+ </Admonition>Install the Vercel integration:- From the [Vercel marketplace](https://vercel.com/integrations/supabase-v2) or- By clicking the blue `Deploy` button in a Supabase example app’s `README` file-<Admonition type="note">--For branching to work with Vercel, you also need the [Vercel GitHub integration](https://vercel.com/docs/deployments/git/vercel-for-github).+ <Admonition type="note">-</Admonition>+ </Admonition>Supabase automatically updates your Vercel project with the correct environment variables for the corresponding preview branches.