@clickup/pg-mig
Version:
PostgreSQL schema migration tool with microsharding and clustering support
33 lines • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractVars = extractVars;
/**
* Migration file may have variables in it to tune behavior of the migration.
* Format is: "-- $var_name=var_value" on any line of the file.
*/
const VALID_VARS = [
// Introduces a delay (in ms) between each migration. Use with
// $parallelism_global to reduce load on the db.
"$delay",
// Limit parallelism of this particular version across all hosts.
"$parallelism_global",
// Limit parallelism of this particular version locally on each host.
"$parallelism_per_host",
// If set, no other migrations (including other versions) will run on any
// other host while this one is running.
"$run_alone",
];
function extractVars(fileName, content) {
const pairs = [];
const regexIterator = /^--\s*(\$\w+)\s*=([^\r\n]+)[\r\n]*/gm;
while (regexIterator.exec(content)) {
pairs.push([RegExp.$1, RegExp.$2]);
}
return Object.fromEntries(pairs.map(([k, v]) => {
if (!VALID_VARS.includes(k)) {
throw `Unknown variable ${k} in ${fileName}`;
}
return [k, parseInt(v.trim())];
}));
}
//# sourceMappingURL=extractVars.js.map