DiscordTickets/scripts/postinstall.js

37 lines
1006 B
JavaScript
Raw Normal View History

require('dotenv').config();
const fs = require('fs-extra');
2022-10-05 19:09:08 +03:00
const util = require('util');
const exec = util.promisify(require('child_process').exec);
async function npx(cmd) {
console.log(`[postinstall] > ${cmd}`);
const {
stderr,
stdout,
} = await exec('npx ' + cmd);
if (stdout) console.log(stdout.toString());
if (stderr) console.log(stderr.toString());
}
const providers = ['mysql', 'postgresql', 'sqlite'];
const provider = process.env.DB_PROVIDER;
2022-07-23 15:27:32 +03:00
if (!provider) {
console.log('[postinstall] environment not set, exiting.');
process.exit(0);
}
if (!providers.includes(provider)) throw new Error(`DB_PROVIDER must be one of: ${providers}`);
2022-10-05 19:09:08 +03:00
console.log(`[postinstall] provider=${provider}`);
console.log(`[postinstall] copying ${provider} schema & migrations`);
if (!fs.existsSync('./prisma')) fs.mkdirSync('./prisma');
fs.copySync(`./db/${provider}`, './prisma'); // copy schema & migrations
2022-10-05 19:09:08 +03:00
(async () => {
await npx('prisma generate');
2023-01-30 23:21:48 +02:00
await npx('prisma migrate deploy');
2022-10-05 19:09:08 +03:00
})();