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(seed-data): reset and add seed data in DB in dev mode✨ #72

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"lint:fix": "bun lint --fix",
"start": "bun src/index.ts",
"db:clear": "NODE_ENV=test bun run src/db/scripts/clear-db.script.ts",
"db:seed": "NODE_ENV=development bun run src/db/scripts/seed-db.script.ts",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"deps:update": "npx npm-check-updates --interactive --format group",
Expand All @@ -34,6 +35,7 @@
"@scalar/hono-api-reference": "^0.5.162",
"drizzle-kit": "^0.28.1",
"drizzle-orm": "^0.36.4",
"drizzle-seed": "^0.1.2",
"drizzle-zod": "^0.5.1",
"hono": "^4.6.12",
"hono-pino": "^0.7.0",
Expand Down
28 changes: 28 additions & 0 deletions src/db/scripts/seed-db.script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable no-console */
import { reset, seed } from "drizzle-seed";

import { db } from "../adapter";
import * as schema from "../schemas";

async function main() {
try {
console.log("Resetting the database");
await reset(db, schema);
console.log("Seed script execution started....");
await seed(db, schema).refine(fn => ({
expenseModel: {
columns: {
currency: fn.default({
defaultValue: "INR",
}),
},
},
}));
console.log("Seed script executed successfully");
process.exit(0);
} catch (error) {
console.log("Something went wrong in seed script execution", error);
}
}

await main();