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() {
|
2021-05-24 02:29:27 +02:00
|
|
|
const password = hashPassword(process.env.ADMIN_PASSWORD || 'umami');
|
2021-03-20 13:01:10 +01:00
|
|
|
await prisma.account.upsert({
|
|
|
|
where: { username: 'admin' },
|
|
|
|
update: {},
|
|
|
|
create: {
|
|
|
|
username: 'admin',
|
|
|
|
password: password,
|
|
|
|
is_admin: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
.catch(e => {
|
|
|
|
console.error(e);
|
|
|
|
process.exit(1);
|
|
|
|
})
|
|
|
|
.finally(async () => {
|
|
|
|
await prisma.$disconnect();
|
|
|
|
});
|