rittenhop-dev/versions/5.94.2/node_modules/knex-migrator/migrations/use-index.js

25 lines
881 B
JavaScript
Raw Normal View History

2024-09-23 19:40:12 -04:00
const debug = require('debug')('knex-migrator:use-index');
/**
* @description Private helper to migrate the migrations table. It will add missing indexes to existing fields.
* @returns {*}
*/
module.exports.up = function (connection) {
debug('Ensure Unique Index.');
return connection.schema.hasTable('migrations')
.then(function (exists) {
if (exists) {
return connection.schema.alterTable('migrations', function (table) {
table.unique(['name', 'version']);
}).catch(function () {
// @NOTE: ignore for now, it's not a urgent, required change
// e.g. index exists already (1061,1)
// e.g. can't index because of already existing duplicates
return Promise.resolve();
});
}
});
};