@rebasepro/server-postgres 0.29.1 → 0.29.2
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-X9R505mP.js} +3 -3
- package/dist/{BranchService-BIIBF5ZL.js.map → BranchService-X9R505mP.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +64 -4
- package/dist/PostgresBootstrapper.d.ts +20 -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-CwiJEp_J.js} +3 -3
- package/dist/{backup-cli-QcOpmRpQ.js.map → backup-cli-CwiJEp_J.js.map} +1 -1
- package/dist/{boot-ddl-BSNpEUOS.js → boot-ddl-CbZj9ovZ.js} +2 -2
- package/dist/{boot-ddl-BSNpEUOS.js.map → boot-ddl-CbZj9ovZ.js.map} +1 -1
- package/dist/{cli-console-DTsm96lW.js → cli-console-DDkNetCz.js} +6 -6
- package/dist/{cli-console-DTsm96lW.js.map → cli-console-DDkNetCz.js.map} +1 -1
- package/dist/{cli-errors-DwqFRIWz.js → cli-errors-C73Qy7WJ.js} +5 -5
- package/dist/{cli-errors-DwqFRIWz.js.map → cli-errors-C73Qy7WJ.js.map} +1 -1
- package/dist/cli.js +165 -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-DIauc8i5.js} +36 -3
- package/dist/database-preflight-DIauc8i5.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-DDdnjaOW.js} +18 -6
- package/dist/deferred-index-build-DDdnjaOW.js.map +1 -0
- package/dist/{doctor-BaR11xUe.js → doctor-DwMXljiq.js} +11 -11
- package/dist/doctor-DwMXljiq.js.map +1 -0
- package/dist/{ensure-collection-policies-85HiG-k1.js → ensure-collection-policies-DJsOMpaI.js} +23 -13
- package/dist/ensure-collection-policies-DJsOMpaI.js.map +1 -0
- package/dist/{ensure-collection-tables-DR_WcxLA.js → ensure-collection-tables-h1mUO7Uu.js} +11 -8
- package/dist/ensure-collection-tables-h1mUO7Uu.js.map +1 -0
- package/dist/{ensure-tables-Dh5UP_Zs.js → ensure-tables-CUqYgMvo.js} +4 -4
- package/dist/ensure-tables-CUqYgMvo.js.map +1 -0
- package/dist/{enum-labels-kept-DSU8lAnd.js → enum-labels-kept-z7ustOl_.js} +3 -3
- package/dist/{enum-labels-kept-DSU8lAnd.js.map → enum-labels-kept-z7ustOl_.js.map} +1 -1
- package/dist/{generate-drizzle-schema-5spbTyQ6.js → generate-drizzle-schema-BIUqhSzh.js} +2 -2
- package/dist/{generate-drizzle-schema-5spbTyQ6.js.map → generate-drizzle-schema-BIUqhSzh.js.map} +1 -1
- package/dist/{generate-drizzle-schema-logic-C5FB7Fpo.js → generate-drizzle-schema-logic-BBXjxm5z.js} +3 -3
- package/dist/{generate-drizzle-schema-logic-C5FB7Fpo.js.map → generate-drizzle-schema-logic-BBXjxm5z.js.map} +1 -1
- package/dist/{generate-files-Bl3_D_oP.js → generate-files-BkiRFoV1.js} +3 -3
- package/dist/{generate-files-Bl3_D_oP.js.map → generate-files-BkiRFoV1.js.map} +1 -1
- package/dist/{generate-postgres-ddl-logic-BC3JA93M.js → generate-postgres-ddl-logic-G9PvjHrr.js} +10 -5
- package/dist/{generate-postgres-ddl-logic-BC3JA93M.js.map → generate-postgres-ddl-logic-G9PvjHrr.js.map} +1 -1
- package/dist/{generated-schema-diff-Jm93vyJB.js → generated-schema-diff-D2soazQU.js} +8 -5
- package/dist/generated-schema-diff-D2soazQU.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-CveNQli3.js} +163 -502
- package/dist/migrate-baseline-CveNQli3.js.map +1 -0
- package/dist/{migrate-policy-stamps-B4k1ggma.js → migrate-policy-stamps-C4qbQ0jK.js} +42 -13
- package/dist/migrate-policy-stamps-C4qbQ0jK.js.map +1 -0
- package/dist/{open-rebase-CiO_sjMT.js → open-rebase-Cvid3iwR.js} +1395 -656
- package/dist/open-rebase-Cvid3iwR.js.map +1 -0
- package/dist/open-rebase.d.ts +1 -1
- package/dist/{pg-error-utils-D1Nc0UML.js → pg-error-utils-80uTIHQs.js} +2 -2
- package/dist/{pg-error-utils-D1Nc0UML.js.map → pg-error-utils-80uTIHQs.js.map} +1 -1
- package/dist/pipelined-transaction.d.ts +24 -37
- package/dist/{plan-schema-BYxOzflz.js → plan-schema-CMhNYEYF.js} +21 -6
- package/dist/plan-schema-CMhNYEYF.js.map +1 -0
- package/dist/{policy-drift-DKuTJHfc.js → policy-drift-Bx6663KD.js} +29 -6
- package/dist/policy-drift-Bx6663KD.js.map +1 -0
- package/dist/push-index-adoption-C-TpM445.js +22 -0
- package/dist/push-index-adoption-C-TpM445.js.map +1 -0
- package/dist/{push-index-prebuild-bqXimSZz.js → push-index-prebuild-xbpgZEJK.js} +4 -4
- package/dist/{push-index-prebuild-bqXimSZz.js.map → push-index-prebuild-xbpgZEJK.js.map} +1 -1
- package/dist/{push-kept-defaults-CN9R8cHf.js → push-kept-defaults-D-JEv0Gn.js} +2 -2
- package/dist/{push-kept-defaults-CN9R8cHf.js.map → push-kept-defaults-D-JEv0Gn.js.map} +1 -1
- package/dist/{push-legacy-renames-CU_UYPbz.js → push-legacy-renames-7UKspspl.js} +4 -4
- package/dist/{push-legacy-renames-CU_UYPbz.js.map → push-legacy-renames-7UKspspl.js.map} +1 -1
- package/dist/{push-policy-plan-JcyK94bc.js → push-policy-plan-BOw5PtU8.js} +14 -8
- package/dist/push-policy-plan-BOw5PtU8.js.map +1 -0
- package/dist/read-routing.d.ts +10 -30
- package/dist/{render-ddl-DCdVP-pQ.js → render-ddl-Di-fTGti.js} +15 -2
- package/dist/render-ddl-Di-fTGti.js.map +1 -0
- package/dist/{request-role-cli-DSdRtvgH.js → request-role-cli-Bxxskru9.js} +10 -10
- package/dist/{request-role-cli-DSdRtvgH.js.map → request-role-cli-Bxxskru9.js.map} +1 -1
- package/dist/{request-role-migration-D9BZ5Uba.js → request-role-migration-BCW4v0rq.js} +2 -2
- package/dist/{request-role-migration-D9BZ5Uba.js.map → request-role-migration-BCW4v0rq.js.map} +1 -1
- package/dist/rls-bootstrap-sql-CxszeSc7.js +534 -0
- package/dist/rls-bootstrap-sql-CxszeSc7.js.map +1 -0
- package/dist/{rls-enforcement-BO618rnr.js → rls-enforcement-CyUCPDH8.js} +213 -10
- package/dist/rls-enforcement-CyUCPDH8.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 +15 -3
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-postgres-ddl-logic.d.ts +5 -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 +2 -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 +13 -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 +19 -1
- package/dist/security/rls-enforcement.d.ts +87 -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-BSYV_KSw.js} +3 -3
- package/dist/websocket-BSYV_KSw.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/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-C73Qy7WJ.js";
|
|
5
|
+
import { a as dropLegacyAuthSchema, n as REQUEST_ROLE_FUNCTION_SQL, r as RLS_BOOTSTRAP_SQL, t as ADMIN_POLICY_ROLE_SQL } from "./rls-bootstrap-sql-CxszeSc7.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-CveNQli3.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-BkiRFoV1.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-DDkNetCz.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-Bxxskru9.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-Bxxskru9.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-CwiJEp_J.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-G9PvjHrr.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,10 @@ 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
|
+
const { stampMigratedPolicies } = await import("./migrate-policy-stamps-C4qbQ0jK.js");
|
|
1792
|
+
await stampMigratedPolicies(databaseUrl, collectionsPath, adminRoleAvailable);
|
|
1764
1793
|
}
|
|
1765
1794
|
}
|
|
1766
1795
|
out("");
|
|
@@ -1787,8 +1816,8 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1787
1816
|
* no such column reads nothing.
|
|
1788
1817
|
*/
|
|
1789
1818
|
async function keepDatabaseOwnedDefaults(databaseUrl, collectionsPath) {
|
|
1790
|
-
const { loadCollections } = await import("./doctor-
|
|
1791
|
-
const { databaseOwnedDefaultColumns, readKeptDefaults, withKeptDefaults } = await import("./push-kept-defaults-
|
|
1819
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
1820
|
+
const { databaseOwnedDefaultColumns, readKeptDefaults, withKeptDefaults } = await import("./push-kept-defaults-D-JEv0Gn.js");
|
|
1792
1821
|
const columns = databaseOwnedDefaultColumns(await loadCollections(path.resolve(process.cwd(), collectionsPath)));
|
|
1793
1822
|
if (columns.length === 0) return;
|
|
1794
1823
|
let kept;
|
|
@@ -1813,8 +1842,8 @@ async function keepDatabaseOwnedDefaults(databaseUrl, collectionsPath) {
|
|
|
1813
1842
|
async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
|
|
1814
1843
|
let renames;
|
|
1815
1844
|
try {
|
|
1816
|
-
const { loadCollections } = await import("./doctor-
|
|
1817
|
-
const { legacyForeignKeyRenames } = await import("./push-legacy-renames-
|
|
1845
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
1846
|
+
const { legacyForeignKeyRenames } = await import("./push-legacy-renames-7UKspspl.js");
|
|
1818
1847
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1819
1848
|
renames = await withAppClient(databaseUrl, (client) => legacyForeignKeyRenames({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1820
1849
|
} catch {
|
|
@@ -1830,11 +1859,31 @@ async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
|
|
|
1830
1859
|
out(chalk.gray(" To keep an old name instead, name the column on the relation (`localKey`, or `through` on a many-to-many)."));
|
|
1831
1860
|
out("");
|
|
1832
1861
|
}
|
|
1862
|
+
/** Renames identical existing indexes to the declared ones' names, as boot does; a dry-run only names them. */
|
|
1863
|
+
async function adoptIdenticalIndexes(databaseUrl, collectionsPath, dryRun) {
|
|
1864
|
+
let adoptions;
|
|
1865
|
+
try {
|
|
1866
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
1867
|
+
const { pushIndexAdoptions } = await import("./push-index-adoption-C-TpM445.js");
|
|
1868
|
+
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1869
|
+
adoptions = await withAppClient(databaseUrl, (client) => pushIndexAdoptions({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1870
|
+
} catch {
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
if (adoptions.length === 0) return;
|
|
1874
|
+
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):`));
|
|
1875
|
+
if (dryRun) out(chalk.gray(" building it again (the plan below still creates them, because nothing ran):"));
|
|
1876
|
+
for (const adoption of adoptions) out(chalk.gray(` ${adoption.schema}.${adoption.table}: "${adoption.from}" → "${adoption.to}"`));
|
|
1877
|
+
if (!dryRun) await withAppClient(databaseUrl, async (client) => {
|
|
1878
|
+
for (const adoption of adoptions) await client.query(indexAdoptionStatement(adoption));
|
|
1879
|
+
});
|
|
1880
|
+
out("");
|
|
1881
|
+
}
|
|
1833
1882
|
/** Names the enum labels the database keeps after the collections dropped them. See `schema/enum-labels-kept.ts`. */
|
|
1834
1883
|
async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
|
|
1835
1884
|
try {
|
|
1836
|
-
const { loadCollections } = await import("./doctor-
|
|
1837
|
-
const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-
|
|
1885
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
1886
|
+
const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-z7ustOl_.js");
|
|
1838
1887
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1839
1888
|
const kept = await withAppClient(databaseUrl, (client) => keptEnumLabels({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1840
1889
|
if (kept.length > 0) outWarn(chalk.yellow(formatKeptEnumLabelsNotice(kept)));
|
|
@@ -1843,8 +1892,8 @@ async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
|
|
|
1843
1892
|
async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
|
|
1844
1893
|
let missing;
|
|
1845
1894
|
try {
|
|
1846
|
-
const { loadCollections } = await import("./doctor-
|
|
1847
|
-
const { missingForeignKeyIndexes } = await import("./push-index-prebuild-
|
|
1895
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
1896
|
+
const { missingForeignKeyIndexes } = await import("./push-index-prebuild-xbpgZEJK.js");
|
|
1848
1897
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1849
1898
|
missing = await withAppClient(databaseUrl, (client) => missingForeignKeyIndexes({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1850
1899
|
} catch {
|
|
@@ -1854,7 +1903,7 @@ async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
|
|
|
1854
1903
|
if (missing.length === 0 || dryRun) return names;
|
|
1855
1904
|
out(chalk.gray(` Building ${missing.length} foreign-key index(es) on existing tables first — CONCURRENTLY, so writes go on:`));
|
|
1856
1905
|
try {
|
|
1857
|
-
const { buildDeferredIndexes } = await import("./deferred-index-build-
|
|
1906
|
+
const { buildDeferredIndexes } = await import("./deferred-index-build-DDdnjaOW.js").then((n) => n.r);
|
|
1858
1907
|
const outcome = await withAppClient(databaseUrl, (client) => buildDeferredIndexes(async () => ({
|
|
1859
1908
|
dedicated: true,
|
|
1860
1909
|
query: async (text) => ({ rows: (await client.query(text)).rows }),
|
|
@@ -1902,10 +1951,10 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
|
|
|
1902
1951
|
let unsecured;
|
|
1903
1952
|
let userRole;
|
|
1904
1953
|
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-
|
|
1954
|
+
const { lockCollectionTables } = await import("./ensure-collection-policies-DJsOMpaI.js");
|
|
1955
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
1956
|
+
const { readRecordedRequestRoles } = await import("./rls-enforcement-CyUCPDH8.js").then((n) => n.y);
|
|
1957
|
+
const { cliRlsSettings } = await import("./rls-settings-BCGMIig3.js").then((n) => n.a);
|
|
1909
1958
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1910
1959
|
({unsecured, userRole} = await withAppClient(databaseUrl, async (client) => {
|
|
1911
1960
|
const runSql = async (text) => (await client.query(text)).rows;
|
|
@@ -1947,8 +1996,8 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
|
|
|
1947
1996
|
async function ensureAuthTables(databaseUrl, collectionsPath) {
|
|
1948
1997
|
try {
|
|
1949
1998
|
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
1950
|
-
const { ensureAuthTablesExist } = await import("./ensure-tables-
|
|
1951
|
-
const { loadCollections } = await import("./doctor-
|
|
1999
|
+
const { ensureAuthTablesExist } = await import("./ensure-tables-CUqYgMvo.js").then((n) => n.n);
|
|
2000
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
1952
2001
|
const authCollection = (await loadCollections(path.resolve(process.cwd(), collectionsPath))).find((c) => {
|
|
1953
2002
|
const a = c.auth;
|
|
1954
2003
|
return a === true || typeof a === "object" && a !== null && a.enabled === true;
|
|
@@ -1968,7 +2017,7 @@ async function ensureRlsUserRole(databaseUrl) {
|
|
|
1968
2017
|
const schemas = ["public", "rebase"];
|
|
1969
2018
|
let rls;
|
|
1970
2019
|
try {
|
|
1971
|
-
rls = await import("./rls-enforcement-
|
|
2020
|
+
rls = await import("./rls-enforcement-CyUCPDH8.js").then((n) => n.y);
|
|
1972
2021
|
} catch (err) {
|
|
1973
2022
|
outError(chalk.red(`\n ✗ Could not load the RLS provisioning module: ${err instanceof Error ? err.message : String(err)}`));
|
|
1974
2023
|
return;
|
|
@@ -1982,7 +2031,7 @@ async function ensureRlsUserRole(databaseUrl) {
|
|
|
1982
2031
|
connectionRole = posture.role;
|
|
1983
2032
|
if (posture.privileged) {
|
|
1984
2033
|
const recorded = await rls.readRecordedRequestRoles(runSql);
|
|
1985
|
-
settings = (await import("./rls-settings-
|
|
2034
|
+
settings = (await import("./rls-settings-BCGMIig3.js").then((n) => n.a)).cliRlsSettings(recorded);
|
|
1986
2035
|
rls.assertRecordedRequestRoles(settings.roles, recorded, await rls.roleHoldsTableGrants(runSql, schemas));
|
|
1987
2036
|
if (recorded ? recorded.join(",") !== settings.roles.join(",") : settings.roles.join(",") !== rls.REBASE_USER_ROLE) await rls.recordRequestRoles(runSql, settings.roles);
|
|
1988
2037
|
for (const role of settings.roles) await rls.ensureAppRole(runSql, schemas, {
|
|
@@ -1990,6 +2039,7 @@ async function ensureRlsUserRole(databaseUrl) {
|
|
|
1990
2039
|
provisionRole: settings.provisionRole,
|
|
1991
2040
|
grants: settings.grants
|
|
1992
2041
|
});
|
|
2042
|
+
await rls.settleAdminSwitch(runSql, schemas, settings, { provision: true });
|
|
1993
2043
|
out(chalk.gray(` ✓ RLS role ${settings.roles.map((r) => `"${r}"`).join(", ")} provisioned/refreshed.`));
|
|
1994
2044
|
}
|
|
1995
2045
|
});
|
|
@@ -2022,8 +2072,13 @@ async function applyPolicies(databaseUrl, collectionsPath) {
|
|
|
2022
2072
|
if (!fs.existsSync(policiesPath)) return;
|
|
2023
2073
|
out(chalk.gray(" Step 3/3: Applying RLS policies to database..."));
|
|
2024
2074
|
out("");
|
|
2025
|
-
|
|
2026
|
-
const
|
|
2075
|
+
let policiesContent = fs.readFileSync(policiesPath, "utf-8");
|
|
2076
|
+
const adminRoleAvailable = policiesContent.includes(`"${REBASE_ADMIN_ROLE}"`) ? await readAdminPoliciesLive(databaseUrl) : true;
|
|
2077
|
+
if (!adminRoleAvailable) {
|
|
2078
|
+
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}.`));
|
|
2079
|
+
policiesContent = (await policiesToPublic(collectionsPath, policiesContent)).split(`${ADMIN_POLICY_ROLE_SQL};`).join("");
|
|
2080
|
+
}
|
|
2081
|
+
const stamping = await policyStamping(databaseUrl, collectionsPath, policiesContent, adminRoleAvailable);
|
|
2027
2082
|
const { stampError } = await withAppClient(databaseUrl, (client) => applyPoliciesFile(client, policiesContent, stamping));
|
|
2028
2083
|
out(chalk.green(" ✓ RLS policies applied successfully."));
|
|
2029
2084
|
if (stampError) outWarn(chalk.yellow(` ⚠️ The policies could not be stamped (${stampError}); the next boot applies them again.`));
|
|
@@ -2035,18 +2090,74 @@ async function applyPolicies(databaseUrl, collectionsPath) {
|
|
|
2035
2090
|
}
|
|
2036
2091
|
}
|
|
2037
2092
|
/**
|
|
2093
|
+
* Whether the server-or-admin policies belong `TO rebase_admin` on this
|
|
2094
|
+
* database (`adminPoliciesLiveForCli`): the one answer the push writes, plans
|
|
2095
|
+
* and reconciles against, so its dry run and the next push agree with what it
|
|
2096
|
+
* wrote. Anything unreadable answers `false`, `TO public`.
|
|
2097
|
+
*
|
|
2098
|
+
* Judged on this connection. A push run as a different, privileged login can
|
|
2099
|
+
* see a switch the server's own login cannot use; that server's boot then
|
|
2100
|
+
* writes the policies `TO public` itself.
|
|
2101
|
+
*/
|
|
2102
|
+
async function readAdminPoliciesLive(databaseUrl) {
|
|
2103
|
+
try {
|
|
2104
|
+
const { adminPoliciesLiveForCli } = await import("./rls-enforcement-CyUCPDH8.js").then((n) => n.y);
|
|
2105
|
+
return await withAppClient(databaseUrl, (client) => adminPoliciesLiveForCli(async (text) => (await client.query(text)).rows));
|
|
2106
|
+
} catch {
|
|
2107
|
+
return false;
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
/**
|
|
2111
|
+
* After a migration: the server-or-admin policies it wrote `TO rebase_admin`
|
|
2112
|
+
* go `TO public` where the admin switch is not live, as `applyPolicies` writes
|
|
2113
|
+
* them on a push. Fatal when it fails — those policies refuse every admin
|
|
2114
|
+
* caller, and a boot without provisioning would leave them so.
|
|
2115
|
+
*/
|
|
2116
|
+
async function moveAdminPoliciesToPublic(databaseUrl, collectionsPath) {
|
|
2117
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
2118
|
+
const { moveMigratedAdminPoliciesToPublic } = await import("./migrate-policy-stamps-C4qbQ0jK.js");
|
|
2119
|
+
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2120
|
+
try {
|
|
2121
|
+
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}.`));
|
|
2122
|
+
} catch (err) {
|
|
2123
|
+
outError(chalk.red(` ✗ Could not write the server-or-admin policies TO public: ${err instanceof Error ? err.message : String(err)}`));
|
|
2124
|
+
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.`));
|
|
2125
|
+
process.exit(1);
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
/**
|
|
2038
2129
|
* The stamps a boot looks for, for the policies `policies.sql` is about to
|
|
2039
2130
|
* create — see `applyPoliciesFile`. None when the collections cannot be read
|
|
2040
2131
|
* here, which costs only the shortcut: the next boot re-applies, as before.
|
|
2041
2132
|
*/
|
|
2042
|
-
|
|
2133
|
+
/**
|
|
2134
|
+
* `policies.sql` with each policy the compiler wrote `TO rebase_admin`
|
|
2135
|
+
* rewritten `TO public` — statement for statement, from the two plans, so a
|
|
2136
|
+
* rule that names `rebase_admin` itself is left exactly as written.
|
|
2137
|
+
*/
|
|
2138
|
+
async function policiesToPublic(collectionsPath, policiesSql) {
|
|
2139
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
2140
|
+
const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-G9PvjHrr.js").then((n) => n.s);
|
|
2141
|
+
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2142
|
+
const fallback = new Map(planCollectionPolicies(collections, { adminRoleAvailable: false }).flatMap((plan) => plan.policies.map((policy) => [`${plan.qualified}.${policy.name}`, policy.statements])));
|
|
2143
|
+
let sql = policiesSql;
|
|
2144
|
+
for (const plan of planCollectionPolicies(collections)) for (const policy of plan.policies) {
|
|
2145
|
+
if (!policy.adminTarget) continue;
|
|
2146
|
+
const replacement = fallback.get(`${plan.qualified}.${policy.name}`) ?? [];
|
|
2147
|
+
policy.statements.forEach((statement, i) => {
|
|
2148
|
+
if (replacement[i]) sql = sql.split(statement).join(replacement[i]);
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
return sql;
|
|
2152
|
+
}
|
|
2153
|
+
async function policyStamping(databaseUrl, collectionsPath, policiesSql, adminRoleAvailable = true) {
|
|
2043
2154
|
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-
|
|
2155
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
2156
|
+
const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-G9PvjHrr.js").then((n) => n.s);
|
|
2157
|
+
const { policyStampSql } = await import("./ensure-collection-policies-DJsOMpaI.js");
|
|
2158
|
+
const { pinSearchPath } = await import("./connection-C1zXTPJq.js").then((n) => n.r);
|
|
2048
2159
|
return {
|
|
2049
|
-
statements: stampableTables(planCollectionPolicies(await loadCollections(path.resolve(process.cwd(), collectionsPath))), policiesSql).map((plan) => policyStampSql(plan)).filter((statement) => statement !== void 0),
|
|
2160
|
+
statements: stampableTables(planCollectionPolicies(await loadCollections(path.resolve(process.cwd(), collectionsPath)), { adminRoleAvailable }), policiesSql).map((plan) => policyStampSql(plan)).filter((statement) => statement !== void 0),
|
|
2050
2161
|
searchPath: pinSearchPath(databaseUrl) === databaseUrl ? void 0 : "public"
|
|
2051
2162
|
};
|
|
2052
2163
|
} catch {
|
|
@@ -2061,11 +2172,15 @@ async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
|
|
|
2061
2172
|
*/
|
|
2062
2173
|
async function readPolicyPushPlan(databaseUrl, collectionsPath) {
|
|
2063
2174
|
try {
|
|
2064
|
-
const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-
|
|
2065
|
-
const { loadCollections } = await import("./doctor-
|
|
2066
|
-
const { pinSearchPath } = await import("./connection-
|
|
2175
|
+
const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-BOw5PtU8.js");
|
|
2176
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
2177
|
+
const { pinSearchPath } = await import("./connection-C1zXTPJq.js").then((n) => n.r);
|
|
2067
2178
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2068
|
-
const
|
|
2179
|
+
const adminRoleAvailable = await readAdminPoliciesLive(databaseUrl);
|
|
2180
|
+
const plan = await withAppClient(databaseUrl, (client) => planPolicyPush({ query: async (text, values) => ({ rows: (await client.query(text, values)).rows }) }, collections, {
|
|
2181
|
+
searchPath: pinSearchPath(databaseUrl) === databaseUrl ? void 0 : "public",
|
|
2182
|
+
adminRoleAvailable
|
|
2183
|
+
}));
|
|
2069
2184
|
return {
|
|
2070
2185
|
...formatPolicyPushPlan(plan),
|
|
2071
2186
|
summary: summarizePolicyPushPlan(plan)
|
|
@@ -2090,11 +2205,12 @@ async function readPolicyPushPlan(databaseUrl, collectionsPath) {
|
|
|
2090
2205
|
*/
|
|
2091
2206
|
async function reconcilePolicies(databaseUrl, collectionsPath) {
|
|
2092
2207
|
try {
|
|
2093
|
-
const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-
|
|
2094
|
-
const { loadCollections } = await import("./doctor-
|
|
2208
|
+
const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-Bx6663KD.js").then((n) => n.s);
|
|
2209
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
2095
2210
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2211
|
+
const adminRoleAvailable = await readAdminPoliciesLive(databaseUrl);
|
|
2096
2212
|
await withAppClient(databaseUrl, async (client) => {
|
|
2097
|
-
const drift = await checkPolicyDrift(client, collections);
|
|
2213
|
+
const drift = await checkPolicyDrift(client, collections, { adminRoleAvailable });
|
|
2098
2214
|
const { dropped, kept } = await dropOrphanedPolicies(client, drift, collections);
|
|
2099
2215
|
for (const p of dropped) out(chalk.gray(` ✓ Dropped superseded policy "${p.name}" on ${p.schema}.${p.table}`));
|
|
2100
2216
|
if (dropped.length > 0) out(chalk.green(` ✓ Removed ${dropped.length} superseded RLS ${dropped.length === 1 ? "policy" : "policies"}.`));
|
|
@@ -2176,8 +2292,8 @@ async function branchCommand(rawArgs) {
|
|
|
2176
2292
|
outError(chalk.red("✗ DATABASE_URL is not set. Make sure your .env file is configured."));
|
|
2177
2293
|
process.exit(1);
|
|
2178
2294
|
}
|
|
2179
|
-
const { DatabasePoolManager } = await import("./databasePoolManager-
|
|
2180
|
-
const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-
|
|
2295
|
+
const { DatabasePoolManager } = await import("./databasePoolManager-DIjzlTK4.js").then((n) => n.n);
|
|
2296
|
+
const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-X9R505mP.js").then((n) => n.n);
|
|
2181
2297
|
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
2182
2298
|
const { Pool } = await import("pg");
|
|
2183
2299
|
const healed = await reopenClosedDatabases(databaseUrl, [branchAction === "create" ? createSource(rawArgs) : void 0, process.env[ACTIVE_BRANCH_DATABASE_ENV]]);
|
|
@@ -2724,9 +2840,9 @@ async function schemaStaleCommand(rawArgs) {
|
|
|
2724
2840
|
const schemaFile = path.resolve(process.cwd(), outputPath);
|
|
2725
2841
|
const fix = Boolean(argsList["--fix"]);
|
|
2726
2842
|
const generatedExists = fs.existsSync(schemaFile);
|
|
2727
|
-
const { loadCollections } = await import("./doctor-
|
|
2843
|
+
const { loadCollections } = await import("./doctor-DwMXljiq.js").then((n) => n.t);
|
|
2728
2844
|
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-
|
|
2845
|
+
const { generateSchema } = await import("./generate-drizzle-schema-logic-BBXjxm5z.js").then((n) => n.n);
|
|
2730
2846
|
const { relationalCollections } = await import("@rebasepro/common");
|
|
2731
2847
|
let stale = [];
|
|
2732
2848
|
let differences = [];
|