Skip to content

Commit

Permalink
refact: move seed to test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniciusCestarii committed Jan 21, 2025
1 parent 8221a63 commit c8deddb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 2 additions & 4 deletions scripts/seed-db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { seed } from "drizzle-seed";
import * as schemas from "@/db/schema";
import db from "@/db";
import { seedDb } from "@/modules/shared/utilities/test";

await seed(db, schemas, { count: 100 });
await seedDb();

console.log("Database seeded successfully");
14 changes: 13 additions & 1 deletion src/modules/shared/utilities/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { drizzle } from "drizzle-orm/node-postgres";
import { reset } from "drizzle-seed";
import { reset, seed } from "drizzle-seed";
import fs from "fs/promises";
import path from "node:path";
import { Pool } from "pg";
Expand Down Expand Up @@ -47,3 +47,15 @@ export const resetDb = async () => {

await pool.end();
};

export const seedDb = async () => {
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});

const db = drizzle(pool);

await seed(db, schemas, { count: 2000 });

await pool.end();
};

0 comments on commit c8deddb

Please sign in to comment.