Skip to content

Commit 7d68060

Browse files
committed
migrate exit if connectionString is not set in production
1 parent 47d849b commit 7d68060

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

scripts/migrate.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ const DBURLLOCAL = require("../configs/config").DBURLLOCAL;
55
const connectionString =
66
process.env.NODE_ENV === "production" ? process.env.DBURL : DBURLLOCAL; //require("../config/config").DBURL; //'postgresql://dbuser:[email protected]:3211/mydb'
77

8-
console.log(connectionString);
8+
if (!connectionString) {
9+
console.warn(
10+
"connectionString is not defined\nPlease define connectionString in Environment variables \nAborting migration"
11+
);
12+
process.exit(1);
13+
}
14+
15+
// console.log(connectionString);
916

1017
const client = new Client({
1118
connectionString: connectionString,
@@ -20,16 +27,16 @@ async function migrate() {
2027

2128
let script = fs.readFileSync(__dirname + "/db-migrate.sql").toString();
2229

23-
console.log(script);
30+
// console.log(script);
2431

2532
let query = {
2633
text: script,
2734
values: [],
2835
};
2936

3037
let res = await client.query(query);
31-
console.log(res.command);
32-
console.log(res.rowCount);
38+
// console.log(res.command);
39+
// console.log(res.rowCount);
3340
await client.end();
3441
console.log("disconnected from database");
3542
console.log("migration ran successfully");

0 commit comments

Comments
 (0)