From f5c48ef650337b78448246debee707d467cdf7b8 Mon Sep 17 00:00:00 2001 From: Julien Goux Date: Tue, 4 Jun 2024 05:41:25 +0200 Subject: [PATCH] docs: update Snaplet instructions (#26328) * update snaplet docs * typo * format --------- Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com> --- .../guides/cli/seeding-your-database.mdx | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/apps/docs/content/guides/cli/seeding-your-database.mdx b/apps/docs/content/guides/cli/seeding-your-database.mdx index 818c59c1efc..98b94f80093 100644 --- a/apps/docs/content/guides/cli/seeding-your-database.mdx +++ b/apps/docs/content/guides/cli/seeding-your-database.mdx @@ -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: ![An example schema](/docs/img/guides/cli/snaplet-example-schema.png) -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)