update
This commit is contained in:
60
server/scripts/start-with-migrate.js
Normal file
60
server/scripts/start-with-migrate.js
Normal file
@@ -0,0 +1,60 @@
|
||||
const { spawn, spawnSync } = require('child_process');
|
||||
|
||||
function normalizeWrappedEnv(name) {
|
||||
const value = process.env[name];
|
||||
if (!value || value.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
const first = value[0];
|
||||
const last = value[value.length - 1];
|
||||
if ((first === '"' && last === '"') || (first === "'" && last === "'")) {
|
||||
process.env[name] = value.slice(1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
function run(command, args, options = {}) {
|
||||
const result = spawnSync(command, args, {
|
||||
stdio: 'inherit',
|
||||
env: process.env,
|
||||
...options,
|
||||
});
|
||||
|
||||
if (result.error) {
|
||||
throw result.error;
|
||||
}
|
||||
|
||||
if (typeof result.status === 'number' && result.status !== 0) {
|
||||
process.exit(result.status);
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
if (!process.env.DATABASE_URL) {
|
||||
process.env.DATABASE_URL = 'file:./dev.db';
|
||||
}
|
||||
|
||||
normalizeWrappedEnv('DATABASE_URL');
|
||||
run(process.platform === 'win32' ? 'npx.cmd' : 'npx', ['prisma', 'migrate', 'deploy']);
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const child = spawn(args[0], args.slice(1), {
|
||||
stdio: 'inherit',
|
||||
env: process.env,
|
||||
});
|
||||
|
||||
child.on('exit', (code, signal) => {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
return;
|
||||
}
|
||||
|
||||
process.exit(code ?? 0);
|
||||
});
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user