add seed script and use postgres for db

This commit is contained in:
i701 2024-11-27 14:14:14 +05:00
parent e9c71c1e58
commit a0d85b1f12
2 changed files with 38 additions and 2 deletions

View File

@ -9,8 +9,8 @@ generator client {
}
datasource db {
provider = "sqlite"
url = "file:./dev.db"
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {

36
prisma/seed.ts Normal file
View File

@ -0,0 +1,36 @@
import { faker } from "@faker-js/faker";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
async function main() {
const users = Array.from({ length: 25 }, () => ({
name: `${faker.person.fullName().split(" ")[1]} House-${crypto
.randomUUID()
.slice(0, 5)}`,
email: faker.internet.email(),
emailVerified: false,
firstPaymentDone: false,
verified: false,
house_name: faker.location.streetAddress(),
id_card: `A${Math.round(Math.random() * 999999)}`,
dob: faker.date.between({
from: "1900-01-01",
to: "2000-01-01",
}),
phoneNumber: String(faker.number.int({ min: 7000000, max: 9999999 })),
phoneNumberVerified: false,
role: "USER",
}));
await prisma.user.createMany({
data: users,
});
}
main()
.then(() => prisma.$disconnect())
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});