2019-06-04 00:37:17 +02:00
|
|
|
const { getTableName } = require('./table-resolver');
|
|
|
|
const { ensureTable } = require('./table-creator');
|
2018-07-17 09:41:44 +02:00
|
|
|
|
|
|
|
// Lists all available migration versions, as a sorted array.
|
2019-06-04 00:37:17 +02:00
|
|
|
function listAll(migrationSource, loadExtensions) {
|
2018-09-12 19:58:37 +08:00
|
|
|
return migrationSource.getMigrations(loadExtensions);
|
2018-07-17 09:41:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lists all migrations that have been completed for the current db, as an
|
|
|
|
// array.
|
2020-05-05 19:10:50 +02:00
|
|
|
async function listCompleted(tableName, schemaName, trxOrKnex) {
|
|
|
|
await ensureTable(tableName, schemaName, trxOrKnex);
|
2021-10-27 22:42:36 +01:00
|
|
|
|
2021-12-01 00:41:18 +01:00
|
|
|
return await trxOrKnex
|
2020-05-05 19:10:50 +02:00
|
|
|
.from(getTableName(tableName, schemaName))
|
|
|
|
.orderBy('id')
|
|
|
|
.select('name');
|
2018-07-17 09:41:44 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 01:31:23 -05:00
|
|
|
// Gets the migration list from the migration directory specified in config, as well as
|
2018-07-17 09:41:44 +02:00
|
|
|
// the list of completed migrations to check what should be run.
|
2019-06-04 00:37:17 +02:00
|
|
|
function listAllAndCompleted(config, trxOrKnex) {
|
2020-02-26 00:50:24 +03:00
|
|
|
return Promise.all([
|
2019-03-09 17:39:55 -05:00
|
|
|
listAll(config.migrationSource, config.loadExtensions),
|
2018-07-17 09:41:44 +02:00
|
|
|
listCompleted(config.tableName, config.schemaName, trxOrKnex),
|
|
|
|
]);
|
|
|
|
}
|
2019-06-04 00:37:17 +02:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
listAll,
|
|
|
|
listAllAndCompleted,
|
|
|
|
listCompleted,
|
|
|
|
};
|