create-t3-app
create-t3-app copied to clipboard
feat: [Drizzle] Data seeding CLI script
Is your feature request related to a problem? Please describe.
I was looking for an elegant solution to add seeding data in Drizzle via a CLI command. There doesn't seem to be an answer from the documentation, so I went ahead and gave it a try. This is what I came up with so far
Describe the solution you'd like to see
additional script for data seeding purpose in the package.json
"script": {
"build": "next build",
"db:push": "dotenv drizzle-kit push:MySQL",
"db:studio": "dotenv drizzle-kit studio",
+ "db:seed": "dotenv npx tsx ./src/server/db/seed.ts",
"dev": "next dev",
"lint": "next lint",
"start": "next start",
}
with a default seed.ts file, defined in ./src/server/db/seed.ts
import { db } from ".";
import { posts } from "./schema";
const firstPost = await db.insert(posts).values({
name: "My first blog post",
});
Describe alternate solutions
N/A
Additional information
No response
Feel free to add this to the documentatin!
I would like to work on it.Please assign this issue to me @juliusmarminge
We don't assign issues, just start working on it
Ok got it.