-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.js
More file actions
70 lines (63 loc) · 2.08 KB
/
entrypoint.js
File metadata and controls
70 lines (63 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { execSync } = require('child_process');
const makeClient = require("./client");
const dbname = require('./pg-diff-config.json').development.targetClient.database;
const pg_config_dev = require("./pg-diff-config.json").development.sourceClient;
RunCommands()
.then(() => {
console.log("Process Completed")
}).catch((e) => {
console.log("Error: ", e)
process.exitCode = -1;
process.exit();
})
async function RunCommands() {
const client = await makeClient(pg_config_dev);
const arguments = process.argv.slice(2);
if (arguments.length <= 0) {
console.log("No argument provided!");
process.exit();
}
if(arguments[0] === 'create-migrations') {
console.log(dbname);
await createDatabase(client).then(() => {
console.log("Creating Database");
}).catch((e) => console.log("Error from postgres", e));
try {
await execSync('yarn pg-diff-file -mt development', {stdio: 'inherit'});
}
catch (err) {
console.log("Error in new command", err.message);
await dropDatabase(client);
process.exit();
}
try {
await execSync('yarn pg-diff-file -c development migrations', {stdio: 'inherit'});
}
catch (err) {
console.log("Error in migration create command", err.message);
await dropDatabase(client);
process.exit();
}
dropDatabase(client).then(() => {
console.log("Dropping database")
client.end();
process.exitCode = 0;
process.exit();
});
}
if( arguments[0] === 'run-migrations') {
try {
await execSync('yarn pg-diff-file -mt local', {stdio: 'inherit'});
process.exit();
}
catch (err) {
console.log("Error in new command", err.message);
}
}
}
async function createDatabase(client) {
await client.query(`CREATE DATABASE ${dbname}`);
}
async function dropDatabase(client) {
await client.query(`DROP DATABASE ${dbname}`);
}