Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Added ability to specify schema for postgres integrations #218
Browse files Browse the repository at this point in the history
  • Loading branch information
pantsel committed Jul 14, 2018
1 parent 8073fca commit 80b11e9
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 82 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ an ephemeral container for the job.
$ docker run -p 1337:1337
-e "DB_ADAPTER={adapter_name}" \
-e "DB_URI={full_connection_string}" \
-e "DB_PG_SCHEMA=my-schema"\ // Optionally define a schema when integrating with prostgres
-e "NODE_ENV=development" \
--name konga \
pantsel/konga node ./bin/konga.js prepare
Expand All @@ -185,6 +186,7 @@ $ docker run -p 1337:1337
-e "DB_USER=your-db-user" \ // Omit if not relevant
-e "DB_PASSWORD=your-db-password" \ // Omit if not relevant
-e "DB_DATABASE=your-db-name" \ // Defaults to 'konga_database'
-e "DB_PG_SCHEMA=my-schema"\ // Optionally define a schema when integrating with prostgres
-e "NODE_ENV=production" \ // or 'development' | defaults to 'development'
--name konga \
pantsel/konga
Expand Down
7 changes: 7 additions & 0 deletions api/models/ApiHealthCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,11 @@ var mongoModel = function() {
return obj;
}

if(sails.config.models.connection == 'postgres' && process.env.DB_PG_SCHEMA) {
defaultModel.meta = {
schemaName: process.env.DB_PG_SCHEMA
}
}


module.exports = sails.config.models.connection == 'mongo' ? mongoModel() : defaultModel
7 changes: 7 additions & 0 deletions api/models/EmailTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,11 @@ var mongoModel = function () {
return obj;
}

if(sails.config.models.connection == 'postgres' && process.env.DB_PG_SCHEMA) {
defaultModel.meta = {
schemaName: process.env.DB_PG_SCHEMA
}
}


module.exports = sails.config.models.connection == 'mongo' ? mongoModel() : defaultModel
7 changes: 7 additions & 0 deletions api/models/KongNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,11 @@ var mongoModel = function () {
return obj;
}

if(sails.config.models.connection == 'postgres' && process.env.DB_PG_SCHEMA) {
defaultModel.meta = {
schemaName: process.env.DB_PG_SCHEMA
}
}


