Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Drizzle] Data seeding CLI script #1679

Open
mikah13 opened this issue Nov 27, 2023 · 4 comments
Open

feat: [Drizzle] Data seeding CLI script #1679

mikah13 opened this issue Nov 27, 2023 · 4 comments
Labels
📚 documentation Improvements or additions to documentation

Comments

@mikah13
Copy link

mikah13 commented Nov 27, 2023

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 mikah13 added the 🌟 enhancement New feature or request label Nov 27, 2023
@mikah13 mikah13 changed the title feat: Data Seeding CLI for Drizzle feat: [Drizzle] Data seeding CLI script Nov 27, 2023
@juliusmarminge
Copy link
Member

Feel free to add this to the documentatin!

@juliusmarminge juliusmarminge added 📚 documentation Improvements or additions to documentation and removed 🌟 enhancement New feature or request labels Dec 14, 2023
@Nitinshukla88
Copy link

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

@juliusmarminge
Copy link
Member

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

@Nitinshukla88
Copy link

Ok got it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants