@@ -836,8 +836,8 @@ function getTableStatus(model, cb) {
836
836
cb ( err , data ) ;
837
837
}
838
838
839
- this . query ( 'SELECT column_name AS "column", data_type AS "type", nullable AS "nullable"' // , data_default AS "Default"'
840
- + ' FROM "information_schema"."tables " WHERE table_name=\'' + this . table ( model ) + '\'' , decoratedCallback ) ;
839
+ this . query ( 'SELECT column_name AS "column", data_type AS "type", is_nullable AS "nullable"' // , data_default AS "Default"'
840
+ + ' FROM "information_schema"."columns " WHERE table_name=\'' + this . table ( model ) + '\'' , decoratedCallback ) ;
841
841
842
842
}
843
843
@@ -956,7 +956,11 @@ function getAddModifyColumns(model, actualFields) {
956
956
var sql = [ ] ;
957
957
var self = this ;
958
958
sql = sql . concat ( getColumnsToAdd . call ( self , model , actualFields ) ) ;
959
- sql = sql . concat ( getPropertiesToModify . call ( self , model , actualFields ) ) ;
959
+ var drops = getPropertiesToModify . call ( self , model , actualFields ) ;
960
+ if ( drops . length > 0 ) {
961
+ sql = sql . concat ( ', ' ) ;
962
+ sql = sql . concat ( drops ) ;
963
+ }
960
964
// sql = sql.concat(getColumnsToDrop.call(self, model, actualFields));
961
965
return sql ;
962
966
}
@@ -977,11 +981,11 @@ function getColumnsToAdd(model, actualFields) {
977
981
if ( self . id ( model , propName ) ) return ;
978
982
var found = searchForPropertyInActual . call ( self , model , self . column ( model , propName ) , actualFields ) ;
979
983
if ( ! found && propertyHasNotBeenDeleted . call ( self , model , propName ) ) {
980
- sql . push ( addPropertyToActual . call ( self , model , propName ) ) ;
984
+ sql . push ( 'ADD COLUMN ' + addPropertyToActual . call ( self , model , propName ) ) ;
981
985
}
982
986
} ) ;
983
987
if ( sql . length > 0 ) {
984
- sql = [ 'ADD' , '(' + sql . join ( ',' ) + ')' ] ;
988
+ sql = [ sql . join ( ', ' ) ] ;
985
989
}
986
990
return sql ;
987
991
}
@@ -1018,17 +1022,18 @@ function getPropertiesToModify(model, actualFields) {
1018
1022
found = searchForPropertyInActual . call ( self , model , propName , actualFields ) ;
1019
1023
if ( found && propertyHasNotBeenDeleted . call ( self , model , propName ) ) {
1020
1024
if ( datatypeChanged ( propName , found ) ) {
1021
- sql . push ( modifyDatatypeInActual . call ( self , model , propName ) ) ;
1025
+ sql . push ( 'ALTER COLUMN ' + modifyDatatypeInActual . call ( self , model , propName ) ) ;
1022
1026
}
1023
1027
if ( nullabilityChanged ( propName , found ) ) {
1024
- sql . push ( modifyNullabilityInActual . call ( self , model , propName ) ) ;
1028
+ sql . push ( 'ALTER COLUMN' + modifyNullabilityInActual . call ( self , model , propName ) ) ;
1025
1029
}
1026
1030
}
1027
1031
} ) ;
1028
1032
1029
- if ( sql . length > 0 ) {
1030
- sql = [ 'MODIFY' , '(' + sql . join ( ',' ) + ')' ] ;
1033
+ if ( sql . length > 0 ) {
1034
+ sql = [ sql . join ( ', ' ) ] ;
1031
1035
}
1036
+
1032
1037
return sql ;
1033
1038
1034
1039
function datatypeChanged ( propName , oldSettings ) {
@@ -1053,7 +1058,7 @@ function getPropertiesToModify(model, actualFields) {
1053
1058
1054
1059
function modifyDatatypeInActual ( model , propName ) {
1055
1060
var self = this ;
1056
- var sqlCommand = self . columnEscaped ( model , propName ) + ' ' + self . columnDataType ( model , propName ) ;
1061
+ var sqlCommand = self . columnEscaped ( model , propName ) + ' TYPE ' + self . columnDataType ( model , propName ) ;
1057
1062
return sqlCommand ;
1058
1063
}
1059
1064
@@ -1077,11 +1082,11 @@ function getColumnsToDrop(model, actualFields) {
1077
1082
return ;
1078
1083
}
1079
1084
if ( actualFieldNotPresentInModel ( actualField , model ) ) {
1080
- sql . push ( self . escapeName ( actualField . column ) ) ;
1085
+ sql . push ( 'DROP COLUMN ' + self . escapeName ( actualField . column ) ) ;
1081
1086
}
1082
1087
} ) ;
1083
- if ( sql . length > 0 ) {
1084
- sql = [ 'DROP' , '(' + sql . join ( ',' ) + ')' ] ;
1088
+ if ( sql . length > 0 ) {
1089
+ sql = [ sql . join ( ', ' ) ] ;
1085
1090
}
1086
1091
return sql ;
1087
1092
@@ -1203,7 +1208,7 @@ PostgreSQL.prototype.disconnect = function disconnect(cb) {
1203
1208
}
1204
1209
var conn = this . connection ;
1205
1210
this . connection = null ;
1206
- conn . close ( ) ; // This is sync
1211
+ conn . end ( ) ; // This is sync
1207
1212
}
1208
1213
1209
1214
if ( cb ) {
0 commit comments