module.exports = sails.config.models.connection == 'mongo' ? mongoModel() : defaultModel
7 changes: 7 additions & 0 deletions api/models/KongServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ var defaultModel = _.merge(_.cloneDeep(require('../base/Model')), {

var mongoModel = _.omit(_.cloneDeep(defaultModel),["autoPK","attributes.id"]);

if(sails.config.models.connection == 'postgres' && process.env.DB_PG_SCHEMA) {
defaultModel.meta = {
schemaName: process.env.DB_PG_SCHEMA
}
}


module.exports = sails.config.models.connection == 'mongo' ? mongoModel : defaultModel
7 changes: 7 additions & 0 deletions api/models/NetdataConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ var mongoModel = function () {
return obj;
}

if(sails.config.models.connection == 'postgres' && process.env.DB_PG_SCHEMA) {
defaultModel.meta = {
schemaName: process.env.DB_PG_SCHEMA
}
}


module.exports = sails.config.models.connection == 'mongo' ? mongoModel() : defaultModel;
7 changes: 7 additions & 0 deletions api/models/Passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,11 @@ var mongoModel = function() {
return obj;
}

if(sails.config.models.connection == 'postgres' && process.env.DB_PG_SCHEMA) {
defaultModel.meta = {
schemaName: process.env.DB_PG_SCHEMA
}
}


module.exports = sails.config.models.connection == 'mongo' ? mongoModel() : defaultModel
7 changes: 7 additions & 0 deletions api/models/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,11 @@ var mongoModel = function () {
return obj;
}

if(sails.config.models.connection == 'postgres' && process.env.DB_PG_SCHEMA) {
defaultModel.meta = {
schemaName: process.env.DB_PG_SCHEMA
}
}


module.exports = sails.config.models.connection == 'mongo' ? mongoModel() : defaultModel
7 changes: 7 additions & 0 deletions api/models/Snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ var mongoModel = function () {
return obj;
}

if(sails.config.models.connection == 'postgres' && process.env.DB_PG_SCHEMA) {
defaultModel.meta = {
schemaName: process.env.DB_PG_SCHEMA
}
}


module.exports = sails.config.models.connection == 'mongo' ? mongoModel() : defaultModel
8 changes: 8 additions & 0 deletions api/models/SnapshotSchedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,12 @@ var mongoModel = function () {
return obj;
}


if(sails.config.models.connection == 'postgres' && process.env.DB_PG_SCHEMA) {
defaultModel.meta = {
schemaName: process.env.DB_PG_SCHEMA
}
}


module.exports = sails.config.models.connection == 'mongo' ? mongoModel() : defaultModel
170 changes: 88 additions & 82 deletions api/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,101 +13,107 @@ var defUserSeedData = require('../../config/default-user-seed-data.js');


var defaultModel = _.merge(_.cloneDeep(require('../base/Model')), {
tableName: "konga_users",
autoPK: false,
attributes: {
id: {
type: 'integer',
primaryKey: true,
unique: true,
autoIncrement: true
},
username: {
type: 'string',
unique: true,
required: true
},
email: {
type: 'email',
unique: true,
required: true
},
firstName: {
type: 'string'
},
lastName: {
type: 'string'
},
admin: {
type: 'boolean',
defaultsTo: false
},

node_id: {
type: 'string',
defaultsTo: ''
},

active: {
type: 'boolean',
defaultsTo: false
},

activationToken : {
type : 'string'
},

node: {
model: 'kongnode'
},

// Passport configurations
passports: {
collection: 'Passport',
via: 'user'
},
tableName: "konga_users",
autoPK: false,
attributes: {
id: {
type: 'integer',
primaryKey: true,
unique: true,
autoIncrement: true
},
username: {
type: 'string',
unique: true,
required: true
},
email: {
type: 'email',
unique: true,
required: true
},
firstName: {
type: 'string'
},
lastName: {
type: 'string'
},
admin: {
type: 'boolean',
defaultsTo: false
},

node_id: {
type: 'string',
defaultsTo: ''
},

active: {
type: 'boolean',
defaultsTo: false
},

afterDestroy: function (values, cb) {
activationToken: {
type: 'string'
},

sails.log("User:afterDestroy:called => ",values);
node: {
model: 'kongnode'
},

// Passport configurations
passports: {
collection: 'Passport',
via: 'user'
},
},

var fns = [];
afterDestroy: function (values, cb) {

values.forEach(function(user){
fns.push(function(callback){
// Delete passports
sails.models.passport.destroy({user : user.id})
.exec(callback)
})
})
sails.log("User:afterDestroy:called => ", values);

async.series(fns,cb);

},
var fns = [];

//seedData object should now come from a file
// the new object has had the password field added
// we need to remove it
seedData: defUserSeedData.seedData.map( function (orig) {
return {
"username": orig.username,
"email": orig.email,
"firstName": orig.firstName,
"lastName": orig.lastName,
"node_id": orig.node_id,
"admin": orig.admin,
"active" : orig.active
}
values.forEach(function (user) {
fns.push(function (callback) {
// Delete passports
sails.models.passport.destroy({user: user.id})
.exec(callback)
})
})

async.series(fns, cb);

},

//seedData object should now come from a file
// the new object has had the password field added
// we need to remove it
seedData: defUserSeedData.seedData.map(function (orig) {
return {
"username": orig.username,
"email": orig.email,
"firstName": orig.firstName,
"lastName": orig.lastName,
"node_id": orig.node_id,
"admin": orig.admin,
"active": orig.active
}
})
});

var mongoModel = function () {
var obj = _.cloneDeep(defaultModel)
delete obj.autoPK
delete obj.attributes.id
return obj;
var obj = _.cloneDeep(defaultModel)
delete obj.autoPK
delete obj.attributes.id
return obj;
}

if(sails.config.models.connection == 'postgres' && process.env.DB_PG_SCHEMA) {
defaultModel.meta = {
schemaName: process.env.DB_PG_SCHEMA
}
}

module.exports = sails.config.models.connection == 'mongo' ? mongoModel() : defaultModel

0 comments on commit 80b11e9

Please sign in to comment.