mirror of
https://github.com/mjrode/WhatToWatch.git
synced 2026-05-07 21:19:08 -05:00
Refactor all db logic, no longer force syncing
This commit is contained in:
@@ -88,12 +88,11 @@ const init = () =>
|
||||
const truncate = model =>
|
||||
models[model]
|
||||
.destroy({
|
||||
where: {},
|
||||
force: true,
|
||||
paranoid: false,
|
||||
truncate: {cascade: true},
|
||||
})
|
||||
.catch(() => {
|
||||
.catch(e => {
|
||||
console.log('Error truncating', model);
|
||||
console.log(e);
|
||||
process.exit(EXIT_CODE);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/* eslint-disable no-console */
|
||||
const {exec} = require('child_process');
|
||||
const configs = require('../config/config');
|
||||
|
||||
const mode = (
|
||||
process.argv.find(arg => /production$|development$/.test(arg)) ||
|
||||
'development'
|
||||
).replace(/[^\w]/g, '');
|
||||
|
||||
const {username, database, host} = configs[mode];
|
||||
|
||||
if (!username || !database || !host) {
|
||||
console.error('Please ensure all required parameters are supplied:');
|
||||
console.error('username:', username);
|
||||
console.error('database:', database);
|
||||
console.error('host:', host);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(username, database, host);
|
||||
|
||||
exec(
|
||||
`createdb -U ${username} -h ${host} ${database}`,
|
||||
(err, stdout, stderr) => {
|
||||
if (err) {
|
||||
console.error('Error creating DB.');
|
||||
console.error(err || stderr);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('Created DB.');
|
||||
exec(
|
||||
`./node_modules/.bin/sequelize db:migrate --env ${mode}`,
|
||||
(err2, stdout2) => {
|
||||
if (err2) {
|
||||
console.error('Error running migrations.');
|
||||
console.error(err2);
|
||||
console.error('Dropping DB');
|
||||
exec(
|
||||
`dropdb -U ${username} -h ${host} ${database}`,
|
||||
(err3, stdout3, stderr3) => {
|
||||
if (err2) {
|
||||
console.error('Error dropping DB');
|
||||
console.error(err3 || stderr3);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.info('Dropped DB.');
|
||||
process.exit(0);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
console.log(stdout2);
|
||||
console.log('Migrations complete.');
|
||||
console.log('Process finished. Exiting.');
|
||||
process.exit(0);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user