diff --git a/ExpressAPI/package.json b/ExpressAPI/package.json index 292da7eb195f91e79ef0209529445484a5319e41..926177cabccb959fb639003e34934e139ef6cbbf 100644 --- a/ExpressAPI/package.json +++ b/ExpressAPI/package.json @@ -11,6 +11,9 @@ "start:dev" : "npx nodemon src/app.ts", "start:prod": "NODE_ENV=production npx node --max-http-header-size=1048576 dist/app.js" }, + "prisma" : { + "seed": "ts-node prisma/seed.ts" + }, "dependencies" : { "@prisma/client" : "^4.16.2", "axios" : "^1.4.0", diff --git a/ExpressAPI/prisma/seed.ts b/ExpressAPI/prisma/seed.ts new file mode 100644 index 0000000000000000000000000000000000000000..603712461e4588d80a27b4b282f32922ae0e230b --- /dev/null +++ b/ExpressAPI/prisma/seed.ts @@ -0,0 +1,33 @@ +require('dotenv').config(); // ATTENTION : This line MUST be the first of this file +require('../src/shared/helpers/TypeScriptExtensions'); // ATTENTION : This line MUST be the second of this file + +import Config from '../src/config/Config'; +import logger from '../src/shared/logging/WinstonLogger'; +import * as bcrypt from 'bcryptjs'; +import db from '../src/helpers/DatabaseHelper'; + + +async function main() { + await db.user.upsert({ + where : { gitlabId: 142 }, + update: {}, + create: { + id : 1, + firstname: 'Michaƫl', + lastname : 'Minelli', + mail : 'michael@minelli.me', + password : bcrypt.hashSync('123456', Config.userPasswordSaltRounds), + gitlabId : 142, + role : 'colsci', + deleted : false + } + }); +} + +main().then(async () => { + await db.$disconnect(); +}).catch(async (e) => { + logger.error(e); + await db.$disconnect(); + process.exit(1); +}); \ No newline at end of file