Skip to content

Commit

Permalink
Merge pull request #72 from GenieWizards/feat/add-seed-data
Browse files Browse the repository at this point in the history
feat(seed-data): reset and add seed data in DB in dev mode✨
  • Loading branch information
shivamvijaywargi authored Dec 1, 2024
2 parents 3f1dead + 9d8093d commit c07c74c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
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();

0 comments on commit c07c74c

Please sign in to comment.