UNPKG

@clickup/pg-microsharding

Version:
39 lines 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.actionAllocate = actionAllocate; const allocate_1 = require("../api/allocate"); const isTrueValue_1 = require("../internal/isTrueValue"); const normalizeDsns_1 = require("../internal/normalizeDsns"); /** * Ensures that some shards exist. */ async function actionAllocate(args) { var _a, _b; const dsns = await (0, normalizeDsns_1.normalizeDsns)(args["dsns"] || args["dsn"]); if (dsns.length === 0) { throw "Please provide --dsn, DB DSN to allocate microshard(s) at"; } let from; let to; if ((_a = (args["shard"] || args["shards"])) === null || _a === void 0 ? void 0 : _a.match(/^(\d+)(?:(?:-|\.\.\.?)(\d+))?$/)) { from = parseInt(RegExp.$1, 10); to = parseInt(RegExp.$2 || String(from), 10); } else { throw "Please provide --shard=N or --shards=N-M, starting and ending microshard numbers"; } let migrateCmd; if (args["migrate-cmd"]) { migrateCmd = args["migrate-cmd"]; } else { throw "Please provide --migrate-cmd, shell command to run migrations in between microshards creation and activation"; } const activate = (0, isTrueValue_1.isTrueValue)((_b = args["activate"]) !== null && _b !== void 0 ? _b : ""); if (activate === undefined) { throw "Please provide --activate=yes or --activate=no"; } await (0, allocate_1.allocate)({ dsns, from, to, migrateCmd, activate }); return true; } //# sourceMappingURL=actionAllocate.js.map