knex-migrator 5.0.7 → 5.0.9

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.
Files changed (2) hide show
  1. package/lib/index.js +80 -79
  2. package/package.json +5 -5
package/lib/index.js CHANGED
@@ -1102,7 +1102,7 @@ KnexMigrator.prototype._afterEach = function _afterEach(options) {
1102
1102
  * @returns {Bluebird<any>}
1103
1103
  * @private
1104
1104
  */
1105
- KnexMigrator.prototype._integrityCheck = function _integrityCheck(options) {
1105
+ KnexMigrator.prototype._integrityCheck = async function _integrityCheck(options) {
1106
1106
  options = options || {};
1107
1107
 
1108
1108
  let self = this,
@@ -1124,97 +1124,98 @@ KnexMigrator.prototype._integrityCheck = function _integrityCheck(options) {
1124
1124
  // ignore
1125
1125
  }
1126
1126
 
1127
- return this
1128
- .connection('migrations')
1129
- .select('version')
1130
- .count('version', {as: 'c'})
1131
- .groupBy('version')
1132
- .then((dbMigrations) => {
1133
- _.each(folders, function (folder) {
1134
- // CASE: versions/1.1-members or versions/2.0-payments
1135
- if (folder !== 'init') {
1136
- try {
1137
- folder = folder.match(/([\d._]+)/)[0];
1138
- } catch (err) {
1139
- logging.warn('Cannot parse folder name.');
1140
- logging.warn('Ignore Folder: ' + folder);
1141
- return;
1142
- }
1127
+ try {
1128
+ const dbMigrations = await this
1129
+ .connection('migrations')
1130
+ .select('version')
1131
+ .count('version', {as: 'c'})
1132
+ .groupBy('version');
1133
+
1134
+ _.each(folders, function (folder) {
1135
+ // CASE: versions/1.1-members or versions/2.0-payments
1136
+ if (folder !== 'init') {
1137
+ try {
1138
+ folder = folder.match(/([\d._]+)/)[0];
1139
+ } catch (err) {
1140
+ logging.warn('Cannot parse folder name.');
1141
+ logging.warn('Ignore Folder: ' + folder);
1142
+ return;
1143
1143
  }
1144
+ }
1144
1145
 
1145
- // CASE:
1146
- // if your current version is 1.0 and you add migration scripts for the next version 1.1
1147
- // we won't execute them until your current version changes to 1.1 or until you force KM to migrate to it
1148
- if (self.currentVersion && !force) {
1149
- if (utils.isGreaterThanVersion({smallerVersion: self.currentVersion, greaterVersion: folder})) {
1150
- futureVersions.push(folder);
1151
- }
1146
+ // CASE:
1147
+ // if your current version is 1.0 and you add migration scripts for the next version 1.1
1148
+ // we won't execute them until your current version changes to 1.1 or until you force KM to migrate to it
1149
+ if (self.currentVersion && !force) {
1150
+ if (utils.isGreaterThanVersion({smallerVersion: self.currentVersion, greaterVersion: folder})) {
1151
+ futureVersions.push(folder);
1152
1152
  }
1153
+ }
1153
1154
 
1154
- let actual = 0;
1155
- let expected;
1155
+ let actual = 0;
1156
+ let expected;
1156
1157
 
1157
- const migrationCount = dbMigrations.find(m => m.version === folder);
1158
- if (migrationCount) {
1159
- actual = migrationCount.c;
1160
- }
1158
+ const migrationCount = dbMigrations.find(m => m.version === folder);
1159
+ if (migrationCount) {
1160
+ actual = migrationCount.c;
1161
+ }
1161
1162
 
1162
- if (folder !== 'init') {
1163
- expected = utils.listFiles(path.join(self.migrationPath, subfolder, folder)).length;
1164
- } else {
1165
- expected = utils.listFiles(path.join(self.migrationPath, folder)).length;
1166
- }
1163
+ if (folder !== 'init') {
1164
+ expected = utils.listFiles(path.join(self.migrationPath, subfolder, folder)).length;
1165
+ } else {
1166
+ expected = utils.listFiles(path.join(self.migrationPath, folder)).length;
1167
+ }
1167
1168
 
1168
- debug('Version ' + folder + ' expected: ' + expected);
1169
- debug('Version ' + folder + ' actual: ' + actual);
1169
+ debug('Version ' + folder + ' expected: ' + expected);
1170
+ debug('Version ' + folder + ' actual: ' + actual);
1170
1171
 
1171
- toReturn[folder] = {
1172
- expected: expected,
1173
- actual: actual
1174
- };
1175
- });
1172
+ toReturn[folder] = {
1173
+ expected: expected,
1174
+ actual: actual
1175
+ };
1176
+ });
1176
1177
 
1177
- // CASE: ensure that either you have to run `migrate --force` or they ran already
1178
- if (futureVersions.length) {
1179
- _.each(futureVersions, function (futureVersion) {
1180
- if (toReturn[futureVersion].actual !== toReturn[futureVersion].expected) {
1181
- logging.warn('knex-migrator is skipping ' + futureVersion);
1182
- logging.warn('Current version in MigratorConfig.js is smaller then requested version, use --force to proceed!');
1183
- logging.warn('Please run `yarn knex-migrator migrate --v ' + futureVersion + ' --force` to proceed!');
1184
- delete toReturn[futureVersion];
1185
- }
1186
- });
1187
- }
1178
+ // CASE: ensure that either you have to run `migrate --force` or they ran already
1179
+ if (futureVersions.length) {
1180
+ _.each(futureVersions, function (futureVersion) {
1181
+ if (toReturn[futureVersion].actual !== toReturn[futureVersion].expected) {
1182
+ logging.warn('knex-migrator is skipping ' + futureVersion);
1183
+ logging.warn('Current version in MigratorConfig.js is smaller then requested version, use --force to proceed!');
1184
+ logging.warn('Please run `yarn knex-migrator migrate --v ' + futureVersion + ' --force` to proceed!');
1185
+ delete toReturn[futureVersion];
1186
+ }
1187
+ });
1188
+ }
1188
1189
 
1189
- return toReturn;
1190
- }).catch(function onMigrationsLookupError(err) {
1191
- // CASE: no database selected (database.connection.database="")
1192
- if (err.errno === 1046) {
1193
- throw new errors.DatabaseIsNotOkError({
1194
- message: 'Please define a target database in your configuration.',
1195
- help: 'database: {\n\tconnection:\n\t\tdatabase:"database_name"\n\t}\n}\n',
1196
- code: 'DB_NOT_INITIALISED'
1197
- });
1198
- }
1190
+ return toReturn;
1191
+ } catch (err) {
1192
+ // CASE: no database selected (database.connection.database="")
1193
+ if (err.errno === 1046) {
1194
+ throw new errors.DatabaseIsNotOkError({
1195
+ message: 'Please define a target database in your configuration.',
1196
+ help: 'database: {\n\tconnection:\n\t\tdatabase:"database_name"\n\t}\n}\n',
1197
+ code: 'DB_NOT_INITIALISED'
1198
+ });
1199
+ }
1199
1200
 
1200
- // CASE: database does not exist
1201
- if (err.errno === 1049) {
1202
- throw new errors.DatabaseIsNotOkError({
1203
- message: 'Please run `yarn knex-migrator init`',
1204
- code: 'DB_NOT_INITIALISED'
1205
- });
1206
- }
1201
+ // CASE: database does not exist
1202
+ if (err.errno === 1049) {
1203
+ throw new errors.DatabaseIsNotOkError({
1204
+ message: 'Please run `yarn knex-migrator init`',
1205
+ code: 'DB_NOT_INITIALISED'
1206
+ });
1207
+ }
1207
1208
 
1208
- // CASE: migration table does not exist
1209
- if (err.errno === 1 || err.errno === 1146) {
1210
- throw new errors.DatabaseIsNotOkError({
1211
- message: 'Please run `yarn knex-migrator init`',
1212
- code: 'MIGRATION_TABLE_IS_MISSING'
1213
- });
1214
- }
1209
+ // CASE: migration table does not exist
1210
+ if (err.errno === 1 || err.errno === 1146) {
1211
+ throw new errors.DatabaseIsNotOkError({
1212
+ message: 'Please run `yarn knex-migrator init`',
1213
+ code: 'MIGRATION_TABLE_IS_MISSING'
1214
+ });
1215
+ }
1215
1216
 
1216
- throw err;
1217
- });
1217
+ throw err;
1218
+ }
1218
1219
  };
1219
1220
 
1220
1221
  module.exports = KnexMigrator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knex-migrator",
3
- "version": "5.0.7",
3
+ "version": "5.0.9",
4
4
  "description": "Database migrations with knex.",
5
5
  "keywords": [
6
6
  "ghost",
@@ -47,9 +47,9 @@
47
47
  "node": "^14.17.0 || ^16.13.0"
48
48
  },
49
49
  "dependencies": {
50
- "@tryghost/database-info": "0.3.10",
51
- "@tryghost/errors": "1.2.17",
52
- "@tryghost/logging": "2.3.2",
50
+ "@tryghost/database-info": "0.3.14",
51
+ "@tryghost/errors": "1.2.20",
52
+ "@tryghost/logging": "2.3.6",
53
53
  "bluebird": "3.7.2",
54
54
  "commander": "5.1.0",
55
55
  "compare-ver": "2.0.2",
@@ -77,6 +77,6 @@
77
77
  "sinon": "9.2.4"
78
78
  },
79
79
  "optionalDependencies": {
80
- "sqlite3": "5.1.2"
80
+ "sqlite3": "5.1.4"
81
81
  }
82
82
  }