mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
docs: update Snaplet instructions (#26328)
* update snaplet docs * typo * format --------- Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
This commit is contained in:
1 parent
1b6a32458f
commit
f5c48ef650
1 file changed
+25
-19
@@ -53,7 +53,7 @@ COPY countries (name, code) FROM 'seed/countries.csv' WITH (FORMAT csv);
|
||||
You can generate seed data for local development using [Snaplet](https://www.snaplet.dev/).
|
||||
|
||||
If this is your first time using Snaplet to seed your project, you'll need to setup Snaplet
|
||||
for your project with `npx snaplet setup`, and follow the interactive prompts. `snaplet setup`
|
||||
for your project with `npx @snaplet/seed init`, and follow the interactive prompts. The command
|
||||
will look at your database and its structure, and use it to generate the configuration files
|
||||
and assets needed by `@snaplet/seed`.
|
||||
|
||||
@@ -61,33 +61,39 @@ Suppose you have a database with the following schema:
|
||||
|
||||

|
||||
|
||||
You can use the Snaplet configuration file `seed.mts` to define the values you want to generate. For example
|
||||
You can use the seed script example generated by Snaplet `seed.ts` to define the values you want to generate. For example:
|
||||
|
||||
- A `Post` with the title `"There is a lot of snow around here!"`
|
||||
- The `Post.createdBy` user with an email address ending in `"@acme.org"`
|
||||
- Three `Post.comments` from three different users.
|
||||
|
||||
```ts seed.mts
|
||||
```ts seed.ts
|
||||
import { createSeedClient } from '@snaplet/seed'
|
||||
import { copycat } from '@snaplet/copycat'
|
||||
|
||||
const seed = await createSeedClient()
|
||||
async function main() {
|
||||
const seed = await createSeedClient({ dryRun: true })
|
||||
|
||||
await seed.posts([
|
||||
{
|
||||
title: 'There is a lot of snow around here!',
|
||||
createdBy: {
|
||||
email: (ctx) =>
|
||||
copycat.email(ctx.seed, {
|
||||
domain: 'acme.org',
|
||||
}),
|
||||
await seed.Post([
|
||||
{
|
||||
title: 'There is a lot of snow around here!',
|
||||
createdBy: {
|
||||
email: (ctx) =>
|
||||
copycat.email(ctx.seed, {
|
||||
domain: 'acme.org',
|
||||
}),
|
||||
},
|
||||
Comment: (x) => x(3),
|
||||
},
|
||||
comments: (x) => x(3),
|
||||
},
|
||||
])
|
||||
])
|
||||
|
||||
process.exit()
|
||||
}
|
||||
|
||||
main()
|
||||
```
|
||||
|
||||
Running `npx tsx seed.mts > supabase/seed.sql` generates the relevant SQL statements inside your `supabase/seed.sql` file:
|
||||
Running `npx tsx seed.ts > supabase/seed.sql` generates the relevant SQL statements inside your `supabase/seed.sql` file:
|
||||
|
||||
```sql
|
||||
-- The `Post.createdBy` user with an email address ending in `"@acme.org"`
|
||||
@@ -99,7 +105,7 @@ INSERT INTO "Post" (title, content, createdBy) VALUES (
|
||||
"Lorem ipsum dolar",
|
||||
1)
|
||||
|
||||
--- Three `Post.comments` from three different users.
|
||||
--- Three `Post.Comment` from three different users.
|
||||
INSERT INTO "User" (name, email) VALUES ("Stephanie Shadow", "shadow@domain.com")
|
||||
INSERT INTO "Comment" (text, userId, postId) VALUES ("I love cheese", 2, 1)
|
||||
|
||||
@@ -111,6 +117,6 @@ INSERT INTO "Comment" (text, userId, postId) VALUES ("Actually, that's not corre
|
||||
```
|
||||
|
||||
Whenever your database structure changes, `@snaplet/seed` will need to be regenerated so that it is
|
||||
in sync with your new database structure. You can do this by running `npx snaplet generate`.
|
||||
in sync with your new database structure. You can do this by running `npx @snaplet/seed sync`.
|
||||
|
||||
For more information, check out Snaplet's [seed documentation](https://docs.snaplet.dev/core-concepts/seed)
|
||||
For more information, check out Snaplet's [seed documentation](https://docs.snaplet.dev/seed/integrations/supabase)
|
||||
Reference in new issue
Block a user