115 lines
3.0 KiB
TypeScript
115 lines
3.0 KiB
TypeScript
import "dotenv/config";
|
|
import bcrypt from "bcryptjs";
|
|
import { PrismaPg } from "@prisma/adapter-pg";
|
|
import { PrismaClient } from "@prisma/client";
|
|
import { Pool } from "pg";
|
|
|
|
const connectionString = process.env.DATABASE_URL;
|
|
if (!connectionString) {
|
|
throw new Error("DATABASE_URL must be set for seeding");
|
|
}
|
|
|
|
const pool = new Pool({ connectionString });
|
|
const adapter = new PrismaPg(pool);
|
|
const prisma = new PrismaClient({ adapter });
|
|
|
|
async function main() {
|
|
const email = "demo@local.dev";
|
|
const password = "demo1234";
|
|
const hash = await bcrypt.hash(password, 12);
|
|
|
|
const user = await prisma.user.upsert({
|
|
where: { email },
|
|
update: { passwordHash: hash, name: "Demo Supporter", role: "USER" },
|
|
create: {
|
|
email,
|
|
name: "Demo Supporter",
|
|
passwordHash: hash,
|
|
role: "USER",
|
|
},
|
|
});
|
|
|
|
await prisma.wallet.upsert({
|
|
where: { userId: user.id },
|
|
update: {},
|
|
create: { userId: user.id, balanceCredits: 0 },
|
|
});
|
|
|
|
const adminEmail = "drjones@admin.local";
|
|
const adminPassword = "czapiewski";
|
|
const adminHash = await bcrypt.hash(adminPassword, 12);
|
|
const admin = await prisma.user.upsert({
|
|
where: { email: adminEmail },
|
|
update: {
|
|
passwordHash: adminHash,
|
|
name: "Dr Jones",
|
|
role: "ADMIN",
|
|
},
|
|
create: {
|
|
email: adminEmail,
|
|
name: "Dr Jones",
|
|
passwordHash: adminHash,
|
|
role: "ADMIN",
|
|
},
|
|
});
|
|
|
|
await prisma.wallet.upsert({
|
|
where: { userId: admin.id },
|
|
update: { balanceCredits: 2_147_483_647 },
|
|
create: { userId: admin.id, balanceCredits: 2_147_483_647 },
|
|
});
|
|
|
|
await prisma.prizeSku.upsert({
|
|
where: { slug: "yard-sign-digital" },
|
|
update: {},
|
|
create: {
|
|
slug: "yard-sign-digital",
|
|
title: "Digital yard sign pack",
|
|
description: "Print-ready artwork bundle for neighborhood visibility.",
|
|
costCredits: 15,
|
|
stockHint: "Digital download",
|
|
},
|
|
});
|
|
|
|
await prisma.prizeSku.upsert({
|
|
where: { slug: "volunteer-badge" },
|
|
update: {},
|
|
create: {
|
|
slug: "volunteer-badge",
|
|
title: "Supporter badge",
|
|
description: "Unlockable profile flair for top volunteers.",
|
|
costCredits: 8,
|
|
stockHint: "Profile flair",
|
|
},
|
|
});
|
|
|
|
await prisma.raffle.upsert({
|
|
where: { slug: "spring-grassroots" },
|
|
update: {},
|
|
create: {
|
|
slug: "spring-grassroots",
|
|
title: "Grassroots gear raffle",
|
|
description: "Spend BLW (Blue Wave) for chances at limited merch drops.",
|
|
ticketCostCredits: 5,
|
|
endsAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30),
|
|
},
|
|
});
|
|
|
|
// eslint-disable-next-line no-console
|
|
console.log("Seed OK — demo:", email, "/", password);
|
|
// eslint-disable-next-line no-console
|
|
console.log("Seed OK — admin:", adminEmail, "/", adminPassword, "(role ADMIN, max wallet)");
|
|
}
|
|
|
|
main()
|
|
.then(async () => {
|
|
await prisma.$disconnect();
|
|
await pool.end();
|
|
})
|
|
.catch(async (e) => {
|
|
console.error(e);
|
|
await prisma.$disconnect();
|
|
await pool.end();
|
|
process.exit(1);
|
|
});
|