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.
- package/lib/index.js +18 -20
- 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
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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 () {
|