This commit is contained in:
parent
74399d5ab6
commit
bf0db89286
|
@ -3,23 +3,17 @@ const {spawn} = require('child_process');
|
|||
|
||||
function watchDatabaseChanges() {
|
||||
console.log('Watching for changes in db/routines and db/versions');
|
||||
|
||||
fs.watch('db', {recursive: true}, (eventType, filename) => {
|
||||
if (filename.endsWith('.sql')) {
|
||||
let command;
|
||||
|
||||
if (filename.startsWith('routines')) command = 'push';
|
||||
else if (filename.startsWith('versions')) command = 'run';
|
||||
|
||||
if (command) {
|
||||
const process = spawn('myt', [command]);
|
||||
|
||||
process.stdout.on('data', data => console.log(data.toString()));
|
||||
|
||||
process.stderr.on('data', data => console.error(`stderr: ${data}`));
|
||||
|
||||
process.on('error', error => console.error(`error: ${error.message}`));
|
||||
|
||||
process.on('close', () => console.log('Watching for changes in db/routines and db/versions'));
|
||||
}
|
||||
}
|
||||
|
@ -27,5 +21,4 @@ function watchDatabaseChanges() {
|
|||
}
|
||||
|
||||
if (require.main === module) watchDatabaseChanges();
|
||||
|
||||
module.exports = watchDatabaseChanges;
|
||||
|
|
Loading…
Reference in New Issue