Some changes on prisma

This commit is contained in:
2026-01-11 12:05:24 +01:00
parent 9fc94f342b
commit 554272d83f
4 changed files with 116 additions and 80 deletions

View File

@ -13,6 +13,8 @@ datasource db {
provider = "postgresql"
}
/** Artworks **/
model Artwork {
id String @id @default(cuid())
createdAt DateTime @default(now())
@ -231,6 +233,7 @@ model FileVariant {
@@unique([artworkId, type])
}
/** Commissions **/
model Commission {
id String @id @default(cuid())
createdAt DateTime @default(now())
@ -411,6 +414,39 @@ model TermsOfService {
version Int @default(autoincrement())
}
/** Voting **/
model Animal {
id String @id @default(cuid())
name String
slug String @unique
description String?
imageUrl String?
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
votes Vote[]
}
model Vote {
id String @id @default(cuid())
animalId String
voterId String? // Twitch user ID (nullable for anon)
source VoteSource
createdAt DateTime @default(now())
animal Animal @relation(fields: [animalId], references: [id])
@@index([animalId])
}
enum VoteSource {
TWITCH_CHAT
CHANNEL_POINTS
ADMIN
}
/** User management **/
model User {
id String @id
name String

View File

@ -1,77 +1,77 @@
import { PrismaClient } from "@/generated/prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";
import { hashPassword } from "better-auth/crypto";
// import { PrismaClient } from "@/generated/prisma/client";
// import { PrismaPg } from "@prisma/adapter-pg";
// import { hashPassword } from "better-auth/crypto";
const connectionString = `${process.env.DATABASE_URL}`
// const connectionString = `${process.env.DATABASE_URL}`
const adapter = new PrismaPg({ connectionString })
const prisma = new PrismaClient({ adapter })
// const adapter = new PrismaPg({ connectionString })
// const prisma = new PrismaClient({ adapter })
function uid() {
return crypto.randomUUID();
}
// function uid() {
// return crypto.randomUUID();
// }
async function main() {
const email = "admin@gaertan.art";
const name = "Admin";
const password = "037Ikk7qmCamW5iYBimcwiPXNELzktIRG9ndiIkA3u";
// async function main() {
// const email = "admin@gaertan.art";
// const name = "Admin";
// const password = "037Ikk7qmCamW5iYBimcwiPXNELzktIRG9ndiIkA3u";
const passwordHash = await hashPassword(password);
// const passwordHash = await hashPassword(password);
// 1) Ensure user exists (your User.id has no default, so we must set it)
const user = await prisma.user.upsert({
where: { email },
update: {
name,
// optional: mark verified for initial admin
emailVerified: true,
},
create: {
id: uid(),
email,
name,
emailVerified: true,
},
});
// // 1) Ensure user exists (your User.id has no default, so we must set it)
// const user = await prisma.user.upsert({
// where: { email },
// update: {
// name,
// // optional: mark verified for initial admin
// emailVerified: true,
// },
// create: {
// id: uid(),
// email,
// name,
// emailVerified: true,
// },
// });
// 2) Ensure credential account exists for this user
// Better Auth expects providerId="credential" and accountId=userId for credential accounts. :contentReference[oaicite:2]{index=2}
const existingCredential = await prisma.account.findFirst({
where: {
userId: user.id,
providerId: "credential",
accountId: user.id,
},
});
// // 2) Ensure credential account exists for this user
// // Better Auth expects providerId="credential" and accountId=userId for credential accounts. :contentReference[oaicite:2]{index=2}
// const existingCredential = await prisma.account.findFirst({
// where: {
// userId: user.id,
// providerId: "credential",
// accountId: user.id,
// },
// });
if (!existingCredential) {
await prisma.account.create({
data: {
id: uid(),
userId: user.id,
providerId: "credential",
accountId: user.id,
password: passwordHash,
},
});
} else {
// If it exists, keep it consistent (optionally reset password on seed)
await prisma.account.update({
where: { id: existingCredential.id },
data: { password: passwordHash },
});
}
// if (!existingCredential) {
// await prisma.account.create({
// data: {
// id: uid(),
// userId: user.id,
// providerId: "credential",
// accountId: user.id,
// password: passwordHash,
// },
// });
// } else {
// // If it exists, keep it consistent (optionally reset password on seed)
// await prisma.account.update({
// where: { id: existingCredential.id },
// data: { password: passwordHash },
// });
// }
console.log("Seeded/updated admin user:");
console.log(" email:", email);
console.log(" password:", password);
}
// console.log("Seeded/updated admin user:");
// console.log(" email:", email);
// console.log(" password:", password);
// }
main()
.catch((err) => {
console.error("Seed failed:", err);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
// main()
// .catch((err) => {
// console.error("Seed failed:", err);
// process.exit(1);
// })
// .finally(async () => {
// await prisma.$disconnect();
// });