Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Getting basic PG migration working

  • Loading branch information...
commit 3ad78af9127f9fb4315461c488c35e71e90e665c 1 parent 4a04391
@alsonkemp alsonkemp authored
Showing with 18 additions and 8 deletions.
  1. +18 −8 lib/driver/pg.js
View
26 lib/driver/pg.js
@@ -14,6 +14,13 @@ var PgDriver = Base.extend({
createColumnDef: function(name, spec, options) {
return [name, spec.autoIncrement ? '' : this.mapDataType(spec.type), this.createColumnConstraint(spec, options)].join(' ');
},
+ mapDataType: function(str) {
+ switch(str) {
+ case type.DATE_TIME:
+ return 'TIMESTAMP';
+ }
+ return this._super(str);
+ },
createColumnConstraint: function(spec, options) {
var constraint = [];
@@ -57,15 +64,18 @@ var PgDriver = Base.extend({
runSql: function() {
params = arguments;
- this.connection.query.apply(this.connection, [params[0], function(err, result){
- console.log(params);
- callback = params[params.length-1];
- if (result != undefined && result != null){
- callback(err, result.rows);
- } else {
- callback(err, []);
+ if (params.length > 2){
+ // We have parameters, but db-migrate uses "?" for param substitutions.
+ // PG uses "$1", "$2", etc so fix up the "?" into "$1", etc
+ var param = params[0].split('?'),
+ new_param = [];
+ for (var i = 0; i < param.length-1; i++){
+ new_param.push(param[i], "$" + (i+1));
}
- }]);
+ new_param.push(param[param.length-1]);
+ params[0] = new_param.join('');
+ }
+ this.connection.query.apply(this.connection, params);
},
all: function() {
Please sign in to comment.
Something went wrong with that request. Please try again.