37 lines
947 B
JavaScript
37 lines
947 B
JavaScript
const bcrypt = require('bcryptjs');
|
|
|
|
async function seedAdmin(prisma) {
|
|
const adminPassword = await bcrypt.hash('homaroma123', 10);
|
|
await prisma.user.upsert({
|
|
where: { username: 'admin' },
|
|
update: { password: adminPassword },
|
|
create: {
|
|
username: 'admin',
|
|
password: adminPassword,
|
|
role: 'ADMIN'
|
|
}
|
|
});
|
|
process.stdout.write('✅ Seeded Admin User (admin / homaroma123).\n');
|
|
}
|
|
|
|
module.exports = seedAdmin;
|
|
|
|
if (require.main === module) {
|
|
const { PrismaClient } = require('@prisma/client');
|
|
const { Pool } = require('pg');
|
|
const { PrismaPg } = require('@prisma/adapter-pg');
|
|
|
|
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
const adapter = new PrismaPg(pool);
|
|
const prisma = new PrismaClient({ adapter });
|
|
|
|
seedAdmin(prisma)
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|
|
}
|