Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
fix: fix seed file
Browse files Browse the repository at this point in the history
  • Loading branch information
2wce committed Jan 21, 2024
1 parent 8b34977 commit 2cc4588
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"prestart": "npm run generate",
"start": "bun --watch src/index.ts",
"reset": "prisma migrate reset -f",
"seed": "ts-node prisma/seed.ts",
"seed": "bun run src/database/seed.ts",
"generate": "bun run src/utils/generateSchema.ts && prisma generate && graphql-codegen",
"studio": "prisma studio",
"migrate": "prisma migrate dev",
Expand Down
41 changes: 16 additions & 25 deletions src/database/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,23 @@ import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

async function main() {
//create posts dummy data
const posts = postFactory.buildList(5);
try {
//create posts dummy data
const posts = postFactory.buildList(5);

// create user dummy data
const users = userFactory.buildList(1);
// create user dummy data
const user = userFactory.build();

const res = await prisma.$transaction([
prisma.post.create({
// @ts-ignore
data: posts,
}),
prisma.user.create({
// @ts-ignore
data: users,
}),
]);
for await (const post of posts) {
await prisma.post.create({ data: post });
}

console.log("seed data created", { res });
}
await prisma.user.create({ data: user });

main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
console.log("seed data created", { posts, user });
} catch (error) {
console.error(error);
process.exit(1);
} finally {
await prisma.$disconnect();
}

0 comments on commit 2cc4588

Please sign in to comment.