mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-09-11 08:55:32 +03:00
check db exists first before creating in postgres (#5968)
Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
parent
8e8cc4b327
commit
102489447d
13
db.js
13
db.js
@ -785,12 +785,18 @@ module.exports.CreateDB = function (parent, func) {
|
||||
var dbname = (connectinArgs.database != null) ? connectinArgs.database : 'meshcentral';
|
||||
delete connectinArgs.database;
|
||||
obj.databaseType = 6;
|
||||
const pgtools = require('pgtools');
|
||||
pgtools.createdb(connectinArgs, dbname, function (err, res) {
|
||||
const { Pool, Client } = require('pg');
|
||||
connectinArgs.database = dbname;
|
||||
Datastore = new Client(connectinArgs);
|
||||
Datastore.connect();
|
||||
sqlDbQuery('SELECT 1 FROM pg_database WHERE datname = $1', [dbname], function (dberr, dbdocs) { // check database exists first before creating
|
||||
if (dberr == null) { // database exists now check tables exists
|
||||
sqlDbQuery('SELECT doc FROM main WHERE id = $1', ['DatabaseIdentifier'], function (err, docs) {
|
||||
if (err == null) { setupFunctions(func); } else { postgreSqlCreateTables(func); } // If not present, create the tables and indexes
|
||||
});
|
||||
} else { // If not present, create the tables and indexes
|
||||
const pgtools = require('pgtools');
|
||||
pgtools.createdb(connectinArgs, dbname, function (err, res) {
|
||||
if (err == null) {
|
||||
// Create the tables and indexes
|
||||
postgreSqlCreateTables(func);
|
||||
@ -801,6 +807,8 @@ module.exports.CreateDB = function (parent, func) {
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (parent.args.mongodb) {
|
||||
// Use MongoDB
|
||||
obj.databaseType = 3;
|
||||
@ -1260,7 +1268,6 @@ module.exports.CreateDB = function (parent, func) {
|
||||
} else if (obj.databaseType == 6) { // Postgres SQL
|
||||
Datastore.query(query, args, function (error, results) {
|
||||
if (error != null) {
|
||||
console.log(query, args, error);
|
||||
if (func) try { func(error); } catch (ex) { console.log('SQLERR4', ex); }
|
||||
} else {
|
||||
var docs = [];
|
||||
|
Loading…
Reference in New Issue
Block a user