baru ni e
This commit is contained in:
48
prisma/schema.prisma
Normal file
48
prisma/schema.prisma
Normal file
@@ -0,0 +1,48 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
output = "../generated/prisma"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
name String?
|
||||
email String? @unique
|
||||
password String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
ApiKey ApiKey[]
|
||||
configs Configs? @relation(fields: [configsId], references: [id])
|
||||
configsId String?
|
||||
role USER_ROLE @default(USER)
|
||||
active Boolean @default(true)
|
||||
}
|
||||
|
||||
model ApiKey {
|
||||
id String @id @default(cuid())
|
||||
User User? @relation(fields: [userId], references: [id])
|
||||
userId String
|
||||
name String
|
||||
key String @unique @db.Text
|
||||
description String?
|
||||
expiredAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model Configs {
|
||||
id String @id @default("1")
|
||||
allowRegister Boolean @default(false)
|
||||
imamKey String @default("imam_key")
|
||||
ikomahKey String @default("ikomah_key")
|
||||
selectedUser User[]
|
||||
}
|
||||
|
||||
enum USER_ROLE {
|
||||
ADMIN
|
||||
USER
|
||||
}
|
||||
74
prisma/seed.ts
Normal file
74
prisma/seed.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { prisma } from "@/server/lib/prisma";
|
||||
import { USER_ROLE } from "generated/prisma";
|
||||
|
||||
const user = [
|
||||
{
|
||||
name: "Bip",
|
||||
email: "wibu@bip.com",
|
||||
password: "Production_123",
|
||||
role: USER_ROLE.ADMIN
|
||||
},
|
||||
{
|
||||
name: "Jun",
|
||||
email: "jun@bip.com",
|
||||
password: "Production_123",
|
||||
role: USER_ROLE.USER
|
||||
},
|
||||
{
|
||||
name: "Malik",
|
||||
email: "malik@bip.com",
|
||||
password: "Production_123",
|
||||
role: USER_ROLE.USER
|
||||
},
|
||||
{
|
||||
name: "Bagas",
|
||||
email: "bagas@bip.com",
|
||||
password: "Production_123",
|
||||
role: USER_ROLE.USER
|
||||
},
|
||||
{
|
||||
name: "Nico",
|
||||
email: "nico@bip.com",
|
||||
password: "Production_123",
|
||||
role: USER_ROLE.USER
|
||||
},
|
||||
{
|
||||
name: "Keano",
|
||||
email: "keano@bip.com",
|
||||
password: "Production_123",
|
||||
role: USER_ROLE.USER
|
||||
}
|
||||
];
|
||||
|
||||
const configs = {
|
||||
allowRegister: false,
|
||||
imamKey: "imam",
|
||||
ikomahKey: "ikomah"
|
||||
}
|
||||
|
||||
; (async () => {
|
||||
for (const u of user) {
|
||||
await prisma.user.upsert({
|
||||
where: { email: u.email },
|
||||
create: { ...u },
|
||||
update: { ...u },
|
||||
})
|
||||
|
||||
console.log(`✅ User ${u.email} seeded successfully`)
|
||||
}
|
||||
|
||||
await prisma.configs.upsert({
|
||||
where: { id: "1" },
|
||||
create: configs,
|
||||
update: configs,
|
||||
})
|
||||
|
||||
console.log(`✅ Configs seeded successfully`)
|
||||
})().catch((e) => {
|
||||
console.error(e)
|
||||
process.exit(1)
|
||||
}).finally(() => {
|
||||
console.log("✅ Seeding completed successfully ")
|
||||
process.exit(0)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user