From ce29dcadd8cb6b1ade0017a36b0bc0913510110f Mon Sep 17 00:00:00 2001 From: Tobias Gurtzick Date: Wed, 4 Apr 2018 18:54:42 +0200 Subject: [PATCH] feat(crdb20): added support for crdb2 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 --- index.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/index.js b/index.js index 0ab7384..73cd17f 100644 --- a/index.js +++ b/index.js @@ -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); } });