@rebasepro/server-postgres 0.29.2 → 0.30.0
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-X9R505mP.js → BranchService-CrXvcES2.js} +3 -3
- package/dist/{BranchService-X9R505mP.js.map → BranchService-CrXvcES2.js.map} +1 -1
- package/dist/PostgresBootstrapper.d.ts +7 -0
- package/dist/{backup-cli-CwiJEp_J.js → backup-cli-CTKCOLpX.js} +3 -3
- package/dist/{backup-cli-CwiJEp_J.js.map → backup-cli-CTKCOLpX.js.map} +1 -1
- package/dist/{boot-ddl-CbZj9ovZ.js → boot-ddl-CqGIwSYx.js} +2 -2
- package/dist/{boot-ddl-CbZj9ovZ.js.map → boot-ddl-CqGIwSYx.js.map} +1 -1
- package/dist/{cli-console-DDkNetCz.js → cli-console-DBPw-oAz.js} +5 -5
- package/dist/{cli-console-DDkNetCz.js.map → cli-console-DBPw-oAz.js.map} +1 -1
- package/dist/{cli-errors-C73Qy7WJ.js → cli-errors-DYTxnLbW.js} +5 -5
- package/dist/{cli-errors-C73Qy7WJ.js.map → cli-errors-DYTxnLbW.js.map} +1 -1
- package/dist/cli.js +62 -42
- package/dist/cli.js.map +1 -1
- package/dist/{database-preflight-DIauc8i5.js → database-preflight-iBpT7-vv.js} +2 -2
- package/dist/{database-preflight-DIauc8i5.js.map → database-preflight-iBpT7-vv.js.map} +1 -1
- package/dist/{deferred-index-build-DDdnjaOW.js → deferred-index-build-BCU9RoHK.js} +6 -6
- package/dist/{deferred-index-build-DDdnjaOW.js.map → deferred-index-build-BCU9RoHK.js.map} +1 -1
- package/dist/{doctor-DwMXljiq.js → doctor-Kg1oUK0Q.js} +6 -6
- package/dist/{doctor-DwMXljiq.js.map → doctor-Kg1oUK0Q.js.map} +1 -1
- package/dist/{ensure-collection-policies-DJsOMpaI.js → ensure-collection-policies-Bo-_fDAy.js} +12 -12
- package/dist/ensure-collection-policies-Bo-_fDAy.js.map +1 -0
- package/dist/{ensure-collection-tables-h1mUO7Uu.js → ensure-collection-tables-DCJINkT_.js} +9 -9
- package/dist/{ensure-collection-tables-h1mUO7Uu.js.map → ensure-collection-tables-DCJINkT_.js.map} +1 -1
- package/dist/{ensure-tables-CUqYgMvo.js → ensure-tables-BPGaGh0y.js} +4 -4
- package/dist/{ensure-tables-CUqYgMvo.js.map → ensure-tables-BPGaGh0y.js.map} +1 -1
- package/dist/{enum-labels-kept-z7ustOl_.js → enum-labels-kept-YAgOZS4I.js} +3 -3
- package/dist/{enum-labels-kept-z7ustOl_.js.map → enum-labels-kept-YAgOZS4I.js.map} +1 -1
- package/dist/{generate-drizzle-schema-BIUqhSzh.js → generate-drizzle-schema-DcrFr7YX.js} +2 -2
- package/dist/{generate-drizzle-schema-BIUqhSzh.js.map → generate-drizzle-schema-DcrFr7YX.js.map} +1 -1
- package/dist/{generate-drizzle-schema-logic-BBXjxm5z.js → generate-drizzle-schema-logic-LTLZvt6r.js} +2 -2
- package/dist/{generate-drizzle-schema-logic-BBXjxm5z.js.map → generate-drizzle-schema-logic-LTLZvt6r.js.map} +1 -1
- package/dist/{generate-files-BkiRFoV1.js → generate-files-CsaVzatS.js} +3 -3
- package/dist/{generate-files-BkiRFoV1.js.map → generate-files-CsaVzatS.js.map} +1 -1
- package/dist/{generate-postgres-ddl-logic-G9PvjHrr.js → generate-postgres-ddl-logic-Dg0bcENZ.js} +39 -6
- package/dist/generate-postgres-ddl-logic-Dg0bcENZ.js.map +1 -0
- package/dist/{generated-schema-diff-D2soazQU.js → generated-schema-diff-By4dxyTH.js} +2 -2
- package/dist/{generated-schema-diff-D2soazQU.js.map → generated-schema-diff-By4dxyTH.js.map} +1 -1
- package/dist/index.es.js +12 -12
- package/dist/{migrate-baseline-CveNQli3.js → migrate-baseline-CmWXL7qx.js} +2 -2
- package/dist/{migrate-baseline-CveNQli3.js.map → migrate-baseline-CmWXL7qx.js.map} +1 -1
- package/dist/{migrate-policy-stamps-C4qbQ0jK.js → migrate-policy-stamps-BN_Qad6c.js} +6 -6
- package/dist/{migrate-policy-stamps-C4qbQ0jK.js.map → migrate-policy-stamps-BN_Qad6c.js.map} +1 -1
- package/dist/{open-rebase-Cvid3iwR.js → open-rebase-40paQfVW.js} +31 -24
- package/dist/{open-rebase-Cvid3iwR.js.map → open-rebase-40paQfVW.js.map} +1 -1
- package/dist/{pg-error-utils-80uTIHQs.js → pg-error-utils-DJHjCF7-.js} +2 -2
- package/dist/{pg-error-utils-80uTIHQs.js.map → pg-error-utils-DJHjCF7-.js.map} +1 -1
- package/dist/{plan-schema-CMhNYEYF.js → plan-schema-vJd3UEmT.js} +24 -9
- package/dist/plan-schema-vJd3UEmT.js.map +1 -0
- package/dist/{policy-drift-Bx6663KD.js → policy-drift-C-m0uWHH.js} +53 -8
- package/dist/policy-drift-C-m0uWHH.js.map +1 -0
- package/dist/{push-index-adoption-C-TpM445.js → push-index-adoption-Cp7oZxSl.js} +3 -3
- package/dist/{push-index-adoption-C-TpM445.js.map → push-index-adoption-Cp7oZxSl.js.map} +1 -1
- package/dist/{push-index-prebuild-xbpgZEJK.js → push-index-prebuild-DbwKGtQT.js} +4 -4
- package/dist/{push-index-prebuild-xbpgZEJK.js.map → push-index-prebuild-DbwKGtQT.js.map} +1 -1
- package/dist/{push-kept-defaults-D-JEv0Gn.js → push-kept-defaults-CLcgsEPt.js} +2 -2
- package/dist/{push-kept-defaults-D-JEv0Gn.js.map → push-kept-defaults-CLcgsEPt.js.map} +1 -1
- package/dist/{push-legacy-renames-7UKspspl.js → push-legacy-renames-BthD0E9W.js} +4 -4
- package/dist/{push-legacy-renames-7UKspspl.js.map → push-legacy-renames-BthD0E9W.js.map} +1 -1
- package/dist/{push-policy-plan-BOw5PtU8.js → push-policy-plan-BgcrroxQ.js} +3 -3
- package/dist/{push-policy-plan-BOw5PtU8.js.map → push-policy-plan-BgcrroxQ.js.map} +1 -1
- package/dist/{render-ddl-Di-fTGti.js → render-ddl-Ci3S_SoI.js} +23 -5
- package/dist/render-ddl-Ci3S_SoI.js.map +1 -0
- package/dist/{request-role-cli-Bxxskru9.js → request-role-cli-Dy1EgJU9.js} +8 -8
- package/dist/{request-role-cli-Bxxskru9.js.map → request-role-cli-Dy1EgJU9.js.map} +1 -1
- package/dist/{request-role-migration-BCW4v0rq.js → request-role-migration-GHTJnPMV.js} +2 -2
- package/dist/{request-role-migration-BCW4v0rq.js.map → request-role-migration-GHTJnPMV.js.map} +1 -1
- package/dist/{rls-bootstrap-sql-CxszeSc7.js → rls-bootstrap-sql-kPX4-MB1.js} +18 -3
- package/dist/rls-bootstrap-sql-kPX4-MB1.js.map +1 -0
- package/dist/{rls-enforcement-CyUCPDH8.js → rls-enforcement-Cc_UhOxb.js} +109 -6
- package/dist/rls-enforcement-Cc_UhOxb.js.map +1 -0
- package/dist/schema/doctor-cli.js +7 -7
- package/dist/schema/ensure-collection-policies.d.ts +8 -0
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-postgres-ddl-logic.d.ts +9 -0
- package/dist/schema/generate-postgres-ddl.js +1 -1
- package/dist/schema/introspect-db.js +1 -1
- package/dist/schema/plan/types.d.ts +13 -0
- package/dist/schema/rls-bootstrap-sql.d.ts +6 -0
- package/dist/security/policy-drift.d.ts +13 -1
- package/dist/security/rls-enforcement.d.ts +31 -0
- package/dist/{websocket-BSYV_KSw.js → websocket-B7ex6AQM.js} +3 -3
- package/dist/{websocket-BSYV_KSw.js.map → websocket-B7ex6AQM.js.map} +1 -1
- package/package.json +7 -7
- package/dist/ensure-collection-policies-DJsOMpaI.js.map +0 -1
- package/dist/generate-postgres-ddl-logic-G9PvjHrr.js.map +0 -1
- package/dist/plan-schema-CMhNYEYF.js.map +0 -1
- package/dist/policy-drift-Bx6663KD.js.map +0 -1
- package/dist/render-ddl-Di-fTGti.js.map +0 -1
- package/dist/rls-bootstrap-sql-CxszeSc7.js.map +0 -1
- package/dist/rls-enforcement-CyUCPDH8.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "module";
|
|
2
2
|
__createRequire(import.meta.url);
|
|
3
3
|
import { u as pinSearchPath } from "./connection-C1zXTPJq.js";
|
|
4
|
-
import { U as withAppClient } from "./cli-errors-
|
|
4
|
+
import { U as withAppClient } from "./cli-errors-DYTxnLbW.js";
|
|
5
5
|
import { a as outWarn, r as out, t as chalk } from "./source-fZb92pN8.js";
|
|
6
|
-
import { c as planCollectionPolicies } from "./generate-postgres-ddl-logic-
|
|
7
|
-
import { n as loadCollections } from "./doctor-
|
|
8
|
-
import { ensureCollectionPolicies, policyStampSql, probeRenderedPolicies, readPolicyStamps } from "./ensure-collection-policies-
|
|
9
|
-
import { underSearchPath } from "./push-policy-plan-
|
|
6
|
+
import { c as planCollectionPolicies } from "./generate-postgres-ddl-logic-Dg0bcENZ.js";
|
|
7
|
+
import { n as loadCollections } from "./doctor-Kg1oUK0Q.js";
|
|
8
|
+
import { ensureCollectionPolicies, policyStampSql, probeRenderedPolicies, readPolicyStamps } from "./ensure-collection-policies-Bo-_fDAy.js";
|
|
9
|
+
import { underSearchPath } from "./push-policy-plan-BgcrroxQ.js";
|
|
10
10
|
import path from "path";
|
|
11
11
|
//#region src/schema/migrate-policy-stamps.ts
|
|
12
12
|
/**
|
|
@@ -115,4 +115,4 @@ async function moveMigratedAdminPoliciesToPublic(client, collections, log) {
|
|
|
115
115
|
//#endregion
|
|
116
116
|
export { moveMigratedAdminPoliciesToPublic, stampMigratedPolicies };
|
|
117
117
|
|
|
118
|
-
//# sourceMappingURL=migrate-policy-stamps-
|
|
118
|
+
//# sourceMappingURL=migrate-policy-stamps-BN_Qad6c.js.map
|
package/dist/{migrate-policy-stamps-C4qbQ0jK.js.map → migrate-policy-stamps-BN_Qad6c.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-policy-stamps-
|
|
1
|
+
{"version":3,"file":"migrate-policy-stamps-BN_Qad6c.js","names":[],"sources":["../src/schema/migrate-policy-stamps.ts"],"sourcesContent":["/**\n * The stamps `rebase db migrate` leaves on the policies it applied.\n *\n * A boot leaves a table's policies alone only when each carries the stamp a\n * boot or a push writes (`COMMENT ON POLICY … IS 'rebase:<hash>'`, see\n * `policyStampSql`). `db push` stamps what `policies.sql` just created. A\n * migration runs the same statements — `db generate` appends `policies.sql` to\n * it — and stamped nothing, so the first boot after every migrate dropped and\n * re-created every policy once, an ACCESS EXCLUSIVE lock per table: 44 on the\n * blog scaffold.\n *\n * Migrate cannot stamp what the files hold, the way push stamps what it just\n * ran: a migration was written from the collections of its day, and the\n * database may hold something a later one, or a hand, made since. A stamp\n * there would tell the boot a policy is what the rule makes when it is not, and\n * the boot would never put it right. So each declared policy without a current\n * stamp is asked of Postgres instead, as `db push --dry-run` asks it\n * (`probeRenderedPolicies`): made again from its rule under a probe name, in a\n * transaction that is rolled back, and compared. Only a policy whose stored\n * definition is exactly what its rule makes is stamped. Any other keeps no\n * stamp, and the boot re-applies its table, as before.\n */\nimport path from \"path\";\nimport chalk from \"chalk\";\nimport type { CollectionConfig } from \"@rebasepro/types\";\nimport type { Queryable } from \"../security/policy-drift\";\nimport { withAppClient } from \"../cli-helpers\";\nimport { out, outWarn } from \"../cli-output\";\nimport { pinSearchPath } from \"../connection\";\nimport { planCollectionPolicies } from \"./generate-postgres-ddl-logic\";\nimport { ensureCollectionPolicies, policyStampSql, probeRenderedPolicies, readPolicyStamps } from \"./ensure-collection-policies\";\nimport { underSearchPath } from \"./push-policy-plan\";\nimport { loadCollections } from \"./doctor\";\n\n/**\n * `rebase db migrate`'s last step: stamp what the migration left as its rules\n * make it, on this process's connection. Never fatal — a policy left\n * unstamped costs the next boot a re-apply of its table, which is what every\n * boot after a migrate did before this.\n */\nexport async function stampMigratedPolicies(databaseUrl: string, collectionsPath: string, adminRoleAvailable = true): Promise<void> {\n try {\n const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));\n // The rule the boot's connections follow: `search_path=public` unless\n // the URL pins one of its own, in which case this connection has it too.\n const searchPath = pinSearchPath(databaseUrl) === databaseUrl ? undefined : \"public\";\n const { stamped } = await withAppClient(databaseUrl, client => stampPoliciesStoredAsRendered(\n { query: async (text, values) => ({ rows: (await client.query(text, values)).rows }) },\n collections,\n { searchPath, adminRoleAvailable }\n ));\n if (stamped > 0) {\n out(chalk.gray(` ✓ Stamped ${stamped} RLS ${stamped === 1 ? \"policy\" : \"policies\"} as their rules make them, so the next boot leaves ${stamped === 1 ? \"it\" : \"them\"} alone.`));\n }\n } catch (err) {\n outWarn(chalk.yellow(` ⚠️ The policies could not be stamped (${err instanceof Error ? err.message : String(err)}); the next boot applies them again.`));\n }\n}\n\n/**\n * Stamp every declared policy whose stored definition its rule would store\n * as it is, and none other.\n *\n * @param options.searchPath the `search_path` a boot reads policies under,\n * when the connection's own differs — the stamp hashes `pg_get_expr`,\n * whose spelling depends on it. See `PolicyStamping.searchPath`.\n * @returns how many policies were stamped.\n */\nexport async function stampPoliciesStoredAsRendered(\n client: Queryable,\n collections: CollectionConfig[],\n options: { searchPath?: string; adminRoleAvailable?: boolean } = {}\n): Promise<{ stamped: number }> {\n const { adminRoleAvailable } = options;\n const plans = planCollectionPolicies(collections, { adminRoleAvailable });\n if (plans.length === 0) return { stamped: 0 };\n\n const states = await underSearchPath(client, options.searchPath, () => readPolicyStamps(client, collections, { adminRoleAvailable }));\n const unsure: { schema: string; table: string; name: string }[] = [];\n for (const plan of plans) {\n for (const [name, state] of states.get(plan.qualified) ?? []) {\n if (state !== \"current\") unsure.push({ schema: plan.schema, table: plan.table, name });\n }\n }\n if (unsure.length === 0) return { stamped: 0 };\n\n const confirmed = await probeRenderedPolicies(client, collections, unsure, { searchPath: options.searchPath, adminRoleAvailable });\n const statements: string[] = [];\n let stamped = 0;\n for (const plan of plans) {\n const names = new Set(unsure\n .filter(p => p.schema === plan.schema && p.table === plan.table\n && confirmed.get(`${p.schema}.${p.table}.${p.name}`) === true)\n .map(p => p.name));\n const statement = names.size > 0 ? policyStampSql(plan, names) : undefined;\n if (!statement) continue;\n statements.push(statement);\n stamped += names.size;\n }\n if (statements.length === 0) return { stamped: 0 };\n\n await underSearchPath(client, options.searchPath, async () => {\n for (const statement of statements) await client.query(statement);\n });\n return { stamped };\n}\n\n/**\n * Where the admin switch is not live, move the server-or-admin policies a\n * migration just wrote `TO rebase_admin` back `TO public`, as `db push` and a\n * provisioning boot write them.\n *\n * A migration replays `policies.sql` as `db generate` wrote it, and that cannot\n * know the database it will run on. Left `TO rebase_admin` while admin requests\n * still run as the request role, those policies refuse every admin caller —\n * `dataAsAdmin` in crons, jobs and functions included — and a boot with\n * `REBASE_PROVISION=false` never puts them right.\n *\n * This is the boot's own ensure under the fallback plan, so a table whose\n * policies are already what that plan makes is left alone.\n *\n * @returns how many policies were written again.\n */\nexport async function moveMigratedAdminPoliciesToPublic(\n client: Queryable,\n collections: CollectionConfig[],\n log?: (message: string) => void\n): Promise<number> {\n if (!planCollectionPolicies(collections).some(plan => plan.policies.some(policy => policy.adminTarget))) return 0;\n const outcome = await ensureCollectionPolicies(client, collections, log, { adminRoleAvailable: false });\n if (outcome.failures.length > 0) {\n throw new Error(outcome.failures.map(f => `${f.table}: ${f.error}`).join(\"; \"));\n }\n return outcome.policiesApplied;\n}\n"],"mappings":"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"}
|
|
@@ -3,23 +3,23 @@ __createRequire(import.meta.url);
|
|
|
3
3
|
import { a as createPostgresDatabaseConnection, f as pooledTransactionSettings, h as transactionSettingsStatements, l as isPooledPool, m as transactionSettingsConfig, n as closeWithPool, p as searchPathList } from "./connection-C1zXTPJq.js";
|
|
4
4
|
import { _ as visibleColumnProjection, a as buildSearchColumnSpec, r as SEARCH_UNACCENT_FN, s as hiddenColumnsOption } from "./search-column-BM-GV6vH.js";
|
|
5
5
|
import { r as viewRowsName, t as DEFAULT_VIEW_ROLES } from "./view-names-Dscp6--B.js";
|
|
6
|
-
import { a as diagnoseDbError, c as isEconnrefused, n as closedDatabaseName, ot as extractCauseMessage, r as deepestErrorMessage, u as parseHostInfo } from "./cli-errors-
|
|
7
|
-
import { a as pgErrorToFriendlyMessage, i as isRowLevelSecurityDenial, n as extractPgError, o as reachedDatabase, r as isRoleSwitchingPermissionError, s as sanitizeErrorForClient, t as classifyConnectFailure } from "./pg-error-utils-
|
|
8
|
-
import { t as BranchService } from "./BranchService-
|
|
6
|
+
import { a as diagnoseDbError, c as isEconnrefused, n as closedDatabaseName, ot as extractCauseMessage, r as deepestErrorMessage, u as parseHostInfo } from "./cli-errors-DYTxnLbW.js";
|
|
7
|
+
import { a as pgErrorToFriendlyMessage, i as isRowLevelSecurityDenial, n as extractPgError, o as reachedDatabase, r as isRoleSwitchingPermissionError, s as sanitizeErrorForClient, t as classifyConnectFailure } from "./pg-error-utils-DJHjCF7-.js";
|
|
8
|
+
import { t as BranchService } from "./BranchService-CrXvcES2.js";
|
|
9
9
|
import { i as rlsHandoverNotes, n as resolveRlsSettings, r as rlsConfigFromEnv } from "./rls-settings-BCGMIig3.js";
|
|
10
|
-
import { C as warnOnAnonymousGrants, S as validatePolicyPgRoles, T as warnOnRoleSchemaCollision, _ as recordRequestRoles, a as assertRecordedRequestRoles, b as roleHoldsTableGrants, c as ensureAppRole, d as findExposedInternalTables, f as findOtherRoleMembers, g as readRecordedRequestRoles, h as proveRoleSwitch, i as assertAppRoleRestricted, l as ensureAppRoleGrants, o as authContextStatement, p as findUngrantableTables, r as applyAuthContext, s as detectConnectionPosture, t as REBASE_USER_ROLE$1, u as ensureConnectionInheritsAdminRole, v as revokeUserRoleSql, w as warnOnLegacyRlsFunctions, x as settleAdminSwitch } from "./rls-enforcement-
|
|
10
|
+
import { C as warnOnAnonymousGrants, S as validatePolicyPgRoles, T as warnOnRoleSchemaCollision, _ as recordRequestRoles, a as assertRecordedRequestRoles, b as roleHoldsTableGrants, c as ensureAppRole, d as findExposedInternalTables, f as findOtherRoleMembers, g as readRecordedRequestRoles, h as proveRoleSwitch, i as assertAppRoleRestricted, l as ensureAppRoleGrants, o as authContextStatement, p as findUngrantableTables, r as applyAuthContext, s as detectConnectionPosture, t as REBASE_USER_ROLE$1, u as ensureConnectionInheritsAdminRole, v as revokeUserRoleSql, w as warnOnLegacyRlsFunctions, x as settleAdminSwitch } from "./rls-enforcement-Cc_UhOxb.js";
|
|
11
11
|
import { u as resolveColumnName } from "./column-plan-helpers-BeSztMor.js";
|
|
12
12
|
import { t as AUTH_USERS_COLUMNS } from "./auth-users-columns-C72EMoDJ.js";
|
|
13
|
-
import { n as planSchema } from "./plan-schema-
|
|
14
|
-
import { t as generateSchema } from "./generate-drizzle-schema-logic-
|
|
15
|
-
import { i as renderPgType } from "./render-ddl-
|
|
16
|
-
import { d as typesAgree, s as diffPlanAgainstCatalogue } from "./deferred-index-build-
|
|
17
|
-
import { a as isLockTimeout, c as resolveBootLockOptions, l as sleep, n as BOOT_LOCK_TIMEOUT_MS } from "./boot-ddl-
|
|
18
|
-
import { a as readSchemaFactsFor, r as planCollectionSchemaEnsure } from "./ensure-collection-tables-
|
|
13
|
+
import { n as planSchema } from "./plan-schema-vJd3UEmT.js";
|
|
14
|
+
import { t as generateSchema } from "./generate-drizzle-schema-logic-LTLZvt6r.js";
|
|
15
|
+
import { i as renderPgType } from "./render-ddl-Ci3S_SoI.js";
|
|
16
|
+
import { d as typesAgree, s as diffPlanAgainstCatalogue } from "./deferred-index-build-BCU9RoHK.js";
|
|
17
|
+
import { a as isLockTimeout, c as resolveBootLockOptions, l as sleep, n as BOOT_LOCK_TIMEOUT_MS } from "./boot-ddl-CqGIwSYx.js";
|
|
18
|
+
import { a as readSchemaFactsFor, r as planCollectionSchemaEnsure } from "./ensure-collection-tables-DCJINkT_.js";
|
|
19
19
|
import { a as mergeDatabaseBranch, i as diffDatabaseBranch } from "./branch-diff-CxE4VlxT.js";
|
|
20
20
|
import { t as DatabasePoolManager } from "./databasePoolManager-DIjzlTK4.js";
|
|
21
|
-
import { a as resolveAuthSchema, i as probeAuthSchema, r as assertAuthSchemaCompatible, t as ensureAuthTablesExist } from "./ensure-tables-
|
|
22
|
-
import { a as buildBaasSchema, c as introspectSchema, i as warnOnGeneratedSchemaDrift, l as readRlsStatus, n as diffGeneratedSchemaAgainstCatalogue, o as readCatalogueSchema, s as buildCollectionsFromSchema } from "./generated-schema-diff-
|
|
21
|
+
import { a as resolveAuthSchema, i as probeAuthSchema, r as assertAuthSchemaCompatible, t as ensureAuthTablesExist } from "./ensure-tables-BPGaGh0y.js";
|
|
22
|
+
import { a as buildBaasSchema, c as introspectSchema, i as warnOnGeneratedSchemaDrift, l as readRlsStatus, n as diffGeneratedSchemaAgainstCatalogue, o as readCatalogueSchema, s as buildCollectionsFromSchema } from "./generated-schema-diff-By4dxyTH.js";
|
|
23
23
|
import pg, { Client, DatabaseError, Pool } from "pg";
|
|
24
24
|
import { NodePgDatabase, NodePgSession, NodePgTransaction, drizzle } from "drizzle-orm/node-postgres";
|
|
25
25
|
import { ApiError, assertQueryFieldsReadable, createDdlBootstrapper, createEmailService, logger, rawQueryLoggingEnabled, resolveBatchRefs, rowETag, splitFieldOps } from "@rebasepro/server";
|
|
@@ -23438,6 +23438,8 @@ async function openPostgresDriver(pgConfig, config) {
|
|
|
23438
23438
|
let exposedInternalTables;
|
|
23439
23439
|
/** Set where the admin switch is settled; see {@link PostgresDriverInternals.adminPoliciesLive}. */
|
|
23440
23440
|
let adminPoliciesLive = false;
|
|
23441
|
+
/** Set where the admin switch is settled; see {@link PostgresDriverInternals.adminRequestPoliciesLive}. */
|
|
23442
|
+
let adminRequestPoliciesLive = false;
|
|
23441
23443
|
const rls = resolveRlsSettings({
|
|
23442
23444
|
...declaredDatabaseRls(sourceKey),
|
|
23443
23445
|
...pgConfig.rls
|
|
@@ -23512,6 +23514,7 @@ async function openPostgresDriver(pgConfig, config) {
|
|
|
23512
23514
|
const settled = await settleAdminSwitch(runSql, managedSchemas, rls, { provision });
|
|
23513
23515
|
const request = settled.request;
|
|
23514
23516
|
adminPoliciesLive = settled.adminPoliciesLive;
|
|
23517
|
+
adminRequestPoliciesLive = settled.adminRequestPoliciesLive;
|
|
23515
23518
|
driver.rlsUserRole = rls.defaultRole;
|
|
23516
23519
|
realtimeService.rlsUserRole = rls.defaultRole;
|
|
23517
23520
|
driver.rlsRequest = request;
|
|
@@ -23732,6 +23735,7 @@ async function openPostgresDriver(pgConfig, config) {
|
|
|
23732
23735
|
provisioned: provision,
|
|
23733
23736
|
rls,
|
|
23734
23737
|
adminPoliciesLive,
|
|
23738
|
+
adminRequestPoliciesLive,
|
|
23735
23739
|
managedTables,
|
|
23736
23740
|
rlsEnforcement,
|
|
23737
23741
|
exposedInternalTables,
|
|
@@ -23805,7 +23809,7 @@ function createPostgresBootstrapper(pgConfig) {
|
|
|
23805
23809
|
const openIndexBuildSession = (driverResult) => async () => {
|
|
23806
23810
|
const db = requireProvisioningDb(driverResult);
|
|
23807
23811
|
const pool = "$client" in db ? db.$client : void 0;
|
|
23808
|
-
const { clientIndexBuildSession, isPgPool, poolIndexBuildSession } = await import("./deferred-index-build-
|
|
23812
|
+
const { clientIndexBuildSession, isPgPool, poolIndexBuildSession } = await import("./deferred-index-build-BCU9RoHK.js").then((n) => n.r);
|
|
23809
23813
|
const config = effectiveConfig();
|
|
23810
23814
|
if (isPooledPool(pool) || config.pooled) {
|
|
23811
23815
|
if (!config.directConnectionString) throw pooledWithoutDirectUrlError(DEFAULT_DATA_SOURCE_KEY);
|
|
@@ -23836,7 +23840,7 @@ function createPostgresBootstrapper(pgConfig) {
|
|
|
23836
23840
|
*/
|
|
23837
23841
|
const provisionRlsRuntime = async (driverResult) => {
|
|
23838
23842
|
const db = requireProvisioningDb(driverResult);
|
|
23839
|
-
const { RLS_BOOTSTRAP_STATEMENTS, rlsRuntimeIsCurrent, ensureRequestRoleFunction } = await import("./rls-bootstrap-sql-
|
|
23843
|
+
const { RLS_BOOTSTRAP_STATEMENTS, rlsRuntimeIsCurrent, ensureRequestRoleFunction } = await import("./rls-bootstrap-sql-kPX4-MB1.js").then((n) => n.l);
|
|
23840
23844
|
const run = async (text) => sqlRows(await db.execute(sql.raw(text)));
|
|
23841
23845
|
if (declaredRlsPolicyShape().policyTarget === "requestRole") await ensureRequestRoleFunction(run);
|
|
23842
23846
|
if (await rlsRuntimeIsCurrent(run).catch(() => false)) return;
|
|
@@ -23950,11 +23954,11 @@ function createPostgresBootstrapper(pgConfig) {
|
|
|
23950
23954
|
unavailable: historyUnavailableReason(state, { requireTransaction: false })
|
|
23951
23955
|
}) };
|
|
23952
23956
|
}
|
|
23953
|
-
const { BOOT_LOCK_TIMEOUT_MS } = await import("./boot-ddl-
|
|
23957
|
+
const { BOOT_LOCK_TIMEOUT_MS } = await import("./boot-ddl-CqGIwSYx.js").then((n) => n.i);
|
|
23954
23958
|
const historyTable = await ensureHistoryTableExists(db, { lockTimeoutMs: BOOT_LOCK_TIMEOUT_MS });
|
|
23955
23959
|
const historyIndexes = await ensureHistoryIndexes(db, { lockTimeoutMs: BOOT_LOCK_TIMEOUT_MS });
|
|
23956
23960
|
if (historyIndexes.length > 0) {
|
|
23957
|
-
const { buildDeferredIndexes, scheduleDeferredIndexBuild } = await import("./deferred-index-build-
|
|
23961
|
+
const { buildDeferredIndexes, scheduleDeferredIndexBuild } = await import("./deferred-index-build-BCU9RoHK.js").then((n) => n.r);
|
|
23958
23962
|
const indexOptions = {
|
|
23959
23963
|
log: (message) => logger.info(`[history] ${message}`),
|
|
23960
23964
|
lockTimeoutMs: BOOT_LOCK_TIMEOUT_MS
|
|
@@ -24010,9 +24014,9 @@ function createPostgresBootstrapper(pgConfig) {
|
|
|
24010
24014
|
* proved it can bootstrap with.
|
|
24011
24015
|
*/
|
|
24012
24016
|
async ensureCollectionSchema(collections, driverResult, log) {
|
|
24013
|
-
const { ensureCollectionTables } = await import("./ensure-collection-tables-
|
|
24017
|
+
const { ensureCollectionTables } = await import("./ensure-collection-tables-DCJINkT_.js").then((n) => n.n);
|
|
24014
24018
|
const queryable = provisioningQueryable(driverResult);
|
|
24015
|
-
const { BOOT_LOCK_TIMEOUT_MS } = await import("./boot-ddl-
|
|
24019
|
+
const { BOOT_LOCK_TIMEOUT_MS } = await import("./boot-ddl-CqGIwSYx.js").then((n) => n.i);
|
|
24016
24020
|
const provisionOnly = ["1", "true"].includes((process.env.REBASE_PROVISION_ONLY ?? "").trim().toLowerCase());
|
|
24017
24021
|
const plan = await ensureCollectionTables(queryable, collections, log, {
|
|
24018
24022
|
lockTimeoutMs: BOOT_LOCK_TIMEOUT_MS,
|
|
@@ -24024,7 +24028,7 @@ function createPostgresBootstrapper(pgConfig) {
|
|
|
24024
24028
|
pendingIndexBuild?.cancel();
|
|
24025
24029
|
pendingIndexBuild = void 0;
|
|
24026
24030
|
if (!provisionOnly && plan.deferredIndexes.length > 0) {
|
|
24027
|
-
const { scheduleDeferredIndexBuild } = await import("./deferred-index-build-
|
|
24031
|
+
const { scheduleDeferredIndexBuild } = await import("./deferred-index-build-BCU9RoHK.js").then((n) => n.r);
|
|
24028
24032
|
logger.info(`[schema] ${plan.deferredIndexes.length} index(es) are missing, or were left INVALID, on tables that already exist. They are built in the background once the server is serving, one at a time, without blocking reads or writes.`);
|
|
24029
24033
|
pendingIndexBuild = scheduleDeferredIndexBuild(openIndexBuildSession(driverResult), plan.deferredIndexes, {
|
|
24030
24034
|
log: (message) => logger.info(`[schema] ${message}`),
|
|
@@ -24064,12 +24068,15 @@ function createPostgresBootstrapper(pgConfig) {
|
|
|
24064
24068
|
await provisionRlsRuntime(driverResult);
|
|
24065
24069
|
},
|
|
24066
24070
|
async ensureCollectionPolicies(collections, driverResult, log) {
|
|
24067
|
-
const { ensureCollectionPolicies, describeRulesDropped } = await import("./ensure-collection-policies-
|
|
24071
|
+
const { ensureCollectionPolicies, describeRulesDropped } = await import("./ensure-collection-policies-Bo-_fDAy.js");
|
|
24068
24072
|
const queryable = provisioningQueryable(driverResult);
|
|
24069
24073
|
const { rows } = await queryable.query("SELECT to_regprocedure('rebase.roles()') IS NOT NULL AS present");
|
|
24070
24074
|
if (!rows[0]?.present) await provisionRlsRuntime(driverResult);
|
|
24071
24075
|
const internals = driverResult?.internals;
|
|
24072
|
-
const outcome = await ensureCollectionPolicies(queryable, collections, log, {
|
|
24076
|
+
const outcome = await ensureCollectionPolicies(queryable, collections, log, {
|
|
24077
|
+
adminRoleAvailable: internals?.adminPoliciesLive === true,
|
|
24078
|
+
adminRequestRoleAvailable: internals?.adminRequestPoliciesLive === true
|
|
24079
|
+
});
|
|
24073
24080
|
withheldTables.clear();
|
|
24074
24081
|
for (const u of outcome.unsecured.filter((u) => u.grantWithdrawn)) {
|
|
24075
24082
|
const dot = u.table.indexOf(".");
|
|
@@ -24090,7 +24097,7 @@ function createPostgresBootstrapper(pgConfig) {
|
|
|
24090
24097
|
for (const u of outcome.unsecured.filter((u) => u.grantWithdrawn)) logger.error(`🔐 [rls] Could not enable row-level security on "${u.table}": ${u.error}. Its privileges have been revoked from the request role, so the table is unreachable rather than unprotected. Reads and writes to that collection will fail until RLS can be enabled.`);
|
|
24091
24098
|
if (unrevoked.length > 0) throw new Error("Refusing to start: row-level security could not be enabled on " + unrevoked.map((u) => `"${u.table}" (${u.error})`).join(", ") + ", and the privileges granted to the request role could not be revoked either. The table would be served with no row filtering. Fix the database permissions (the connection role must own these tables, or be able to ALTER them) and boot again.");
|
|
24092
24099
|
try {
|
|
24093
|
-
const { dropLegacyAuthSchema } = await import("./rls-bootstrap-sql-
|
|
24100
|
+
const { dropLegacyAuthSchema } = await import("./rls-bootstrap-sql-kPX4-MB1.js").then((n) => n.l);
|
|
24094
24101
|
await dropLegacyAuthSchema(async (text) => (await queryable.query(text)).rows, {
|
|
24095
24102
|
info: (m) => logger.info(m),
|
|
24096
24103
|
warn: (m) => logger.warn(m)
|
|
@@ -24196,7 +24203,7 @@ function createPostgresBootstrapper(pgConfig) {
|
|
|
24196
24203
|
return driverResult.internals.driver.admin;
|
|
24197
24204
|
},
|
|
24198
24205
|
async initializeWebsockets(server, realtimeService, driver, config, adapter, limits) {
|
|
24199
|
-
const { createPostgresWebSocket, isSocketRealtimeService, socketRealtimeMissing } = await import("./websocket-
|
|
24206
|
+
const { createPostgresWebSocket, isSocketRealtimeService, socketRealtimeMissing } = await import("./websocket-B7ex6AQM.js").then((n) => n.c);
|
|
24200
24207
|
if (!isSocketRealtimeService(realtimeService)) throw new Error(`The realtime service handed to the Postgres socket cannot serve it — it has no ${socketRealtimeMissing(realtimeService).join(", ")}. Every socket would fail on its first frame.`);
|
|
24201
24208
|
const realtimeConfig = effectiveConfig().realtime;
|
|
24202
24209
|
const maxSocketsPerUser = realtimeConfig?.maxSocketsPerUser !== void 0 ? parseMaxSocketsPerUser(realtimeConfig.maxSocketsPerUser, "realtime.maxSocketsPerUser") : void 0;
|
|
@@ -24358,4 +24365,4 @@ async function openRebase(options) {
|
|
|
24358
24365
|
//#endregion
|
|
24359
24366
|
export { AuthenticatedPostgresBackendDriver as $, budgetSendBuffers as A, mfaFactors as B, PG_NOTIFY_MAX_PAYLOAD_BYTES as C, MemoryChannelBus as D, parseChannelBusPayload as E, createAuthSchema as F, recoveryCodesRelations as G, passwordResetTokens as H, magicLinkTokens as I, userIdentities as J, refreshTokens as K, magicLinkTokensRelations as L, terminateIfBacklogged as M, assertReadRequestReadable as N, frameByteLength as O, appConfig as P, usersSchema as Q, mfaChallenges as R, DEFAULT_BATCH_WINDOW_MS as S, parseChannelBusFrame as T, passwordResetTokensRelations as U, mfaFactorsRelations as V, recoveryCodes as W, users as X, userIdentitiesRelations as Y, usersRelations as Z, parseRealtimeTuning as _, listedColumnKeys as _t, openPostgresDriver as a, isRoleSwitchingOptedOut as at, resolveChannelBusSetting as b, resolveSourceUrls as c, SqlResultTooLargeError as ct, DEFAULT_RECOUNT_MIN_ROWS as d, DrizzleConditionBuilder as dt, CONNECTION_OWNER as et, PostgresRealtimeProvider as f, PostgresConditionBuilder as ft, parseMaxSubscriptionsPerSocket as g, joinColumn as gt, parseMaxSocketsPerUser as h, getUnknownFilterFieldsMode as ht, isScaffoldedLocalDatabase as i, effectiveSqlRole as it, reapSilentSockets as j, isChannelBusInstance$1 as k, PostgresCollectionRegistry as l, isNestedPath as lt, packEntityChanges as m, escapeLikePattern as mt, createPostgresBootstrapper as n, RoleSwitchUnavailableError as nt, postgresDriverConfigFromEnv as o, sqlRoleRanAs as ot, RealtimeService as p, configureUnknownFilterFields as pt, refreshTokensRelations as q, describeSchemaDriftCause as r, branchParentDatabase as rt, resolveDriftCheckName as s, SQL_RESULT_BYTE_BUDGET as st, openRebase as t, PostgresBackendDriver as tt, DEFAULT_MAX_SUBSCRIPTIONS_PER_SOCKET as u, resolveNestedPath as ut, refetchConcurrencyFor as v, PostgresChannelBus as w, CHANNEL_BUS_NOTIFY_CHANNEL as x, createChannelBus as y, mfaChallengesRelations as z };
|
|
24360
24367
|
|
|
24361
|
-
//# sourceMappingURL=open-rebase-
|
|
24368
|
+
//# sourceMappingURL=open-rebase-40paQfVW.js.map
|