@@ -17,14 +17,21 @@ function mixinMigration(PostgreSQL) {
17
17
return ! ! ( fields && indexes ) ;
18
18
} ;
19
19
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
+
21
28
const sql = 'SELECT column_name AS "column", data_type AS "type", ' +
22
29
'datetime_precision AS time_precision, ' +
23
30
'is_nullable AS "nullable", character_maximum_length as "length"' // , data_default AS "Default"'
24
31
+ ' FROM "information_schema"."columns" WHERE table_name=\'' +
25
32
this . table ( model ) + '\' and table_schema=\'' +
26
33
this . schema ( model ) + '\'' ;
27
- this . execute ( sql , function ( err , fields ) {
34
+ this . execute ( sql , options , function ( err , fields ) {
28
35
if ( err ) {
29
36
return cb ( err ) ;
30
37
} else {
@@ -36,7 +43,14 @@ function mixinMigration(PostgreSQL) {
36
43
} ) ;
37
44
} ;
38
45
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
+
40
54
const sql = 'SELECT t.relname AS "table", i.relname AS "name", ' +
41
55
'am.amname AS "type", ix.indisprimary AS "primary", ' +
42
56
'ix.indisunique AS "unique", ' +
@@ -56,7 +70,7 @@ function mixinMigration(PostgreSQL) {
56
70
this . table ( model ) + '\'' +
57
71
' and (ns.oid = t.relnamespace and ns.nspname=\'' +
58
72
this . schema ( model ) + '\')' ;
59
- this . execute ( sql , function ( err , indexes ) {
73
+ this . execute ( sql , options , function ( err , indexes ) {
60
74
if ( err ) {
61
75
return cb ( err ) ;
62
76
} else {
@@ -70,9 +84,17 @@ function mixinMigration(PostgreSQL) {
70
84
* @param {String } model The model name
71
85
* @param {Object[] } actualFields Actual columns in the table
72
86
* @param {Object[] } actualIndexes Actual indexes in the table
87
+ * @param {Object } options Options object
73
88
* @param {Function } [cb] The callback function
74
89
*/
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
+
76
98
const self = this ;
77
99
const m = this . _models [ model ] ;
78
100
const propNames = Object . keys ( m . properties ) . filter ( function ( name ) {
@@ -329,11 +351,18 @@ function mixinMigration(PostgreSQL) {
329
351
* @param {String } model The model name
330
352
* @param {Function } [cb] The callback function
331
353
*/
332
- PostgreSQL . prototype . createTable = function ( model , cb ) {
354
+ PostgreSQL . prototype . createTable = function ( model , options , cb ) {
333
355
const self = this ;
334
356
const name = self . tableEscaped ( model ) ;
335
357
const modelDef = this . getModelDefinition ( model ) ;
336
358
359
+ if ( ( ! cb ) && typeof options === 'function' ) {
360
+ cb = options ;
361
+ options = { } ;
362
+ }
363
+ options = options || { } ;
364
+
365
+
337
366
// collects all extensions needed to be created
338
367
let createExtensions ;
339
368
Object . keys ( this . getModelDefinition ( model ) . properties ) . forEach ( function ( propName ) {
@@ -356,17 +385,19 @@ function mixinMigration(PostgreSQL) {
356
385
createExtensions +
357
386
'CREATE SCHEMA ' +
358
387
self . escapeName ( self . schema ( model ) ) ,
388
+ options ,
359
389
function ( err ) {
360
390
if ( err && err . code !== '42P06' ) {
361
391
return cb && cb ( err ) ;
362
392
}
363
393
self . execute ( 'CREATE TABLE ' + name + ' (\n ' +
364
394
self . propertiesSQL ( model ) + '\n)' ,
395
+ options ,
365
396
function ( err , info ) {
366
397
if ( err ) {
367
398
return cb ( err , info ) ;
368
399
}
369
- self . addIndexes ( model , undefined , function ( err ) {
400
+ self . addIndexes ( model , undefined , options , function ( err ) {
370
401
if ( err ) {
371
402
return cb ( err ) ;
372
403
}
0 commit comments