@@ -25,24 +25,78 @@ function mixinMigration(PostgreSQL) {
25
25
}
26
26
options = options || { } ;
27
27
28
- const sql = 'SELECT column_name AS "column", data_type AS "type", ' +
29
- 'datetime_precision AS time_precision, ' +
30
- 'is_nullable AS "nullable", character_maximum_length as "length"' // , data_default AS "Default"'
31
- + ' FROM "information_schema"."columns" WHERE table_name=\'' +
32
- this . table ( model ) + '\' and table_schema=\'' +
33
- this . schema ( model ) + '\'' ;
34
- this . execute ( sql , [ ] , options , function ( err , fields ) {
28
+
29
+ const sql =
30
+ 'SELECT column_name AS "column", data_type AS "type", ' +
31
+ 'datetime_precision AS time_precision, ' +
32
+ 'is_nullable AS "nullable", character_maximum_length as "length" , numeric_precision, numeric_scale' + // , data_default AS "Default"'
33
+ ' FROM "information_schema"."columns" WHERE table_name=\'' +
34
+ this . table ( model ) +
35
+ "' and table_schema='" +
36
+ this . schema ( model ) +
37
+ "'" ;
38
+
39
+ connector . execute ( sql , [ ] , options , function ( err , fields ) {
35
40
if ( err ) {
36
41
return cb ( err ) ;
37
42
} else {
38
- fields . forEach ( function ( field ) {
39
- field . type = mapPostgreSQLDatatypes ( field . type , field . length , field . time_precision ) ;
43
+ fields . forEach ( function ( field ) {
44
+ const type = field . type . toUpperCase ( ) ;
45
+
46
+ let strPrecision = '' ;
47
+
48
+ if ( field . time_precision < 6 ) {
49
+ // default is 6
50
+ strPrecision = '(' + field . time_precision + ') ' ;
51
+ }
52
+
53
+ switch ( type ) {
54
+ case 'CHARACTER VARYING' :
55
+ case 'VARCHAR' :
56
+ field . type = field . length ? 'VARCHAR(' + field . length + ')' : 'VARCHAR(1024)' ;
57
+ break ;
58
+ case 'NUMERIC' :
59
+ field . type = 'NUMERIC(' + field . numeric_precision + ',' + field . numeric_scale + ')' ;
60
+ break ;
61
+ case 'TIMESTAMP WITHOUT TIME ZONE' :
62
+ field . type = 'TIMESTAMP ' + strPrecision + 'WITHOUT TIME ZONE' ;
63
+ break ;
64
+ case 'TIMESTAMP WITH TIME ZONE' :
65
+ field . type = 'TIMESTAMP ' + strPrecision + 'WITH TIME ZONE' ;
66
+ break ;
67
+ case 'TIME WITHOUT TIME ZONE' :
68
+ field . type = 'TIME ' + strPrecision + 'WITHOUT TIME ZONE' ;
69
+ break ;
70
+ case 'TIME WITH TIME ZONE' :
71
+ field . type = 'TIME ' + strPrecision + 'WITH TIME ZONE' ;
72
+ break ;
73
+ default :
74
+ field . type = field . type ;
75
+ }
40
76
} ) ;
41
77
cb ( err , fields ) ;
42
78
}
43
79
} ) ;
44
80
} ;
45
81
82
+ // const sql = 'SELECT column_name AS "column", data_type AS "type", ' +
83
+ // 'datetime_precision AS time_precision, ' +
84
+ // 'is_nullable AS "nullable", character_maximum_length as "length"' // , data_default AS "Default"'
85
+ // + ' FROM "information_schema"."columns" WHERE table_name=\'' +
86
+ // this.table(model) + '\' and table_schema=\'' +
87
+ // this.schema(model) + '\'';
88
+ // this.execute(sql, [], options, function(err, fields) {
89
+ // if (err) {
90
+ // return cb(err);
91
+ // } else {
92
+ // fields.forEach(function(field) {
93
+ // field.type = mapPostgreSQLDatatypes(field.type, field.length, field.time_precision);
94
+ // });
95
+ // cb(err, fields);
96
+ // }
97
+ // });
98
+ } ;
99
+
46
100
PostgreSQL . prototype . showIndexes = function ( model , options , cb ) {
47
101
48
102
if ( ( ! cb ) && typeof options === 'function' ) {
0 commit comments