### Run Snaplet Seed Installation Wizard Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/installation.mdx This command initiates the automatic installation wizard for Snaplet Seed. It guides users through the setup process, simplifying the initial configuration of their project. ```bash npx @snaplet/seed init ``` -------------------------------- ### Initializing Snaplet Seed with the new CLI Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/migrations.mdx Command to start your `@snaplet/seed` journey using the new onboarding wizard, which is part of its dedicated CLI, streamlining the initial setup process. ```bash npx @snaplet/seed init ``` -------------------------------- ### Create and Execute Basic Snaplet Seed Script Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/installation.mdx This TypeScript script demonstrates how to create a basic Seed script to populate a database. It initializes the Seed client, truncates all existing data, and then seeds the `users` table with 10 entries. ```ts import { createSeedClient } from "@snaplet/seed"; const seed = await createSeedClient(); // Truncate all tables in the database await seed.$resetDatabase(); // Seed the database with 10 users await seed.users((x) => x(10)); process.exit(); ``` -------------------------------- ### Install Snaplet Seed Development Dependencies Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/installation.mdx This command installs the necessary development dependencies for Snaplet Seed and Snaplet Copycat. These packages are required for manual setup and development of seeding scripts within your project. ```bash npm install -D @snaplet/seed @snaplet/copycat ``` -------------------------------- ### Install Local Documentation Project Dependencies Source: https://github.com/supabase-community/seed/blob/main/README.md These commands navigate into the `docs` directory and install the project's dependencies using `pnpm`. This is a necessary step to set up the documentation for local hosting and development. ```bash cd docs pnpm install ``` -------------------------------- ### Install Nix-Direnv with Nix Profile Source: https://github.com/supabase-community/seed/blob/main/README.md Installs `nix-direnv` directly using `nix profile`, an alternative method for users who prefer not to manage their entire home environment with Home Manager. ```sh nix profile install nixpkgs#nix-direnv ``` -------------------------------- ### Initialize Snaplet Project in Custom Directory Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx Provides a command-line example for initializing a Snaplet project in a specified custom directory. This allows for greater flexibility in project setup, such as initializing within a `prisma/seed` directory. ```shell # it will initialize the project in the ./prisma/seed directory npx @snaplet/seed init prisma/seed ``` -------------------------------- ### Example Structure for AI Data Examples JSON Source: https://github.com/supabase-community/seed/blob/main/README.md This JSON snippet illustrates the structure of the `.snaplet/dataExamples.json` file, which stores AI-generated data examples. It shows how to define inputs, examples, and descriptions for specific columns, allowing users to modify or regenerate examples by running `npx @snaplet/seed sync`. ```json [ { "input": "post title", "examples": [ "Tips for Effective Time Management", ... ], "description": "This column is about storing the titles of the user-generated posts in the project." }, ... ] ``` -------------------------------- ### Execute Snaplet Seed Script Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/installation.mdx This command executes the generated or created Seed script using `tsx`. It is used to populate the database according to the defined seeding logic, applicable after both automatic and manual installation. ```bash npx tsx seed.ts ``` -------------------------------- ### Install and Configure Nix for Development Environment Source: https://github.com/supabase-community/seed/blob/main/README.md This command installs Nix, a package manager, and configures its substituters and trusted public keys. It is a prerequisite for setting up the local development environment for both the documentation and contributions, ensuring consistent dependencies. ```sh curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install \ --extra-conf "substituters = https://cache.nixos.org https://devenv.cachix.org" \ --extra-conf "trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=" ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/supabase-community/seed/blob/main/docs/README.md Navigates into the 'docs' directory and installs project dependencies using pnpm, preparing the project for development. ```bash cd docs pnpm install ``` -------------------------------- ### Generate Snaplet Seed Client from Database Schema Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/installation.mdx This command introspects the database schema and generates the necessary client files for Snaplet Seed. It ensures the Seed client is synchronized with the current database structure, enabling type-safe seeding operations. ```bash npx @snaplet/seed sync ``` -------------------------------- ### Example `dataExamples.json` Structure for AI Data Source: https://github.com/supabase-community/seed/blob/main/packages/seed/README.md This JSON snippet illustrates the structure of the `.snaplet/dataExamples.json` file, which stores predicted data examples for text-based entries generated by an LLM. It includes an input field, a list of examples, and a description for each column. ```json [ { "input": "post title", "examples": [ "Tips for Effective Time Management", ... ], "description": "This column is about storing the titles of the user-generated posts in the project." }, ... ] ``` -------------------------------- ### Initialize Home Manager for Direnv Installation Source: https://github.com/supabase-community/seed/blob/main/README.md Initializes Home Manager, a Nix-based tool for managing user environments, which is recommended for configuring `direnv` and other dependencies. ```sh nix run home-manager/master -- init ``` -------------------------------- ### Apply Initial Home Manager Configuration Source: https://github.com/supabase-community/seed/blob/main/README.md Applies the initial `home.nix` configuration, switching the user's environment to reflect the defined settings, including the installation of `direnv`. ```sh nix run home-manager/master -- init --switch ``` -------------------------------- ### Initialize Snaplet Seed Environment Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx Users now initialize their Snaplet Seed environment using the updated `npx @snaplet/seed init` command, replacing the previous `npx snaplet setup` for a more focused setup. ```shell # New initialization command npx @snaplet/seed init # Old initialization command (deprecated) npx snaplet setup ``` -------------------------------- ### Run Local Documentation Development Server Source: https://github.com/supabase-community/seed/blob/main/README.md These commands start the local development server for the documentation project using `pnpm dev`. Once running, the documentation can be accessed in a web browser at `http://localhost:3000`. ```bash pnpm dev # Go to http://localhost:3000 ``` -------------------------------- ### Initialize Snaplet Seed Project Source: https://github.com/supabase-community/seed/blob/main/packages/seed/README.md This command initializes a new Snaplet Seed project, setting up the necessary configuration to start seeding your database with production-like data. ```bash npx @snaplet/seed init ``` -------------------------------- ### Configure Snaplet Seed with PostgreSQL Adapter Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/installation.mdx This TypeScript configuration file defines how Snaplet Seed connects to the database. It specifies the use of the `Postgres.js` adapter, connecting to a PostgreSQL database using the `DATABASE_URL` environment variable. ```ts import { SeedPostgres } from "@snaplet/seed/adapter-postgres"; import { defineConfig } from "@snaplet/seed/config"; import postgres from "postgres"; export default defineConfig({ adapter: () => { const client = postgres(process.env.DATABASE_URL); return new SeedPostgres(client); } }); ``` -------------------------------- ### Asynchronously Create Snaplet Seed Client Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx This example demonstrates the updated asynchronous method for instantiating the Snaplet Seed client. Users should now use `await createSeedClient()` to ensure the client is fully initialized before use, accommodating potential asynchronous operations during its setup. This change is part of refining the API towards a stable v1 release. ```TypeScript import { createSeedClient } from '@snaplet/seed' const seed = await createSeedClient({ /* options */ }) ``` -------------------------------- ### Install Snaplet Seed Package Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/migrations.mdx This command installs the new `@snaplet/seed` package as a development dependency, which provides the Snaplet data client. ```bash npm install -D @snaplet/seed ``` -------------------------------- ### Seeding Records with `x` Function Helper Examples Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Examples demonstrating various ways to use the `x` function helper for seeding records, including fixed counts, ranges, and dynamic data generation based on index. ```ts await seed.users((x) => x(10)); ``` ```ts await seed.users((x) => x({ min: 1, max: 5 })); ``` ```ts await seed.posts((x) => x(3, { title: "Hello, world!", })); ``` ```ts await seed.posts((x) => x(3, (ctx) => ({ title: `Post ${ctx.index}` }))); ``` -------------------------------- ### Example Home Manager Configuration for Direnv and Zsh Source: https://github.com/supabase-community/seed/blob/main/README.md A comprehensive Nix configuration file (`home.nix`) demonstrating how to enable `direnv` and its Zsh integration, along with other packages like Node.js and `cachix`, and Zsh settings including plugins and path modifications. ```nix { pkgs, ... }: { home.username = "jgoux"; home.homeDirectory = "/Users/jgoux"; home.stateVersion = "23.05"; home.packages = [ pkgs.cachix pkgs.corepack_20 pkgs.nodejs_20 pkgs.nil pkgs.nixpkgs-fmt ]; home.sessionVariables = { EDITOR = "code-insiders"; DIRENV_LOG_FORMAT = ""; }; programs = { home-manager.enable = true; # direnv is installed here! direnv = { enable = true; enableZshIntegration = true; nix-direnv.enable = true; }; zsh = { enable = true; autosuggestion.enable = true; syntaxHighlighting.enable = true; oh-my-zsh = { enable = true; plugins = [ "git" ]; theme = "robbyrussell"; }; initExtra = '' export PATH="$PATH:/usr/local/bin:/opt/homebrew/bin" ''; }; }; } ``` -------------------------------- ### Example: Seeding Posts with Object Inputs Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Demonstrates how to seed posts by providing an array of `PostInputs` objects directly to the `seed.posts` function. ```ts await seed.posts([ { title: "Hello, world!" }, ]); ``` -------------------------------- ### Seed Client Models Functions API Reference Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx API documentation for the models functions, detailing their example type signature and purpose for seeding one or more records in the database starting from a given model. ```APIDOC Models functions: Example type: (plan: Array | xCallback, options?: PlanOptions) => Promise Description: Seed one or more records in the database starting from the given model. ``` -------------------------------- ### Run Local Development Server Source: https://github.com/supabase-community/seed/blob/main/docs/README.md Starts the local development server for the project, making it accessible via a web browser at the specified address. ```bash pnpm dev # Go to http://localhost:3000 ``` -------------------------------- ### Example: Resetting All Database Tables Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Shows how to call `$resetDatabase` without arguments to truncate all tables in the database. ```ts await seed.$resetDatabase(); ``` -------------------------------- ### Example: Connect Option with Partial Store Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Illustrates using `connect` with a `Partial` to link 10 posts to a specific user from a custom store. ```ts const store = await seed.users((x) => x(2)); await seed.posts((x) => x(10), { connect: { users: [store.users[0]] }, }); ``` -------------------------------- ### Example: Connect Option with `true` Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Demonstrates using `connect: true` to link 10 posts to 2 previously seeded users from the default `$store`. ```ts await seed.users((x) => x(2)); await seed.posts((x) => x(10), { connect: true, }); ``` -------------------------------- ### Initialize Snaplet Seed Project Source: https://github.com/supabase-community/seed/blob/main/README.md This command initializes a new Snaplet Seed project, setting up the necessary configuration to start seeding your database. It's the first step to integrate Seed into your development workflow for local development and testing. ```bash npx @snaplet/seed init ``` -------------------------------- ### Initialize Snaplet Seed Client in TypeScript Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/quick-start.mdx Starts a basic `seed.ts` script by importing `createSeedClient` and initializing the seed client. This client provides the programmatic interface for defining seeding requirements. ```ts import { createSeedClient } from '@snaplet/seed'; const seed = await createSeedClient(); ``` -------------------------------- ### Install Postgres Adapter for Snaplet Seed Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/integrations/supabase.mdx Command to install the `postgres` npm package as a development dependency, which is required for `@snaplet/seed` to interact with a PostgreSQL database. ```bash npm install -D postgres ``` -------------------------------- ### Example: Seeding Posts with Callback Inputs Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Illustrates seeding posts using a callback function that receives the `PlanContext` to generate dynamic data, such as incorporating the index. ```ts await seed.posts([ (ctx) => ({ title: `Hello, world #${ctx.index}!` }), ]); ``` -------------------------------- ### Install Snaplet Seed in Prisma Project Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/integrations/prisma.mdx This command initializes Snaplet Seed within your Prisma project, creating a `prisma/seed` folder with necessary configuration and script files to begin the seeding process. ```bash npx @snaplet/seed init prisma/seed ``` -------------------------------- ### Supabase Local Development Database URL Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/integrations/supabase.mdx Output from `npx supabase start` showing the local PostgreSQL database URL, essential for connecting Snaplet Seed. ```bash Started supabase local development setup. ... DB URL: postgresql://postgres:postgres@127.0.0.1:54322/postgresql ... ``` -------------------------------- ### Using `dryRun` Option with Seed Client Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Example of initializing the Seed Client in dry run mode to preview SQL queries without executing any database operations. ```ts const seed = await createSeedClient({ dryRun: true, }); ``` -------------------------------- ### Configuring Seed with Prisma Adapter in seed.config.ts Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/migrations.mdx Example configuration for `seed.config.ts` demonstrating the use of the new 'database adapter' parameter, specifically for Prisma. It shows how to import `SeedPrisma` and `defineConfig` and pass a Prisma database instance for seeding operations. ```typescript import { SeedPrisma } from "@snaplet/seed/adapter-prisma"; import { defineConfig } from "@snaplet/seed/config"; // You can import the prisma instance from your own code like you would // in your backend code import { db } from "./src/utils/db"; export default defineConfig({ adapter: () => new SeedPrisma(db), }); ``` -------------------------------- ### Configure AI API Keys for Seed Source: https://github.com/supabase-community/seed/blob/main/README.md This snippet shows how to set up environment variables for OpenAI or Groq API keys in your `.env` file, enabling Seed to use Large Language Models for generating text-based data examples. Optionally, the `AI_MODEL_NAME` variable can specify a particular AI model. ```bash OPENAI_API_KEY= GROQ_API_KEY= ``` -------------------------------- ### Example: Accessing Seeded Data from `$store` Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Demonstrates how to access previously seeded user data from the `$store` property after a seeding operation. ```ts await seed.users((x) => x(2)); // [{ id: '...', username: 'Alice' }, { id: '...', username: 'Bob' }] console.log(seed.$store.users); ``` -------------------------------- ### Seeding Users with Static Array Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Example of seeding three users by providing a static array of user objects with specific or default values. ```ts await seed.users([ { username: "Alice" }, { username: "Bob" }, {}, ]); ``` -------------------------------- ### Overriding Seed Client Adapter Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Example of providing a custom PostgreSQL adapter instance to `createSeedClient` to override the default configuration. ```ts import { SeedPostgres } from "@snaplet/seed/adapter-postgres"; import postgres from "postgres"; const client = postgres(process.env.DATABASE_URL); const seed = await createSeedClient({ adapter: new SeedPostgres(client), }); ``` -------------------------------- ### Programmatic Data Seeding with SnapletClient Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx This TypeScript example illustrates the new `SnapletClient` for advanced data seeding. It demonstrates generating multiple user records, each with nested related data like posts, showcasing the client's capability to create complex, interconnected datasets programmatically. ```TypeScript // seed.mts import { SnapletClient } from "@snaplet/seed"; const snaplet = new SnapletClient(); await snaplet.users(x => x(3, () => ({ posts: (x) => x(10) }))); ``` -------------------------------- ### Create User with Specific Email using Seed Client (TypeScript) Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/overview.mdx This example shows how to create a user with a predefined attribute, specifically an email address, using the Seed Client. It allows for precise data generation based on specific requirements. ```TypeScript await seed.users([ { email: 'snappy@snaplet.dev' }, ]) ``` -------------------------------- ### Seeding and Linking Supabase User Pools with Snaplet Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/recipes/data-pools-connection.mdx This example illustrates how to integrate Supabase for user management (signup, authentication) with Snaplet for seeding and linking additional application data (posts) to these Supabase-managed user profiles. It covers creating users in Supabase, retrieving their profiles, and then connecting new seeded data to them. ```typescript import { createSeedClient } from "@snaplet/seed"; import { createClient } from '@supabase/supabase-js'; const supabase = createClient( process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.NEXT_PUBLIC_SUPABASE_ROLE_KEY ); const PASSWORD = "testuser"; const seed = await createSeedClient(); // Reset our database to start from a clean state await seed.$resetDatabase(); // Creating a pool of users with common attributes for (let i = 0; i < 5; i++) { await supabase.auth.signUp({ email: `user${i}@example.com`, password: PASSWORD, options: { data: { user_name: `user${i}` } } }); } // Retrieving profiles for linking with new data const { data: profiles } = await supabase.from("profiles").select("id"); // Linking new posts to these profiles await seed.posts(x => x(10), { connect: { profiles } }); ``` -------------------------------- ### Define Database Schema for Todo Application Example Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx SQL schema for a todo application demonstrating `board`, `column`, and `item` tables with foreign key relationships. This schema is used to illustrate how `@snaplet/seed` handles automatic connection of descendant models. ```sql create table board ( id uuid not null primary key, name text not null ); create table "column" ( id uuid not null primary key, name text not null, board_id uuid not null references board(id) ); create table item ( id uuid not null primary key, name text not null, column_id uuid not null references "column"(id), board_id uuid not null references board(id) ); ``` -------------------------------- ### Example: Scalar Field as a Callback Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Demonstrates using a callback for a scalar field, allowing access to `ctx.data` for dynamic content based on other generated fields. ```ts await seed.posts([ { title: "Hello, world!", content: (ctx) => `The title of this post is "${ctx.data.title}"`, }, ]); ``` -------------------------------- ### Example: Parent Relationship Field as a Callback with Connect Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Demonstrates connecting a parent relationship using a callback with `ctx.connect`, linking to an existing model instance from the store. ```ts await seed.users([{}]); await seed.posts([ { author: (ctx) => ctx.connect(seed.$store.users[0]), } ]); ``` -------------------------------- ### Example: Child Relationship Field as a Callback Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Shows how to define child relationships using a callback, allowing dynamic generation of multiple child instances. ```ts await seed.posts([ { comments: (x) => x(2), }, ]); ``` -------------------------------- ### Example: Seed Option with Custom String Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Demonstrates using the `seed` option to set a custom seed value, ensuring consistent data generation across runs. ```ts await seed.users((x) => x(2), { seed: 'snappy', }); ``` -------------------------------- ### Example: Models Option with Custom Email Generation Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Shows how to use the `models` option to define a custom email generation function for users, leveraging `copycat` for dynamic values. ```ts import { copycat } from "@snaplet/copycat"; await seed.users((x) => x(2), { models: { users: { data: { email: (ctx) => copycat.email(ctx.seed, { domain: "snaplet.dev" }), }, }, }, }); ``` -------------------------------- ### Deprecated Snaplet CLI Commands Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx This snippet lists commands that have been removed in Snaplet CLI v0.70.0, marking a breaking change. Users should be aware that `snaplet snapshot subset`, `snaplet subset command`, and `snaplet config setup` are no longer available. ```bash snaplet snapshot subset ``` ```bash snaplet subset command ``` ```bash snaplet config setup ``` -------------------------------- ### Customize Snaplet Seed Script for Database Seeding Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/integrations/prisma.mdx This TypeScript script demonstrates how to use `createSeedClient` to interact with the database. It includes examples for truncating all tables and seeding a specific number of users, providing a foundation for custom data generation logic. ```typescript import { createSeedClient } from "@snaplet/seed"; const seed = await createSeedClient(); // Truncate all tables in the database await seed.$resetDatabase(); // Seed the database with 10 users await seed.user((x) => x(10)); process.exit(); ``` -------------------------------- ### Initialize Seed Project with CLI (Bash) Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/overview.mdx This command initializes a new Seed project in the current directory, setting up the necessary files and configurations. It's the first step to integrate Seed into your development workflow. ```Bash npx @snaplet/seed init ``` -------------------------------- ### Seed Posts with Basic Structure in Snaplet Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/quick-start.mdx Demonstrates the initial step of seeding data for the `posts` model using `@snaplet/seed`. It shows how to call the `posts` function on the seed client to create new post entries. ```ts import { createSeedClient } from '@snaplet/seed'; const seed = await createSeedClient(); await seed.posts([{}]); ``` -------------------------------- ### Apply Global Connections for Consistent Data Values Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/recipes/relationships.mdx This example illustrates how to use global connections to ensure consistent values across the entire data generation process. By declaring a base client and seeding common lookup data (like 'admin' and 'member' for `workspace_user_type`), these values can be made globally available to subsequent seeding operations. This approach simplifies data consistency and reduces redundancy in connection definitions. ```typescript // Declare a base client to reset our database and set up global values const baseClient = await createSeedClient(); // Truncate all tables in the database await baseClient.$resetDatabase(); // Seed our database with our two workspace user types const { workspace_user_type } = await baseClient.workspace_user_type([ { type: "admin" }, { type: "member" } ]); // Initialize another client to seed the rest // of the data and link with global values const seed = await createSeedClient({ connect: { // Make our user types globally available in all plans workspace_user_type } }); ``` -------------------------------- ### Initialize Snaplet Seed CLI for a project Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/cli.mdx The `npx @snaplet/seed init` command initializes Seed locally for your project. It accepts an optional `` argument to specify the initialization path. If a directory is provided, subsequent commands might require the `--config` option. ```bash npx @snaplet/seed init ``` ```bash npx @snaplet/seed init prisma/seed ``` -------------------------------- ### Example: Scalar Field as a String Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Shows how to define a scalar field with a static string value. ```ts await seed.posts([ { title: (ctx) => "Hello, world!" }, ]); ``` -------------------------------- ### Final Seed Script with Dry Run and Database Reset Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/quick-start.mdx Presents the complete seed script, incorporating advanced options. It demonstrates using `dryRun: true` to preview SQL statements without modifying the database and `await seed.$resetDatabase()` to clear existing data before seeding, ensuring a clean state. ```ts import { createSeedClient } from '@snaplet/seed'; import { copycat } from '@snaplet/copycat'; const seed = await createSeedClient({ dryRun: true }); await seed.$resetDatabase(); await seed.posts([ { title: 'Hello World!', author: { email: (ctx) => copycat.email(ctx.seed, { domain: 'acme.org', }), }, comments: (x) => x(3), }, ]); ``` -------------------------------- ### Generate Snaplet Seed Assets via CLI Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/quick-start.mdx Command-line instruction to synchronize and generate necessary assets for `@snaplet/seed`. This step prepares the environment for writing and executing seed scripts based on the configured database schema. ```bash npx @snaplet/seed sync ``` -------------------------------- ### Example: Resetting Database Tables with Exclusions Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Illustrates using `$resetDatabase` with a `selectConfig` array to exclude specific tables, such as `public._prisma_migrations`, from truncation. ```ts await seed.$resetDatabase([ "!public._prisma_migrations", ]); ``` -------------------------------- ### Initialize Seed Client and Define Post Data Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/quick-start.mdx This TypeScript snippet initializes the Snaplet seed client with `dryRun: true` and defines a plan to seed 'posts'. It demonstrates creating a post with a title, an author whose email is generated using `copycat`, and three comments, showcasing automatic relationship fulfillment. ```TypeScript import { copycat } from '@snaplet/copycat'; const seed = await createSeedClient({ dryRun: true }); await seed.$resetDatabase() await seed.posts([ { title: 'Hello World!', author: { email: (ctx) => copycat.email(ctx.seed, { domain: 'acme.org', }), }, comments: (x) => x(3), }, ]); ``` -------------------------------- ### Update Snaplet Seed Configuration File Name Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx The primary configuration file for @snaplet/seed has been moved from `snaplet.config.ts` to `seed.config.ts` to provide a more focused setup. ```typescript // Old configuration file name // snaplet.config.ts // New configuration file name // seed.config.ts ``` -------------------------------- ### Initializing Seed Client with createSeedClient Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Demonstrates how to import and initialize a new Seed Client instance using the `createSeedClient` function. ```ts import { createSeedClient } from "@snaplet/seed"; const seed = await createSeedClient(); ``` -------------------------------- ### Example: Child Relationship Field as a Static Array Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Illustrates defining child relationships by providing a static array of child model inputs. ```ts await seed.posts([ { comments: [ { title: "Very interesting!" }, { title: "It's Internet so I disagree!" }, ], }, ]); ``` -------------------------------- ### Example: Parent Relationship Field as an Object Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Shows how to define a parent relationship by providing an object with the parent model's data directly. ```ts await seed.posts([ { author: { username: "Snappy" }, } ]); ``` -------------------------------- ### Importing Components and Utilities for Next.js Page Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes.mdx This JavaScript snippet demonstrates how to import various components (`Step`, `ReleaseNotes`, `Steps`) and a data fetching utility (`getReleases`) into a Next.js page. These imports are essential for structuring the page's UI and populating it with dynamic content. ```JavaScript import { Step } from '../../components/Step' import { ReleaseNotes } from "../../components/ReleaseNotes" import { getReleases } from '../../lib/getReleases' import { Steps } from "nextra/components" ``` -------------------------------- ### Models Functions: plan (x function helper) Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx API documentation for the `x` function helper, explaining how to seed a given model `n` times with options for fixed counts, ranges, and dynamic data generation. ```APIDOC x function helper: Example type: (n: number | MinMaxOption, plan?: UserPlanInputs) => Array Description: Seed a given model n times. ``` -------------------------------- ### Configure Direnvrc for Nix-Direnv Integration Source: https://github.com/supabase-community/seed/blob/main/README.md Adds a source line to the `direnvrc` configuration file, enabling `nix-direnv` integration so that `direnv` can automatically load Nix-managed dependencies. ```sh source $HOME/.nix-profile/share/nix-direnv/direnvrc ``` -------------------------------- ### Enable Intellisense for Seed Configuration with defineConfig Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/configuration.mdx Shows how to use the `defineConfig` helper from `@snaplet/seed/config` to define your Seed client configuration. This provides type-checking and Intellisense for available options, which becomes typed against your database schema after syncing. ```ts import { defineConfig } from "@snaplet/seed/config"; export default defineConfig({ // your configuration options here... }); ``` -------------------------------- ### Example: Scalar Field as an Async Callback Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx Illustrates defining a scalar field using an asynchronous callback, useful for fetching data or performing other async operations during seeding. ```ts await seed.posts([ { title: async (ctx) => { return await fetchTitle(ctx.seed); }, }, ]); ``` -------------------------------- ### Re-apply Home Manager Configuration Source: https://github.com/supabase-community/seed/blob/main/README.md Command to re-apply the Home Manager configuration after making changes to `home.nix`, ensuring the environment is updated without re-initializing. ```sh home-manager switch ``` -------------------------------- ### Configure Snaplet Seed for PostgreSQL Database Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/quick-start.mdx Configures the `seed.config.ts` file to connect `@snaplet/seed` to a PostgreSQL database. It uses the `postgres` client library and specifies the database connection string for local development. ```ts import { SeedPostgres } from "@snaplet/seed/adapter-postgres"; import { defineConfig } from "@snaplet/seed/config"; import postgres from "postgres"; export default defineConfig({ adapter: () => { const client = postgres("postgres://postgres@localhost:5432/blog"); return new SeedPostgres(client); } }); ``` -------------------------------- ### Initialize Next.js Application with Global Styles Source: https://github.com/supabase-community/seed/blob/main/docs/pages/_app.mdx This snippet defines the root `App` component for a Next.js application. It imports global CSS files, including `@code-hike/mdx` styles and custom `global.css`, ensuring they are applied across all pages. The `App` component then renders the current `Component` with its `pageProps`. ```JavaScript import "@code-hike/mdx/dist/index.css"; import "../styles/global.css"; export default function App({ Component, pageProps }) { return ; } ``` -------------------------------- ### Support Asynchronous Field Functions in Snaplet Seed Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx Shows an example of using promise-returning functions for field generation within `@snaplet/seed`, addressing a previous lack of type support for this feature. ```TypeScript snaplet.users([{ name: async () => { return await Promise.resolve('Foo Bar') } }]) ``` -------------------------------- ### Complete Snaplet Seed Script Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/migrations.mdx This complete `seed.ts` file includes the `SnapletClient` initialization, database reset, and the data generation logic previously found in the `run` function of `seed.config.ts`. ```ts import { SnapletClient } from '@snaplet/seed'; const snaplet = new SnapletClient(); snaplet.$resetDatabase(); await snaplet.users((x) => x(3, () => ({ posts: (x) => x(10), }))); ``` -------------------------------- ### Configure Snaplet Seed for Supabase Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/integrations/supabase.mdx Example `seed.config.ts` configuration file. It sets up the PostgreSQL client connection and specifies which schemas and tables (`public` and selected `auth` tables) Snaplet Seed should alter. ```typescript import { SeedPostgres } from "@snaplet/seed/adapter-postgres"; import { defineConfig } from "@snaplet/seed/config"; import postgres from "postgres"; export default defineConfig({ adapter: () => { const client = postgres("postgresql://postgres:postgres@127.0.0.1:54322/postgresql"); return new SeedPostgres(client); }, select: [ // We don't alter any extensions tables that might be owned by extensions "!*", // We want to alter all the tables under public schema "public*", // We also want to alter some of the tables under the auth schema "auth.users", "auth.identities", "auth.sessions" ] }); ``` -------------------------------- ### Generate Multiple Posts with Seed Client (TypeScript) Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/overview.mdx This snippet demonstrates how to generate a specified number of data entries, such as 5 posts for a blog application, using the Seed Client. It leverages a functional approach to define the quantity of data to be created. ```TypeScript await seed.posts((x) => x(5)) ``` -------------------------------- ### Enabling Inflection in Snaplet Seed Configuration Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/migrations.mdx Configuration example showing how to explicitly opt-in to the inflection feature within the `alias` object in `seed.config.ts`. Inflection is now disabled by default, allowing users to enable it based on their specific needs. ```typescript export default defineConfig({ // Additional configuration options alias: { // Opt-in to enable inflection behavior inflection: true, } }); ``` -------------------------------- ### Configure Seed Client for Database Insertion Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/quick-start.mdx This TypeScript snippet shows how to modify the seed client initialization to enable actual data insertion into the database. By removing the `dryRun` option, the script will execute the generated SQL statements directly against the configured database. ```TypeScript const seed = await createSeedClient(); ``` -------------------------------- ### Utilizing `store` and `$store` Parameters in Snaplet Generate and Connect Functions Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx Explains the use of `store` (containing models created in the current plan) and `$store` (containing all models created in the Snaplet instance so far) parameters within both generate and connect functions for advanced data generation and relation linking scenarios. ```typescript // generate function await snaplet.customers([{ email: ({ store, $store }) => /* ... */ }]) ``` ```typescript // connect function await snaplet.reservations([{ customer: ({ store, $store }) => /* ... */, }]); ``` -------------------------------- ### Demonstrating Snaplet User Seeding Behavior Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx Illustrates a previous behavior of Snaplet's `generate` where identical IDs were returned for different user inputs. This snippet highlights the change to a new hash-based seeding mechanism, which ensures more predictable and input-dependent outputs, similar to Snaplet Copycat's behavior. ```JavaScript await snaplet.User({ email: 'alice@acme.com' }) await snaplet.User({ email: 'bob@acme.com' }) ``` -------------------------------- ### Synchronize Seed Client with Database Schema Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/quick-start.mdx This Bash command is used to regenerate `@snaplet/seed` assets. It fetches the latest database structure and updates the seed client's understanding of the schema, ensuring it remains in sync with any database changes. ```Bash npx @snaplet/seed sync ``` -------------------------------- ### Models Functions: plan Parameter Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx API documentation for the `plan` parameter used in models functions, describing how to define the data to seed using either a static array or the dynamic `x` function helper. ```APIDOC plan: Description: Describes the data to seed. You can provide the plan's inputs as a static array of inputs or more dynamically using the x function helper. ``` -------------------------------- ### Uninstalling the old Snaplet CLI Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/migrations.mdx Instructions to uninstall the previous `snaplet` CLI if you are not using the Snapshot tool, as `@snaplet/seed` now has its own dedicated command-line interface. ```bash npm uninstall snaplet ``` -------------------------------- ### Seed Posts with Custom Author Email using Copycat Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/quick-start.mdx Shows how to define related data by setting the `author` field for a post. It uses `copycat.email` to generate a realistic email address with a custom domain, demonstrating dynamic data generation for relationships. ```ts import { createSeedClient } from '@snaplet/seed'; import { copycat } from '@snaplet/copycat'; const seed = await createSeedClient(); await seed.posts([ { title: 'Hello World!', author: { email: (ctx) => copycat.email(ctx.seed, { domain: 'acme.org', }), }, }, ]); ``` -------------------------------- ### Resetting Database with Selective Table Persistence Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/migrations.mdx Example of using the `$resetDatabase` method to reset the database, showing how to exclude specific tables (e.g., `public.users`) from the reset operation. This is particularly useful for testing scenarios where certain data needs to persist across test runs. ```typescript import { createSeedClient } from "@snaplet/seed"; const seed = await createSeedClient(); await seed.$resetDatabase(); // Resets, respecting exclusions from config // Example usage in tests test('your_test', () => {}); test('another_test', async () => { await seed.$resetDatabase([ '!public.users', // Keeps user data intact ]); }); ``` -------------------------------- ### Execute Snaplet Generate Command Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx This command initiates the generation of assets for `@snaplet/seed`. It is specifically mentioned for use when reverting to `@snaplet/copycat`, ensuring the necessary files are updated for the seeding process. ```Shell npx snaplet generate ``` -------------------------------- ### Demonstrate Snaplet Seed Default Value Behavior Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx This TypeScript example illustrates how `@snaplet/seed` handles data generation when values are either explicitly provided or omitted. It highlights that default values, when not explicitly set, might change after a major version upgrade, affecting the initial `snaplet generate` run. ```TypeScript // name given explicitly snaplet.users({ name: 'Garnet Harley' }) // name not given explicitly // => the generated value might have now changed // (after the first `snaplet generate` after upgrading) snaplet.users({}) ``` -------------------------------- ### Initialize Snaplet Seed Project Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/integrations/supabase.mdx Command to initialize `@snaplet/seed` in your project's root directory, which creates a `seed.config.ts` file for configuration. ```bash npx @snaplet/seed init ``` -------------------------------- ### Initialize SnapletClient and Reset Database Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/migrations.mdx Instantiate the `SnapletClient` and explicitly call `$resetDatabase()` if you previously relied on Snaplet to clear existing data. This ensures a clean state before seeding. ```ts import { SnapletClient } from '@snaplet/seed'; const snaplet = new SnapletClient(); snaplet.$resetDatabase(); ``` -------------------------------- ### Configuring Snaplet to Use Database-Managed Defaults Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/recipes/contraints-and-defaults.mdx This example shows how to configure Snaplet to integrate with database-managed default value generation. It uses a Prisma client to call a database function (`generate_random_id`) and assigns its output as the default ID for a 'post' model, allowing the database to handle specific default logic. ```javascript import { createSeedClient } from "@snaplet/seed"; import { PrismaClient } from "@prisma/client"; // Get a database client const client = new PrismaClient(); async function getDatabaseGeneratedId() { // Use the client to call our internal function const res = (await client.$queryRawUnsafe) < { id: string } > `SELECT generate_random_id(12) as id`; return res[0]["id"]; } const seed = await createSeedClient({ models: { post: { data: { id: getDatabaseGeneratedId, }, }, }, }); ``` -------------------------------- ### Understanding Default Value Changes After Snaplet AI Model Upgrade Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx This example demonstrates how the @snaplet/seed AI model improvements might affect default generated values. Explicitly provided values remain unchanged, but implicitly generated values for fields (columns) might differ after the first snaplet generate run post-upgrade. ```TypeScript // name given explicitly await snaplet.users({ name: 'Garnet Harley' }) // name not given explicitly // => the generated value might have now changed // (after the first `snaplet generate` after upgrading) await snaplet.users({}) ``` -------------------------------- ### Asynchronous Client Instantiation with createSeedClient Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/migrations.mdx Understand the breaking change in `@snaplet/seed` where client instantiation is now asynchronous. Replace `new SnapletClient()` with the promise-returning `await createSeedClient()` function. ```TypeScript // before import { SnapletClient } from '@snaplet/seed' const snaplet = new SnapletClient({ /* options */ }) ``` ```TypeScript // after import { createSeedClient } from '@snaplet/seed' const seed = await createSeedClient({ /* options */ }) ``` -------------------------------- ### PostgreSQL Blog Application Schema Definition Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/getting-started/quick-start.mdx Defines the database schema for a blog application, including tables for users, posts, and comments. It establishes primary keys and foreign key relationships to ensure data integrity. ```sql CREATE TABLE public.user ( id uuid NOT NULL PRIMARY KEY, username text NOT NULL, email text NOT NULL ); CREATE TABLE public.post ( id uuid NOT NULL PRIMARY KEY, title text NOT NULL, content text NOT NULL, author_id uuid NOT NULL REFERENCES public.user(id) ); CREATE TABLE public.comment ( id uuid NOT NULL PRIMARY KEY, content text NOT NULL, author_id uuid NOT NULL REFERENCES public.user(id), post_id uuid NOT NULL REFERENCES public.post(id), written_at timestamptz NOT NULL DEFAULT now() ); ``` -------------------------------- ### Implicit Path Connections for Related Data in @snaplet/seed Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/recipes/relationships.mdx Demonstrates how `@snaplet/seed`'s path connect implicitly links related data. When a parent entity (e.g., a user) declares child entities (e.g., messages, channels), the system automatically establishes connections, making the parent the default author or recipient for these related records. This example shows a user creating direct messages and a channel with threads and messages. ```TypeScript await seed.users((x) => x(1, { // Ensure we are the author of two direct messages authored_user_messages: [{}, {}], // Ensure we are the recipient of two direct messages received_user_messages: [{}, {}], // Create a channel channel: [{ // With a thread in it channel_thread: [{ // And three messages in this thread channel_thread_message: [{}, {}, {}] }] }] }) ); ``` -------------------------------- ### Configure Snaplet Seed Alias Overrides for Name Conflicts Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx This configuration example demonstrates how to resolve model name conflicts in `snaplet.config.ts` using the `alias.override` option. It allows mapping conflicting singular and plural table names (e.g., `user` and `users`) to distinct aliases like `users` and `allUsers` to prevent data loss during inflection. This is necessary when tables from the same schema have singular and plural forms that would otherwise map to the same generated name. ```TypeScript /// import { defineConfig } from 'snaplet'; export default defineConfig({ seed: { alias: { override: { user: { // e.g. seed.users(x => x(2)) name: 'users', }, users: { // e.g. seed.allUsers(x => x(2)) name: 'allUsers', }, }, }, }, }); ``` -------------------------------- ### createSeedClient Option: connect Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx API documentation for the `connect` option of `createSeedClient`, which, if true, applies the connect option to every plan, linking generated records to existing ones. ```APIDOC connect: Type: boolean Description: If true, the Seed Client will apply the connect option to every plan. ``` -------------------------------- ### Link local directory to a Snaplet Project Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/cli.mdx The `npx @snaplet/seed link` command establishes a connection between your local project directory and a specific Snaplet Project, enabling project-specific operations. ```bash npx @snaplet/seed link ``` -------------------------------- ### Generate necessary assets for Seed Client Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/cli.mdx The `npx @snaplet/seed generate` command is responsible for generating all required assets for the Seed Client to function correctly, preparing it for data seeding operations. ```bash npx @snaplet/seed generate ``` -------------------------------- ### Seed Client Configuration Option: adapter Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/configuration.mdx Defines the database adapter to be used by the Seed client. This option is required and expects a function that returns a `DatabaseClient` instance or a Promise resolving to one, connecting Seed to your database. ```APIDOC adapter: Type: () => DatabaseClient | Promise> Required: true Description: The database adapter to use. Example: import { SeedPostgres } from "@snaplet/seed/adapter-postgres"; import { defineConfig } from "@snaplet/seed/config"; import postgres from "postgres"; export default defineConfig({ adapter: () => { const client = postgres(process.env.DATABASE_URL); return new SeedPostgres(client); }, }); ``` -------------------------------- ### Update Snaplet Dependencies Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/release-notes-archive.mdx Before previewing the `copycat.float()` change or using `@snaplet/copycat/next` with `@snaplet/seed`, it is necessary to update your Snaplet dependencies to their latest versions using Yarn. ```Shell yarn up snaplet @snaplet/seed ``` -------------------------------- ### createSeedClient Function API Reference Source: https://github.com/supabase-community/seed/blob/main/docs/pages/seed/reference/client.mdx API documentation for the `createSeedClient` function, including its type signature and purpose for initializing a new Seed Client instance. ```APIDOC createSeedClient: Type: (options?: SeedClientOptions) => Promise Description: Create a new Seed Client instance. ```