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