UNPKG

@clickup/pg-microsharding

Version:
17 lines 955 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.changeTableOwners = changeTableOwners; const groupBy_1 = __importDefault(require("lodash/groupBy")); const quote_1 = require("./quote"); const runSql_1 = require("./runSql"); async function changeTableOwners({ toDsn, tables, comment, }) { if (tables.length === 0) { return; } const queries = Object.entries((0, groupBy_1.default)(tables, (table) => table.schema)).map(([schema, tables]) => (0, quote_1.join)(tables.map(({ name, owner }) => (0, quote_1.sql) `ALTER TABLE ONLY ${(0, quote_1.ident)(schema)}.${(0, quote_1.ident)(name)} OWNER TO ${(0, quote_1.ident)(owner)};`), " ")); await (0, runSql_1.runSql)(toDsn, (0, quote_1.join)(queries, "\n"), comment); } //# sourceMappingURL=changeTableOwners.js.map