Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore(docs): add custom seed paths documentation (#29512)

Andrew Valleteau1c9af2eeed85
diff --git a/apps/docs/content/guides/cli/local-development.mdx b/apps/docs/content/guides/cli/local-development.mdx
index 3846335c3e3..4f9da9b7fc1 100644
--- a/apps/docs/content/guides/cli/local-development.mdx
+++ b/apps/docs/content/guides/cli/local-development.mdx
@@ -296,7 +296,7 @@ alter table
Now that you are managing your database with migrations scripts, it would be great have some seed data to use every time you reset the database.
-For this, you can use the seed script in `supabase/seed.sql`. This file was automatically created when you ran [`supabase init`](/docs/reference/cli/usage#supabase-init)) at the beginning.
+For this, you can create a seed script in `supabase/seed.sql`.
<StepHikeCompact>
diff --git a/apps/docs/content/guides/cli/seeding-your-database.mdx b/apps/docs/content/guides/cli/seeding-your-database.mdx
index 45a6f57ccd9..efb8e47ea26 100644
--- a/apps/docs/content/guides/cli/seeding-your-database.mdx
+++ b/apps/docs/content/guides/cli/seeding-your-database.mdx
@@ -5,19 +5,19 @@ description: 'Populate your database with initial data for reproducible environm
subtitle: 'Populate your database with initial data for reproducible environments across local and testing.'
---
-When you run `supabase init` we create an empty `seed.sql` file in the root of the `supabase` folder. You can use this to populate your database with seed data.
-
## What is seed data?
Seeding is the process of populating a database with initial data, typically used to provide sample or default records for testing and development purposes. You can use this to create "reproducible environments" for local development, staging, and production.
-## Using the seed file
+## Using seed files
+
+Seed files are executed every time you run `supabase start` or `supabase db reset`. Seeding occurs _after_ all database migrations have been completed. As a best practice, only include data insertions in your seed files, and avoid adding schema statements.
-The `seed.sql` file is run every time you run `supabase start` or `supabase db reset`. Seeding is done _after_ all the database migrations have been run. As a general rule, you should not add schema statements to your seed file, only data.
+By default, if no specific configuration is provided, the system will look for a seed file matching the pattern `supabase/seed.sql`. This maintains backward compatibility with earlier versions, where the seed file was placed in the `supabase` folder.
You can add any SQL statements to this file. For example:
-```sql supabase/seed.sql
+```sql
insert into countries
(name, code)
values
@@ -26,27 +26,35 @@ values
('Mexico', 'MX');
```
-{/* prettier-ignore */}
-{/*
+If you want to manage multiple seed files or organize them across different folders, you can configure additional paths or glob patterns in your `config.toml` (see the [next section](#splitting-up-your-seed-data) for details).
### Splitting up your seed file
-The seed file can grow quite large, so you can split it up into multiple files. For example, you can create a `seed` folder and add a `countries.sql` file. Then you can add the following to your `seed.sql` file.
+For better modularity and maintainability, you can split your seed data into multiple files. For example, you can organize your seeds by table and include files such as `countries.sql` and `cities.sql`. Configure them in `config.toml` like so:
-```sql supabase/seed.sql
-\i seed/countries.sql
+```toml supabase/config.toml
+[db.seed]
+enabled = true
+sql_paths = ['./countries.sql', './cities.sql']
```
-### Using CSV data to seed your database
+Or to include all `.sql` files under a specific folder you can do:
-co
-You can use the `COPY` command to import CSV data into your database. For example, you can create a `seed` folder and add a `countries.csv` file. Then you can add the following to your `seed.sql` file.
-
-```sql supabase/seed.sql
-COPY countries (name, code) FROM 'seed/countries.csv' WITH (FORMAT csv);
+```toml supabase/config.toml
+[db.seed]
+enabled = true
+sql_paths = ['./seeds/*.sql']
```
-\*/}
+<Admonition type="tip">
+
+The CLI processes seed files in the order they are declared in the `sql_paths` array. If a glob pattern is used and matches multiple files, those files are sorted in lexicographic order to ensure consistent execution. Additionally:
+
+- The base folder for the pattern matching is `supabase` so `./contries.sql` will search for `supabase/contries.sql`
+- Files matched by multiple patterns will be deduplicated to prevent redundant seeding.
+- If a pattern does not match any files, a warning will be logged to help you troubleshoot potential configuration issues.
+
+</Admonition>
## Generating seed data
diff --git a/apps/docs/content/guides/platform/branching.mdx b/apps/docs/content/guides/platform/branching.mdx
index e7c73754214..aaeaf2cc543 100644
--- a/apps/docs/content/guides/platform/branching.mdx
+++ b/apps/docs/content/guides/platform/branching.mdx
@@ -45,7 +45,7 @@ In Git, you have a Production Branch (typically this is `main`, `master`, `prod`
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.
+The Preview Branch is also seeded with sample data based on `./supabase/seed.sql` by default, if that file exists.
Supabase Branching follows the [Trunk Based Development](https://trunkbaseddevelopment.com/) workflow, with one main Production branch and multiple development branches:
@@ -83,7 +83,7 @@ The Git integration can read files from your Git provider, watching every commit
### Data changes
-The Preview Branch is seeded with sample data based on `./supabase/seed.sql`, if that file exists.
+The Preview Branch is seeded with sample data based on `./supabase/seed.sql` by default, if that file exists.
For security reasons, Preview Branches do not contain production data. Future versions of Branching may allow for automated data cloning after we are confident that we can provide safe data masking.
@@ -542,11 +542,11 @@ You might want to roll back changes you've made in an earlier migration change.
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.
+The new preview branch is reseeded from your `./supabase/seed.sql` file by default. 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 from the file `./supabase/seed.sql`.
+Your Preview Branches are seeded with sample data from the file `./supabase/seed.sql` by default.
The database is only seeded once, when the preview branch is created. To rerun seeding, delete the preview branch and recreate it by closing, and reopening your pull request.
diff --git a/apps/docs/spec/cli_v1_commands.yaml b/apps/docs/spec/cli_v1_commands.yaml
index 175b14b3d56..cda35983ec8 100644
--- a/apps/docs/spec/cli_v1_commands.yaml
+++ b/apps/docs/spec/cli_v1_commands.yaml
@@ -2878,7 +2878,7 @@ commands:
Requires the local development stack to be started by running `supabase start`.
- Recreates the local Postgres container and applies all local migrations found in `supabase/migrations` directory. If test data is defined in `supabase/seed.sql`, it will be seeded after the migrations are run. Any other data or schema changes made during local development will be discarded.
+ Recreates the local Postgres container and applies all local migrations found in `supabase/migrations` directory. If test data is defined in `supabase/seed.sql` by default, it will be seeded after the migrations are run. Any other data or schema changes made during local development will be discarded.
Note that since Postgres roles are cluster level entities, those changes will persist between resets. In order to reset custom roles, you need to restart the local development stack.
examples:
diff --git a/apps/docs/spec/cli_v1_config.yaml b/apps/docs/spec/cli_v1_config.yaml
index 063f2ecca5e..c1c5657b914 100644
--- a/apps/docs/spec/cli_v1_config.yaml
+++ b/apps/docs/spec/cli_v1_config.yaml
@@ -201,6 +201,26 @@ parameters:
- name: 'PgBouncer Configuration'
link: https://www.pgbouncer.org/config.html#max_client_conn
+ - id: 'db.seed.enabled'
+ title: 'db.seed.enabled'
+ tags: ['database']
+ required: false
+ default: 'true'
+ description: |
+ Enables running seeds when starting or resetting the database.
+ links: []
+
+ - id: 'db.seed.sql_paths'
+ title: 'db.seed.sql_paths'
+ tags: ['database']
+ required: false
+ default: '["./seed.sql"]'
+ description: |
+ An array of files or glob patterns to find seeds in.
+ links:
+ - name: 'Seeding your database'
+ link: 'https://supabase.com/docs/guides/cli/seeding-your-database'
+
- id: 'realtime.enabled'
title: 'realtime.enabled'
tags: ['realtime']