32 lines
831 B
TypeScript
Executable File
32 lines
831 B
TypeScript
Executable File
import dotenv from "dotenv";
|
|
import path from "path";
|
|
dotenv.config({ path: path.resolve(__dirname, ".env") });
|
|
|
|
import { PrismaClient } from "../generated/prisma";
|
|
import { PrismaPg } from "@prisma/adapter-pg";
|
|
import bcrypt from "bcrypt";
|
|
|
|
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
|
|
const prisma = new PrismaClient({ adapter } as any);
|
|
|
|
async function main() {
|
|
const hashedPassword = await bcrypt.hash("123456", 10);
|
|
|
|
await prisma.user.upsert({
|
|
where: { username: "admin" },
|
|
update: {},
|
|
create: { username: "admin", password: hashedPassword },
|
|
});
|
|
|
|
console.log("Seed complete: admin user created (username: admin, password: 123456)");
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|