2021-05-24 02:29:27 +02:00
|
|
|
const bcrypt = require('bcryptjs');
|
2021-03-20 13:01:10 +01:00
|
|
|
const { PrismaClient } = require('@prisma/client');
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
const SALT_ROUNDS = 10;
|
|
|
|
|
|
|
|
const hashPassword = password => {
|
2021-05-24 02:29:27 +02:00
|
|
|
return bcrypt.hashSync(password, SALT_ROUNDS);
|
2021-03-20 13:01:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
await prisma.account.upsert({
|
|
|
|
where: { username: 'admin' },
|
|
|
|
update: {},
|
|
|
|
create: {
|
|
|
|
username: 'admin',
|
2022-04-01 04:25:04 +02:00
|
|
|
password: hashPassword(process.env.ADMIN_PASSWORD || 'umami'),
|
2021-03-20 13:01:10 +01:00
|
|
|
is_admin: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
.catch(e => {
|
|
|
|
console.error(e);
|
|
|
|
process.exit(1);
|
|
|
|
})
|
|
|
|
.finally(async () => {
|
|
|
|
await prisma.$disconnect();
|
|
|
|
});
|