@clickup/pg-mig
Version:
PostgreSQL schema migration tool with microsharding and clustering support
50 lines • 2.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.actionListDB = actionListDB;
const sortBy_1 = __importDefault(require("lodash/sortBy"));
const collapse_1 = require("../internal/helpers/collapse");
const DefaultMap_1 = require("../internal/helpers/DefaultMap");
const promiseAllMap_1 = require("../internal/helpers/promiseAllMap");
const render_1 = require("../internal/render");
/**
* Prints the list of migration versions applied in the database by querying
* mig_versions_const() on each schema. Groups schemas with identical version
* lists together for readability.
*/
async function actionListDB(_options, hostDests) {
// Groups schemas that share the same set of applied versions.
// Key is the JSON-serialized version list, value is the list of "host:schema" names.
// e.g. '["20260212173432.create_cred_data.sh"]' => ["127.0.0.1(1):sh0001", "127.0.0.1(1):sh0002"]
const versionsByGroup = new DefaultMap_1.DefaultMap();
await (0, promiseAllMap_1.promiseAllMap)(hostDests, async (dest) => {
const allSchemas = await dest.loadSchemas();
const versionsBySchema = await dest.loadVersionsBySchema(allSchemas);
for (const [schema, versions] of versionsBySchema) {
const key = JSON.stringify(versions);
versionsByGroup
.getOrAdd(key, [])
.push(dest.getName("short") + ":" + schema);
}
});
if (versionsByGroup.size === 0) {
(0, render_1.printText)("No schemas found in the database.");
return true;
}
for (const [key, dests] of (0, sortBy_1.default)(Array.from(versionsByGroup), ([key]) => key)) {
const versions = JSON.parse(key);
(0, render_1.printText)(`\n${(0, collapse_1.collapse)(dests)}:`);
if (versions.length === 0) {
(0, render_1.printText)(" <no versions>");
}
else {
for (const version of versions) {
(0, render_1.printText)(` > ${version}`);
}
}
}
return true;
}
//# sourceMappingURL=actionListDB.js.map