Adds some seed commands

This commit is contained in:
Copple committed 2023-08-03 12:43:19 +02:00
1 parent 1a3f1bd890
commit ea9e29c52a
1 file changed
+30 -2
@@ -7,14 +7,42 @@ export const meta = {
subtitle: 'Testing emails for Supabase Auth on your local machine.',
}
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 "reproducable environments" for local development, staging, and production.
## Using the seed file
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.
You can add any SQL statements to this file. For example.
```sql supabase/seed.sql
insert into countries
(name, code)
values
('United States', 'US'),
('Canada', 'CA'),
('Mexico', 'MX');
```
supabase/seed.sql
### 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.
```sql supabase/seed.sql
\i seed/countries.sql
```
### Using CSV data to seed your database
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);
```
## Generating seed data from Production