Skip to content

Commit

Permalink
feat(crdb20): added support for crdb2
Browse files Browse the repository at this point in the history
In crdb 2 virtual schemas where introduced, the db name now is located under
table_catalog. We also removed set search_path as it is not necessary for
cockroach queries to function.

Signed-off-by: Tobias Gurtzick <magic@wizardtales.com>
  • Loading branch information
wzrdtales committed Apr 4, 2018
1 parent c4a51b8 commit ce29dca
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,40 @@ var CockroachDriver = Base.extend({
);

return this.runSql(sql).nodeify(callback);
},

createMigrationsTable: function(callback) {
var options = {
columns: {
id: {
type: this.type.INTEGER,
notNull: true,
primaryKey: true,
autoIncrement: true
},
name: { type: this.type.STRING, length: 255, notNull: true },
run_on: { type: this.type.DATE_TIME, notNull: true }
},
ifNotExists: false
};

return this.all(
"SELECT table_name FROM information_schema.tables WHERE table_name = '" +
this.internals.migrationTable +
"'" +
(this.schema ? " AND table_catalog = '" + this.schema + "'" : "") +
" AND table_schema = 'public'"
)
.then(
function(result) {
if (result && result && result.length < 1) {
return this.createTable(this.internals.migrationTable, options);
} else {
return Promise.resolve();
}
}.bind(this)
)
.nodeify(callback);
}
});

Expand Down

0 comments on commit ce29dca

Please sign in to comment.