Skip to content

Commit

Permalink
Updated makedb for latest Postgres Node module
Browse files Browse the repository at this point in the history
  • Loading branch information
leobeckp committed Jan 8, 2022
1 parent f219359 commit 158cde3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
19 changes: 9 additions & 10 deletions makedb/dbs/pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'use strict'

var pg = require("../../node_modules/sails-postgresql/node_modules/pg");
const { Client } = require('pg')
var dbConf = require("../../config/connections");
var _ = require("lodash");
var url = require('url');
Expand Down Expand Up @@ -82,14 +82,14 @@ module.exports = {
}

// console.log("Connection Options =>", opts);
const client = new Client(opts);

pg.connect(opts, function (err, client, done) {
client.connect(function (err) {
if (err) {

if(err.code == "3D000")
{
console.log("Database `" + opts.database + "` does not exist. Creating...");
done();
console.log("Database `" + opts.database + "` does not exist. Creating...");
return self.create(opts,next);

}else{
Expand All @@ -112,19 +112,18 @@ module.exports = {
database : "postgres"
});

pg.connect(defaultDbOpts, function (err, client, done) {
const client = new Client(defaultDbOpts);

client.connect(function (err) {
if (err) {
console.log(err);
done();
console.log(err);
return next(err);
}

client.query('CREATE DATABASE ' + opts.database, function (err, res) {
if (err) {
console.log("Failed to create `" + opts.database +"`",err);
done();
console.log("Failed to create `" + opts.database +"`",err);
return next(err);

}

console.log("Database `" + opts.database + "` created! Continue...");
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"passport": "0.3.0",
"passport-ldapauth": "^2.1.4",
"passport-local": "1.0.0",
"pg": "^8.7.1",
"rc": "^1.2.8",
"sails": "~0.12.14",
"sails-disk": "^0.10.10",
Expand Down

0 comments on commit 158cde3

Please sign in to comment.