Snaplet can provide data for your Supabase project!
Pick your own path:
- Generate data for your Supabase local development stack
- Restore data from your production Supabase project to your local development stack
We've spent a lot of time ensuring that Snaplet works seamlessly with Supabase, however, if you experience any issues with this integration or this guide, feel free to come chat with us on Discord (opens in a new tab).
Supabase makes it easy to set up a local environment (opens in a new tab) linked to your Supabase project. Snaplet can improve your local development by seeding your local database with data, making coding and testing more efficient and accurate.
In this short guide, we will use the Nextjs + Supabase template (opens in a new tab), to demonstrate how one could use the
snaplet generate command to seed their local Supabase stack.
Create a new project in the Supabase Dashboard by visiting https://supabase.com/ (opens in a new tab)
2.1. Create a Next.js app using the Supabase starter template by running the
npx create-next-app -e with-supabase
cd to change into the newly created directory:
3.1. Link your Nextjs starter template to your Supabase project
3.2. Apply the migrations in
/supabase/migrations to your project
Migrations are required to be applied to your target database, as the
snaplet generateneeds a database structure to generate data for.
supabase db push
3.3. Start your Supabase local stack
This command will print out your the following:
Started supabase local development setup.API URL: http://localhost:54321DB URL: postgresql://postgres:postgres@localhost:54322/postgresStudio URL: http://localhost:54323Inbucket URL: http://localhost:54324anon key: eyJh......service_role key: eyJh......
3.4. Copy the DB URL - we will use this in the next step (step 4) as your target database credentials.
4.1. Create a
snaplet.config.ts file in the root of your project.
The source database credentials will be used to introspect your database and generate a base config
4.2. In the
snaplet.config.ts update the
generate statement to create 10 users and 20 todos, the todos should be assigned to at least one of the 10 users.
Once you have gone through all the steps, you are now ready to seed your database.
5.1. Run the
snaplet generate to populate the project seed script in the
snaplet generate --sql > supabase/seed.sql
5.2 Reset your local development database, this will run all the existing migrations and applu the seed script.
supabase db reset
5.3 Check your local database to see if the seed script was applied.
Now if you visit the local studio URL (http://localhost:54323 (opens in a new tab)) and inspect the "todo" table, you should see 20 todo items.
In your project if you move the
app/todos/page.tsx and then visit http://localhost:3000/todos (opens in a new tab) you should see the following:
You have now successfully seeded your local Supabase development stack. You can now use the
snaplet generate command to seed your local database with any data you need.
If you have any questions or feedback, please feel free to reach out to us on Discord (opens in a new tab).
Supabase makes it easy to start a project with a dedicated PostgreSQL database. However, achieving a development environment populated with data closely resembling producation, still requires some set up. This guide will help you integrate Snaplet with your Supabase project, allowing you to restore a snapshot of your production database into your local development stack.
The first thing you'll want to do is navigate to https://www.snaplet.dev (opens in a new tab) and sign up for a new account (it's free). Once you have successfully signed up for a new account, you'll begin the onboarding process...
On the “Connect database” step click on "Connect Supabase" to connect your Supabase account to Snaplet. Proceed through all the steps of authorizing your Supabase organization, selecting a Supabase project and giving us the password associated to the project.
The snapshots for your Supabase project will be set to only capture the
authschemas. Learn more below.
Once that is done, continue to the next steps:
- Subsetting (skipping will create a snapshot with all your data).
- Transforming (skipping will leave all your table columns untouched).
Once you have gone through those steps, a new snapshot process will start and you will now be on the “capture step.” Wait for it to finish - this is the snapshot you will restore into your target database.
Below is a summary of commands you will have to run in your terminal to get Supabase set up on your local machine. For a more detailed steps you can visit the Supabase docs here (opens in a new tab).
supabase start will output your Supabase credentials, copy the DB_URL field, as we will use it in your snaplet configuration file (step 5).
- Open your terminal and run
curl -sL https://app.snaplet.dev/get-cli/ | bash
snaplet auth login
- Navigate to
https://app.snaplet.dev/access-token/clito get your access token.
- Paste the access token in the terminal.
You're now ready to restore your production snapshot into your Supabase development project.
Navigate to your project directory
- You will be shown a warning to write
.snaplet/configin your project directory. Select yes (y) to create the file.
- Then you will be asked for a target database connection string. . Paste in the DB URL you copied in step 3.
- You will be shown a warning to write
snaplet project setup- you will be presented with a list of projects, these are databases that are connected to your Snaplet account. Choose the project that contains the snapshot you created in step 2.
With all the above steps complete, we can now restore!
snaplet snapshot restore --no-resetin your project path.
--no-reset: This will skip the “reset” step of the restore command. So no existing schemas will be dropped. Learn more about data operations here
If you want to learn more about Snaplet, you can explore our docs. If you have any questions, feel free to reach out on Discord (opens in a new tab).
That's it! You're all done, and should have restored a version of your Supabase production database with transformed data into your target database. You can now code against production-realistic data.
When running the restore command, you may see warnings such as:
Supabase includes a few schemas that are not owned by the
postgres user, for example: auth, graphql, realtime, and storage. During the capture process, Snaplet will try to capture data for tables under these schemas (if it has permission to read data from them)
Your target database may already contain these schemas when restoring. The warnings just mean that when Snaplet attempted to restore these schemas (auth, graphql, etc) but was unable to drop the ones already existing in your target database (since the user is not an owner of these), and consequently it was not able to create any structure for them (since that structure still exists)
Snaplet will still make sure to clear all data for tables in these schemas and restore data for each of these tables to what is in the snapshot. In other words, these warnings do not mean that the restore failed, but rather show you what Snaplet tried to do.
If you aren't actually needing the data for some of these schemas, you can stop these warnings by excluding the schema from the captured snapshots. You can read more on how to do this over here in our docs:
We recommand excluding the
supabase_functions schemas from your snapshots. This is because these schemas contain data that may not have relevant context of the target project you are restoring to.
e.g: the storage schema may contain files that belong to your production project, but may not be relevant to your development project.
Your snapshot config should look something like this:
During onboarding, this
select option is automatically added to your config. In the web editor you will be shown a warning, if you choose to remove the
You may run into problems restoring to a Supabase project hosted in the cloud. This is because the snaplet restore command will drop your database first, before restoring any schemas and tables, which results in your project being in a broken state. The reason for this is that Snaplet was unable to restore schemas that Supabase requires a super user role to perform write operations.
To get around this, run the
restore command with the
--no-reset flag, e.g: