UNPKG

@clickup/pg-microsharding

Version:
49 lines 2.48 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.dsnFromToShort = exports.dsnShort = exports.libSchema = exports.schemaCleanupRe = exports.schemaNew = exports.schemaOld = exports.shardFactorToComment = exports.shardFactorFromComment = exports.shardNo = exports.psql = exports.pgDump = exports.subName = exports.pubName = void 0; const round_1 = __importDefault(require("lodash/round")); const quote_1 = require("./quote"); const pubName = (schema) => `pg_microsharding_move_${schema}_pub`; exports.pubName = pubName; const subName = (schema) => `pg_microsharding_move_${schema}_sub`; exports.subName = subName; const pgDump = (fromDsn) => `pg_dump --schema-only ${(0, quote_1.shellQuote)(fromDsn)}`; exports.pgDump = pgDump; const psql = (dsn) => `psql ${(0, quote_1.shellQuote)(dsn)} -vON_ERROR_STOP=on -At`; exports.psql = psql; const shardNo = (schema) => schema.match(/(\d+)/) ? parseInt(RegExp.$1) : null; exports.shardNo = shardNo; const shardFactorFromComment = (comment) => comment.match(/\bfactor\s*[=:]\s*(\d+(\.\d+)?)\b/) ? parseFloat(RegExp.$1) : null; exports.shardFactorFromComment = shardFactorFromComment; const shardFactorToComment = (factor) => Math.abs(factor - 1) < 0.001 || Math.abs(factor) < 0.001 ? "" : `factor=${(0, round_1.default)(factor, 3)}`; exports.shardFactorToComment = shardFactorToComment; const schemaOld = (schema, dateSuffix) => `${schema}old${dateSuffix}`; exports.schemaOld = schemaOld; const schemaNew = (schema) => `${schema}new`; exports.schemaNew = schemaNew; const schemaCleanupRe = (schemaNameRe) => `^(${schemaNameRe})(old_\\d+|old\\d*|new)$`; exports.schemaCleanupRe = schemaCleanupRe; const libSchema = () => (0, quote_1.ident)("microsharding"); exports.libSchema = libSchema; const dsnShort = (dsn) => { const url = new URL(dsn); return url.hostname + url.pathname; }; exports.dsnShort = dsnShort; const dsnFromToShort = (fromDsn, toDsn) => { const fromUrl = new URL(fromDsn); const toUrl = new URL(toDsn); const [fromStr, toStr] = fromUrl.hostname === toUrl.hostname ? [fromUrl.hostname + fromUrl.pathname, toUrl.hostname + toUrl.pathname] : [fromUrl.hostname, toUrl.hostname]; return `from ${fromStr} to ${toStr}`; }; exports.dsnFromToShort = dsnFromToShort; //# sourceMappingURL=names.js.map