@rebasepro/server-postgres 0.29.1 → 0.29.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BranchService-BIIBF5ZL.js → BranchService-CrXvcES2.js} +3 -3
- package/dist/{BranchService-BIIBF5ZL.js.map → BranchService-CrXvcES2.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +64 -4
- package/dist/PostgresBootstrapper.d.ts +27 -0
- package/dist/auth/ensure-tables.d.ts +2 -2
- package/dist/auth/schema-version.d.ts +5 -5
- package/dist/auth/services.d.ts +9 -9
- package/dist/{backup-cli-QcOpmRpQ.js → backup-cli-CTKCOLpX.js} +3 -3
- package/dist/{backup-cli-QcOpmRpQ.js.map → backup-cli-CTKCOLpX.js.map} +1 -1
- package/dist/{boot-ddl-BSNpEUOS.js → boot-ddl-CqGIwSYx.js} +2 -2
- package/dist/{boot-ddl-BSNpEUOS.js.map → boot-ddl-CqGIwSYx.js.map} +1 -1
- package/dist/{cli-console-DTsm96lW.js → cli-console-DBPw-oAz.js} +6 -6
- package/dist/{cli-console-DTsm96lW.js.map → cli-console-DBPw-oAz.js.map} +1 -1
- package/dist/{cli-errors-DwqFRIWz.js → cli-errors-DYTxnLbW.js} +5 -5
- package/dist/{cli-errors-DwqFRIWz.js.map → cli-errors-DYTxnLbW.js.map} +1 -1
- package/dist/cli.js +185 -49
- package/dist/cli.js.map +1 -1
- package/dist/{connection-COuS5Fm-.js → connection-C1zXTPJq.js} +7 -3
- package/dist/{connection-COuS5Fm-.js.map → connection-C1zXTPJq.js.map} +1 -1
- package/dist/data-transformer.d.ts +2 -2
- package/dist/database-health.d.ts +2 -1
- package/dist/{database-preflight-D5JtPt8i.js → database-preflight-iBpT7-vv.js} +36 -3
- package/dist/database-preflight-iBpT7-vv.js.map +1 -0
- package/dist/{databasePoolManager-7hXVurmG.js → databasePoolManager-DIjzlTK4.js} +2 -2
- package/dist/{databasePoolManager-7hXVurmG.js.map → databasePoolManager-DIjzlTK4.js.map} +1 -1
- package/dist/{deferred-index-build-B8feKnUj.js → deferred-index-build-BCU9RoHK.js} +18 -6
- package/dist/deferred-index-build-BCU9RoHK.js.map +1 -0
- package/dist/{doctor-BaR11xUe.js → doctor-Kg1oUK0Q.js} +11 -11
- package/dist/doctor-Kg1oUK0Q.js.map +1 -0
- package/dist/{ensure-collection-policies-85HiG-k1.js → ensure-collection-policies-Bo-_fDAy.js} +25 -15
- package/dist/ensure-collection-policies-Bo-_fDAy.js.map +1 -0
- package/dist/{ensure-collection-tables-DR_WcxLA.js → ensure-collection-tables-DCJINkT_.js} +11 -8
- package/dist/ensure-collection-tables-DCJINkT_.js.map +1 -0
- package/dist/{ensure-tables-Dh5UP_Zs.js → ensure-tables-BPGaGh0y.js} +4 -4
- package/dist/ensure-tables-BPGaGh0y.js.map +1 -0
- package/dist/{enum-labels-kept-DSU8lAnd.js → enum-labels-kept-YAgOZS4I.js} +3 -3
- package/dist/{enum-labels-kept-DSU8lAnd.js.map → enum-labels-kept-YAgOZS4I.js.map} +1 -1
- package/dist/{generate-drizzle-schema-5spbTyQ6.js → generate-drizzle-schema-DcrFr7YX.js} +2 -2
- package/dist/{generate-drizzle-schema-5spbTyQ6.js.map → generate-drizzle-schema-DcrFr7YX.js.map} +1 -1
- package/dist/{generate-drizzle-schema-logic-C5FB7Fpo.js → generate-drizzle-schema-logic-LTLZvt6r.js} +3 -3
- package/dist/{generate-drizzle-schema-logic-C5FB7Fpo.js.map → generate-drizzle-schema-logic-LTLZvt6r.js.map} +1 -1
- package/dist/{generate-files-Bl3_D_oP.js → generate-files-CsaVzatS.js} +3 -3
- package/dist/{generate-files-Bl3_D_oP.js.map → generate-files-CsaVzatS.js.map} +1 -1
- package/dist/{generate-postgres-ddl-logic-BC3JA93M.js → generate-postgres-ddl-logic-Dg0bcENZ.js} +45 -7
- package/dist/generate-postgres-ddl-logic-Dg0bcENZ.js.map +1 -0
- package/dist/{generated-schema-diff-Jm93vyJB.js → generated-schema-diff-By4dxyTH.js} +8 -5
- package/dist/generated-schema-diff-By4dxyTH.js.map +1 -0
- package/dist/history/HistoryService.d.ts +2 -3
- package/dist/history/ensure-history-table.d.ts +8 -3
- package/dist/index.es.js +15 -15
- package/dist/interfaces.d.ts +24 -2
- package/dist/{introspect-db-logic-DgQVzccW.js → introspect-db-logic-DWqAEURB.js} +7 -5
- package/dist/introspect-db-logic-DWqAEURB.js.map +1 -0
- package/dist/{migrate-baseline-BfHmq3vN.js → migrate-baseline-CmWXL7qx.js} +163 -502
- package/dist/migrate-baseline-CmWXL7qx.js.map +1 -0
- package/dist/{migrate-policy-stamps-B4k1ggma.js → migrate-policy-stamps-BN_Qad6c.js} +42 -13
- package/dist/migrate-policy-stamps-BN_Qad6c.js.map +1 -0
- package/dist/{open-rebase-CiO_sjMT.js → open-rebase-40paQfVW.js} +1401 -655
- package/dist/open-rebase-40paQfVW.js.map +1 -0
- package/dist/open-rebase.d.ts +1 -1
- package/dist/{pg-error-utils-D1Nc0UML.js → pg-error-utils-DJHjCF7-.js} +2 -2
- package/dist/{pg-error-utils-D1Nc0UML.js.map → pg-error-utils-DJHjCF7-.js.map} +1 -1
- package/dist/pipelined-transaction.d.ts +24 -37
- package/dist/{plan-schema-BYxOzflz.js → plan-schema-vJd3UEmT.js} +41 -11
- package/dist/plan-schema-vJd3UEmT.js.map +1 -0
- package/dist/{policy-drift-DKuTJHfc.js → policy-drift-C-m0uWHH.js} +78 -10
- package/dist/policy-drift-C-m0uWHH.js.map +1 -0
- package/dist/push-index-adoption-Cp7oZxSl.js +22 -0
- package/dist/push-index-adoption-Cp7oZxSl.js.map +1 -0
- package/dist/{push-index-prebuild-bqXimSZz.js → push-index-prebuild-DbwKGtQT.js} +4 -4
- package/dist/{push-index-prebuild-bqXimSZz.js.map → push-index-prebuild-DbwKGtQT.js.map} +1 -1
- package/dist/{push-kept-defaults-CN9R8cHf.js → push-kept-defaults-CLcgsEPt.js} +2 -2
- package/dist/{push-kept-defaults-CN9R8cHf.js.map → push-kept-defaults-CLcgsEPt.js.map} +1 -1
- package/dist/{push-legacy-renames-CU_UYPbz.js → push-legacy-renames-BthD0E9W.js} +4 -4
- package/dist/{push-legacy-renames-CU_UYPbz.js.map → push-legacy-renames-BthD0E9W.js.map} +1 -1
- package/dist/{push-policy-plan-JcyK94bc.js → push-policy-plan-BgcrroxQ.js} +14 -8
- package/dist/push-policy-plan-BgcrroxQ.js.map +1 -0
- package/dist/read-routing.d.ts +10 -30
- package/dist/{render-ddl-DCdVP-pQ.js → render-ddl-Ci3S_SoI.js} +34 -3
- package/dist/render-ddl-Ci3S_SoI.js.map +1 -0
- package/dist/{request-role-cli-DSdRtvgH.js → request-role-cli-Dy1EgJU9.js} +10 -10
- package/dist/{request-role-cli-DSdRtvgH.js.map → request-role-cli-Dy1EgJU9.js.map} +1 -1
- package/dist/{request-role-migration-D9BZ5Uba.js → request-role-migration-GHTJnPMV.js} +2 -2
- package/dist/{request-role-migration-D9BZ5Uba.js.map → request-role-migration-GHTJnPMV.js.map} +1 -1
- package/dist/rls-bootstrap-sql-kPX4-MB1.js +549 -0
- package/dist/rls-bootstrap-sql-kPX4-MB1.js.map +1 -0
- package/dist/{rls-enforcement-BO618rnr.js → rls-enforcement-Cc_UhOxb.js} +316 -10
- package/dist/rls-enforcement-Cc_UhOxb.js.map +1 -0
- package/dist/{rls-settings-De5NoHHy.js → rls-settings-BCGMIig3.js} +23 -3
- package/dist/rls-settings-BCGMIig3.js.map +1 -0
- package/dist/schema/doctor-cli.js +9 -9
- package/dist/schema/doctor-cli.js.map +1 -1
- package/dist/schema/drizzle-ddl.d.ts +2 -2
- package/dist/schema/ensure-collection-policies.d.ts +23 -3
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-postgres-ddl-logic.d.ts +14 -1
- package/dist/schema/generate-postgres-ddl.js +1 -1
- package/dist/schema/index-adoption.d.ts +99 -0
- package/dist/schema/introspect-db-logic.d.ts +2 -1
- package/dist/schema/introspect-db.js +3 -3
- package/dist/schema/migrate-policy-stamps.d.ts +19 -1
- package/dist/schema/plan/diff-plan.d.ts +8 -1
- package/dist/schema/plan/render-ddl.d.ts +7 -0
- package/dist/schema/plan/types.d.ts +15 -0
- package/dist/schema/push-index-adoption.d.ts +10 -0
- package/dist/schema/push-policy-plan.d.ts +5 -1
- package/dist/schema/rls-bootstrap-sql.d.ts +19 -2
- package/dist/schema/search-column.d.ts +2 -2
- package/dist/search-column-BM-GV6vH.js.map +1 -1
- package/dist/security/policy-drift.d.ts +31 -1
- package/dist/security/rls-enforcement.d.ts +118 -1
- package/dist/security/rls-settings.d.ts +33 -0
- package/dist/services/FetchService.d.ts +33 -8
- package/dist/services/PersistService.d.ts +75 -4
- package/dist/services/RelationService.d.ts +1 -1
- package/dist/services/channel-bus/PostgresChannelBus.d.ts +2 -2
- package/dist/services/channel-bus/index.d.ts +2 -2
- package/dist/services/channel-history.d.ts +2 -2
- package/dist/services/channel-presence.d.ts +3 -3
- package/dist/services/dataService.d.ts +6 -2
- package/dist/services/realtimeService.d.ts +18 -5
- package/dist/services/socket-liveness.d.ts +6 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/drizzle-conditions.d.ts +12 -0
- package/dist/utils/positional-params.d.ts +40 -0
- package/dist/{websocket-B33YjKhs.js → websocket-B7ex6AQM.js} +3 -3
- package/dist/websocket-B7ex6AQM.js.map +1 -0
- package/dist/websocket.d.ts +14 -3
- package/package.json +7 -7
- package/dist/database-preflight-D5JtPt8i.js.map +0 -1
- package/dist/deferred-index-build-B8feKnUj.js.map +0 -1
- package/dist/doctor-BaR11xUe.js.map +0 -1
- package/dist/ensure-collection-policies-85HiG-k1.js.map +0 -1
- package/dist/ensure-collection-tables-DR_WcxLA.js.map +0 -1
- package/dist/ensure-tables-Dh5UP_Zs.js.map +0 -1
- package/dist/generate-postgres-ddl-logic-BC3JA93M.js.map +0 -1
- package/dist/generated-schema-diff-Jm93vyJB.js.map +0 -1
- package/dist/introspect-db-logic-DgQVzccW.js.map +0 -1
- package/dist/migrate-baseline-BfHmq3vN.js.map +0 -1
- package/dist/migrate-policy-stamps-B4k1ggma.js.map +0 -1
- package/dist/open-rebase-CiO_sjMT.js.map +0 -1
- package/dist/plan-schema-BYxOzflz.js.map +0 -1
- package/dist/policy-drift-DKuTJHfc.js.map +0 -1
- package/dist/push-policy-plan-JcyK94bc.js.map +0 -1
- package/dist/render-ddl-DCdVP-pQ.js.map +0 -1
- package/dist/rls-enforcement-BO618rnr.js.map +0 -1
- package/dist/rls-settings-De5NoHHy.js.map +0 -1
- package/dist/websocket-B33YjKhs.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "module";
|
|
2
2
|
__createRequire(import.meta.url);
|
|
3
3
|
import { n as require_arg, o as __toESM, t as promptConfirm } from "./cli-prompt-DXG0yk-h.js";
|
|
4
|
-
import { $ as fromAlterTable, A as getTableExcludes, B as readVectorDdl, C as detectProjectPackageManager, D as ensureDevDatabaseExists, E as dropGeneratedColumns, F as queryColumnTypes, G as DESIRED_STATE_URL, H as resolveLocalBin, I as queryGeneratedColumnDependencies, J as prepareGeneratedSqlDir, K as GENERATED_SQL_DIR, L as queryUndeclarableConstraints, M as getUndeclaredConstraintExcludes, N as getVectorExcludes, O as getForeignIndexExcludes, P as loadCollectionsForCli, Q as extractPlanStatements, R as readSearchDdl, S as describeReinstallCommand, T as dropDevDatabase, U as withAppClient, V as readViewsDdl, W as workspaceMemberDir, X as destructiveOptInFlag, Y as decidePushSafety, Z as detectDestructiveStatements, _ as atlasDevDatabaseUrl, a as diagnoseDbError, b as describeBuildScriptRemedy, c as isEconnrefused, d as reportCommandFailure, et as isSyncedPlan, f as ExcludeIntrospectionError, g as applyViewsDdl, h as applyVectorDdl, i as diagnoseAtlasFailure, it as redactConnectionPasswords, j as getTriggerExcludes, k as getSearchExcludes, l as isSslNotEnabled, m as applyTriggersDdl, nt as forAtlas, o as formatForeignGeneratedColumnBanner, p as applySearchDdl, q as generatedSqlDir, s as isAuthFailure, t as checkDatabaseConnectivity, tt as warnIfYesApprovedDestructive, w as diagnoseMissingBin, x as describeDevAddCommand, y as closeAppClients, z as readTriggersDdl } from "./cli-errors-
|
|
4
|
+
import { $ as fromAlterTable, A as getTableExcludes, B as readVectorDdl, C as detectProjectPackageManager, D as ensureDevDatabaseExists, E as dropGeneratedColumns, F as queryColumnTypes, G as DESIRED_STATE_URL, H as resolveLocalBin, I as queryGeneratedColumnDependencies, J as prepareGeneratedSqlDir, K as GENERATED_SQL_DIR, L as queryUndeclarableConstraints, M as getUndeclaredConstraintExcludes, N as getVectorExcludes, O as getForeignIndexExcludes, P as loadCollectionsForCli, Q as extractPlanStatements, R as readSearchDdl, S as describeReinstallCommand, T as dropDevDatabase, U as withAppClient, V as readViewsDdl, W as workspaceMemberDir, X as destructiveOptInFlag, Y as decidePushSafety, Z as detectDestructiveStatements, _ as atlasDevDatabaseUrl, a as diagnoseDbError, b as describeBuildScriptRemedy, c as isEconnrefused, d as reportCommandFailure, et as isSyncedPlan, f as ExcludeIntrospectionError, g as applyViewsDdl, h as applyVectorDdl, i as diagnoseAtlasFailure, it as redactConnectionPasswords, j as getTriggerExcludes, k as getSearchExcludes, l as isSslNotEnabled, m as applyTriggersDdl, nt as forAtlas, o as formatForeignGeneratedColumnBanner, p as applySearchDdl, q as generatedSqlDir, s as isAuthFailure, t as checkDatabaseConnectivity, tt as warnIfYesApprovedDestructive, w as diagnoseMissingBin, x as describeDevAddCommand, y as closeAppClients, z as readTriggersDdl } from "./cli-errors-DYTxnLbW.js";
|
|
5
|
+
import { i as RLS_BOOTSTRAP_SQL, o as dropLegacyAuthSchema, r as REQUEST_ROLE_FUNCTION_SQL, t as ADMIN_POLICY_ROLE_SQL } from "./rls-bootstrap-sql-kPX4-MB1.js";
|
|
5
6
|
import { a as outWarn, i as outError, o as atlasExcludePattern, r as out, s as excludePatternParts, t as chalk } from "./source-fZb92pN8.js";
|
|
7
|
+
import { C as declaredIndexesIfNotExists, S as execa, b as parseDriverLine, c as isDriverDbSubcommand, d as branchNameIn, f as branchSourceIn, g as assertKnownFlags, i as latestRecordedMigration, l as backupActionOf, m as unexpectedBranchArgs, o as planBaseline, p as resolveBranchSwitches, r as describeBaselinePlan, s as DRIVER_DB_SUBCOMMANDS, t as baselineVersionProblem, v as collectionsPathIn, w as indexAdoptionStatement, x as resolveDriverSwitches } from "./migrate-baseline-CmWXL7qx.js";
|
|
6
8
|
import { t as nextStepAfterDbGenerate } from "./generate-next-step-DgK5BlBn.js";
|
|
7
|
-
import {
|
|
8
|
-
import { declaredRlsPolicyShape } from "@rebasepro/types";
|
|
9
|
+
import { REBASE_ADMIN_ROLE, declaredRlsPolicyShape } from "@rebasepro/types";
|
|
9
10
|
import { formatRelativeTime } from "@rebasepro/utils";
|
|
10
11
|
import path from "path";
|
|
11
12
|
import fs from "fs";
|
|
@@ -1126,6 +1127,8 @@ function planPrune(input, options = {}) {
|
|
|
1126
1127
|
* The RLS helpers a migration or a push creates ahead of the policies — with
|
|
1127
1128
|
* `rebase.is_request_role` for a project that declared
|
|
1128
1129
|
* `rls.policyTarget: "requestRole"`, whose every permissive policy calls it.
|
|
1130
|
+
* (`policies.sql` itself creates the `rebase_admin` role its server-or-admin
|
|
1131
|
+
* policies are written `TO` — `adminRolePreamble`.)
|
|
1129
1132
|
*/
|
|
1130
1133
|
var rlsBootstrapSql = () => declaredRlsPolicyShape().policyTarget === "requestRole" ? `${RLS_BOOTSTRAP_SQL}\n${REQUEST_ROLE_FUNCTION_SQL};\n` : RLS_BOOTSTRAP_SQL;
|
|
1131
1134
|
var __cliDirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -1214,7 +1217,7 @@ function generatesInProcess() {
|
|
|
1214
1217
|
async function generateInProcess(what, label, run) {
|
|
1215
1218
|
let generators;
|
|
1216
1219
|
try {
|
|
1217
|
-
generators = await import("./generate-files-
|
|
1220
|
+
generators = await import("./generate-files-CsaVzatS.js").then((n) => n.t);
|
|
1218
1221
|
} catch (err) {
|
|
1219
1222
|
outError(chalk.red(`✗ Failed to run ${what}: ${err instanceof Error ? err.message : String(err)}`));
|
|
1220
1223
|
process.exit(1);
|
|
@@ -1261,7 +1264,7 @@ async function runPluginCommand(args) {
|
|
|
1261
1264
|
else if (domain === "schema") await schemaCommand(subcommand, args);
|
|
1262
1265
|
else if (domain === "doctor") await doctorPluginCommand(args);
|
|
1263
1266
|
else if (domain === "console") {
|
|
1264
|
-
const { consoleCommand } = await import("./cli-console-
|
|
1267
|
+
const { consoleCommand } = await import("./cli-console-DBPw-oAz.js");
|
|
1265
1268
|
process.exitCode = await consoleCommand(args);
|
|
1266
1269
|
} else {
|
|
1267
1270
|
outError(chalk.red(`Unknown domain command: ${domain}`));
|
|
@@ -1341,6 +1344,25 @@ async function stripCarvedOutFromNewestMigration(collectionsPath) {
|
|
|
1341
1344
|
return !result.empty;
|
|
1342
1345
|
}
|
|
1343
1346
|
/**
|
|
1347
|
+
* The newest migration's declared indexes as `CREATE INDEX IF NOT EXISTS`, so
|
|
1348
|
+
* `rebase db migrate` can adopt an identical existing index under the declared
|
|
1349
|
+
* name before applying it (`adoptIdenticalIndexes`) and the statement then
|
|
1350
|
+
* finds it there. Re-hashes the directory when it rewrote anything.
|
|
1351
|
+
*/
|
|
1352
|
+
async function makeDeclaredIndexesAdoptable(collectionsPath) {
|
|
1353
|
+
const newest = listMigrationFiles().at(-1);
|
|
1354
|
+
if (!newest) return;
|
|
1355
|
+
const file = path.resolve(process.cwd(), "drizzle", "migrations", newest);
|
|
1356
|
+
const result = declaredIndexesIfNotExists(fs.readFileSync(file, "utf-8"));
|
|
1357
|
+
if (result.rewritten === 0) return;
|
|
1358
|
+
fs.writeFileSync(file, result.sql, "utf-8");
|
|
1359
|
+
await runAtlas("migrate", [
|
|
1360
|
+
"hash",
|
|
1361
|
+
"--dir",
|
|
1362
|
+
"file://drizzle/migrations"
|
|
1363
|
+
], collectionsPath);
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1344
1366
|
* One line per destructive statement, as `db push` prints them — shared by
|
|
1345
1367
|
* push, `db generate` and `db migrate --refuse-destructive`, so the three
|
|
1346
1368
|
* describe the same statement the same way.
|
|
@@ -1428,17 +1450,17 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1428
1450
|
return;
|
|
1429
1451
|
}
|
|
1430
1452
|
if (subcommand === "request-role") {
|
|
1431
|
-
const { requestRoleCommand } = await import("./request-role-cli-
|
|
1453
|
+
const { requestRoleCommand } = await import("./request-role-cli-Dy1EgJU9.js").then((n) => n.r);
|
|
1432
1454
|
await requestRoleCommand(rawArgs);
|
|
1433
1455
|
return;
|
|
1434
1456
|
}
|
|
1435
1457
|
if (subcommand === "provision") {
|
|
1436
|
-
const { provisionCommand } = await import("./request-role-cli-
|
|
1458
|
+
const { provisionCommand } = await import("./request-role-cli-Dy1EgJU9.js").then((n) => n.r);
|
|
1437
1459
|
await provisionCommand(rawArgs);
|
|
1438
1460
|
return;
|
|
1439
1461
|
}
|
|
1440
1462
|
if (subcommand === "backup" || subcommand === "restore" || subcommand === "backups") {
|
|
1441
|
-
const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-
|
|
1463
|
+
const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-CTKCOLpX.js").then((n) => n.t);
|
|
1442
1464
|
if (subcommand === "backup" && backupActionOf(rawArgs) === "list") await backupsCommand(rawArgs);
|
|
1443
1465
|
else if (subcommand === "backup") await backupCommand(rawArgs);
|
|
1444
1466
|
else if (subcommand === "restore") await restoreCommand(rawArgs);
|
|
@@ -1469,6 +1491,7 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1469
1491
|
], collectionsPath);
|
|
1470
1492
|
let wroteNewMigration = listMigrationFiles().length > migrationsBefore.length;
|
|
1471
1493
|
if (wroteNewMigration) wroteNewMigration = await stripCarvedOutFromNewestMigration(collectionsPath);
|
|
1494
|
+
if (wroteNewMigration) await makeDeclaredIndexesAdoptable(collectionsPath);
|
|
1472
1495
|
const newestWritten = wroteNewMigration ? listMigrationFiles().at(-1) : void 0;
|
|
1473
1496
|
if (newestWritten) await reportDestructiveMigration(fs.readFileSync(path.resolve(process.cwd(), "drizzle", "migrations", newestWritten), "utf-8"), newestWritten, process.env.DATABASE_URL);
|
|
1474
1497
|
const migrationsDir = path.resolve(process.cwd(), "drizzle", "migrations");
|
|
@@ -1485,7 +1508,7 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1485
1508
|
}
|
|
1486
1509
|
const searchContent = readSearchDdl();
|
|
1487
1510
|
if (searchContent) {
|
|
1488
|
-
const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-
|
|
1511
|
+
const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-Dg0bcENZ.js").then((n) => n.s);
|
|
1489
1512
|
const migrationConflicts = findGeneratedColumnConflicts(parseColumnMutations(migrationContent), searchColumnDependencies(await loadCollectionsForCli(collectionsPath)));
|
|
1490
1513
|
const preamble = migrationDropPreamble(migrationConflicts);
|
|
1491
1514
|
if (preamble) {
|
|
@@ -1563,6 +1586,7 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1563
1586
|
const databaseUrl = process.env.DATABASE_URL;
|
|
1564
1587
|
if (databaseUrl && !dryRun) await ensureAuthSchemaAndFunctions(databaseUrl);
|
|
1565
1588
|
if (databaseUrl) await renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun);
|
|
1589
|
+
if (databaseUrl) await adoptIdenticalIndexes(databaseUrl, collectionsPath, dryRun);
|
|
1566
1590
|
const prebuilt = databaseUrl ? await prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) : [];
|
|
1567
1591
|
if (databaseUrl) await keepDatabaseOwnedDefaults(databaseUrl, collectionsPath);
|
|
1568
1592
|
const plan = await runAtlas("schema", [
|
|
@@ -1711,9 +1735,9 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1711
1735
|
await applySearchDdl(databaseUrl);
|
|
1712
1736
|
await applyTriggersDdl(databaseUrl);
|
|
1713
1737
|
await applyViewsDdl(databaseUrl);
|
|
1738
|
+
await ensureRlsUserRole(databaseUrl);
|
|
1714
1739
|
await applyPolicies(databaseUrl, collectionsPath);
|
|
1715
1740
|
await reconcilePolicies(databaseUrl, collectionsPath);
|
|
1716
|
-
await ensureRlsUserRole(databaseUrl);
|
|
1717
1741
|
await retireLegacyAuthSchema(databaseUrl);
|
|
1718
1742
|
}
|
|
1719
1743
|
});
|
|
@@ -1744,7 +1768,10 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1744
1768
|
out(chalk.gray(` --refuse-destructive: ${extractPlanStatements(plan).length} pending statement(s), none destructive.`));
|
|
1745
1769
|
out("");
|
|
1746
1770
|
}
|
|
1747
|
-
if (databaseUrl)
|
|
1771
|
+
if (databaseUrl) {
|
|
1772
|
+
await ensureAuthSchemaAndFunctions(databaseUrl);
|
|
1773
|
+
if (collectionsPath) await adoptIdenticalIndexes(databaseUrl, collectionsPath, false);
|
|
1774
|
+
}
|
|
1748
1775
|
if (baseline && baselinePlan) {
|
|
1749
1776
|
out(chalk.gray(` ${describeBaselinePlan(baseline, baselinePlan)}`));
|
|
1750
1777
|
out("");
|
|
@@ -1759,8 +1786,11 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1759
1786
|
if (databaseUrl) {
|
|
1760
1787
|
await ensureRlsUserRole(databaseUrl);
|
|
1761
1788
|
await retireLegacyAuthSchema(databaseUrl);
|
|
1762
|
-
const
|
|
1763
|
-
await
|
|
1789
|
+
const adminRoleAvailable = await readAdminPoliciesLive(databaseUrl);
|
|
1790
|
+
if (!adminRoleAvailable) await moveAdminPoliciesToPublic(databaseUrl, collectionsPath);
|
|
1791
|
+
await dropStaleCompanions(databaseUrl, collectionsPath, adminRoleAvailable);
|
|
1792
|
+
const { stampMigratedPolicies } = await import("./migrate-policy-stamps-BN_Qad6c.js");
|
|
1793
|
+
await stampMigratedPolicies(databaseUrl, collectionsPath, adminRoleAvailable);
|
|
1764
1794
|
}
|
|
1765
1795
|
}
|
|
1766
1796
|
out("");
|
|
@@ -1787,8 +1817,8 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1787
1817
|
* no such column reads nothing.
|
|
1788
1818
|
*/
|
|
1789
1819
|
async function keepDatabaseOwnedDefaults(databaseUrl, collectionsPath) {
|
|
1790
|
-
const { loadCollections } = await import("./doctor-
|
|
1791
|
-
const { databaseOwnedDefaultColumns, readKeptDefaults, withKeptDefaults } = await import("./push-kept-defaults-
|
|
1820
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
1821
|
+
const { databaseOwnedDefaultColumns, readKeptDefaults, withKeptDefaults } = await import("./push-kept-defaults-CLcgsEPt.js");
|
|
1792
1822
|
const columns = databaseOwnedDefaultColumns(await loadCollections(path.resolve(process.cwd(), collectionsPath)));
|
|
1793
1823
|
if (columns.length === 0) return;
|
|
1794
1824
|
let kept;
|
|
@@ -1813,8 +1843,8 @@ async function keepDatabaseOwnedDefaults(databaseUrl, collectionsPath) {
|
|
|
1813
1843
|
async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
|
|
1814
1844
|
let renames;
|
|
1815
1845
|
try {
|
|
1816
|
-
const { loadCollections } = await import("./doctor-
|
|
1817
|
-
const { legacyForeignKeyRenames } = await import("./push-legacy-renames-
|
|
1846
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
1847
|
+
const { legacyForeignKeyRenames } = await import("./push-legacy-renames-BthD0E9W.js");
|
|
1818
1848
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1819
1849
|
renames = await withAppClient(databaseUrl, (client) => legacyForeignKeyRenames({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1820
1850
|
} catch {
|
|
@@ -1830,11 +1860,31 @@ async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
|
|
|
1830
1860
|
out(chalk.gray(" To keep an old name instead, name the column on the relation (`localKey`, or `through` on a many-to-many)."));
|
|
1831
1861
|
out("");
|
|
1832
1862
|
}
|
|
1863
|
+
/** Renames identical existing indexes to the declared ones' names, as boot does; a dry-run only names them. */
|
|
1864
|
+
async function adoptIdenticalIndexes(databaseUrl, collectionsPath, dryRun) {
|
|
1865
|
+
let adoptions;
|
|
1866
|
+
try {
|
|
1867
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
1868
|
+
const { pushIndexAdoptions } = await import("./push-index-adoption-Cp7oZxSl.js");
|
|
1869
|
+
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1870
|
+
adoptions = await withAppClient(databaseUrl, (client) => pushIndexAdoptions({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1871
|
+
} catch {
|
|
1872
|
+
return;
|
|
1873
|
+
}
|
|
1874
|
+
if (adoptions.length === 0) return;
|
|
1875
|
+
out(chalk.gray(dryRun ? ` ${adoptions.length} existing index(es) match a declared index; a push renames each to the declared name instead of` : ` Adopting ${adoptions.length} existing index(es) that match a declared index (renamed, not rebuilt):`));
|
|
1876
|
+
if (dryRun) out(chalk.gray(" building it again (the plan below still creates them, because nothing ran):"));
|
|
1877
|
+
for (const adoption of adoptions) out(chalk.gray(` ${adoption.schema}.${adoption.table}: "${adoption.from}" → "${adoption.to}"`));
|
|
1878
|
+
if (!dryRun) await withAppClient(databaseUrl, async (client) => {
|
|
1879
|
+
for (const adoption of adoptions) await client.query(indexAdoptionStatement(adoption));
|
|
1880
|
+
});
|
|
1881
|
+
out("");
|
|
1882
|
+
}
|
|
1833
1883
|
/** Names the enum labels the database keeps after the collections dropped them. See `schema/enum-labels-kept.ts`. */
|
|
1834
1884
|
async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
|
|
1835
1885
|
try {
|
|
1836
|
-
const { loadCollections } = await import("./doctor-
|
|
1837
|
-
const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-
|
|
1886
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
1887
|
+
const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-YAgOZS4I.js");
|
|
1838
1888
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1839
1889
|
const kept = await withAppClient(databaseUrl, (client) => keptEnumLabels({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1840
1890
|
if (kept.length > 0) outWarn(chalk.yellow(formatKeptEnumLabelsNotice(kept)));
|
|
@@ -1843,8 +1893,8 @@ async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
|
|
|
1843
1893
|
async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
|
|
1844
1894
|
let missing;
|
|
1845
1895
|
try {
|
|
1846
|
-
const { loadCollections } = await import("./doctor-
|
|
1847
|
-
const { missingForeignKeyIndexes } = await import("./push-index-prebuild-
|
|
1896
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
1897
|
+
const { missingForeignKeyIndexes } = await import("./push-index-prebuild-DbwKGtQT.js");
|
|
1848
1898
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1849
1899
|
missing = await withAppClient(databaseUrl, (client) => missingForeignKeyIndexes({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1850
1900
|
} catch {
|
|
@@ -1854,7 +1904,7 @@ async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
|
|
|
1854
1904
|
if (missing.length === 0 || dryRun) return names;
|
|
1855
1905
|
out(chalk.gray(` Building ${missing.length} foreign-key index(es) on existing tables first — CONCURRENTLY, so writes go on:`));
|
|
1856
1906
|
try {
|
|
1857
|
-
const { buildDeferredIndexes } = await import("./deferred-index-build-
|
|
1907
|
+
const { buildDeferredIndexes } = await import("./deferred-index-build-BCU9RoHK.js").then((n) => n.r);
|
|
1858
1908
|
const outcome = await withAppClient(databaseUrl, (client) => buildDeferredIndexes(async () => ({
|
|
1859
1909
|
dedicated: true,
|
|
1860
1910
|
query: async (text) => ({ rows: (await client.query(text)).rows }),
|
|
@@ -1902,10 +1952,10 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
|
|
|
1902
1952
|
let unsecured;
|
|
1903
1953
|
let userRole;
|
|
1904
1954
|
try {
|
|
1905
|
-
const { lockCollectionTables } = await import("./ensure-collection-policies-
|
|
1906
|
-
const { loadCollections } = await import("./doctor-
|
|
1907
|
-
const { readRecordedRequestRoles } = await import("./rls-enforcement-
|
|
1908
|
-
const { cliRlsSettings } = await import("./rls-settings-
|
|
1955
|
+
const { lockCollectionTables } = await import("./ensure-collection-policies-Bo-_fDAy.js");
|
|
1956
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
1957
|
+
const { readRecordedRequestRoles } = await import("./rls-enforcement-Cc_UhOxb.js").then((n) => n.y);
|
|
1958
|
+
const { cliRlsSettings } = await import("./rls-settings-BCGMIig3.js").then((n) => n.a);
|
|
1909
1959
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1910
1960
|
({unsecured, userRole} = await withAppClient(databaseUrl, async (client) => {
|
|
1911
1961
|
const runSql = async (text) => (await client.query(text)).rows;
|
|
@@ -1947,8 +1997,8 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
|
|
|
1947
1997
|
async function ensureAuthTables(databaseUrl, collectionsPath) {
|
|
1948
1998
|
try {
|
|
1949
1999
|
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
1950
|
-
const { ensureAuthTablesExist } = await import("./ensure-tables-
|
|
1951
|
-
const { loadCollections } = await import("./doctor-
|
|
2000
|
+
const { ensureAuthTablesExist } = await import("./ensure-tables-BPGaGh0y.js").then((n) => n.n);
|
|
2001
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
1952
2002
|
const authCollection = (await loadCollections(path.resolve(process.cwd(), collectionsPath))).find((c) => {
|
|
1953
2003
|
const a = c.auth;
|
|
1954
2004
|
return a === true || typeof a === "object" && a !== null && a.enabled === true;
|
|
@@ -1968,7 +2018,7 @@ async function ensureRlsUserRole(databaseUrl) {
|
|
|
1968
2018
|
const schemas = ["public", "rebase"];
|
|
1969
2019
|
let rls;
|
|
1970
2020
|
try {
|
|
1971
|
-
rls = await import("./rls-enforcement-
|
|
2021
|
+
rls = await import("./rls-enforcement-Cc_UhOxb.js").then((n) => n.y);
|
|
1972
2022
|
} catch (err) {
|
|
1973
2023
|
outError(chalk.red(`\n ✗ Could not load the RLS provisioning module: ${err instanceof Error ? err.message : String(err)}`));
|
|
1974
2024
|
return;
|
|
@@ -1982,7 +2032,7 @@ async function ensureRlsUserRole(databaseUrl) {
|
|
|
1982
2032
|
connectionRole = posture.role;
|
|
1983
2033
|
if (posture.privileged) {
|
|
1984
2034
|
const recorded = await rls.readRecordedRequestRoles(runSql);
|
|
1985
|
-
settings = (await import("./rls-settings-
|
|
2035
|
+
settings = (await import("./rls-settings-BCGMIig3.js").then((n) => n.a)).cliRlsSettings(recorded);
|
|
1986
2036
|
rls.assertRecordedRequestRoles(settings.roles, recorded, await rls.roleHoldsTableGrants(runSql, schemas));
|
|
1987
2037
|
if (recorded ? recorded.join(",") !== settings.roles.join(",") : settings.roles.join(",") !== rls.REBASE_USER_ROLE) await rls.recordRequestRoles(runSql, settings.roles);
|
|
1988
2038
|
for (const role of settings.roles) await rls.ensureAppRole(runSql, schemas, {
|
|
@@ -1990,6 +2040,7 @@ async function ensureRlsUserRole(databaseUrl) {
|
|
|
1990
2040
|
provisionRole: settings.provisionRole,
|
|
1991
2041
|
grants: settings.grants
|
|
1992
2042
|
});
|
|
2043
|
+
await rls.settleAdminSwitch(runSql, schemas, settings, { provision: true });
|
|
1993
2044
|
out(chalk.gray(` ✓ RLS role ${settings.roles.map((r) => `"${r}"`).join(", ")} provisioned/refreshed.`));
|
|
1994
2045
|
}
|
|
1995
2046
|
});
|
|
@@ -2022,8 +2073,13 @@ async function applyPolicies(databaseUrl, collectionsPath) {
|
|
|
2022
2073
|
if (!fs.existsSync(policiesPath)) return;
|
|
2023
2074
|
out(chalk.gray(" Step 3/3: Applying RLS policies to database..."));
|
|
2024
2075
|
out("");
|
|
2025
|
-
|
|
2026
|
-
const
|
|
2076
|
+
let policiesContent = fs.readFileSync(policiesPath, "utf-8");
|
|
2077
|
+
const adminRoleAvailable = policiesContent.includes(`"${REBASE_ADMIN_ROLE}"`) ? await readAdminPoliciesLive(databaseUrl) : true;
|
|
2078
|
+
if (!adminRoleAvailable) {
|
|
2079
|
+
out(chalk.gray(` The server-or-admin policies are written TO public: the admin request roles are not set up for this database (\`rebase doctor --database\` says what is missing). A server boot that sets them up moves them TO ${REBASE_ADMIN_ROLE}.`));
|
|
2080
|
+
policiesContent = (await policiesToPublic(collectionsPath, policiesContent)).split(`${ADMIN_POLICY_ROLE_SQL};`).join("");
|
|
2081
|
+
}
|
|
2082
|
+
const stamping = await policyStamping(databaseUrl, collectionsPath, policiesContent, adminRoleAvailable);
|
|
2027
2083
|
const { stampError } = await withAppClient(databaseUrl, (client) => applyPoliciesFile(client, policiesContent, stamping));
|
|
2028
2084
|
out(chalk.green(" ✓ RLS policies applied successfully."));
|
|
2029
2085
|
if (stampError) outWarn(chalk.yellow(` ⚠️ The policies could not be stamped (${stampError}); the next boot applies them again.`));
|
|
@@ -2035,18 +2091,93 @@ async function applyPolicies(databaseUrl, collectionsPath) {
|
|
|
2035
2091
|
}
|
|
2036
2092
|
}
|
|
2037
2093
|
/**
|
|
2094
|
+
* Whether the server-or-admin policies belong `TO rebase_admin` on this
|
|
2095
|
+
* database (`adminPoliciesLiveForCli`): the one answer the push writes, plans
|
|
2096
|
+
* and reconciles against, so its dry run and the next push agree with what it
|
|
2097
|
+
* wrote. Anything unreadable answers `false`, `TO public`.
|
|
2098
|
+
*
|
|
2099
|
+
* Judged on this connection. A push run as a different, privileged login can
|
|
2100
|
+
* see a switch the server's own login cannot use; that server's boot then
|
|
2101
|
+
* writes the policies `TO public` itself.
|
|
2102
|
+
*/
|
|
2103
|
+
async function readAdminPoliciesLive(databaseUrl) {
|
|
2104
|
+
try {
|
|
2105
|
+
const { adminPoliciesLiveForCli } = await import("./rls-enforcement-Cc_UhOxb.js").then((n) => n.y);
|
|
2106
|
+
return await withAppClient(databaseUrl, (client) => adminPoliciesLiveForCli(async (text) => (await client.query(text)).rows));
|
|
2107
|
+
} catch {
|
|
2108
|
+
return false;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
/**
|
|
2112
|
+
* After a migration: drop the admin-request companions no current rule earns
|
|
2113
|
+
* (`dropStaleAdminRequestCompanions`). Fatal when it fails — a stale one
|
|
2114
|
+
* admits every admin to every row, and a boot without provisioning never
|
|
2115
|
+
* takes it back.
|
|
2116
|
+
*/
|
|
2117
|
+
async function dropStaleCompanions(databaseUrl, collectionsPath, adminRoleAvailable) {
|
|
2118
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
2119
|
+
const { dropStaleAdminRequestCompanions } = await import("./policy-drift-C-m0uWHH.js").then((n) => n.s);
|
|
2120
|
+
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2121
|
+
try {
|
|
2122
|
+
const dropped = await withAppClient(databaseUrl, (client) => dropStaleAdminRequestCompanions(client, collections, { adminRoleAvailable }));
|
|
2123
|
+
for (const p of dropped) out(chalk.gray(` ✓ Dropped stale admin-request policy "${p.name}" on ${p.schema}.${p.table}`));
|
|
2124
|
+
} catch (err) {
|
|
2125
|
+
outError(chalk.red(` ✗ Could not drop stale admin-request policies: ${err instanceof Error ? err.message : String(err)}`));
|
|
2126
|
+
outError(chalk.gray(" A rule changed since they were written, and they still admit every admin to every row. Run `rebase db push`, or boot the server with provisioning on."));
|
|
2127
|
+
process.exit(1);
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* After a migration: the server-or-admin policies it wrote `TO rebase_admin`
|
|
2132
|
+
* go `TO public` where the admin switch is not live, as `applyPolicies` writes
|
|
2133
|
+
* them on a push. Fatal when it fails — those policies refuse every admin
|
|
2134
|
+
* caller, and a boot without provisioning would leave them so.
|
|
2135
|
+
*/
|
|
2136
|
+
async function moveAdminPoliciesToPublic(databaseUrl, collectionsPath) {
|
|
2137
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
2138
|
+
const { moveMigratedAdminPoliciesToPublic } = await import("./migrate-policy-stamps-BN_Qad6c.js");
|
|
2139
|
+
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2140
|
+
try {
|
|
2141
|
+
if (await withAppClient(databaseUrl, (client) => moveMigratedAdminPoliciesToPublic({ query: async (text, values) => ({ rows: (await client.query(text, values)).rows }) }, collections, (message) => outWarn(chalk.yellow(` ⚠️ ${message}`)))) > 0) out(chalk.gray(` The server-or-admin policies are written TO public: the admin request roles are not set up for this database (\`rebase doctor --database\` says what is missing). A server boot that sets them up moves them TO ${REBASE_ADMIN_ROLE}.`));
|
|
2142
|
+
} catch (err) {
|
|
2143
|
+
outError(chalk.red(` ✗ Could not write the server-or-admin policies TO public: ${err instanceof Error ? err.message : String(err)}`));
|
|
2144
|
+
outError(chalk.gray(` They are TO ${REBASE_ADMIN_ROLE}, which admin requests cannot use here, so admins read no rows. Run \`rebase db push\` or boot the server with provisioning on.`));
|
|
2145
|
+
process.exit(1);
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
/**
|
|
2038
2149
|
* The stamps a boot looks for, for the policies `policies.sql` is about to
|
|
2039
2150
|
* create — see `applyPoliciesFile`. None when the collections cannot be read
|
|
2040
2151
|
* here, which costs only the shortcut: the next boot re-applies, as before.
|
|
2041
2152
|
*/
|
|
2042
|
-
|
|
2153
|
+
/**
|
|
2154
|
+
* `policies.sql` with each policy the compiler wrote `TO rebase_admin`
|
|
2155
|
+
* rewritten `TO public` — statement for statement, from the two plans, so a
|
|
2156
|
+
* rule that names `rebase_admin` itself is left exactly as written.
|
|
2157
|
+
*/
|
|
2158
|
+
async function policiesToPublic(collectionsPath, policiesSql) {
|
|
2159
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
2160
|
+
const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-Dg0bcENZ.js").then((n) => n.s);
|
|
2161
|
+
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2162
|
+
const fallback = new Map(planCollectionPolicies(collections, { adminRoleAvailable: false }).flatMap((plan) => plan.policies.map((policy) => [`${plan.qualified}.${policy.name}`, policy.statements])));
|
|
2163
|
+
let sql = policiesSql;
|
|
2164
|
+
for (const plan of planCollectionPolicies(collections)) for (const policy of plan.policies) {
|
|
2165
|
+
if (!policy.adminTarget) continue;
|
|
2166
|
+
const replacement = fallback.get(`${plan.qualified}.${policy.name}`) ?? [];
|
|
2167
|
+
policy.statements.forEach((statement, i) => {
|
|
2168
|
+
if (replacement[i]) sql = sql.split(statement).join(replacement[i]);
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
return sql;
|
|
2172
|
+
}
|
|
2173
|
+
async function policyStamping(databaseUrl, collectionsPath, policiesSql, adminRoleAvailable = true) {
|
|
2043
2174
|
try {
|
|
2044
|
-
const { loadCollections } = await import("./doctor-
|
|
2045
|
-
const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-
|
|
2046
|
-
const { policyStampSql } = await import("./ensure-collection-policies-
|
|
2047
|
-
const { pinSearchPath } = await import("./connection-
|
|
2175
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
2176
|
+
const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-Dg0bcENZ.js").then((n) => n.s);
|
|
2177
|
+
const { policyStampSql } = await import("./ensure-collection-policies-Bo-_fDAy.js");
|
|
2178
|
+
const { pinSearchPath } = await import("./connection-C1zXTPJq.js").then((n) => n.r);
|
|
2048
2179
|
return {
|
|
2049
|
-
statements: stampableTables(planCollectionPolicies(await loadCollections(path.resolve(process.cwd(), collectionsPath))), policiesSql).map((plan) => policyStampSql(plan)).filter((statement) => statement !== void 0),
|
|
2180
|
+
statements: stampableTables(planCollectionPolicies(await loadCollections(path.resolve(process.cwd(), collectionsPath)), { adminRoleAvailable }), policiesSql).map((plan) => policyStampSql(plan)).filter((statement) => statement !== void 0),
|
|
2050
2181
|
searchPath: pinSearchPath(databaseUrl) === databaseUrl ? void 0 : "public"
|
|
2051
2182
|
};
|
|
2052
2183
|
} catch {
|
|
@@ -2061,11 +2192,15 @@ async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
|
|
|
2061
2192
|
*/
|
|
2062
2193
|
async function readPolicyPushPlan(databaseUrl, collectionsPath) {
|
|
2063
2194
|
try {
|
|
2064
|
-
const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-
|
|
2065
|
-
const { loadCollections } = await import("./doctor-
|
|
2066
|
-
const { pinSearchPath } = await import("./connection-
|
|
2195
|
+
const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-BgcrroxQ.js");
|
|
2196
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
2197
|
+
const { pinSearchPath } = await import("./connection-C1zXTPJq.js").then((n) => n.r);
|
|
2067
2198
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2068
|
-
const
|
|
2199
|
+
const adminRoleAvailable = await readAdminPoliciesLive(databaseUrl);
|
|
2200
|
+
const plan = await withAppClient(databaseUrl, (client) => planPolicyPush({ query: async (text, values) => ({ rows: (await client.query(text, values)).rows }) }, collections, {
|
|
2201
|
+
searchPath: pinSearchPath(databaseUrl) === databaseUrl ? void 0 : "public",
|
|
2202
|
+
adminRoleAvailable
|
|
2203
|
+
}));
|
|
2069
2204
|
return {
|
|
2070
2205
|
...formatPolicyPushPlan(plan),
|
|
2071
2206
|
summary: summarizePolicyPushPlan(plan)
|
|
@@ -2090,11 +2225,12 @@ async function readPolicyPushPlan(databaseUrl, collectionsPath) {
|
|
|
2090
2225
|
*/
|
|
2091
2226
|
async function reconcilePolicies(databaseUrl, collectionsPath) {
|
|
2092
2227
|
try {
|
|
2093
|
-
const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-
|
|
2094
|
-
const { loadCollections } = await import("./doctor-
|
|
2228
|
+
const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-C-m0uWHH.js").then((n) => n.s);
|
|
2229
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
2095
2230
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2231
|
+
const adminRoleAvailable = await readAdminPoliciesLive(databaseUrl);
|
|
2096
2232
|
await withAppClient(databaseUrl, async (client) => {
|
|
2097
|
-
const drift = await checkPolicyDrift(client, collections);
|
|
2233
|
+
const drift = await checkPolicyDrift(client, collections, { adminRoleAvailable });
|
|
2098
2234
|
const { dropped, kept } = await dropOrphanedPolicies(client, drift, collections);
|
|
2099
2235
|
for (const p of dropped) out(chalk.gray(` ✓ Dropped superseded policy "${p.name}" on ${p.schema}.${p.table}`));
|
|
2100
2236
|
if (dropped.length > 0) out(chalk.green(` ✓ Removed ${dropped.length} superseded RLS ${dropped.length === 1 ? "policy" : "policies"}.`));
|
|
@@ -2176,8 +2312,8 @@ async function branchCommand(rawArgs) {
|
|
|
2176
2312
|
outError(chalk.red("✗ DATABASE_URL is not set. Make sure your .env file is configured."));
|
|
2177
2313
|
process.exit(1);
|
|
2178
2314
|
}
|
|
2179
|
-
const { DatabasePoolManager } = await import("./databasePoolManager-
|
|
2180
|
-
const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-
|
|
2315
|
+
const { DatabasePoolManager } = await import("./databasePoolManager-DIjzlTK4.js").then((n) => n.n);
|
|
2316
|
+
const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-CrXvcES2.js").then((n) => n.n);
|
|
2181
2317
|
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
2182
2318
|
const { Pool } = await import("pg");
|
|
2183
2319
|
const healed = await reopenClosedDatabases(databaseUrl, [branchAction === "create" ? createSource(rawArgs) : void 0, process.env[ACTIVE_BRANCH_DATABASE_ENV]]);
|
|
@@ -2724,9 +2860,9 @@ async function schemaStaleCommand(rawArgs) {
|
|
|
2724
2860
|
const schemaFile = path.resolve(process.cwd(), outputPath);
|
|
2725
2861
|
const fix = Boolean(argsList["--fix"]);
|
|
2726
2862
|
const generatedExists = fs.existsSync(schemaFile);
|
|
2727
|
-
const { loadCollections } = await import("./doctor-
|
|
2863
|
+
const { loadCollections } = await import("./doctor-Kg1oUK0Q.js").then((n) => n.t);
|
|
2728
2864
|
const { findLegacyForeignKeyNames, compareGeneratedDeclarations, staleVerdict } = await import("./generated-schema-staleness-BvNF3i-s.js").then((n) => n.r);
|
|
2729
|
-
const { generateSchema } = await import("./generate-drizzle-schema-logic-
|
|
2865
|
+
const { generateSchema } = await import("./generate-drizzle-schema-logic-LTLZvt6r.js").then((n) => n.n);
|
|
2730
2866
|
const { relationalCollections } = await import("@rebasepro/common");
|
|
2731
2867
|
let stale = [];
|
|
2732
2868
|
let differences = [];
|