create-t3-app icon indicating copy to clipboard operation
create-t3-app copied to clipboard

feat: [Drizzle] Data seeding CLI script

Open mikah13 opened this issue 1 year ago • 5 comments

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

mikah13 avatar Nov 27 '23 03:11 mikah13

Feel free to add this to the documentatin!

juliusmarminge avatar Dec 14 '23 16:12 juliusmarminge

I would like to work on it.Please assign this issue to me @juliusmarminge

Nitinshukla88 avatar Dec 18 '23 20:12 Nitinshukla88

We don't assign issues, just start working on it

juliusmarminge avatar Dec 19 '23 07:12 juliusmarminge

Ok got it.

Nitinshukla88 avatar Dec 19 '23 08:12 Nitinshukla88