Permalink
Browse files

Fix migration table creation for PostgreSQL version > 9.1.0

  • Loading branch information...
1 parent e441022 commit f3170bbf4f3d87ae7adddf12f416c2100cbff5f7 @kunklejr kunklejr committed Jul 5, 2012
Showing with 49 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +19 −4 lib/driver/pg.js
  3. +29 −8 package.json
View
@@ -2,3 +2,4 @@ migrations/
node_modules/
*.db
.DS_Store
+.idea
View
@@ -1,10 +1,10 @@
var util = require('util');
var pg = require('pg');
+var semver = require('semver');
var Base = require('./base');
var type = require('../data_type');
var log = require('../log');
-
var PgDriver = Base.extend({
init: function(connection) {
this._super();
@@ -47,8 +47,23 @@ var PgDriver = Base.extend({
'run_on': { type: type.DATE_TIME, notNull: true}
},
ifNotExists: false
- }
- this.createTable('migrations', options, callback);
+ };
+
+ this.runSql('select version() as version', function(err, result) {
+ if (err) {
+ return callback(err);
+ }
+
+ if (result.rows && result.rows.length > 0 && result.rows[0].version) {
+ var version = result.rows[0].version;
+ var match = version.match(/\d+\.\d+\.\d+/);
+ if (match && match[0] && semver.gte(match[0], '9.1.0')) {
+ options.ifNotExists = true;
+ }
+ }
+
+ this.createTable('migrations', options, callback);
+ });
},
createColumnConstraint: function(spec, options) {
@@ -111,7 +126,7 @@ var PgDriver = Base.extend({
new_param.push(param[param.length-1]);
params[0] = new_param.join('');
}
- log.info('pg.runSql', params);
+ log.verbose('pg.runSql', params);
this.connection.query.apply(this.connection, params);
},
View
@@ -3,19 +3,40 @@
"description": "Database migration framework for node.js",
"author": "Jeff Kunkle <jeff.kunkle@nearinfinity.com>",
"bin": "./bin/db-migrate",
- "keywords": ["database", "db", "migrate", "migration", "sqlite", "mysql"],
- "version": "0.1.3",
- "engines": { "node" : ">=0.6.0" },
+ "keywords": [
+ "database",
+ "db",
+ "migrate",
+ "migration",
+ "sqlite",
+ "mysql"
+ ],
+ "version": "0.1.4",
+ "engines": {
+ "node": ">=0.6.0"
+ },
"maintainers": [
- { "name": "Jeff Kunkle", "email": "jeff.kunkle@nearinfinity.com" },
- { "name": "Joe Ferner", "email": "joe.ferner@nearinfinity.com" }
+ {
+ "name": "Jeff Kunkle",
+ "email": "jeff.kunkle@nearinfinity.com"
+ },
+ {
+ "name": "Joe Ferner",
+ "email": "joe.ferner@nearinfinity.com"
+ }
],
- "bugs": { "url": "https://github.com/nearinfinity/node-db-migrate/issues" },
+ "bugs": {
+ "url": "https://github.com/nearinfinity/node-db-migrate/issues"
+ },
"license": "MIT",
- "repository": { "type": "git", "url": "https://github.com/nearinfinity/node-db-migrate.git" },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/nearinfinity/node-db-migrate.git"
+ },
"dependencies": {
"optimist": "~0.3.0",
- "async": "~0.1.15"
+ "async": "~0.1.15",
+ "semver": "~1.0.14"
},
"devDependencies": {
"vows": "~0.6.2",

0 comments on commit f3170bb

Please sign in to comment.