Seeding
turbine seed runs a seed file against your database. The file can be TypeScript, JavaScript or SQL.
npx turbine seedTypeScript seeds with defineSeed#
defineSeed connects with DATABASE_URL, passes a client to your function, and disconnects when it returns:
// turbine/seed.ts
import { defineSeed } from 'turbine-orm';
export default defineSeed(async (db) => {
await db.raw`
INSERT INTO organizations (name, slug) VALUES (${'Acme'}, ${'acme'})
ON CONFLICT (slug) DO NOTHING
`;
});That client has no table accessors, so write with db.raw or db.sql. For typed accessors, import your generated client and disconnect it yourself:
// turbine/seed.ts
import { turbine } from '../generated/turbine/index.js';
const db = turbine();
await db.organizations.createMany({
data: [
{ name: 'Acme', slug: 'acme' },
{ name: 'Widgets', slug: 'widgets' },
],
});
await db.disconnect();A seed without defineSeed, like this one, runs to completion and exits 0 with a notice that Turbine cannot confirm what it wrote. TypeScript seeds need tsx installed as a dev dependency.
JavaScript and SQL seeds#
.js: imported; if the default export is a function, Turbine calls it..sql: executed as raw SQL.
-- seed.sql
INSERT INTO organizations (name, slug) VALUES ('Acme', 'acme')
ON CONFLICT (slug) DO NOTHING;Which file runs#
seedFileinturbine.config.ts, if set.seedis an older alias;seedFilewins when both are set.- Otherwise the first that exists of
seed.ts,seed.js,seed.sql,turbine/seed.ts,turbine/seed.jsandturbine/seed.sql.
When turbine.config.ts sets a schema, the seed runs with that schema first on the search_path, so unqualified table names resolve the way they do for migrate.
Seeding in CI#
npx turbine migrate deploy
npx turbine seedmigrate deploy applies pending migrations without prompts, and fails the build on a modified or missing migration file. See migrate deploy.
See also#
- CLI:
turbine seedand every flag. - Migrations: the workflow your seeds run after.