knex 0.12.9 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/bin/cli.js +0 -0
- package/lib/client.js +1 -1
- package/lib/dialects/maria/transaction.js +10 -1
- package/lib/dialects/mssql/index.js +4 -4
- package/lib/dialects/mysql/index.js +2 -2
- package/lib/dialects/mysql/transaction.js +10 -1
- package/lib/dialects/mysql2/transaction.js +10 -1
- package/lib/dialects/oracle/transaction.js +13 -1
- package/lib/dialects/oracledb/index.js +16 -0
- package/lib/dialects/oracledb/transaction.js +7 -0
- package/lib/dialects/postgres/index.js +6 -2
- package/lib/migrate/index.js +69 -34
- package/lib/migrate/stub/coffee.stub +12 -12
- package/lib/migrate/stub/eg.stub +14 -14
- package/lib/migrate/stub/js.stub +15 -15
- package/lib/migrate/stub/knexfile-coffee.stub +34 -34
- package/lib/migrate/stub/knexfile-eg.stub +43 -43
- package/lib/migrate/stub/knexfile-js.stub +44 -44
- package/lib/migrate/stub/knexfile-ls.stub +35 -35
- package/lib/migrate/stub/ls.stub +14 -14
- package/lib/query/builder.js +3 -4
- package/lib/query/string.js +2 -2
- package/lib/raw.js +3 -4
- package/lib/runner.js +3 -3
- package/lib/schema/columncompiler.js +1 -1
- package/lib/schema/tablecompiler.js +1 -1
- package/lib/transaction.js +3 -3
- package/lib/util/batchInsert.js +12 -5
- package/lib/util/make-knex.js +1 -1
- package/package.json +1 -1
- package/scripts/release.sh +1 -1
- package/src/dialects/maria/transaction.js +7 -1
- package/src/dialects/mysql/transaction.js +7 -2
- package/src/dialects/mysql2/transaction.js +7 -2
- package/src/dialects/oracle/transaction.js +8 -1
- package/src/dialects/oracledb/index.js +16 -0
- package/src/dialects/oracledb/transaction.js +5 -0
- package/src/dialects/postgres/index.js +7 -3
- package/src/migrate/index.js +98 -79
- package/src/migrate/stub/coffee.stub +12 -12
- package/src/migrate/stub/eg.stub +14 -14
- package/src/migrate/stub/js.stub +15 -15
- package/src/migrate/stub/knexfile-coffee.stub +34 -34
- package/src/migrate/stub/knexfile-eg.stub +43 -43
- package/src/migrate/stub/knexfile-js.stub +44 -44
- package/src/migrate/stub/knexfile-ls.stub +35 -35
- package/src/migrate/stub/ls.stub +14 -14
- package/src/transaction.js +3 -3
- package/src/util/batchInsert.js +10 -5
- package/README.md +0 -80
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
|
|
2
2
|
# Master (Unreleased)
|
|
3
3
|
|
|
4
|
+
# 0.13 - 29 Apr, 2017
|
|
5
|
+
|
|
6
|
+
### Breaking Changes:
|
|
7
|
+
- Multiple concurrent migration runners blocks instead of throwing error when possible #1962
|
|
8
|
+
- Fixed transaction promise mutation issue #1991
|
|
9
|
+
|
|
10
|
+
### Other Changes:
|
|
11
|
+
- Allow passing version of connected db in configuration file #1993
|
|
12
|
+
- Bugfixes on batchInsert and transactions for mysql/maria #1992
|
|
13
|
+
- Add fetchAsString optional parameter to oracledb dialect #1998
|
|
14
|
+
- fix: escapeObject parameter order for Postgres dialect. #2003
|
|
15
|
+
|
|
4
16
|
# 0.12.9 - 23 Mar, 2017
|
|
5
17
|
- Fixed unhandled exception in batchInsert when the rows to be inserted resulted in duplicate key violation #1880
|
|
6
18
|
|
package/bin/cli.js
CHANGED
|
File without changes
|
package/lib/client.js
CHANGED
|
@@ -97,7 +97,7 @@ function clientId() {
|
|
|
97
97
|
// The base client provides the general structure
|
|
98
98
|
// for a dialect specific client object.
|
|
99
99
|
function Client() {
|
|
100
|
-
var config = arguments.length
|
|
100
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
101
101
|
|
|
102
102
|
this.config = config;
|
|
103
103
|
|
|
@@ -14,6 +14,10 @@ var _inherits2 = require('babel-runtime/helpers/inherits');
|
|
|
14
14
|
|
|
15
15
|
var _inherits3 = _interopRequireDefault(_inherits2);
|
|
16
16
|
|
|
17
|
+
var _isUndefined2 = require('lodash/isUndefined');
|
|
18
|
+
|
|
19
|
+
var _isUndefined3 = _interopRequireDefault(_isUndefined2);
|
|
20
|
+
|
|
17
21
|
var _debug = require('debug');
|
|
18
22
|
|
|
19
23
|
var _debug2 = _interopRequireDefault(_debug);
|
|
@@ -53,7 +57,12 @@ var Transaction_Maria = function (_Transaction) {
|
|
|
53
57
|
debug('%s error running transaction query', t.txid);
|
|
54
58
|
}).tap(function () {
|
|
55
59
|
if (status === 1) t._resolver(value);
|
|
56
|
-
if (status === 2)
|
|
60
|
+
if (status === 2) {
|
|
61
|
+
if ((0, _isUndefined3.default)(value)) {
|
|
62
|
+
value = new Error('Transaction rejected with non-error: ' + value);
|
|
63
|
+
}
|
|
64
|
+
t._rejecter(value);
|
|
65
|
+
}
|
|
57
66
|
});
|
|
58
67
|
if (status === 1 || status === 2) {
|
|
59
68
|
t._completed = true;
|
|
@@ -180,8 +180,8 @@ function Client_MSSQL(config) {
|
|
|
180
180
|
rejecter(err);
|
|
181
181
|
});
|
|
182
182
|
stream.on('end', resolver);
|
|
183
|
-
var _obj = obj
|
|
184
|
-
|
|
183
|
+
var _obj = obj,
|
|
184
|
+
sql = _obj.sql;
|
|
185
185
|
|
|
186
186
|
if (!sql) return resolver();
|
|
187
187
|
var req = (connection.tx_ || connection).request();
|
|
@@ -207,8 +207,8 @@ function Client_MSSQL(config) {
|
|
|
207
207
|
// convert ? params into positional bindings (@p1)
|
|
208
208
|
obj.sql = this.positionBindings(obj.sql);
|
|
209
209
|
return new _bluebird2.default(function (resolver, rejecter) {
|
|
210
|
-
var _obj2 = obj
|
|
211
|
-
|
|
210
|
+
var _obj2 = obj,
|
|
211
|
+
sql = _obj2.sql;
|
|
212
212
|
|
|
213
213
|
if (!sql) return resolver();
|
|
214
214
|
var req = (connection.tx_ || connection).request();
|
|
@@ -144,8 +144,8 @@ function Client_MySQL(config) {
|
|
|
144
144
|
_query: function _query(connection, obj) {
|
|
145
145
|
if (!obj || typeof obj === 'string') obj = { sql: obj };
|
|
146
146
|
return new _bluebird2.default(function (resolver, rejecter) {
|
|
147
|
-
var _obj = obj
|
|
148
|
-
|
|
147
|
+
var _obj = obj,
|
|
148
|
+
sql = _obj.sql;
|
|
149
149
|
|
|
150
150
|
if (!sql) return resolver();
|
|
151
151
|
if (obj.options) sql = (0, _assign3.default)({ sql: sql }, obj.options);
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
|
|
5
|
+
var _isUndefined2 = require('lodash/isUndefined');
|
|
6
|
+
|
|
7
|
+
var _isUndefined3 = _interopRequireDefault(_isUndefined2);
|
|
8
|
+
|
|
5
9
|
var _assign2 = require('lodash/assign');
|
|
6
10
|
|
|
7
11
|
var _assign3 = _interopRequireDefault(_assign2);
|
|
@@ -47,7 +51,12 @@ function Transaction_MySQL() {
|
|
|
47
51
|
debug('%s error running transaction query', t.txid);
|
|
48
52
|
}).tap(function () {
|
|
49
53
|
if (status === 1) t._resolver(value);
|
|
50
|
-
if (status === 2)
|
|
54
|
+
if (status === 2) {
|
|
55
|
+
if ((0, _isUndefined3.default)(value)) {
|
|
56
|
+
value = new Error('Transaction rejected with non-error: ' + value);
|
|
57
|
+
}
|
|
58
|
+
t._rejecter(value);
|
|
59
|
+
}
|
|
51
60
|
});
|
|
52
61
|
if (status === 1 || status === 2) {
|
|
53
62
|
t._completed = true;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
|
|
5
|
+
var _isUndefined2 = require('lodash/isUndefined');
|
|
6
|
+
|
|
7
|
+
var _isUndefined3 = _interopRequireDefault(_isUndefined2);
|
|
8
|
+
|
|
5
9
|
var _assign2 = require('lodash/assign');
|
|
6
10
|
|
|
7
11
|
var _assign3 = _interopRequireDefault(_assign2);
|
|
@@ -44,7 +48,12 @@ function Transaction_MySQL2() {
|
|
|
44
48
|
debug('%s error running transaction query', t.txid);
|
|
45
49
|
}).tap(function () {
|
|
46
50
|
if (status === 1) t._resolver(value);
|
|
47
|
-
if (status === 2)
|
|
51
|
+
if (status === 2) {
|
|
52
|
+
if ((0, _isUndefined3.default)(value)) {
|
|
53
|
+
value = new Error('Transaction rejected with non-error: ' + value);
|
|
54
|
+
}
|
|
55
|
+
t._rejecter(value);
|
|
56
|
+
}
|
|
48
57
|
});
|
|
49
58
|
if (status === 1 || status === 2) {
|
|
50
59
|
t._completed = true;
|
|
@@ -14,6 +14,10 @@ var _inherits2 = require('babel-runtime/helpers/inherits');
|
|
|
14
14
|
|
|
15
15
|
var _inherits3 = _interopRequireDefault(_inherits2);
|
|
16
16
|
|
|
17
|
+
var _isUndefined2 = require('lodash/isUndefined');
|
|
18
|
+
|
|
19
|
+
var _isUndefined3 = _interopRequireDefault(_isUndefined2);
|
|
20
|
+
|
|
17
21
|
var _bluebird = require('bluebird');
|
|
18
22
|
|
|
19
23
|
var _bluebird2 = _interopRequireDefault(_bluebird);
|
|
@@ -49,9 +53,17 @@ var Oracle_Transaction = function (_Transaction) {
|
|
|
49
53
|
};
|
|
50
54
|
|
|
51
55
|
Oracle_Transaction.prototype.rollback = function rollback(conn, err) {
|
|
56
|
+
var _this2 = this;
|
|
57
|
+
|
|
52
58
|
this._completed = true;
|
|
53
59
|
debugTx('%s: rolling back', this.txid);
|
|
54
|
-
return conn.rollbackAsync().throw(err).catch(
|
|
60
|
+
return conn.rollbackAsync().throw(err).catch(function (error) {
|
|
61
|
+
if ((0, _isUndefined3.default)(error)) {
|
|
62
|
+
error = new Error('Transaction rejected with non-error: ' + error);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return _this2._rejecter(error);
|
|
66
|
+
});
|
|
55
67
|
};
|
|
56
68
|
|
|
57
69
|
Oracle_Transaction.prototype.acquireConnection = function acquireConnection(config) {
|
|
@@ -43,7 +43,21 @@ inherits(Client_Oracledb, Client_Oracle);
|
|
|
43
43
|
Client_Oracledb.prototype.driverName = 'oracledb';
|
|
44
44
|
|
|
45
45
|
Client_Oracledb.prototype._driver = function () {
|
|
46
|
+
var client = this;
|
|
46
47
|
var oracledb = require('oracledb');
|
|
48
|
+
client.fetchAsString = [];
|
|
49
|
+
if (this.config.fetchAsString && _.isArray(this.config.fetchAsString)) {
|
|
50
|
+
this.config.fetchAsString.forEach(function (type) {
|
|
51
|
+
if (!_.isString(type)) return;
|
|
52
|
+
type = type.toUpperCase();
|
|
53
|
+
if (oracledb[type]) {
|
|
54
|
+
if (type !== 'NUMBER' && type !== 'DATE' && type !== 'CLOB') {
|
|
55
|
+
helpers.warn('Only "date", "number" and "clob" are supported for fetchAsString');
|
|
56
|
+
}
|
|
57
|
+
client.fetchAsString.push(oracledb[type]);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
47
61
|
return oracledb;
|
|
48
62
|
};
|
|
49
63
|
|
|
@@ -100,6 +114,8 @@ Client_Oracledb.prototype.acquireRawConnection = function () {
|
|
|
100
114
|
oracleDbConfig.stmtCacheSize = client.connectionSettings.stmtCacheSize;
|
|
101
115
|
}
|
|
102
116
|
|
|
117
|
+
client.driver.fetchAsString = client.fetchAsString;
|
|
118
|
+
|
|
103
119
|
client.driver.getConnection(oracleDbConfig, function (err, connection) {
|
|
104
120
|
if (err) {
|
|
105
121
|
return rejecter(err);
|
|
@@ -14,6 +14,10 @@ var _inherits2 = require('babel-runtime/helpers/inherits');
|
|
|
14
14
|
|
|
15
15
|
var _inherits3 = _interopRequireDefault(_inherits2);
|
|
16
16
|
|
|
17
|
+
var _isUndefined2 = require('lodash/isUndefined');
|
|
18
|
+
|
|
19
|
+
var _isUndefined3 = _interopRequireDefault(_isUndefined2);
|
|
20
|
+
|
|
17
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
22
|
|
|
19
23
|
var Promise = require('bluebird');
|
|
@@ -49,6 +53,9 @@ var Oracle_Transaction = function (_Transaction) {
|
|
|
49
53
|
return conn.rollbackAsync().timeout(5000).catch(Promise.TimeoutError, function (e) {
|
|
50
54
|
self._rejecter(e);
|
|
51
55
|
}).then(function () {
|
|
56
|
+
if ((0, _isUndefined3.default)(err)) {
|
|
57
|
+
err = new Error('Transaction rejected with non-error: ' + err);
|
|
58
|
+
}
|
|
52
59
|
self._rejecter(err);
|
|
53
60
|
});
|
|
54
61
|
};
|
|
@@ -61,6 +61,10 @@ function Client_PG(config) {
|
|
|
61
61
|
if (config.searchPath) {
|
|
62
62
|
this.searchPath = config.searchPath;
|
|
63
63
|
}
|
|
64
|
+
|
|
65
|
+
if (config.version) {
|
|
66
|
+
this.version = config.version;
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
69
|
(0, _inherits2.default)(Client_PG, _client2.default);
|
|
66
70
|
|
|
@@ -112,8 +116,8 @@ function Client_PG(config) {
|
|
|
112
116
|
}
|
|
113
117
|
return escaped;
|
|
114
118
|
},
|
|
115
|
-
escapeObject: function escapeObject(val,
|
|
116
|
-
var seen = arguments.length
|
|
119
|
+
escapeObject: function escapeObject(val, prepareValue, timezone) {
|
|
120
|
+
var seen = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
117
121
|
|
|
118
122
|
if (val && typeof val.toPostgres === 'function') {
|
|
119
123
|
seen = seen || [];
|
package/lib/migrate/index.js
CHANGED
|
@@ -127,7 +127,20 @@ var Migrator = function () {
|
|
|
127
127
|
|
|
128
128
|
this.config = this.setConfig(config);
|
|
129
129
|
return this._migrationData().tap(validateMigrationList).spread(function (all, completed) {
|
|
130
|
-
|
|
130
|
+
var migrations = (0, _difference3.default)(all, completed);
|
|
131
|
+
|
|
132
|
+
var transactionForAll = !_this.config.disableTransactions && (0, _isEmpty3.default)((0, _filter3.default)(migrations, function (name) {
|
|
133
|
+
var migration = require(_path2.default.join(_this._absoluteConfigDir(), name));
|
|
134
|
+
return !_this._useTransaction(migration);
|
|
135
|
+
}));
|
|
136
|
+
|
|
137
|
+
if (transactionForAll) {
|
|
138
|
+
return _this.knex.transaction(function (trx) {
|
|
139
|
+
return _this._runBatch(migrations, 'up', trx);
|
|
140
|
+
});
|
|
141
|
+
} else {
|
|
142
|
+
return _this._runBatch(migrations, 'up');
|
|
143
|
+
}
|
|
131
144
|
});
|
|
132
145
|
};
|
|
133
146
|
|
|
@@ -228,18 +241,20 @@ var Migrator = function () {
|
|
|
228
241
|
Migrator.prototype._ensureTable = function _ensureTable() {
|
|
229
242
|
var _this5 = this;
|
|
230
243
|
|
|
244
|
+
var trx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.knex;
|
|
245
|
+
|
|
231
246
|
var table = this.config.tableName;
|
|
232
247
|
var lockTable = this._getLockTableName();
|
|
233
|
-
return
|
|
234
|
-
return !exists && _this5._createMigrationTable(table);
|
|
248
|
+
return trx.schema.hasTable(table).then(function (exists) {
|
|
249
|
+
return !exists && _this5._createMigrationTable(table, trx);
|
|
235
250
|
}).then(function () {
|
|
236
|
-
return
|
|
251
|
+
return trx.schema.hasTable(lockTable);
|
|
237
252
|
}).then(function (exists) {
|
|
238
|
-
return !exists && _this5._createMigrationLockTable(lockTable);
|
|
253
|
+
return !exists && _this5._createMigrationLockTable(lockTable, trx);
|
|
239
254
|
}).then(function () {
|
|
240
|
-
return
|
|
255
|
+
return trx.from(lockTable).select('*');
|
|
241
256
|
}).then(function (data) {
|
|
242
|
-
return !data.length &&
|
|
257
|
+
return !data.length && trx.into(lockTable).insert({ is_locked: 0 });
|
|
243
258
|
});
|
|
244
259
|
};
|
|
245
260
|
|
|
@@ -247,7 +262,9 @@ var Migrator = function () {
|
|
|
247
262
|
|
|
248
263
|
|
|
249
264
|
Migrator.prototype._createMigrationTable = function _createMigrationTable(tableName) {
|
|
250
|
-
|
|
265
|
+
var trx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.knex;
|
|
266
|
+
|
|
267
|
+
return trx.schema.createTableIfNotExists(tableName, function (t) {
|
|
251
268
|
t.increments();
|
|
252
269
|
t.string('name');
|
|
253
270
|
t.integer('batch');
|
|
@@ -256,7 +273,9 @@ var Migrator = function () {
|
|
|
256
273
|
};
|
|
257
274
|
|
|
258
275
|
Migrator.prototype._createMigrationLockTable = function _createMigrationLockTable(tableName) {
|
|
259
|
-
|
|
276
|
+
var trx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.knex;
|
|
277
|
+
|
|
278
|
+
return trx.schema.createTableIfNotExists(tableName, function (t) {
|
|
260
279
|
t.integer('is_locked');
|
|
261
280
|
});
|
|
262
281
|
};
|
|
@@ -277,10 +296,16 @@ var Migrator = function () {
|
|
|
277
296
|
return this.knex(tableName).transacting(trx).update({ is_locked: 1 });
|
|
278
297
|
};
|
|
279
298
|
|
|
280
|
-
Migrator.prototype._getLock = function _getLock() {
|
|
299
|
+
Migrator.prototype._getLock = function _getLock(trx) {
|
|
281
300
|
var _this6 = this;
|
|
282
301
|
|
|
283
|
-
|
|
302
|
+
var transact = trx ? function (fn) {
|
|
303
|
+
return fn(trx);
|
|
304
|
+
} : function (fn) {
|
|
305
|
+
return _this6.knex.transaction(fn);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
return transact(function (trx) {
|
|
284
309
|
return _this6._isLocked(trx).then(function (isLocked) {
|
|
285
310
|
if (isLocked) {
|
|
286
311
|
throw new Error("Migration table is already locked");
|
|
@@ -294,27 +319,36 @@ var Migrator = function () {
|
|
|
294
319
|
};
|
|
295
320
|
|
|
296
321
|
Migrator.prototype._freeLock = function _freeLock() {
|
|
322
|
+
var trx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.knex;
|
|
323
|
+
|
|
297
324
|
var tableName = this._getLockTableName();
|
|
298
|
-
return
|
|
325
|
+
return trx.table(tableName).update({ is_locked: 0 });
|
|
299
326
|
};
|
|
300
327
|
|
|
301
328
|
// Run a batch of current migrations, in sequence.
|
|
302
329
|
|
|
303
330
|
|
|
304
|
-
Migrator.prototype._runBatch = function _runBatch(migrations, direction) {
|
|
331
|
+
Migrator.prototype._runBatch = function _runBatch(migrations, direction, trx) {
|
|
305
332
|
var _this7 = this;
|
|
306
333
|
|
|
307
|
-
return this._getLock()
|
|
334
|
+
return this._getLock(trx)
|
|
335
|
+
// When there is a wrapping transaction, some migrations
|
|
336
|
+
// could have been done while waiting for the lock:
|
|
337
|
+
.then(function () {
|
|
338
|
+
return trx ? _this7._listCompleted(trx) : [];
|
|
339
|
+
}).then(function (completed) {
|
|
340
|
+
return migrations = (0, _difference3.default)(migrations, completed);
|
|
341
|
+
}).then(function () {
|
|
308
342
|
return _bluebird2.default.all((0, _map3.default)(migrations, (0, _bind3.default)(_this7._validateMigrationStructure, _this7)));
|
|
309
343
|
}).then(function () {
|
|
310
|
-
return _this7._latestBatchNumber();
|
|
344
|
+
return _this7._latestBatchNumber(trx);
|
|
311
345
|
}).then(function (batchNo) {
|
|
312
346
|
if (direction === 'up') batchNo++;
|
|
313
347
|
return batchNo;
|
|
314
348
|
}).then(function (batchNo) {
|
|
315
|
-
return _this7._waterfallBatch(batchNo, migrations, direction);
|
|
349
|
+
return _this7._waterfallBatch(batchNo, migrations, direction, trx);
|
|
316
350
|
}).tap(function () {
|
|
317
|
-
return _this7._freeLock();
|
|
351
|
+
return _this7._freeLock(trx);
|
|
318
352
|
}).catch(function (error) {
|
|
319
353
|
var cleanupReady = _bluebird2.default.resolve();
|
|
320
354
|
|
|
@@ -325,7 +359,7 @@ var Migrator = function () {
|
|
|
325
359
|
} else {
|
|
326
360
|
helpers.warn('migrations failed with error: ' + error.message);
|
|
327
361
|
// If the error was not due to a locking issue, then remove the lock.
|
|
328
|
-
cleanupReady = _this7._freeLock();
|
|
362
|
+
cleanupReady = _this7._freeLock(trx);
|
|
329
363
|
}
|
|
330
364
|
|
|
331
365
|
return cleanupReady.finally(function () {
|
|
@@ -351,12 +385,11 @@ var Migrator = function () {
|
|
|
351
385
|
|
|
352
386
|
|
|
353
387
|
Migrator.prototype._listCompleted = function _listCompleted() {
|
|
354
|
-
var
|
|
355
|
-
|
|
388
|
+
var trx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.knex;
|
|
356
389
|
var tableName = this.config.tableName;
|
|
357
390
|
|
|
358
|
-
return this._ensureTable(
|
|
359
|
-
return
|
|
391
|
+
return this._ensureTable(trx).then(function () {
|
|
392
|
+
return trx.from(tableName).orderBy('id').select('name');
|
|
360
393
|
}).then(function (migrations) {
|
|
361
394
|
return (0, _map3.default)(migrations, 'name');
|
|
362
395
|
});
|
|
@@ -410,7 +443,9 @@ var Migrator = function () {
|
|
|
410
443
|
|
|
411
444
|
|
|
412
445
|
Migrator.prototype._latestBatchNumber = function _latestBatchNumber() {
|
|
413
|
-
|
|
446
|
+
var trx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.knex;
|
|
447
|
+
|
|
448
|
+
return trx.from(this.config.tableName).max('batch as max_batch').then(function (obj) {
|
|
414
449
|
return obj[0].max_batch || 0;
|
|
415
450
|
});
|
|
416
451
|
};
|
|
@@ -431,13 +466,13 @@ var Migrator = function () {
|
|
|
431
466
|
// appropriate database information as the migrations are run.
|
|
432
467
|
|
|
433
468
|
|
|
434
|
-
Migrator.prototype._waterfallBatch = function _waterfallBatch(batchNo, migrations, direction) {
|
|
435
|
-
var
|
|
469
|
+
Migrator.prototype._waterfallBatch = function _waterfallBatch(batchNo, migrations, direction, trx) {
|
|
470
|
+
var _this8 = this;
|
|
436
471
|
|
|
437
|
-
var
|
|
438
|
-
var _config = this.config
|
|
439
|
-
|
|
440
|
-
|
|
472
|
+
var trxOrKnex = trx || this.knex;
|
|
473
|
+
var _config = this.config,
|
|
474
|
+
tableName = _config.tableName,
|
|
475
|
+
disableTransactions = _config.disableTransactions;
|
|
441
476
|
|
|
442
477
|
var directory = this._absoluteConfigDir();
|
|
443
478
|
var current = _bluebird2.default.bind({ failed: false, failedOn: 0 });
|
|
@@ -448,21 +483,21 @@ var Migrator = function () {
|
|
|
448
483
|
|
|
449
484
|
// We're going to run each of the migrations in the current "up".
|
|
450
485
|
current = current.then(function () {
|
|
451
|
-
if (
|
|
452
|
-
return
|
|
486
|
+
if (!trx && _this8._useTransaction(migration, disableTransactions)) {
|
|
487
|
+
return _this8._transaction(migration, direction, name);
|
|
453
488
|
}
|
|
454
|
-
return warnPromise(migration[direction](
|
|
489
|
+
return warnPromise(migration[direction](trxOrKnex, _bluebird2.default), name);
|
|
455
490
|
}).then(function () {
|
|
456
491
|
log.push(_path2.default.join(directory, name));
|
|
457
492
|
if (direction === 'up') {
|
|
458
|
-
return
|
|
493
|
+
return trxOrKnex.into(tableName).insert({
|
|
459
494
|
name: name,
|
|
460
495
|
batch: batchNo,
|
|
461
496
|
migration_time: new Date()
|
|
462
497
|
});
|
|
463
498
|
}
|
|
464
499
|
if (direction === 'down') {
|
|
465
|
-
return
|
|
500
|
+
return trxOrKnex.from(tableName).where({ name: name }).del();
|
|
466
501
|
}
|
|
467
502
|
});
|
|
468
503
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
exports.up = (knex, Promise) ->
|
|
3
|
-
<% if (d.tableName) { %>
|
|
4
|
-
knex.schema.createTable "<%= d.tableName %>", (t) ->
|
|
5
|
-
t.increments()
|
|
6
|
-
t.timestamp()
|
|
7
|
-
<% } %>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.down = (knex, Promise) ->
|
|
11
|
-
<% if (d.tableName) { %>
|
|
12
|
-
knex.schema.dropTable "<%= d.tableName %>"
|
|
1
|
+
|
|
2
|
+
exports.up = (knex, Promise) ->
|
|
3
|
+
<% if (d.tableName) { %>
|
|
4
|
+
knex.schema.createTable "<%= d.tableName %>", (t) ->
|
|
5
|
+
t.increments()
|
|
6
|
+
t.timestamp()
|
|
7
|
+
<% } %>
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.down = (knex, Promise) ->
|
|
11
|
+
<% if (d.tableName) { %>
|
|
12
|
+
knex.schema.dropTable "<%= d.tableName %>"
|
|
13
13
|
<% } %>
|
package/lib/migrate/stub/eg.stub
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
provide: up, down
|
|
2
|
-
|
|
3
|
-
up = (knex, Promise) ->
|
|
4
|
-
<% if (d.tableName) { %>
|
|
5
|
-
knex.schema.createTable "<%= d.tableName %>": t ->
|
|
6
|
-
t.increments()
|
|
7
|
-
t.timestamp()
|
|
8
|
-
<% } %>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
down = (knex, Promise) ->
|
|
12
|
-
<% if (d.tableName) { %>
|
|
13
|
-
knex.schema.dropTable("<%= d.tableName %>")
|
|
14
|
-
<% } %>
|
|
1
|
+
provide: up, down
|
|
2
|
+
|
|
3
|
+
up = (knex, Promise) ->
|
|
4
|
+
<% if (d.tableName) { %>
|
|
5
|
+
knex.schema.createTable "<%= d.tableName %>": t ->
|
|
6
|
+
t.increments()
|
|
7
|
+
t.timestamp()
|
|
8
|
+
<% } %>
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
down = (knex, Promise) ->
|
|
12
|
+
<% if (d.tableName) { %>
|
|
13
|
+
knex.schema.dropTable("<%= d.tableName %>")
|
|
14
|
+
<% } %>
|
package/lib/migrate/stub/js.stub
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
exports.up = function(knex, Promise) {
|
|
3
|
-
<% if (d.tableName) { %>
|
|
4
|
-
return knex.schema.createTable("<%= d.tableName %>", function(t) {
|
|
5
|
-
t.increments();
|
|
6
|
-
t.timestamp();
|
|
7
|
-
});
|
|
8
|
-
<% } %>
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
exports.down = function(knex, Promise) {
|
|
12
|
-
<% if (d.tableName) { %>
|
|
13
|
-
return knex.schema.dropTable("<%= d.tableName %>");
|
|
14
|
-
<% } %>
|
|
15
|
-
};
|
|
1
|
+
|
|
2
|
+
exports.up = function(knex, Promise) {
|
|
3
|
+
<% if (d.tableName) { %>
|
|
4
|
+
return knex.schema.createTable("<%= d.tableName %>", function(t) {
|
|
5
|
+
t.increments();
|
|
6
|
+
t.timestamp();
|
|
7
|
+
});
|
|
8
|
+
<% } %>
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
exports.down = function(knex, Promise) {
|
|
12
|
+
<% if (d.tableName) { %>
|
|
13
|
+
return knex.schema.dropTable("<%= d.tableName %>");
|
|
14
|
+
<% } %>
|
|
15
|
+
};
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
# Update with your config settings.
|
|
2
|
-
|
|
3
|
-
module.exports =
|
|
4
|
-
|
|
5
|
-
development:
|
|
6
|
-
client: 'sqlite3'
|
|
7
|
-
connection:
|
|
8
|
-
filename: './dev.sqlite3'
|
|
9
|
-
migrations:
|
|
10
|
-
tableName: 'knex_migrations'
|
|
11
|
-
|
|
12
|
-
staging:
|
|
13
|
-
client: 'postgresql'
|
|
14
|
-
connection:
|
|
15
|
-
database: 'my_db'
|
|
16
|
-
user: 'username'
|
|
17
|
-
password: 'password'
|
|
18
|
-
pool:
|
|
19
|
-
min: 2
|
|
20
|
-
max: 10
|
|
21
|
-
migrations:
|
|
22
|
-
tableName: 'knex_migrations'
|
|
23
|
-
|
|
24
|
-
production:
|
|
25
|
-
client: 'postgresql'
|
|
26
|
-
connection:
|
|
27
|
-
database: 'my_db'
|
|
28
|
-
user: 'username'
|
|
29
|
-
password: 'password'
|
|
30
|
-
pool:
|
|
31
|
-
min: 2
|
|
32
|
-
max: 10
|
|
33
|
-
migrations:
|
|
34
|
-
tableName: 'knex_migrations'
|
|
1
|
+
# Update with your config settings.
|
|
2
|
+
|
|
3
|
+
module.exports =
|
|
4
|
+
|
|
5
|
+
development:
|
|
6
|
+
client: 'sqlite3'
|
|
7
|
+
connection:
|
|
8
|
+
filename: './dev.sqlite3'
|
|
9
|
+
migrations:
|
|
10
|
+
tableName: 'knex_migrations'
|
|
11
|
+
|
|
12
|
+
staging:
|
|
13
|
+
client: 'postgresql'
|
|
14
|
+
connection:
|
|
15
|
+
database: 'my_db'
|
|
16
|
+
user: 'username'
|
|
17
|
+
password: 'password'
|
|
18
|
+
pool:
|
|
19
|
+
min: 2
|
|
20
|
+
max: 10
|
|
21
|
+
migrations:
|
|
22
|
+
tableName: 'knex_migrations'
|
|
23
|
+
|
|
24
|
+
production:
|
|
25
|
+
client: 'postgresql'
|
|
26
|
+
connection:
|
|
27
|
+
database: 'my_db'
|
|
28
|
+
user: 'username'
|
|
29
|
+
password: 'password'
|
|
30
|
+
pool:
|
|
31
|
+
min: 2
|
|
32
|
+
max: 10
|
|
33
|
+
migrations:
|
|
34
|
+
tableName: 'knex_migrations'
|