knex-migrator 4.1.1 → 4.1.2

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 +18 -20
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -155,30 +155,28 @@ KnexMigrator.prototype.init = function init(options) {
155
155
  throw err;
156
156
  }
157
157
 
158
- return database.createTransaction(self.connection, function (transacting) {
158
+ return database.createTransaction(self.connection, async function (transacting) {
159
+ const existingMigrations = await transacting('migrations').select('name');
160
+ const existingMigrationsNames = existingMigrations.map(m => m.name);
161
+
159
162
  // CASE: Run over all migration scripts and add the file name to the database.
160
- return Promise.each(versionsToMigrateTo, function (versionToMigrateTo) {
163
+ for (const versionToMigrateTo of versionsToMigrateTo) {
161
164
  let versionPath = path.join(self.migrationPath, self.subfolder, versionToMigrateTo);
162
165
  let filesToMigrateTo = utils.listFiles(versionPath) || [];
163
166
 
164
- return Promise.each(filesToMigrateTo, function (fileToMigrateTo) {
165
- // CASE: check if migration exists, do not insert twice
166
- return transacting('migrations')
167
- .where('name', fileToMigrateTo)
168
- .then(function (migrationExists) {
169
- if (migrationExists.length) {
170
- return Promise.resolve();
171
- }
172
-
173
- return transacting('migrations')
174
- .insert({
175
- name: fileToMigrateTo,
176
- version: versionToMigrateTo,
177
- currentVersion: self.currentVersion
178
- });
179
- });
180
- });
181
- });
167
+ // CASE: check if migration exists, do not insert twice
168
+ for (const name of filesToMigrateTo) {
169
+ if (existingMigrationsNames.includes(name)) {
170
+ continue;
171
+ }
172
+
173
+ await transacting('migrations').insert({
174
+ name,
175
+ version: versionToMigrateTo,
176
+ currentVersion: self.currentVersion
177
+ });
178
+ }
179
+ }
182
180
  });
183
181
  })
184
182
  .then(function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knex-migrator",
3
- "version": "4.1.1",
3
+ "version": "4.1.2",
4
4
  "description": "Database migrations with knex.",
5
5
  "keywords": [
6
6
  "ghost",