@rebasepro/server-postgres 0.29.0-canary.g0e3a0e7 → 0.29.1
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-BPssiD8_.js → BranchService-BIIBF5ZL.js} +3 -3
- package/dist/{BranchService-BPssiD8_.js.map → BranchService-BIIBF5ZL.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +105 -9
- package/dist/PostgresBootstrapper.d.ts +14 -0
- package/dist/{backup-cli-C1wcj-rc.js → backup-cli-QcOpmRpQ.js} +3 -3
- package/dist/{backup-cli-C1wcj-rc.js.map → backup-cli-QcOpmRpQ.js.map} +1 -1
- package/dist/{boot-ddl-CIGoIGcC.js → boot-ddl-BSNpEUOS.js} +2 -2
- package/dist/{boot-ddl-CIGoIGcC.js.map → boot-ddl-BSNpEUOS.js.map} +1 -1
- package/dist/{cli-console-CJLtH58M.js → cli-console-DTsm96lW.js} +6 -6
- package/dist/{cli-console-CJLtH58M.js.map → cli-console-DTsm96lW.js.map} +1 -1
- package/dist/{cli-errors-DYets7cp.js → cli-errors-DwqFRIWz.js} +69 -6
- package/dist/cli-errors-DwqFRIWz.js.map +1 -0
- package/dist/cli-helpers.d.ts +10 -0
- package/dist/cli.js +90 -44
- package/dist/cli.js.map +1 -1
- package/dist/{connection-CcYqncW5.js → connection-COuS5Fm-.js} +15 -2
- package/dist/connection-COuS5Fm-.js.map +1 -0
- package/dist/connection.d.ts +6 -0
- package/dist/database-preflight-D5JtPt8i.js +151 -0
- package/dist/database-preflight-D5JtPt8i.js.map +1 -0
- package/dist/{databasePoolManager-XmhMczz0.js → databasePoolManager-7hXVurmG.js} +2 -2
- package/dist/{databasePoolManager-XmhMczz0.js.map → databasePoolManager-7hXVurmG.js.map} +1 -1
- package/dist/db-subcommands.d.ts +1 -1
- package/dist/{deferred-index-build-BwH6k1Og.js → deferred-index-build-B8feKnUj.js} +12 -8
- package/dist/deferred-index-build-B8feKnUj.js.map +1 -0
- package/dist/{doctor-TJApVglQ.js → doctor-BaR11xUe.js} +20 -6
- package/dist/doctor-BaR11xUe.js.map +1 -0
- package/dist/{ensure-collection-policies-f0LIwiwp.js → ensure-collection-policies-85HiG-k1.js} +8 -8
- package/dist/{ensure-collection-policies-f0LIwiwp.js.map → ensure-collection-policies-85HiG-k1.js.map} +1 -1
- package/dist/{ensure-collection-tables-DvaCEy6X.js → ensure-collection-tables-DR_WcxLA.js} +20 -9
- package/dist/ensure-collection-tables-DR_WcxLA.js.map +1 -0
- package/dist/{ensure-tables-CF-8zgYA.js → ensure-tables-Dh5UP_Zs.js} +4 -4
- package/dist/{ensure-tables-CF-8zgYA.js.map → ensure-tables-Dh5UP_Zs.js.map} +1 -1
- package/dist/{enum-labels-kept-DAbJ_IIl.js → enum-labels-kept-DSU8lAnd.js} +3 -3
- package/dist/{enum-labels-kept-DAbJ_IIl.js.map → enum-labels-kept-DSU8lAnd.js.map} +1 -1
- package/dist/{generate-drizzle-schema-BAIp9nKT.js → generate-drizzle-schema-5spbTyQ6.js} +2 -2
- package/dist/{generate-drizzle-schema-BAIp9nKT.js.map → generate-drizzle-schema-5spbTyQ6.js.map} +1 -1
- package/dist/{generate-drizzle-schema-logic-CVRmZjP3.js → generate-drizzle-schema-logic-C5FB7Fpo.js} +2 -2
- package/dist/{generate-drizzle-schema-logic-CVRmZjP3.js.map → generate-drizzle-schema-logic-C5FB7Fpo.js.map} +1 -1
- package/dist/{generate-files-DutUrsSS.js → generate-files-Bl3_D_oP.js} +11 -4
- package/dist/generate-files-Bl3_D_oP.js.map +1 -0
- package/dist/{generate-postgres-ddl-logic-0rbAqwYT.js → generate-postgres-ddl-logic-BC3JA93M.js} +11 -4
- package/dist/{generate-postgres-ddl-logic-0rbAqwYT.js.map → generate-postgres-ddl-logic-BC3JA93M.js.map} +1 -1
- package/dist/{generated-schema-diff-ChFg6UxI.js → generated-schema-diff-Jm93vyJB.js} +29 -6
- package/dist/generated-schema-diff-Jm93vyJB.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.es.js +22 -14
- package/dist/index.es.js.map +1 -1
- package/dist/{migrate-baseline-DPawvckr.js → migrate-baseline-BfHmq3vN.js} +49 -4
- package/dist/{migrate-baseline-DPawvckr.js.map → migrate-baseline-BfHmq3vN.js.map} +1 -1
- package/dist/{migrate-policy-stamps-CdljD_y1.js → migrate-policy-stamps-B4k1ggma.js} +7 -7
- package/dist/{migrate-policy-stamps-CdljD_y1.js.map → migrate-policy-stamps-B4k1ggma.js.map} +1 -1
- package/dist/{open-rebase-DvmKIu7q.js → open-rebase-CiO_sjMT.js} +1574 -195
- package/dist/open-rebase-CiO_sjMT.js.map +1 -0
- package/dist/open-rebase.d.ts +6 -1
- package/dist/{pg-error-utils-BIHfsGZL.js → pg-error-utils-D1Nc0UML.js} +2 -2
- package/dist/{pg-error-utils-BIHfsGZL.js.map → pg-error-utils-D1Nc0UML.js.map} +1 -1
- package/dist/pipelined-transaction.d.ts +131 -0
- package/dist/{plan-schema-DMVh77yb.js → plan-schema-BYxOzflz.js} +147 -8
- package/dist/plan-schema-BYxOzflz.js.map +1 -0
- package/dist/{policy-drift-0Cp4Lc0x.js → policy-drift-DKuTJHfc.js} +2 -2
- package/dist/{policy-drift-0Cp4Lc0x.js.map → policy-drift-DKuTJHfc.js.map} +1 -1
- package/dist/{push-index-prebuild-C6wKdjYV.js → push-index-prebuild-bqXimSZz.js} +4 -4
- package/dist/{push-index-prebuild-C6wKdjYV.js.map → push-index-prebuild-bqXimSZz.js.map} +1 -1
- package/dist/{push-kept-defaults-BSqPzp0T.js → push-kept-defaults-CN9R8cHf.js} +2 -2
- package/dist/{push-kept-defaults-BSqPzp0T.js.map → push-kept-defaults-CN9R8cHf.js.map} +1 -1
- package/dist/{push-legacy-renames-BFF72tHG.js → push-legacy-renames-CU_UYPbz.js} +4 -4
- package/dist/{push-legacy-renames-BFF72tHG.js.map → push-legacy-renames-CU_UYPbz.js.map} +1 -1
- package/dist/{push-policy-plan-lOTPeQ1u.js → push-policy-plan-JcyK94bc.js} +4 -4
- package/dist/{push-policy-plan-lOTPeQ1u.js.map → push-policy-plan-JcyK94bc.js.map} +1 -1
- package/dist/{render-ddl-NpPPDACz.js → render-ddl-DCdVP-pQ.js} +95 -4
- package/dist/render-ddl-DCdVP-pQ.js.map +1 -0
- package/dist/request-role-cli-DSdRtvgH.js +260 -0
- package/dist/request-role-cli-DSdRtvgH.js.map +1 -0
- package/dist/request-role-cli.d.ts +86 -0
- package/dist/request-role-migration-D9BZ5Uba.js +150 -0
- package/dist/request-role-migration-D9BZ5Uba.js.map +1 -0
- package/dist/rls-enforcement-BO618rnr.js +992 -0
- package/dist/rls-enforcement-BO618rnr.js.map +1 -0
- package/dist/rls-settings-De5NoHHy.js +211 -0
- package/dist/rls-settings-De5NoHHy.js.map +1 -0
- package/dist/schema/doctor-cli.js +144 -6
- package/dist/schema/doctor-cli.js.map +1 -1
- package/dist/schema/doctor-database.d.ts +27 -0
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-files.d.ts +2 -1
- package/dist/schema/generate-postgres-ddl-logic.d.ts +6 -0
- package/dist/schema/generate-postgres-ddl.js +1 -1
- package/dist/schema/introspect-db.js +2 -2
- package/dist/schema/introspect-runtime.d.ts +10 -1
- package/dist/schema/plan/diff-plan.d.ts +6 -1
- package/dist/schema/plan/plan-schema.d.ts +9 -1
- package/dist/schema/plan/render-ddl.d.ts +32 -1
- package/dist/schema/plan/tenant-keep-trigger.d.ts +9 -0
- package/dist/schema/plan/types.d.ts +39 -0
- package/dist/schema/plan/updated-at-trigger.d.ts +1 -1
- package/dist/schema/plan/view-names.d.ts +6 -0
- package/dist/schema/rls-bootstrap-sql.d.ts +23 -0
- package/dist/security/caller-sql-columns.d.ts +60 -0
- package/dist/security/caller-sql.d.ts +8 -0
- package/dist/security/database-preflight.d.ts +24 -0
- package/dist/security/request-role-migration.d.ts +36 -0
- package/dist/security/rls-enforcement.d.ts +201 -20
- package/dist/security/rls-settings.d.ts +177 -0
- package/dist/services/FetchService.d.ts +12 -12
- package/dist/services/PersistService.d.ts +59 -0
- package/dist/services/collection-helpers.d.ts +3 -1
- package/dist/services/dataService.d.ts +2 -0
- package/dist/services/realtimeService.d.ts +3 -0
- package/dist/services/view-access.d.ts +21 -0
- package/dist/view-names-Dscp6--B.js +24 -0
- package/dist/view-names-Dscp6--B.js.map +1 -0
- package/dist/{websocket-CCJnghvG.js → websocket-B33YjKhs.js} +3 -3
- package/dist/{websocket-CCJnghvG.js.map → websocket-B33YjKhs.js.map} +1 -1
- package/package.json +7 -7
- package/dist/cli-errors-DYets7cp.js.map +0 -1
- package/dist/connection-CcYqncW5.js.map +0 -1
- package/dist/deferred-index-build-BwH6k1Og.js.map +0 -1
- package/dist/doctor-TJApVglQ.js.map +0 -1
- package/dist/ensure-collection-tables-DvaCEy6X.js.map +0 -1
- package/dist/generate-files-DutUrsSS.js.map +0 -1
- package/dist/generated-schema-diff-ChFg6UxI.js.map +0 -1
- package/dist/open-rebase-DvmKIu7q.js.map +0 -1
- package/dist/plan-schema-DMVh77yb.js.map +0 -1
- package/dist/render-ddl-NpPPDACz.js.map +0 -1
- package/dist/rls-enforcement-BOHuHVlc.js +0 -502
- package/dist/rls-enforcement-BOHuHVlc.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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
|
|
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-DwqFRIWz.js";
|
|
5
5
|
import { a as outWarn, i as outError, o as atlasExcludePattern, r as out, s as excludePatternParts, t as chalk } from "./source-fZb92pN8.js";
|
|
6
6
|
import { t as nextStepAfterDbGenerate } from "./generate-next-step-DgK5BlBn.js";
|
|
7
|
-
import {
|
|
7
|
+
import { C as RLS_BOOTSTRAP_SQL, O as execa, S as REQUEST_ROLE_FUNCTION_SQL, T as dropLegacyAuthSchema, 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, x as resolveDriverSwitches } from "./migrate-baseline-BfHmq3vN.js";
|
|
8
|
+
import { declaredRlsPolicyShape } from "@rebasepro/types";
|
|
8
9
|
import { formatRelativeTime } from "@rebasepro/utils";
|
|
9
10
|
import path from "path";
|
|
10
11
|
import fs from "fs";
|
|
@@ -1121,6 +1122,12 @@ function planPrune(input, options = {}) {
|
|
|
1121
1122
|
}
|
|
1122
1123
|
//#endregion
|
|
1123
1124
|
//#region src/cli.ts
|
|
1125
|
+
/**
|
|
1126
|
+
* The RLS helpers a migration or a push creates ahead of the policies — with
|
|
1127
|
+
* `rebase.is_request_role` for a project that declared
|
|
1128
|
+
* `rls.policyTarget: "requestRole"`, whose every permissive policy calls it.
|
|
1129
|
+
*/
|
|
1130
|
+
var rlsBootstrapSql = () => declaredRlsPolicyShape().policyTarget === "requestRole" ? `${RLS_BOOTSTRAP_SQL}\n${REQUEST_ROLE_FUNCTION_SQL};\n` : RLS_BOOTSTRAP_SQL;
|
|
1124
1131
|
var __cliDirname = path.dirname(fileURLToPath(import.meta.url));
|
|
1125
1132
|
/**
|
|
1126
1133
|
* A script this CLI spawns, and how to run it.
|
|
@@ -1207,7 +1214,7 @@ function generatesInProcess() {
|
|
|
1207
1214
|
async function generateInProcess(what, label, run) {
|
|
1208
1215
|
let generators;
|
|
1209
1216
|
try {
|
|
1210
|
-
generators = await import("./generate-files-
|
|
1217
|
+
generators = await import("./generate-files-Bl3_D_oP.js").then((n) => n.t);
|
|
1211
1218
|
} catch (err) {
|
|
1212
1219
|
outError(chalk.red(`✗ Failed to run ${what}: ${err instanceof Error ? err.message : String(err)}`));
|
|
1213
1220
|
process.exit(1);
|
|
@@ -1254,7 +1261,7 @@ async function runPluginCommand(args) {
|
|
|
1254
1261
|
else if (domain === "schema") await schemaCommand(subcommand, args);
|
|
1255
1262
|
else if (domain === "doctor") await doctorPluginCommand(args);
|
|
1256
1263
|
else if (domain === "console") {
|
|
1257
|
-
const { consoleCommand } = await import("./cli-console-
|
|
1264
|
+
const { consoleCommand } = await import("./cli-console-DTsm96lW.js");
|
|
1258
1265
|
process.exitCode = await consoleCommand(args);
|
|
1259
1266
|
} else {
|
|
1260
1267
|
outError(chalk.red(`Unknown domain command: ${domain}`));
|
|
@@ -1420,8 +1427,18 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1420
1427
|
await branchCommand(rawArgs);
|
|
1421
1428
|
return;
|
|
1422
1429
|
}
|
|
1430
|
+
if (subcommand === "request-role") {
|
|
1431
|
+
const { requestRoleCommand } = await import("./request-role-cli-DSdRtvgH.js").then((n) => n.r);
|
|
1432
|
+
await requestRoleCommand(rawArgs);
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1435
|
+
if (subcommand === "provision") {
|
|
1436
|
+
const { provisionCommand } = await import("./request-role-cli-DSdRtvgH.js").then((n) => n.r);
|
|
1437
|
+
await provisionCommand(rawArgs);
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1423
1440
|
if (subcommand === "backup" || subcommand === "restore" || subcommand === "backups") {
|
|
1424
|
-
const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-
|
|
1441
|
+
const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-QcOpmRpQ.js").then((n) => n.t);
|
|
1425
1442
|
if (subcommand === "backup" && backupActionOf(rawArgs) === "list") await backupsCommand(rawArgs);
|
|
1426
1443
|
else if (subcommand === "backup") await backupCommand(rawArgs);
|
|
1427
1444
|
else if (subcommand === "restore") await restoreCommand(rawArgs);
|
|
@@ -1468,7 +1485,7 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1468
1485
|
}
|
|
1469
1486
|
const searchContent = readSearchDdl();
|
|
1470
1487
|
if (searchContent) {
|
|
1471
|
-
const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-
|
|
1488
|
+
const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-BC3JA93M.js").then((n) => n.s);
|
|
1472
1489
|
const migrationConflicts = findGeneratedColumnConflicts(parseColumnMutations(migrationContent), searchColumnDependencies(await loadCollectionsForCli(collectionsPath)));
|
|
1473
1490
|
const preamble = migrationDropPreamble(migrationConflicts);
|
|
1474
1491
|
if (preamble) {
|
|
@@ -1483,11 +1500,16 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1483
1500
|
migrationContent = `${migrationContent}\n\n${triggersContent}`;
|
|
1484
1501
|
out(chalk.gray(" ✓ Appended `updated_at` triggers to the migration"));
|
|
1485
1502
|
}
|
|
1503
|
+
const viewsContent = readViewsDdl();
|
|
1504
|
+
if (viewsContent) {
|
|
1505
|
+
migrationContent = `${migrationContent}\n\n${viewsContent}`;
|
|
1506
|
+
out(chalk.gray(" ✓ Appended views to the migration"));
|
|
1507
|
+
}
|
|
1486
1508
|
fs.writeFileSync(newestMigrationFile, migrationContent, "utf-8");
|
|
1487
1509
|
const policiesFile = path.join(generatedSqlDir(), "policies.sql");
|
|
1488
1510
|
if (fs.existsSync(policiesFile)) {
|
|
1489
1511
|
const policiesContent = fs.readFileSync(policiesFile, "utf-8");
|
|
1490
|
-
fs.appendFileSync(newestMigrationFile, "\n\n" +
|
|
1512
|
+
fs.appendFileSync(newestMigrationFile, "\n\n" + rlsBootstrapSql() + "\n" + policiesContent);
|
|
1491
1513
|
out(chalk.gray(` ✓ Appended RLS policies to migration file: ${path.basename(newestMigrationFile)}`));
|
|
1492
1514
|
out(chalk.gray(" Re-hashing migration files..."));
|
|
1493
1515
|
await runAtlas("migrate", [
|
|
@@ -1688,6 +1710,7 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1688
1710
|
await applyVectorDdl(databaseUrl);
|
|
1689
1711
|
await applySearchDdl(databaseUrl);
|
|
1690
1712
|
await applyTriggersDdl(databaseUrl);
|
|
1713
|
+
await applyViewsDdl(databaseUrl);
|
|
1691
1714
|
await applyPolicies(databaseUrl, collectionsPath);
|
|
1692
1715
|
await reconcilePolicies(databaseUrl, collectionsPath);
|
|
1693
1716
|
await ensureRlsUserRole(databaseUrl);
|
|
@@ -1736,7 +1759,7 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1736
1759
|
if (databaseUrl) {
|
|
1737
1760
|
await ensureRlsUserRole(databaseUrl);
|
|
1738
1761
|
await retireLegacyAuthSchema(databaseUrl);
|
|
1739
|
-
const { stampMigratedPolicies } = await import("./migrate-policy-stamps-
|
|
1762
|
+
const { stampMigratedPolicies } = await import("./migrate-policy-stamps-B4k1ggma.js");
|
|
1740
1763
|
await stampMigratedPolicies(databaseUrl, collectionsPath);
|
|
1741
1764
|
}
|
|
1742
1765
|
}
|
|
@@ -1764,8 +1787,8 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1764
1787
|
* no such column reads nothing.
|
|
1765
1788
|
*/
|
|
1766
1789
|
async function keepDatabaseOwnedDefaults(databaseUrl, collectionsPath) {
|
|
1767
|
-
const { loadCollections } = await import("./doctor-
|
|
1768
|
-
const { databaseOwnedDefaultColumns, readKeptDefaults, withKeptDefaults } = await import("./push-kept-defaults-
|
|
1790
|
+
const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
|
|
1791
|
+
const { databaseOwnedDefaultColumns, readKeptDefaults, withKeptDefaults } = await import("./push-kept-defaults-CN9R8cHf.js");
|
|
1769
1792
|
const columns = databaseOwnedDefaultColumns(await loadCollections(path.resolve(process.cwd(), collectionsPath)));
|
|
1770
1793
|
if (columns.length === 0) return;
|
|
1771
1794
|
let kept;
|
|
@@ -1790,8 +1813,8 @@ async function keepDatabaseOwnedDefaults(databaseUrl, collectionsPath) {
|
|
|
1790
1813
|
async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
|
|
1791
1814
|
let renames;
|
|
1792
1815
|
try {
|
|
1793
|
-
const { loadCollections } = await import("./doctor-
|
|
1794
|
-
const { legacyForeignKeyRenames } = await import("./push-legacy-renames-
|
|
1816
|
+
const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
|
|
1817
|
+
const { legacyForeignKeyRenames } = await import("./push-legacy-renames-CU_UYPbz.js");
|
|
1795
1818
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1796
1819
|
renames = await withAppClient(databaseUrl, (client) => legacyForeignKeyRenames({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1797
1820
|
} catch {
|
|
@@ -1810,8 +1833,8 @@ async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
|
|
|
1810
1833
|
/** Names the enum labels the database keeps after the collections dropped them. See `schema/enum-labels-kept.ts`. */
|
|
1811
1834
|
async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
|
|
1812
1835
|
try {
|
|
1813
|
-
const { loadCollections } = await import("./doctor-
|
|
1814
|
-
const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-
|
|
1836
|
+
const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
|
|
1837
|
+
const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-DSU8lAnd.js");
|
|
1815
1838
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1816
1839
|
const kept = await withAppClient(databaseUrl, (client) => keptEnumLabels({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1817
1840
|
if (kept.length > 0) outWarn(chalk.yellow(formatKeptEnumLabelsNotice(kept)));
|
|
@@ -1820,8 +1843,8 @@ async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
|
|
|
1820
1843
|
async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
|
|
1821
1844
|
let missing;
|
|
1822
1845
|
try {
|
|
1823
|
-
const { loadCollections } = await import("./doctor-
|
|
1824
|
-
const { missingForeignKeyIndexes } = await import("./push-index-prebuild-
|
|
1846
|
+
const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
|
|
1847
|
+
const { missingForeignKeyIndexes } = await import("./push-index-prebuild-bqXimSZz.js");
|
|
1825
1848
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1826
1849
|
missing = await withAppClient(databaseUrl, (client) => missingForeignKeyIndexes({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1827
1850
|
} catch {
|
|
@@ -1831,7 +1854,7 @@ async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
|
|
|
1831
1854
|
if (missing.length === 0 || dryRun) return names;
|
|
1832
1855
|
out(chalk.gray(` Building ${missing.length} foreign-key index(es) on existing tables first — CONCURRENTLY, so writes go on:`));
|
|
1833
1856
|
try {
|
|
1834
|
-
const { buildDeferredIndexes } = await import("./deferred-index-build-
|
|
1857
|
+
const { buildDeferredIndexes } = await import("./deferred-index-build-B8feKnUj.js").then((n) => n.r);
|
|
1835
1858
|
const outcome = await withAppClient(databaseUrl, (client) => buildDeferredIndexes(async () => ({
|
|
1836
1859
|
dedicated: true,
|
|
1837
1860
|
query: async (text) => ({ rows: (await client.query(text)).rows }),
|
|
@@ -1847,7 +1870,7 @@ async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
|
|
|
1847
1870
|
async function ensureAuthSchemaAndFunctions(databaseUrl) {
|
|
1848
1871
|
try {
|
|
1849
1872
|
await withAppClient(databaseUrl, async (client) => {
|
|
1850
|
-
await client.query(
|
|
1873
|
+
await client.query(rlsBootstrapSql());
|
|
1851
1874
|
});
|
|
1852
1875
|
} catch (err) {
|
|
1853
1876
|
if (isEconnrefused(err) || isAuthFailure(err) || isSslNotEnabled(err)) {
|
|
@@ -1879,11 +1902,19 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
|
|
|
1879
1902
|
let unsecured;
|
|
1880
1903
|
let userRole;
|
|
1881
1904
|
try {
|
|
1882
|
-
const { lockCollectionTables } = await import("./ensure-collection-policies-
|
|
1883
|
-
const { loadCollections } = await import("./doctor-
|
|
1884
|
-
|
|
1905
|
+
const { lockCollectionTables } = await import("./ensure-collection-policies-85HiG-k1.js");
|
|
1906
|
+
const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
|
|
1907
|
+
const { readRecordedRequestRoles } = await import("./rls-enforcement-BO618rnr.js").then((n) => n.v);
|
|
1908
|
+
const { cliRlsSettings } = await import("./rls-settings-De5NoHHy.js").then((n) => n.a);
|
|
1885
1909
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1886
|
-
({unsecured} = await withAppClient(databaseUrl,
|
|
1910
|
+
({unsecured, userRole} = await withAppClient(databaseUrl, async (client) => {
|
|
1911
|
+
const runSql = async (text) => (await client.query(text)).rows;
|
|
1912
|
+
const roles = cliRlsSettings(await readRecordedRequestRoles(runSql)).roles;
|
|
1913
|
+
return {
|
|
1914
|
+
unsecured: (await lockCollectionTables({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections)).unsecured,
|
|
1915
|
+
userRole: roles.join(", ")
|
|
1916
|
+
};
|
|
1917
|
+
}));
|
|
1887
1918
|
} catch (err) {
|
|
1888
1919
|
outError(chalk.red(`\n ✗ The schema was applied, but row-level security could not be switched on for its tables: ${err instanceof Error ? err.message : String(err)}`));
|
|
1889
1920
|
outError(chalk.gray(" A table this push created may be readable and writable by every authenticated request\n until it is. Re-run `rebase db push` — it locks every collection table before anything else."));
|
|
@@ -1916,8 +1947,8 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
|
|
|
1916
1947
|
async function ensureAuthTables(databaseUrl, collectionsPath) {
|
|
1917
1948
|
try {
|
|
1918
1949
|
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
1919
|
-
const { ensureAuthTablesExist } = await import("./ensure-tables-
|
|
1920
|
-
const { loadCollections } = await import("./doctor-
|
|
1950
|
+
const { ensureAuthTablesExist } = await import("./ensure-tables-Dh5UP_Zs.js").then((n) => n.n);
|
|
1951
|
+
const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
|
|
1921
1952
|
const authCollection = (await loadCollections(path.resolve(process.cwd(), collectionsPath))).find((c) => {
|
|
1922
1953
|
const a = c.auth;
|
|
1923
1954
|
return a === true || typeof a === "object" && a !== null && a.enabled === true;
|
|
@@ -1937,22 +1968,35 @@ async function ensureRlsUserRole(databaseUrl) {
|
|
|
1937
1968
|
const schemas = ["public", "rebase"];
|
|
1938
1969
|
let rls;
|
|
1939
1970
|
try {
|
|
1940
|
-
rls = await import("./rls-enforcement-
|
|
1971
|
+
rls = await import("./rls-enforcement-BO618rnr.js").then((n) => n.v);
|
|
1941
1972
|
} catch (err) {
|
|
1942
1973
|
outError(chalk.red(`\n ✗ Could not load the RLS provisioning module: ${err instanceof Error ? err.message : String(err)}`));
|
|
1943
1974
|
return;
|
|
1944
1975
|
}
|
|
1976
|
+
let connectionRole;
|
|
1977
|
+
let settings;
|
|
1945
1978
|
try {
|
|
1946
1979
|
await withAppClient(databaseUrl, async (client) => {
|
|
1947
1980
|
const runSql = async (text) => (await client.query(text)).rows;
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1981
|
+
const posture = await rls.detectConnectionPosture(runSql);
|
|
1982
|
+
connectionRole = posture.role;
|
|
1983
|
+
if (posture.privileged) {
|
|
1984
|
+
const recorded = await rls.readRecordedRequestRoles(runSql);
|
|
1985
|
+
settings = (await import("./rls-settings-De5NoHHy.js").then((n) => n.a)).cliRlsSettings(recorded);
|
|
1986
|
+
rls.assertRecordedRequestRoles(settings.roles, recorded, await rls.roleHoldsTableGrants(runSql, schemas));
|
|
1987
|
+
if (recorded ? recorded.join(",") !== settings.roles.join(",") : settings.roles.join(",") !== rls.REBASE_USER_ROLE) await rls.recordRequestRoles(runSql, settings.roles);
|
|
1988
|
+
for (const role of settings.roles) await rls.ensureAppRole(runSql, schemas, {
|
|
1989
|
+
role,
|
|
1990
|
+
provisionRole: settings.provisionRole,
|
|
1991
|
+
grants: settings.grants
|
|
1992
|
+
});
|
|
1993
|
+
out(chalk.gray(` ✓ RLS role ${settings.roles.map((r) => `"${r}"`).join(", ")} provisioned/refreshed.`));
|
|
1951
1994
|
}
|
|
1952
1995
|
});
|
|
1953
1996
|
} catch (err) {
|
|
1954
|
-
|
|
1955
|
-
outError(chalk.
|
|
1997
|
+
const setup = err instanceof rls.AppRoleSetupError;
|
|
1998
|
+
outError(chalk.red(`\n ✗ The schema change was applied, but the "${settings?.defaultRole ?? rls.REBASE_USER_ROLE}" role could not be provisioned: ${setup ? err.message.slice(0, -err.instructions.length).trimEnd() : err instanceof Error ? err.message : String(err)}`));
|
|
1999
|
+
outError(chalk.gray(setup ? err.instructions : rls.appRoleSetupInstructions(connectionRole, schemas, settings?.defaultRole, settings?.grants)));
|
|
1956
2000
|
}
|
|
1957
2001
|
}
|
|
1958
2002
|
/**
|
|
@@ -1997,10 +2041,10 @@ async function applyPolicies(databaseUrl, collectionsPath) {
|
|
|
1997
2041
|
*/
|
|
1998
2042
|
async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
|
|
1999
2043
|
try {
|
|
2000
|
-
const { loadCollections } = await import("./doctor-
|
|
2001
|
-
const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-
|
|
2002
|
-
const { policyStampSql } = await import("./ensure-collection-policies-
|
|
2003
|
-
const { pinSearchPath } = await import("./connection-
|
|
2044
|
+
const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
|
|
2045
|
+
const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-BC3JA93M.js").then((n) => n.s);
|
|
2046
|
+
const { policyStampSql } = await import("./ensure-collection-policies-85HiG-k1.js");
|
|
2047
|
+
const { pinSearchPath } = await import("./connection-COuS5Fm-.js").then((n) => n.r);
|
|
2004
2048
|
return {
|
|
2005
2049
|
statements: stampableTables(planCollectionPolicies(await loadCollections(path.resolve(process.cwd(), collectionsPath))), policiesSql).map((plan) => policyStampSql(plan)).filter((statement) => statement !== void 0),
|
|
2006
2050
|
searchPath: pinSearchPath(databaseUrl) === databaseUrl ? void 0 : "public"
|
|
@@ -2017,9 +2061,9 @@ async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
|
|
|
2017
2061
|
*/
|
|
2018
2062
|
async function readPolicyPushPlan(databaseUrl, collectionsPath) {
|
|
2019
2063
|
try {
|
|
2020
|
-
const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-
|
|
2021
|
-
const { loadCollections } = await import("./doctor-
|
|
2022
|
-
const { pinSearchPath } = await import("./connection-
|
|
2064
|
+
const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-JcyK94bc.js");
|
|
2065
|
+
const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
|
|
2066
|
+
const { pinSearchPath } = await import("./connection-COuS5Fm-.js").then((n) => n.r);
|
|
2023
2067
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2024
2068
|
const plan = await withAppClient(databaseUrl, (client) => planPolicyPush({ query: async (text, values) => ({ rows: (await client.query(text, values)).rows }) }, collections, { searchPath: pinSearchPath(databaseUrl) === databaseUrl ? void 0 : "public" }));
|
|
2025
2069
|
return {
|
|
@@ -2046,8 +2090,8 @@ async function readPolicyPushPlan(databaseUrl, collectionsPath) {
|
|
|
2046
2090
|
*/
|
|
2047
2091
|
async function reconcilePolicies(databaseUrl, collectionsPath) {
|
|
2048
2092
|
try {
|
|
2049
|
-
const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-
|
|
2050
|
-
const { loadCollections } = await import("./doctor-
|
|
2093
|
+
const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-DKuTJHfc.js").then((n) => n.s);
|
|
2094
|
+
const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
|
|
2051
2095
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2052
2096
|
await withAppClient(databaseUrl, async (client) => {
|
|
2053
2097
|
const drift = await checkPolicyDrift(client, collections);
|
|
@@ -2132,8 +2176,8 @@ async function branchCommand(rawArgs) {
|
|
|
2132
2176
|
outError(chalk.red("✗ DATABASE_URL is not set. Make sure your .env file is configured."));
|
|
2133
2177
|
process.exit(1);
|
|
2134
2178
|
}
|
|
2135
|
-
const { DatabasePoolManager } = await import("./databasePoolManager-
|
|
2136
|
-
const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-
|
|
2179
|
+
const { DatabasePoolManager } = await import("./databasePoolManager-7hXVurmG.js").then((n) => n.n);
|
|
2180
|
+
const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-BIIBF5ZL.js").then((n) => n.n);
|
|
2137
2181
|
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
2138
2182
|
const { Pool } = await import("pg");
|
|
2139
2183
|
const healed = await reopenClosedDatabases(databaseUrl, [branchAction === "create" ? createSource(rawArgs) : void 0, process.env[ACTIVE_BRANCH_DATABASE_ENV]]);
|
|
@@ -2680,9 +2724,9 @@ async function schemaStaleCommand(rawArgs) {
|
|
|
2680
2724
|
const schemaFile = path.resolve(process.cwd(), outputPath);
|
|
2681
2725
|
const fix = Boolean(argsList["--fix"]);
|
|
2682
2726
|
const generatedExists = fs.existsSync(schemaFile);
|
|
2683
|
-
const { loadCollections } = await import("./doctor-
|
|
2727
|
+
const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
|
|
2684
2728
|
const { findLegacyForeignKeyNames, compareGeneratedDeclarations, staleVerdict } = await import("./generated-schema-staleness-BvNF3i-s.js").then((n) => n.r);
|
|
2685
|
-
const { generateSchema } = await import("./generate-drizzle-schema-logic-
|
|
2729
|
+
const { generateSchema } = await import("./generate-drizzle-schema-logic-C5FB7Fpo.js").then((n) => n.n);
|
|
2686
2730
|
const { relationalCollections } = await import("@rebasepro/common");
|
|
2687
2731
|
let stale = [];
|
|
2688
2732
|
let differences = [];
|
|
@@ -2843,6 +2887,7 @@ async function doctorPluginCommand(rawArgs) {
|
|
|
2843
2887
|
"--schema": String,
|
|
2844
2888
|
"--sdk": String,
|
|
2845
2889
|
"--policies": Boolean,
|
|
2890
|
+
"--database": Boolean,
|
|
2846
2891
|
"-c": "--collections",
|
|
2847
2892
|
"-s": "--schema",
|
|
2848
2893
|
"-k": "--sdk"
|
|
@@ -2864,7 +2909,8 @@ async function doctorPluginCommand(rawArgs) {
|
|
|
2864
2909
|
`--collections=${collectionsPath}`,
|
|
2865
2910
|
`--schema=${schemaPath}`,
|
|
2866
2911
|
`--sdk=${sdkPath}`,
|
|
2867
|
-
...parsedArgs["--policies"] ? ["--policies"] : []
|
|
2912
|
+
...parsedArgs["--policies"] ? ["--policies"] : [],
|
|
2913
|
+
...parsedArgs["--database"] ? ["--database"] : []
|
|
2868
2914
|
];
|
|
2869
2915
|
try {
|
|
2870
2916
|
await execa(cmdParts[0], cmdParts.slice(1), {
|