Documentation
Database

Seeds

Learn how to manage and automatically populate your database with initial data.

AI Skill for database seeds

Prompt: Type /database-seeds in your Copilot / Cursor or other chat to use skill with the provided context.
/database-seeds Generate seed for [describe data/change].

Tracked seeds are executed automatically during startup to ensure your database always has the necessary base data.

How it works

Instead of running seeds blindly on every startup, GoLiveKit tracks which operations have already been applied using a dedicated seed_execution table in your database.

Each seed is assigned a unique key. When the application starts:

  • If the unique key exists in the seed_execution table, the operation is skipped.
  • If the key is missing, the operation runs securely and the key is inserted into the table.

This architecture ensures that seed scripts are inherently safe and run exactly once in production environments.

Adding a new seed

Create the seed logic

Create a new seed operation function inside the src/prisma/seed/targets folder.

src/prisma/seed/targets/feature.ts
import { PrismaClient } from '@prisma/client';

export const seedFeatureData = async (prisma: PrismaClient) => {
  await prisma.feature.createMany({
    data: [
      { name: 'Beta Access', enabled: true },
    ],
    skipDuplicates: true,
  });
};

Register the seed

Open src/prisma/seed/seed.ts and register your new function with a distinct and stable key.

src/prisma/seed/seed.ts
import { seedFeatureData } from './targets/feature';

// ...

export const seeds = [
  // ... existing seeds ...
  {
    key: 'features:initial:v1', // This key goes into the seed_execution table
    operation: seedFeatureData,
  }
];

Apply the seed

Locally, you can apply your new seed immediately by running:

pnpm db:seed

In production, deploying your repository will automatically detect the new key and run the seed once during the deployment startup phase.

Re-running a seed

Because operations are strictly one-time, they will not run again once recorded. If you absolutely need to re-run a specific seed, you must manually delete its row from the seed_execution database table and run the seed command.

On this page