Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for postgres driver blindly recreating the migrations table #89

Merged
merged 1 commit into from

2 participants

Shane Gibbons Jeff Kunkle
Shane Gibbons

Despite this ticket: #20 being marked as closed, I'm still experiencing this problem with the latest version.

As it exists now, the createMigrationsTable function in the pg driver has ifNotExists: false, which I assume is because pg doesn't support IF NOT EXISTS create statements. This results in the migrations table getting recreated each time the migrations are run, which results in a crash after the first run.

This change fixes the issue by querying the information_schema.tables table to check for the existence of a migrations table. If it exists, the creation of the table is skipped.

Shane Gibbons sgibbons The postgres driver blindly creates the migrations table regardless o…
…f whether or not it's already been created - this change to the driver first checks the information schema for the existence of the table and does/doesn't create it accordingly
2dc4cfd
Jeff Kunkle kunklejr merged commit 545b706 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 13, 2013
  1. Shane Gibbons

    The postgres driver blindly creates the migrations table regardless o…

    sgibbons authored
    …f whether or not it's already been created - this change to the driver first checks the information schema for the existence of the table and does/doesn't create it accordingly
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 1 deletion.
  1. +11 −1 lib/driver/pg.js
12 lib/driver/pg.js
View
@@ -62,7 +62,17 @@ var PgDriver = Base.extend({
}
}
- this.createTable('migrations', options, callback);
+ this.runSql("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'migrations'", function(err, result) {
+ if(err) {
+ return callback(err);
+ }
+
+ if (result.rows && result.rows.length < 1) {
+ this.createTable('migrations', options, callback);
+ } else {
+ callback();
+ }
+ });
}.bind(this));
},
Something went wrong with that request. Please try again.