Skip to content

Commit 62afdf1

Browse files
committed
Added options input to methods in migration missing options input
1 parent 91f8b82 commit 62afdf1

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

lib/migration.js

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ function mixinMigration(PostgreSQL) {
1717
return !!(fields && indexes);
1818
};
1919

20-
PostgreSQL.prototype.showFields = function(model, cb) {
20+
PostgreSQL.prototype.showFields = function(model, options, cb) {
21+
22+
if ((!cb) && typeof options === 'function') {
23+
cb = options;
24+
options = {};
25+
}
26+
options = options || {};
27+
2128
const sql = 'SELECT column_name AS "column", data_type AS "type", ' +
2229
'datetime_precision AS time_precision, ' +
2330
'is_nullable AS "nullable", character_maximum_length as "length"' // , data_default AS "Default"'
2431
+ ' FROM "information_schema"."columns" WHERE table_name=\'' +
2532
this.table(model) + '\' and table_schema=\'' +
2633
this.schema(model) + '\'';
27-
this.execute(sql, function(err, fields) {
34+
this.execute(sql, options, function(err, fields) {
2835
if (err) {
2936
return cb(err);
3037
} else {
@@ -36,7 +43,14 @@ function mixinMigration(PostgreSQL) {
3643
});
3744
};
3845

39-
PostgreSQL.prototype.showIndexes = function(model, cb) {
46+
PostgreSQL.prototype.showIndexes = function(model, options, cb) {
47+
48+
if ((!cb) && typeof options === 'function') {
49+
cb = options;
50+
options = {};
51+
}
52+
options = options || {};
53+
4054
const sql = 'SELECT t.relname AS "table", i.relname AS "name", ' +
4155
'am.amname AS "type", ix.indisprimary AS "primary", ' +
4256
'ix.indisunique AS "unique", ' +
@@ -56,7 +70,7 @@ function mixinMigration(PostgreSQL) {
5670
this.table(model) + '\'' +
5771
' and (ns.oid = t.relnamespace and ns.nspname=\'' +
5872
this.schema(model) + '\')';
59-
this.execute(sql, function(err, indexes) {
73+
this.execute(sql, options, function(err, indexes) {
6074
if (err) {
6175
return cb(err);
6276
} else {
@@ -70,9 +84,17 @@ function mixinMigration(PostgreSQL) {
7084
* @param {String} model The model name
7185
* @param {Object[]} actualFields Actual columns in the table
7286
* @param {Object[]} actualIndexes Actual indexes in the table
87+
* @param {Object} options Options object
7388
* @param {Function} [cb] The callback function
7489
*/
75-
PostgreSQL.prototype.alterTable = function(model, actualFields, actualIndexes, cb) {
90+
PostgreSQL.prototype.alterTable = function (model, actualFields, actualIndexes, options, cb) {
91+
92+
if ((!cb) && typeof options === 'function') {
93+
cb = options;
94+
options = {};
95+
}
96+
options = options || {};
97+
7698
const self = this;
7799
const m = this._models[model];
78100
const propNames = Object.keys(m.properties).filter(function(name) {
@@ -329,11 +351,18 @@ function mixinMigration(PostgreSQL) {
329351
* @param {String} model The model name
330352
* @param {Function} [cb] The callback function
331353
*/
332-
PostgreSQL.prototype.createTable = function(model, cb) {
354+
PostgreSQL.prototype.createTable = function(model, options, cb) {
333355
const self = this;
334356
const name = self.tableEscaped(model);
335357
const modelDef = this.getModelDefinition(model);
336358

359+
if ((!cb) && typeof options === 'function') {
360+
cb = options;
361+
options = {};
362+
}
363+
options = options || {};
364+
365+
337366
// collects all extensions needed to be created
338367
let createExtensions;
339368
Object.keys(this.getModelDefinition(model).properties).forEach(function(propName) {
@@ -356,17 +385,19 @@ function mixinMigration(PostgreSQL) {
356385
createExtensions +
357386
'CREATE SCHEMA ' +
358387
self.escapeName(self.schema(model)),
388+
options,
359389
function(err) {
360390
if (err && err.code !== '42P06') {
361391
return cb && cb(err);
362392
}
363393
self.execute('CREATE TABLE ' + name + ' (\n ' +
364394
self.propertiesSQL(model) + '\n)',
395+
options,
365396
function(err, info) {
366397
if (err) {
367398
return cb(err, info);
368399
}
369-
self.addIndexes(model, undefined, function(err) {
400+
self.addIndexes(model, undefined, options, function(err) {
370401
if (err) {
371402
return cb(err);
372403
}

0 commit comments

Comments
 (0)