mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Prisma Migrate with database seeding fixes #559
This commit is contained in:
parent
f8ac987bfc
commit
3925258bc7
12 changed files with 340 additions and 68 deletions
30
prisma/seed.js
Normal file
30
prisma/seed.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
const bcrypt = require('bcrypt');
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const prisma = new PrismaClient();
|
||||
const SALT_ROUNDS = 10;
|
||||
|
||||
const hashPassword = password => {
|
||||
return bcrypt.hash(password, SALT_ROUNDS);
|
||||
};
|
||||
|
||||
async function main() {
|
||||
const password = await hashPassword(process.env.ADMIN_PASSWORD || 'umami');
|
||||
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();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue