first commit
This commit is contained in:
31
prisma/schema.prisma
Normal file
31
prisma/schema.prisma
Normal file
@@ -0,0 +1,31 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
enum Role {
|
||||
SUPERADMIN
|
||||
ADMIN
|
||||
EDITOR
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
email String @unique
|
||||
passwordHash String
|
||||
role Role @default(EDITOR)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model SiteContent {
|
||||
id String @id @default("main")
|
||||
content Json
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
37
prisma/seed.ts
Normal file
37
prisma/seed.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { PrismaClient, Role } from "@prisma/client";
|
||||
import { hashSync } from "bcryptjs";
|
||||
import { defaultSiteContent } from "../src/lib/default-content";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
await prisma.siteContent.upsert({
|
||||
where: { id: "main" },
|
||||
update: { content: defaultSiteContent as unknown as object },
|
||||
create: {
|
||||
id: "main",
|
||||
content: defaultSiteContent as unknown as object
|
||||
}
|
||||
});
|
||||
|
||||
await prisma.user.upsert({
|
||||
where: { email: "superadmin@example.com" },
|
||||
update: {},
|
||||
create: {
|
||||
name: "Super Admin",
|
||||
email: "superadmin@example.com",
|
||||
passwordHash: hashSync("ChangeMe123!", 10),
|
||||
role: Role.SUPERADMIN
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
main()
|
||||
.then(async () => {
|
||||
await prisma.$disconnect();
|
||||
})
|
||||
.catch(async (error) => {
|
||||
console.error(error);
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user