@rebasepro/server-postgres 0.26.0 → 0.27.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/README.md +1 -1
- package/dist/{BranchService-CWBnDhcv.js → BranchService-B9Lu8e-P.js} +3 -3
- package/dist/{BranchService-CWBnDhcv.js.map → BranchService-B9Lu8e-P.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +7 -0
- package/dist/auth/services.d.ts +15 -1
- package/dist/{backup-cli-PoRG-zEq.js → backup-cli-BZM2Fj1I.js} +4 -4
- package/dist/backup-cli-BZM2Fj1I.js.map +1 -0
- package/dist/{boot-ddl-EsgqDkx0.js → boot-ddl-yukSebLA.js} +2 -2
- package/dist/{boot-ddl-EsgqDkx0.js.map → boot-ddl-yukSebLA.js.map} +1 -1
- package/dist/{cli-console-f0k6_TsJ.js → cli-console-BtzxzzvU.js} +5 -5
- package/dist/{cli-console-f0k6_TsJ.js.map → cli-console-BtzxzzvU.js.map} +1 -1
- package/dist/{cli-errors-DsYyNYzd.js → cli-errors-BBSJqlYX.js} +6 -6
- package/dist/{cli-errors-DsYyNYzd.js.map → cli-errors-BBSJqlYX.js.map} +1 -1
- package/dist/cli.js +30 -30
- package/dist/{column-plan-helpers-IG6uFb1s.js → column-plan-helpers-BeSztMor.js} +5 -1
- package/dist/{column-plan-helpers-IG6uFb1s.js.map → column-plan-helpers-BeSztMor.js.map} +1 -1
- package/dist/{deferred-index-build-CqaOv1Xx.js → deferred-index-build-DRnoMq-O.js} +5 -5
- package/dist/{deferred-index-build-CqaOv1Xx.js.map → deferred-index-build-DRnoMq-O.js.map} +1 -1
- package/dist/{doctor-DW_mlTzz.js → doctor-Cs6AtizY.js} +6 -6
- package/dist/{doctor-DW_mlTzz.js.map → doctor-Cs6AtizY.js.map} +1 -1
- package/dist/{ensure-collection-policies-DLWgabQ2.js → ensure-collection-policies-H8HN1Gbd.js} +7 -7
- package/dist/{ensure-collection-policies-DLWgabQ2.js.map → ensure-collection-policies-H8HN1Gbd.js.map} +1 -1
- package/dist/{ensure-collection-tables-CFIRq8ni.js → ensure-collection-tables-BeF1lArf.js} +7 -7
- package/dist/{ensure-collection-tables-CFIRq8ni.js.map → ensure-collection-tables-BeF1lArf.js.map} +1 -1
- package/dist/{ensure-tables-4nA-tfwi.js → ensure-tables-DDkNaPN2.js} +3 -3
- package/dist/{ensure-tables-4nA-tfwi.js.map → ensure-tables-DDkNaPN2.js.map} +1 -1
- package/dist/{enum-labels-kept-PcPW65xy.js → enum-labels-kept-B6loB2U_.js} +3 -3
- package/dist/{enum-labels-kept-PcPW65xy.js.map → enum-labels-kept-B6loB2U_.js.map} +1 -1
- package/dist/{generate-drizzle-schema-DC0BOUpn.js → generate-drizzle-schema-D_O8_iyT.js} +2 -2
- package/dist/{generate-drizzle-schema-DC0BOUpn.js.map → generate-drizzle-schema-D_O8_iyT.js.map} +1 -1
- package/dist/{generate-drizzle-schema-logic-CPzCRD-8.js → generate-drizzle-schema-logic-D0E64iwx.js} +2 -2
- package/dist/{generate-drizzle-schema-logic-CPzCRD-8.js.map → generate-drizzle-schema-logic-D0E64iwx.js.map} +1 -1
- package/dist/{generate-files-BP-4W_gm.js → generate-files-BpgyRwhU.js} +3 -3
- package/dist/{generate-files-BP-4W_gm.js.map → generate-files-BpgyRwhU.js.map} +1 -1
- package/dist/{generate-postgres-ddl-logic-DPl1oH_z.js → generate-postgres-ddl-logic-CogQBrzs.js} +3 -3
- package/dist/{generate-postgres-ddl-logic-DPl1oH_z.js.map → generate-postgres-ddl-logic-CogQBrzs.js.map} +1 -1
- package/dist/{generated-schema-diff-eZCklRZQ.js → generated-schema-diff-X9NA2Vig.js} +2 -2
- package/dist/{generated-schema-diff-eZCklRZQ.js.map → generated-schema-diff-X9NA2Vig.js.map} +1 -1
- package/dist/index.es.js +10 -10
- package/dist/{migrate-baseline-B-2Ef4Mv.js → migrate-baseline-Bfk1LGC6.js} +2 -2
- package/dist/{migrate-baseline-B-2Ef4Mv.js.map → migrate-baseline-Bfk1LGC6.js.map} +1 -1
- package/dist/{migrate-policy-stamps-BQtFHApx.js → migrate-policy-stamps-DHxwcawC.js} +6 -6
- package/dist/{migrate-policy-stamps-BQtFHApx.js.map → migrate-policy-stamps-DHxwcawC.js.map} +1 -1
- package/dist/{open-rebase-C8jQ6s5a.js → open-rebase-DZ5JbZpg.js} +272 -24
- package/dist/open-rebase-DZ5JbZpg.js.map +1 -0
- package/dist/{pg-error-utils-DhiUTlVx.js → pg-error-utils-BueZEJ0S.js} +2 -2
- package/dist/{pg-error-utils-DhiUTlVx.js.map → pg-error-utils-BueZEJ0S.js.map} +1 -1
- package/dist/{plan-schema-Czf3q4-Q.js → plan-schema-YagMlmNE.js} +2 -2
- package/dist/{plan-schema-Czf3q4-Q.js.map → plan-schema-YagMlmNE.js.map} +1 -1
- package/dist/{policy-drift-X4A-xAzv.js → policy-drift-Dqp_yFeE.js} +2 -2
- package/dist/{policy-drift-X4A-xAzv.js.map → policy-drift-Dqp_yFeE.js.map} +1 -1
- package/dist/{push-index-prebuild-UTvB5pqH.js → push-index-prebuild-hVRrfTi-.js} +4 -4
- package/dist/{push-index-prebuild-UTvB5pqH.js.map → push-index-prebuild-hVRrfTi-.js.map} +1 -1
- package/dist/{push-kept-defaults-BGOlOqRQ.js → push-kept-defaults-M_ZCcXuy.js} +3 -3
- package/dist/{push-kept-defaults-BGOlOqRQ.js.map → push-kept-defaults-M_ZCcXuy.js.map} +1 -1
- package/dist/{push-legacy-renames-BwaKi8xF.js → push-legacy-renames-DcoAWmGt.js} +4 -4
- package/dist/{push-legacy-renames-BwaKi8xF.js.map → push-legacy-renames-DcoAWmGt.js.map} +1 -1
- package/dist/{push-policy-plan-DQ2tWceD.js → push-policy-plan-Bq1bcb3Y.js} +4 -4
- package/dist/{push-policy-plan-DQ2tWceD.js.map → push-policy-plan-Bq1bcb3Y.js.map} +1 -1
- package/dist/{render-ddl-4v88y-Gv.js → render-ddl-D5jeXKR-.js} +2 -2
- package/dist/{render-ddl-4v88y-Gv.js.map → render-ddl-D5jeXKR-.js.map} +1 -1
- package/dist/schema/doctor-cli.js +3 -3
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-postgres-ddl.js +1 -1
- package/dist/schema/introspect-db.js +1 -1
- package/dist/services/channel-bus/PostgresChannelBus.d.ts +1 -0
- package/dist/services/realtimeService.d.ts +30 -1
- package/dist/{websocket-CKYc3V4N.js → websocket-C9Fx7iSx.js} +32 -6
- package/dist/websocket-C9Fx7iSx.js.map +1 -0
- package/package.json +7 -7
- package/dist/backup-cli-PoRG-zEq.js.map +0 -1
- package/dist/open-rebase-C8jQ6s5a.js.map +0 -1
- package/dist/websocket-CKYc3V4N.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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 forAtlas, A as getUndeclaredConstraintExcludes, B as withAppClient, C as dropDevDatabase, D as getSearchExcludes, E as getForeignIndexExcludes, F as queryUndeclarableConstraints, G as prepareGeneratedSqlDir, H as DESIRED_STATE_URL, I as readSearchDdl, J as detectDestructiveStatements, K as decidePushSafety, L as readTriggersDdl, M as loadCollectionsForCli, N as queryColumnTypes, O as getTableExcludes, P as queryGeneratedColumnDependencies, Q as warnIfYesApprovedDestructive, R as readVectorDdl, S as diagnoseMissingBin, T as ensureDevDatabaseExists, U as GENERATED_SQL_DIR, V as workspaceMemberDir, W as generatedSqlDir, X as fromAlterTable, Y as extractPlanStatements, Z as isSyncedPlan, _ as closeAppClients, a as diagnoseDbError, b as describeReinstallCommand, c as isEconnrefused, d as reportCommandFailure, f as ExcludeIntrospectionError, g as atlasDevDatabaseUrl, h as applyVectorDdl, i as diagnoseAtlasFailure, j as getVectorExcludes, k as getTriggerExcludes, l as isSslNotEnabled, m as applyTriggersDdl, o as formatForeignGeneratedColumnBanner, p as applySearchDdl, q as destructiveOptInFlag, s as isAuthFailure, t as checkDatabaseConnectivity, tt as redactConnectionPasswords, v as describeBuildScriptRemedy, w as dropGeneratedColumns, x as detectProjectPackageManager, y as describeDevAddCommand, z as resolveLocalBin } from "./cli-errors-
|
|
4
|
+
import { $ as forAtlas, A as getUndeclaredConstraintExcludes, B as withAppClient, C as dropDevDatabase, D as getSearchExcludes, E as getForeignIndexExcludes, F as queryUndeclarableConstraints, G as prepareGeneratedSqlDir, H as DESIRED_STATE_URL, I as readSearchDdl, J as detectDestructiveStatements, K as decidePushSafety, L as readTriggersDdl, M as loadCollectionsForCli, N as queryColumnTypes, O as getTableExcludes, P as queryGeneratedColumnDependencies, Q as warnIfYesApprovedDestructive, R as readVectorDdl, S as diagnoseMissingBin, T as ensureDevDatabaseExists, U as GENERATED_SQL_DIR, V as workspaceMemberDir, W as generatedSqlDir, X as fromAlterTable, Y as extractPlanStatements, Z as isSyncedPlan, _ as closeAppClients, a as diagnoseDbError, b as describeReinstallCommand, c as isEconnrefused, d as reportCommandFailure, f as ExcludeIntrospectionError, g as atlasDevDatabaseUrl, h as applyVectorDdl, i as diagnoseAtlasFailure, j as getVectorExcludes, k as getTriggerExcludes, l as isSslNotEnabled, m as applyTriggersDdl, o as formatForeignGeneratedColumnBanner, p as applySearchDdl, q as destructiveOptInFlag, s as isAuthFailure, t as checkDatabaseConnectivity, tt as redactConnectionPasswords, v as describeBuildScriptRemedy, w as dropGeneratedColumns, x as detectProjectPackageManager, y as describeDevAddCommand, z as resolveLocalBin } from "./cli-errors-BBSJqlYX.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 { S as dropLegacyAuthSchema, T as execa, b as RLS_BOOTSTRAP_SQL, c as isDriverDbSubcommand, d as resolveBranchSwitches, f as unexpectedBranchArgs, g as collectionsPathIn, i as latestRecordedMigration, l as backupActionOf, m as assertKnownFlags, o as planBaseline, r as describeBaselinePlan, s as DRIVER_DB_SUBCOMMANDS, t as baselineVersionProblem, v as parseDriverLine, y as resolveDriverSwitches } from "./migrate-baseline-
|
|
7
|
+
import { S as dropLegacyAuthSchema, T as execa, b as RLS_BOOTSTRAP_SQL, c as isDriverDbSubcommand, d as resolveBranchSwitches, f as unexpectedBranchArgs, g as collectionsPathIn, i as latestRecordedMigration, l as backupActionOf, m as assertKnownFlags, o as planBaseline, r as describeBaselinePlan, s as DRIVER_DB_SUBCOMMANDS, t as baselineVersionProblem, v as parseDriverLine, y as resolveDriverSwitches } from "./migrate-baseline-Bfk1LGC6.js";
|
|
8
8
|
import { formatRelativeTime } from "@rebasepro/utils";
|
|
9
9
|
import path from "path";
|
|
10
10
|
import fs from "fs";
|
|
@@ -1205,7 +1205,7 @@ function generatesInProcess() {
|
|
|
1205
1205
|
async function generateInProcess(what, label, run) {
|
|
1206
1206
|
let generators;
|
|
1207
1207
|
try {
|
|
1208
|
-
generators = await import("./generate-files-
|
|
1208
|
+
generators = await import("./generate-files-BpgyRwhU.js").then((n) => n.t);
|
|
1209
1209
|
} catch (err) {
|
|
1210
1210
|
outError(chalk.red(`✗ Failed to run ${what}: ${err instanceof Error ? err.message : String(err)}`));
|
|
1211
1211
|
process.exit(1);
|
|
@@ -1252,7 +1252,7 @@ async function runPluginCommand(args) {
|
|
|
1252
1252
|
else if (domain === "schema") await schemaCommand(subcommand, args);
|
|
1253
1253
|
else if (domain === "doctor") await doctorPluginCommand(args);
|
|
1254
1254
|
else if (domain === "console") {
|
|
1255
|
-
const { consoleCommand } = await import("./cli-console-
|
|
1255
|
+
const { consoleCommand } = await import("./cli-console-BtzxzzvU.js");
|
|
1256
1256
|
process.exitCode = await consoleCommand(args);
|
|
1257
1257
|
} else {
|
|
1258
1258
|
outError(chalk.red(`Unknown domain command: ${domain}`));
|
|
@@ -1419,7 +1419,7 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1419
1419
|
return;
|
|
1420
1420
|
}
|
|
1421
1421
|
if (subcommand === "backup" || subcommand === "restore" || subcommand === "backups") {
|
|
1422
|
-
const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-
|
|
1422
|
+
const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-BZM2Fj1I.js").then((n) => n.t);
|
|
1423
1423
|
if (subcommand === "backup" && backupActionOf(rawArgs) === "list") await backupsCommand(rawArgs);
|
|
1424
1424
|
else if (subcommand === "backup") await backupCommand(rawArgs);
|
|
1425
1425
|
else if (subcommand === "restore") await restoreCommand(rawArgs);
|
|
@@ -1466,7 +1466,7 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1466
1466
|
}
|
|
1467
1467
|
const searchContent = readSearchDdl();
|
|
1468
1468
|
if (searchContent) {
|
|
1469
|
-
const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-
|
|
1469
|
+
const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-CogQBrzs.js").then((n) => n.o);
|
|
1470
1470
|
const migrationConflicts = findGeneratedColumnConflicts(parseColumnMutations(migrationContent), searchColumnDependencies(await loadCollectionsForCli(collectionsPath)));
|
|
1471
1471
|
const preamble = migrationDropPreamble(migrationConflicts);
|
|
1472
1472
|
if (preamble) {
|
|
@@ -1734,7 +1734,7 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1734
1734
|
if (databaseUrl) {
|
|
1735
1735
|
await ensureRlsUserRole(databaseUrl);
|
|
1736
1736
|
await retireLegacyAuthSchema(databaseUrl);
|
|
1737
|
-
const { stampMigratedPolicies } = await import("./migrate-policy-stamps-
|
|
1737
|
+
const { stampMigratedPolicies } = await import("./migrate-policy-stamps-DHxwcawC.js");
|
|
1738
1738
|
await stampMigratedPolicies(databaseUrl, collectionsPath);
|
|
1739
1739
|
}
|
|
1740
1740
|
}
|
|
@@ -1762,8 +1762,8 @@ async function dbCommand(subcommand, rawArgs) {
|
|
|
1762
1762
|
* no such column reads nothing.
|
|
1763
1763
|
*/
|
|
1764
1764
|
async function keepDatabaseOwnedDefaults(databaseUrl, collectionsPath) {
|
|
1765
|
-
const { loadCollections } = await import("./doctor-
|
|
1766
|
-
const { databaseOwnedDefaultColumns, readKeptDefaults, withKeptDefaults } = await import("./push-kept-defaults-
|
|
1765
|
+
const { loadCollections } = await import("./doctor-Cs6AtizY.js").then((n) => n.t);
|
|
1766
|
+
const { databaseOwnedDefaultColumns, readKeptDefaults, withKeptDefaults } = await import("./push-kept-defaults-M_ZCcXuy.js");
|
|
1767
1767
|
const columns = databaseOwnedDefaultColumns(await loadCollections(path.resolve(process.cwd(), collectionsPath)));
|
|
1768
1768
|
if (columns.length === 0) return;
|
|
1769
1769
|
let kept;
|
|
@@ -1788,8 +1788,8 @@ async function keepDatabaseOwnedDefaults(databaseUrl, collectionsPath) {
|
|
|
1788
1788
|
async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
|
|
1789
1789
|
let renames;
|
|
1790
1790
|
try {
|
|
1791
|
-
const { loadCollections } = await import("./doctor-
|
|
1792
|
-
const { legacyForeignKeyRenames } = await import("./push-legacy-renames-
|
|
1791
|
+
const { loadCollections } = await import("./doctor-Cs6AtizY.js").then((n) => n.t);
|
|
1792
|
+
const { legacyForeignKeyRenames } = await import("./push-legacy-renames-DcoAWmGt.js");
|
|
1793
1793
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1794
1794
|
renames = await withAppClient(databaseUrl, (client) => legacyForeignKeyRenames({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1795
1795
|
} catch {
|
|
@@ -1808,8 +1808,8 @@ async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
|
|
|
1808
1808
|
/** Names the enum labels the database keeps after the collections dropped them. See `schema/enum-labels-kept.ts`. */
|
|
1809
1809
|
async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
|
|
1810
1810
|
try {
|
|
1811
|
-
const { loadCollections } = await import("./doctor-
|
|
1812
|
-
const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-
|
|
1811
|
+
const { loadCollections } = await import("./doctor-Cs6AtizY.js").then((n) => n.t);
|
|
1812
|
+
const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-B6loB2U_.js");
|
|
1813
1813
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1814
1814
|
const kept = await withAppClient(databaseUrl, (client) => keptEnumLabels({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1815
1815
|
if (kept.length > 0) outWarn(chalk.yellow(formatKeptEnumLabelsNotice(kept)));
|
|
@@ -1818,8 +1818,8 @@ async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
|
|
|
1818
1818
|
async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
|
|
1819
1819
|
let missing;
|
|
1820
1820
|
try {
|
|
1821
|
-
const { loadCollections } = await import("./doctor-
|
|
1822
|
-
const { missingForeignKeyIndexes } = await import("./push-index-prebuild-
|
|
1821
|
+
const { loadCollections } = await import("./doctor-Cs6AtizY.js").then((n) => n.t);
|
|
1822
|
+
const { missingForeignKeyIndexes } = await import("./push-index-prebuild-hVRrfTi-.js");
|
|
1823
1823
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1824
1824
|
missing = await withAppClient(databaseUrl, (client) => missingForeignKeyIndexes({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
|
|
1825
1825
|
} catch {
|
|
@@ -1829,7 +1829,7 @@ async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
|
|
|
1829
1829
|
if (missing.length === 0 || dryRun) return names;
|
|
1830
1830
|
out(chalk.gray(` Building ${missing.length} foreign-key index(es) on existing tables first — CONCURRENTLY, so writes go on:`));
|
|
1831
1831
|
try {
|
|
1832
|
-
const { buildDeferredIndexes } = await import("./deferred-index-build-
|
|
1832
|
+
const { buildDeferredIndexes } = await import("./deferred-index-build-DRnoMq-O.js").then((n) => n.r);
|
|
1833
1833
|
const outcome = await withAppClient(databaseUrl, (client) => buildDeferredIndexes(async () => ({
|
|
1834
1834
|
dedicated: true,
|
|
1835
1835
|
query: async (text) => ({ rows: (await client.query(text)).rows }),
|
|
@@ -1877,8 +1877,8 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
|
|
|
1877
1877
|
let unsecured;
|
|
1878
1878
|
let userRole;
|
|
1879
1879
|
try {
|
|
1880
|
-
const { lockCollectionTables } = await import("./ensure-collection-policies-
|
|
1881
|
-
const { loadCollections } = await import("./doctor-
|
|
1880
|
+
const { lockCollectionTables } = await import("./ensure-collection-policies-H8HN1Gbd.js");
|
|
1881
|
+
const { loadCollections } = await import("./doctor-Cs6AtizY.js").then((n) => n.t);
|
|
1882
1882
|
userRole = (await import("./rls-enforcement-BOHuHVlc.js").then((n) => n.l)).REBASE_USER_ROLE;
|
|
1883
1883
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
1884
1884
|
({unsecured} = await withAppClient(databaseUrl, (client) => lockCollectionTables({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections)));
|
|
@@ -1914,8 +1914,8 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
|
|
|
1914
1914
|
async function ensureAuthTables(databaseUrl, collectionsPath) {
|
|
1915
1915
|
try {
|
|
1916
1916
|
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
1917
|
-
const { ensureAuthTablesExist } = await import("./ensure-tables-
|
|
1918
|
-
const { loadCollections } = await import("./doctor-
|
|
1917
|
+
const { ensureAuthTablesExist } = await import("./ensure-tables-DDkNaPN2.js").then((n) => n.n);
|
|
1918
|
+
const { loadCollections } = await import("./doctor-Cs6AtizY.js").then((n) => n.t);
|
|
1919
1919
|
const authCollection = (await loadCollections(path.resolve(process.cwd(), collectionsPath))).find((c) => {
|
|
1920
1920
|
const a = c.auth;
|
|
1921
1921
|
return a === true || typeof a === "object" && a !== null && a.enabled === true;
|
|
@@ -1995,9 +1995,9 @@ async function applyPolicies(databaseUrl, collectionsPath) {
|
|
|
1995
1995
|
*/
|
|
1996
1996
|
async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
|
|
1997
1997
|
try {
|
|
1998
|
-
const { loadCollections } = await import("./doctor-
|
|
1999
|
-
const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-
|
|
2000
|
-
const { policyStampSql } = await import("./ensure-collection-policies-
|
|
1998
|
+
const { loadCollections } = await import("./doctor-Cs6AtizY.js").then((n) => n.t);
|
|
1999
|
+
const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-CogQBrzs.js").then((n) => n.o);
|
|
2000
|
+
const { policyStampSql } = await import("./ensure-collection-policies-H8HN1Gbd.js");
|
|
2001
2001
|
const { pinSearchPath } = await import("./connection-czvI7TZL.js").then((n) => n.n);
|
|
2002
2002
|
return {
|
|
2003
2003
|
statements: stampableTables(planCollectionPolicies(await loadCollections(path.resolve(process.cwd(), collectionsPath))), policiesSql).map((plan) => policyStampSql(plan)).filter((statement) => statement !== void 0),
|
|
@@ -2015,8 +2015,8 @@ async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
|
|
|
2015
2015
|
*/
|
|
2016
2016
|
async function readPolicyPushPlan(databaseUrl, collectionsPath) {
|
|
2017
2017
|
try {
|
|
2018
|
-
const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-
|
|
2019
|
-
const { loadCollections } = await import("./doctor-
|
|
2018
|
+
const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-Bq1bcb3Y.js");
|
|
2019
|
+
const { loadCollections } = await import("./doctor-Cs6AtizY.js").then((n) => n.t);
|
|
2020
2020
|
const { pinSearchPath } = await import("./connection-czvI7TZL.js").then((n) => n.n);
|
|
2021
2021
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2022
2022
|
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" }));
|
|
@@ -2044,8 +2044,8 @@ async function readPolicyPushPlan(databaseUrl, collectionsPath) {
|
|
|
2044
2044
|
*/
|
|
2045
2045
|
async function reconcilePolicies(databaseUrl, collectionsPath) {
|
|
2046
2046
|
try {
|
|
2047
|
-
const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-
|
|
2048
|
-
const { loadCollections } = await import("./doctor-
|
|
2047
|
+
const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-Dqp_yFeE.js").then((n) => n.s);
|
|
2048
|
+
const { loadCollections } = await import("./doctor-Cs6AtizY.js").then((n) => n.t);
|
|
2049
2049
|
const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
|
|
2050
2050
|
await withAppClient(databaseUrl, async (client) => {
|
|
2051
2051
|
const drift = await checkPolicyDrift(client, collections);
|
|
@@ -2131,7 +2131,7 @@ async function branchCommand(rawArgs) {
|
|
|
2131
2131
|
process.exit(1);
|
|
2132
2132
|
}
|
|
2133
2133
|
const { DatabasePoolManager } = await import("./databasePoolManager-3stMNFL-.js").then((n) => n.n);
|
|
2134
|
-
const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-
|
|
2134
|
+
const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-B9Lu8e-P.js").then((n) => n.n);
|
|
2135
2135
|
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
2136
2136
|
const { Pool } = await import("pg");
|
|
2137
2137
|
const healed = await reopenClosedDatabases(databaseUrl, [branchAction === "create" ? createSource(rawArgs) : void 0, process.env[ACTIVE_BRANCH_DATABASE_ENV]]);
|
|
@@ -2678,9 +2678,9 @@ async function schemaStaleCommand(rawArgs) {
|
|
|
2678
2678
|
const schemaFile = path.resolve(process.cwd(), outputPath);
|
|
2679
2679
|
const fix = Boolean(argsList["--fix"]);
|
|
2680
2680
|
const generatedExists = fs.existsSync(schemaFile);
|
|
2681
|
-
const { loadCollections } = await import("./doctor-
|
|
2681
|
+
const { loadCollections } = await import("./doctor-Cs6AtizY.js").then((n) => n.t);
|
|
2682
2682
|
const { findLegacyForeignKeyNames, compareGeneratedDeclarations, staleVerdict } = await import("./generated-schema-staleness-BvNF3i-s.js").then((n) => n.r);
|
|
2683
|
-
const { generateSchema } = await import("./generate-drizzle-schema-logic-
|
|
2683
|
+
const { generateSchema } = await import("./generate-drizzle-schema-logic-D0E64iwx.js").then((n) => n.n);
|
|
2684
2684
|
const { relationalCollections } = await import("@rebasepro/common");
|
|
2685
2685
|
let stale = [];
|
|
2686
2686
|
let differences = [];
|
|
@@ -140,6 +140,10 @@ var idColumnDefault = (propName, prop, collection) => {
|
|
|
140
140
|
if (typeof isId !== "string") return void 0;
|
|
141
141
|
if (prop.type === "string" && isId === "uuid") return { kind: "uuid" };
|
|
142
142
|
if (prop.type === "number" && isId === "increment") return { kind: "identity" };
|
|
143
|
+
if (isId === "increment" || isId === "uuid") {
|
|
144
|
+
const needs = isId === "increment" ? "number" : "string";
|
|
145
|
+
throw new Error(`Property "${propName}" of collection "${collection.slug ?? collection.name ?? "(unnamed)"}" is a ${prop.type} property, and \`isId: "${isId}"\` needs a ${needs} property. ` + (isId === "increment" ? "Make the key `type: \"number\"`, or use `isId: \"uuid\"` for a string key." : "Make the key `type: \"string\"`, or use `isId: \"increment\"` for a number key."));
|
|
146
|
+
}
|
|
143
147
|
if (isId === "cuid") throw new Error(`Property "${propName}" of collection "${collection.slug ?? collection.name ?? "(unnamed)"}" uses \`isId: "cuid"\`, which Postgres cannot honour: the generated default calls a \`cuid()\` function that Rebase has never created, so every insert relying on it fails. Use \`isId: "uuid"\`, or give the strategy as SQL — \`\`isId: "sql\`my_id()\`"\`\` — and create that function in a migration.`);
|
|
144
148
|
return {
|
|
145
149
|
kind: "sql",
|
|
@@ -154,4 +158,4 @@ var sqlExpressionText = (value) => value.startsWith("sql`") && value.endsWith("`
|
|
|
154
158
|
//#endregion
|
|
155
159
|
export { getPrimaryKeyName as a, isIdProperty as c, sqlExpressionText as d, getPrimaryKeyColumn as i, primaryKeyPropertyNames as l, declaresEnumType as n, getPrimaryKeyProp as o, enumLabelsOf as r, idColumnDefault as s, column_plan_helpers_exports as t, resolveColumnName as u };
|
|
156
160
|
|
|
157
|
-
//# sourceMappingURL=column-plan-helpers-
|
|
161
|
+
//# sourceMappingURL=column-plan-helpers-BeSztMor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-plan-helpers-IG6uFb1s.js","names":[],"sources":["../src/schema/column-plan-helpers.ts"],"sourcesContent":["/**\n * The questions about a property that the schema planner asks first.\n *\n * What is the primary key, what is this column called, what does an id default\n * to, what labels does this enum have. `schema/plan/plan-schema.ts` is the only\n * caller — it is the only reader of a `Property` — and these live beside it\n * rather than inside it because they are also where the *refusals* are, and a\n * refusal wants to be reachable and testable on its own.\n *\n * They were extracted while there were still three emitters, each carrying its\n * own verbatim copy of all four rules until one of them was edited: the audit\n * that produced this module counted twelve open disagreements and found that a\n * third of the commits touching those files were re-synchronisations. The\n * emitters are renderers now and there is nothing left to keep in step, but the\n * questions are still questions about a property rather than about a plan, so\n * this is where they belong.\n *\n * Everything here is pure and synchronous, and it throws rather than guesses:\n * an enum with no values, a `cuid` id on Postgres and a foreign key into a\n * composite key are all configurations that produce a broken database in\n * silence, so they are refused where every path passes.\n */\nimport type {\n CollectionConfig,\n NumberProperty,\n Property,\n StringProperty\n} from \"@rebasepro/types\";\nimport { toSnakeCase } from \"@rebasepro/utils\";\n\n/**\n * Resolve the SQL column name for a property.\n *\n * Uses the explicit `columnName` when set (e.g. from introspection), falling\n * back to `toSnakeCase(propName)` for manually-authored collections.\n */\nexport const resolveColumnName = (propName: string, prop?: Property | null): string => {\n if (prop && \"columnName\" in prop && typeof prop.columnName === \"string\") {\n return prop.columnName;\n }\n return toSnakeCase(propName);\n};\n\n/** Every property that carries a truthy `isId`, in declaration order. */\nconst idPropertyEntries = (collection: CollectionConfig): [string, Property][] =>\n Object.entries(collection.properties ?? {}).filter(\n ([, prop]) => prop && typeof prop === \"object\" && \"isId\" in prop && Boolean((prop as { isId?: unknown }).isId)\n ) as [string, Property][];\n\n/**\n * The properties marked `isId`, in declaration order.\n *\n * Several of them are one composite primary key: the table carries a single\n * `PRIMARY KEY (a, b)` constraint over their columns, and a row's address lists\n * the parts in this same order (`buildCompositeId`), which is the order the\n * admin reads them in too.\n */\nexport const primaryKeyPropertyNames = (collection: CollectionConfig): string[] =>\n idPropertyEntries(collection).map(([name]) => name);\n\n/**\n * A collection's primary key, by both of its names.\n *\n * `name` is the property key — what the generated Drizzle table is keyed by,\n * so it is what a relation's `references` names. `column` is the SQL\n * identifier, so it is what a foreign key's `REFERENCES` names. They differ\n * whenever the key is camelCase or carries a `columnName` (`authorId` is\n * `author_id`, and every table `rebase schema introspect` adopts is spelled\n * that way), and a constraint written with the key named a column that does\n * not exist: `db push` could not build its desired state, and boot failed the\n * constraint on every start.\n */\nexport interface PrimaryKey {\n /** Property key: the Drizzle object key and the JSON field. */\n name: string;\n /** SQL column. */\n column: string;\n /** The declaring property; absent for the implicit `id TEXT` of a collection that declares none. */\n prop?: Property;\n}\n\n/**\n * The one column a link into this collection points at.\n *\n * A foreign key column references a single column, and Postgres only accepts\n * that column when it is unique on its own — `REFERENCES t (a)` against a\n * composite key `(a, b)` fails with \"there is no unique constraint matching\n * given keys for referenced table\". So a link into a collection whose key\n * spans several columns has no column to point at, and it is refused here,\n * naming the link, rather than emitted as a constraint `db push` or boot would\n * then fail to create.\n *\n * @param via the link that needs the column, for the refusal: `relation \"posts.author\"`.\n */\nexport const getPrimaryKeyProp = (collection: CollectionConfig, via: string): PrimaryKey => {\n const ids = idPropertyEntries(collection);\n if (ids.length > 1) {\n throw new Error(\n `${via} points at collection \"${collection.slug ?? collection.name ?? \"(unnamed)\"}\", whose primary ` +\n `key spans ${ids.length} columns (${ids.map(([name]) => `\"${name}\"`).join(\", \")}). A foreign key is ` +\n \"one column and cannot reference a composite key. Point the link at a collection with a \" +\n \"single-column key, or reach these rows with a `via` relation, whose `joinPath` compares every \" +\n \"key column.\"\n );\n }\n const idPropEntry = ids[0];\n if (idPropEntry) {\n const [name, prop] = idPropEntry;\n return { name, column: resolveColumnName(name, prop), prop };\n }\n // Fallback: a collection that declares no `isId` gets an implicit `id`.\n const idProp = collection.properties?.[\"id\"] as Property | undefined;\n return { name: \"id\", column: resolveColumnName(\"id\", idProp), prop: idProp };\n};\n\n/**\n * The primary key's property key. What a Drizzle relation's `references`\n * names. Refused on the same terms as {@link getPrimaryKeyProp}.\n */\nexport const getPrimaryKeyName = (collection: CollectionConfig, via: string): string =>\n getPrimaryKeyProp(collection, via).name;\n\n/**\n * The primary key's column. What a foreign key's `REFERENCES` names. Refused\n * on the same terms as {@link getPrimaryKeyProp}.\n */\nexport const getPrimaryKeyColumn = (collection: CollectionConfig, via: string): string =>\n getPrimaryKeyProp(collection, via).column;\n\nexport const isIdProperty = (propName: string, prop: Property, collection: CollectionConfig): boolean => {\n if (\"isId\" in prop && Boolean(prop.isId)) return true;\n\n // Only fall back to \"id\" when NO property is explicitly marked.\n return idPropertyEntries(collection).length === 0 && propName === \"id\";\n};\n\n/**\n * The labels an `enum` declares, in order, whichever form it was written in.\n *\n * `EnumValues` is `EnumValueConfig[] | Record<id, label>` and the docs recommend\n * the record. Boot-ensure read only the array form — `(p.enum as unknown[]).map`\n * — so a record-form enum threw `p.enum.map is not a function` on a managed\n * tenant, at boot, with no developer in the loop. The other two emitters each\n * carried their own copy of the both-forms walk.\n *\n * An empty list throws rather than returning `[]`. `CREATE TYPE … AS ENUM ()`\n * is not valid SQL, so every emitter \"handled\" it by skipping the type and then\n * typing the column with it anyway: Drizzle referenced an enum variable it never\n * declared (the generated file does not compile), the DDL named a type nothing\n * creates, and boot-ensure's `ADD COLUMN` failed — and add-column is not a\n * survivable action, so the boot died. There is no useful column at the end of\n * any of those paths.\n */\nexport const enumLabelsOf = (propName: string, prop: Property, collection: CollectionConfig): string[] => {\n const values = (prop as { enum?: unknown }).enum;\n if (values === undefined || values === null) return [];\n\n const labels = Array.isArray(values)\n ? values.map((entry: unknown) =>\n String(entry !== null && typeof entry === \"object\" && \"id\" in (entry as Record<string, unknown>)\n ? (entry as Record<string, unknown>).id\n : entry))\n : Object.keys(values as Record<string, unknown>).map(String);\n\n const usable = labels.filter(label => label.length > 0);\n if (usable.length === 0) {\n throw new Error(\n `Property \"${propName}\" of collection \"${collection.slug ?? collection.name ?? \"(unnamed)\"}\" ` +\n \"declares an empty `enum`. A Postgres enum type needs at least one label — \" +\n \"`CREATE TYPE … AS ENUM ()` is not valid SQL — so the column would reference a type \" +\n \"nothing creates. List the values, or drop the `enum` for a plain column.\"\n );\n }\n return usable;\n};\n\n/**\n * Does this property compile to a Postgres enum *type*?\n *\n * Strings only. A `number` property with an `enum` used to create a type on all\n * three paths and then declare the column `NUMERIC`/`INTEGER`, so the type was\n * orphaned the moment it was created and the values it listed were enforced by\n * nothing. The dropdown in the panel is driven by the config, not the column, so\n * nothing is lost by not creating it — and a type no column uses is one more\n * object `db push` has to plan a DROP for.\n */\nexport const declaresEnumType = (prop: Property): boolean =>\n prop.type === \"string\" && Boolean((prop as StringProperty).enum);\n\n/**\n * The `DEFAULT` an id column carries, as the thing itself rather than a\n * rendered string — each emitter spells it differently.\n *\n * The three of them disagreed on all four strategies. The DDL generator wrote\n * `DEFAULT ${prop.isId}` verbatim, so the documented `` isId: \"sql`gen_id()`\" ``\n * reached Postgres with the template wrapper still on it — a syntax error in\n * `schema.sql`. Boot-ensure gave a default to `uuid` and to nothing else, so on\n * a managed tenant every other strategy produced a column with no default at\n * all, and the first insert that trusted the config failed on a NULL primary\n * key. Only the Drizzle generator stripped the wrapper.\n */\nexport type IdColumnDefault =\n /** `gen_random_uuid()` / `.defaultRandom()`. */\n | { kind: \"uuid\" }\n /** `GENERATED BY DEFAULT AS IDENTITY` / `.generatedByDefaultAsIdentity()` — part of the type, not a DEFAULT. */\n | { kind: \"identity\" }\n /** A raw SQL expression, wrapper already stripped. */\n | { kind: \"sql\"; expression: string };\n\n/**\n * Refuses `isId: \"cuid\"`.\n *\n * `DEFAULT cuid()` has been emitted since the option existed and no `cuid()`\n * function has ever been created — not by the generators, not by boot, not by\n * any migration. So the column has never had a working default on Postgres: the\n * first insert that relied on it failed with `function cuid() does not exist`.\n * There is nothing to keep compatible.\n *\n * It is refused rather than implemented. Shipping a real `rebase.cuid()` means a\n * new SQL function in the same carved-out class as the search helpers — excluded\n * from Atlas by pattern, applied by boot, re-applied by push, checked by the\n * doctor, and versioned across the fleet forever — to reproduce a monotonic id\n * that `uuid` already provides and that a project wanting cuid's exact shape can\n * write itself in one line of SQL.\n */\nexport const idColumnDefault = (propName: string, prop: Property, collection: CollectionConfig): IdColumnDefault | undefined => {\n if (!(\"isId\" in prop)) return undefined;\n const isId = (prop as { isId?: unknown }).isId;\n // `true` and `\"manual\"` both mean \"the application supplies it\".\n if (isId === undefined || isId === null || isId === true || isId === \"manual\" || isId === false) return undefined;\n if (typeof isId !== \"string\") return undefined;\n\n if (prop.type === \"string\" && (isId as StringProperty[\"isId\"]) === \"uuid\") return { kind: \"uuid\" };\n if (prop.type === \"number\" && (isId as NumberProperty[\"isId\"]) === \"increment\") return { kind: \"identity\" };\n\n if (isId === \"cuid\") {\n throw new Error(\n `Property \"${propName}\" of collection \"${collection.slug ?? collection.name ?? \"(unnamed)\"}\" ` +\n \"uses `isId: \\\"cuid\\\"`, which Postgres cannot honour: the generated default calls a `cuid()` \" +\n \"function that Rebase has never created, so every insert relying on it fails. \" +\n \"Use `isId: \\\"uuid\\\"`, or give the strategy as SQL — ``isId: \\\"sql`my_id()`\\\"`` — and create that \" +\n \"function in a migration.\"\n );\n }\n\n // Any other string is a raw SQL default. Written either bare\n // (`gen_random_uuid()::text`) or in the documented template form\n // (``sql`gen_random_uuid()::text` ``); the wrapper is markup, not SQL.\n return { kind: \"sql\", expression: sqlExpressionText(isId) };\n};\n\n/**\n * The SQL inside a template-form expression (``sql`now()` `` → `now()`); a\n * bare expression is returned as it is.\n */\nexport const sqlExpressionText = (value: string): string =>\n value.startsWith(\"sql`\") && value.endsWith(\"`\") && value.length >= 5\n ? value.substring(4, value.length - 1)\n : value;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,qBAAqB,UAAkB,SAAmC;CACnF,IAAI,QAAQ,gBAAgB,QAAQ,OAAO,KAAK,eAAe,UAC3D,OAAO,KAAK;CAEhB,OAAO,YAAY,QAAQ;AAC/B;;AAGA,IAAM,qBAAqB,eACvB,OAAO,QAAQ,WAAW,cAAc,CAAC,CAAC,CAAC,CAAC,QACvC,GAAG,UAAU,QAAQ,OAAO,SAAS,YAAY,UAAU,QAAQ,QAAS,KAA4B,IAAI,CACjH;;;;;;;;;AAUJ,IAAa,2BAA2B,eACpC,kBAAkB,UAAU,CAAC,CAAC,KAAK,CAAC,UAAU,IAAI;;;;;;;;;;;;;;AAoCtD,IAAa,qBAAqB,YAA8B,QAA4B;CACxF,MAAM,MAAM,kBAAkB,UAAU;CACxC,IAAI,IAAI,SAAS,GACb,MAAM,IAAI,MACN,GAAG,IAAI,yBAAyB,WAAW,QAAQ,WAAW,QAAQ,YAAY,6BACrE,IAAI,OAAO,YAAY,IAAI,KAAK,CAAC,UAAU,IAAI,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,yNAIpF;CAEJ,MAAM,cAAc,IAAI;CACxB,IAAI,aAAa;EACb,MAAM,CAAC,MAAM,QAAQ;EACrB,OAAO;GAAE;GAAM,QAAQ,kBAAkB,MAAM,IAAI;GAAG;EAAK;CAC/D;CAEA,MAAM,SAAS,WAAW,aAAa;CACvC,OAAO;EAAE,M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AAK,SAAS,YAAa,SAAoC,QAAQ,OAAO,EAAE,MAAM,OAAO;CACjG,IAAI,KAAK,SAAS,YAAa,SAAoC,aAAa,OAAO,EAAE,MAAM,WAAW;CAE1G,IAAI,SAAS,QACT,MAAM,IAAI,MACN,aAAa,SAAS,mBAAmB,WAAW,QAAQ,WAAW,QAAQ,YAAY,2SAK/F;CAMJ,OAAO;EAAE,MAAM;EAAO,YAAY,kBAAkB,IAAI;CAAE;AAC9D;;;;;AAMA,IAAa,qBAAqB,UAC9B,MAAM,WAAW,MAAM,KAAK,MAAM,SAAS,GAAG,KAAK,MAAM,UAAU,IAC7D,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,IACnC"}
|
|
1
|
+
{"version":3,"file":"column-plan-helpers-BeSztMor.js","names":[],"sources":["../src/schema/column-plan-helpers.ts"],"sourcesContent":["/**\n * The questions about a property that the schema planner asks first.\n *\n * What is the primary key, what is this column called, what does an id default\n * to, what labels does this enum have. `schema/plan/plan-schema.ts` is the only\n * caller — it is the only reader of a `Property` — and these live beside it\n * rather than inside it because they are also where the *refusals* are, and a\n * refusal wants to be reachable and testable on its own.\n *\n * They were extracted while there were still three emitters, each carrying its\n * own verbatim copy of all four rules until one of them was edited: the audit\n * that produced this module counted twelve open disagreements and found that a\n * third of the commits touching those files were re-synchronisations. The\n * emitters are renderers now and there is nothing left to keep in step, but the\n * questions are still questions about a property rather than about a plan, so\n * this is where they belong.\n *\n * Everything here is pure and synchronous, and it throws rather than guesses:\n * an enum with no values, a `cuid` id on Postgres and a foreign key into a\n * composite key are all configurations that produce a broken database in\n * silence, so they are refused where every path passes.\n */\nimport type {\n CollectionConfig,\n NumberProperty,\n Property,\n StringProperty\n} from \"@rebasepro/types\";\nimport { toSnakeCase } from \"@rebasepro/utils\";\n\n/**\n * Resolve the SQL column name for a property.\n *\n * Uses the explicit `columnName` when set (e.g. from introspection), falling\n * back to `toSnakeCase(propName)` for manually-authored collections.\n */\nexport const resolveColumnName = (propName: string, prop?: Property | null): string => {\n if (prop && \"columnName\" in prop && typeof prop.columnName === \"string\") {\n return prop.columnName;\n }\n return toSnakeCase(propName);\n};\n\n/** Every property that carries a truthy `isId`, in declaration order. */\nconst idPropertyEntries = (collection: CollectionConfig): [string, Property][] =>\n Object.entries(collection.properties ?? {}).filter(\n ([, prop]) => prop && typeof prop === \"object\" && \"isId\" in prop && Boolean((prop as { isId?: unknown }).isId)\n ) as [string, Property][];\n\n/**\n * The properties marked `isId`, in declaration order.\n *\n * Several of them are one composite primary key: the table carries a single\n * `PRIMARY KEY (a, b)` constraint over their columns, and a row's address lists\n * the parts in this same order (`buildCompositeId`), which is the order the\n * admin reads them in too.\n */\nexport const primaryKeyPropertyNames = (collection: CollectionConfig): string[] =>\n idPropertyEntries(collection).map(([name]) => name);\n\n/**\n * A collection's primary key, by both of its names.\n *\n * `name` is the property key — what the generated Drizzle table is keyed by,\n * so it is what a relation's `references` names. `column` is the SQL\n * identifier, so it is what a foreign key's `REFERENCES` names. They differ\n * whenever the key is camelCase or carries a `columnName` (`authorId` is\n * `author_id`, and every table `rebase schema introspect` adopts is spelled\n * that way), and a constraint written with the key named a column that does\n * not exist: `db push` could not build its desired state, and boot failed the\n * constraint on every start.\n */\nexport interface PrimaryKey {\n /** Property key: the Drizzle object key and the JSON field. */\n name: string;\n /** SQL column. */\n column: string;\n /** The declaring property; absent for the implicit `id TEXT` of a collection that declares none. */\n prop?: Property;\n}\n\n/**\n * The one column a link into this collection points at.\n *\n * A foreign key column references a single column, and Postgres only accepts\n * that column when it is unique on its own — `REFERENCES t (a)` against a\n * composite key `(a, b)` fails with \"there is no unique constraint matching\n * given keys for referenced table\". So a link into a collection whose key\n * spans several columns has no column to point at, and it is refused here,\n * naming the link, rather than emitted as a constraint `db push` or boot would\n * then fail to create.\n *\n * @param via the link that needs the column, for the refusal: `relation \"posts.author\"`.\n */\nexport const getPrimaryKeyProp = (collection: CollectionConfig, via: string): PrimaryKey => {\n const ids = idPropertyEntries(collection);\n if (ids.length > 1) {\n throw new Error(\n `${via} points at collection \"${collection.slug ?? collection.name ?? \"(unnamed)\"}\", whose primary ` +\n `key spans ${ids.length} columns (${ids.map(([name]) => `\"${name}\"`).join(\", \")}). A foreign key is ` +\n \"one column and cannot reference a composite key. Point the link at a collection with a \" +\n \"single-column key, or reach these rows with a `via` relation, whose `joinPath` compares every \" +\n \"key column.\"\n );\n }\n const idPropEntry = ids[0];\n if (idPropEntry) {\n const [name, prop] = idPropEntry;\n return { name, column: resolveColumnName(name, prop), prop };\n }\n // Fallback: a collection that declares no `isId` gets an implicit `id`.\n const idProp = collection.properties?.[\"id\"] as Property | undefined;\n return { name: \"id\", column: resolveColumnName(\"id\", idProp), prop: idProp };\n};\n\n/**\n * The primary key's property key. What a Drizzle relation's `references`\n * names. Refused on the same terms as {@link getPrimaryKeyProp}.\n */\nexport const getPrimaryKeyName = (collection: CollectionConfig, via: string): string =>\n getPrimaryKeyProp(collection, via).name;\n\n/**\n * The primary key's column. What a foreign key's `REFERENCES` names. Refused\n * on the same terms as {@link getPrimaryKeyProp}.\n */\nexport const getPrimaryKeyColumn = (collection: CollectionConfig, via: string): string =>\n getPrimaryKeyProp(collection, via).column;\n\nexport const isIdProperty = (propName: string, prop: Property, collection: CollectionConfig): boolean => {\n if (\"isId\" in prop && Boolean(prop.isId)) return true;\n\n // Only fall back to \"id\" when NO property is explicitly marked.\n return idPropertyEntries(collection).length === 0 && propName === \"id\";\n};\n\n/**\n * The labels an `enum` declares, in order, whichever form it was written in.\n *\n * `EnumValues` is `EnumValueConfig[] | Record<id, label>` and the docs recommend\n * the record. Boot-ensure read only the array form — `(p.enum as unknown[]).map`\n * — so a record-form enum threw `p.enum.map is not a function` on a managed\n * tenant, at boot, with no developer in the loop. The other two emitters each\n * carried their own copy of the both-forms walk.\n *\n * An empty list throws rather than returning `[]`. `CREATE TYPE … AS ENUM ()`\n * is not valid SQL, so every emitter \"handled\" it by skipping the type and then\n * typing the column with it anyway: Drizzle referenced an enum variable it never\n * declared (the generated file does not compile), the DDL named a type nothing\n * creates, and boot-ensure's `ADD COLUMN` failed — and add-column is not a\n * survivable action, so the boot died. There is no useful column at the end of\n * any of those paths.\n */\nexport const enumLabelsOf = (propName: string, prop: Property, collection: CollectionConfig): string[] => {\n const values = (prop as { enum?: unknown }).enum;\n if (values === undefined || values === null) return [];\n\n const labels = Array.isArray(values)\n ? values.map((entry: unknown) =>\n String(entry !== null && typeof entry === \"object\" && \"id\" in (entry as Record<string, unknown>)\n ? (entry as Record<string, unknown>).id\n : entry))\n : Object.keys(values as Record<string, unknown>).map(String);\n\n const usable = labels.filter(label => label.length > 0);\n if (usable.length === 0) {\n throw new Error(\n `Property \"${propName}\" of collection \"${collection.slug ?? collection.name ?? \"(unnamed)\"}\" ` +\n \"declares an empty `enum`. A Postgres enum type needs at least one label — \" +\n \"`CREATE TYPE … AS ENUM ()` is not valid SQL — so the column would reference a type \" +\n \"nothing creates. List the values, or drop the `enum` for a plain column.\"\n );\n }\n return usable;\n};\n\n/**\n * Does this property compile to a Postgres enum *type*?\n *\n * Strings only. A `number` property with an `enum` used to create a type on all\n * three paths and then declare the column `NUMERIC`/`INTEGER`, so the type was\n * orphaned the moment it was created and the values it listed were enforced by\n * nothing. The dropdown in the panel is driven by the config, not the column, so\n * nothing is lost by not creating it — and a type no column uses is one more\n * object `db push` has to plan a DROP for.\n */\nexport const declaresEnumType = (prop: Property): boolean =>\n prop.type === \"string\" && Boolean((prop as StringProperty).enum);\n\n/**\n * The `DEFAULT` an id column carries, as the thing itself rather than a\n * rendered string — each emitter spells it differently.\n *\n * The three of them disagreed on all four strategies. The DDL generator wrote\n * `DEFAULT ${prop.isId}` verbatim, so the documented `` isId: \"sql`gen_id()`\" ``\n * reached Postgres with the template wrapper still on it — a syntax error in\n * `schema.sql`. Boot-ensure gave a default to `uuid` and to nothing else, so on\n * a managed tenant every other strategy produced a column with no default at\n * all, and the first insert that trusted the config failed on a NULL primary\n * key. Only the Drizzle generator stripped the wrapper.\n */\nexport type IdColumnDefault =\n /** `gen_random_uuid()` / `.defaultRandom()`. */\n | { kind: \"uuid\" }\n /** `GENERATED BY DEFAULT AS IDENTITY` / `.generatedByDefaultAsIdentity()` — part of the type, not a DEFAULT. */\n | { kind: \"identity\" }\n /** A raw SQL expression, wrapper already stripped. */\n | { kind: \"sql\"; expression: string };\n\n/**\n * Refuses `isId: \"cuid\"`.\n *\n * `DEFAULT cuid()` has been emitted since the option existed and no `cuid()`\n * function has ever been created — not by the generators, not by boot, not by\n * any migration. So the column has never had a working default on Postgres: the\n * first insert that relied on it failed with `function cuid() does not exist`.\n * There is nothing to keep compatible.\n *\n * It is refused rather than implemented. Shipping a real `rebase.cuid()` means a\n * new SQL function in the same carved-out class as the search helpers — excluded\n * from Atlas by pattern, applied by boot, re-applied by push, checked by the\n * doctor, and versioned across the fleet forever — to reproduce a monotonic id\n * that `uuid` already provides and that a project wanting cuid's exact shape can\n * write itself in one line of SQL.\n */\nexport const idColumnDefault = (propName: string, prop: Property, collection: CollectionConfig): IdColumnDefault | undefined => {\n if (!(\"isId\" in prop)) return undefined;\n const isId = (prop as { isId?: unknown }).isId;\n // `true` and `\"manual\"` both mean \"the application supplies it\".\n if (isId === undefined || isId === null || isId === true || isId === \"manual\" || isId === false) return undefined;\n if (typeof isId !== \"string\") return undefined;\n\n if (prop.type === \"string\" && (isId as StringProperty[\"isId\"]) === \"uuid\") return { kind: \"uuid\" };\n if (prop.type === \"number\" && (isId as NumberProperty[\"isId\"]) === \"increment\") return { kind: \"identity\" };\n\n // A strategy keyword on a type that cannot honour it. Without this it fell\n // through to \"any other string is raw SQL\", and `DEFAULT increment` on a\n // TEXT key — or `DEFAULT uuid` on an INTEGER one — names a column that does\n // not exist, refused by Postgres at the first CREATE TABLE.\n if (isId === \"increment\" || isId === \"uuid\") {\n const needs = isId === \"increment\" ? \"number\" : \"string\";\n throw new Error(\n `Property \"${propName}\" of collection \"${collection.slug ?? collection.name ?? \"(unnamed)\"}\" ` +\n `is a ${prop.type} property, and \\`isId: \"${isId}\"\\` needs a ${needs} property. ` +\n (isId === \"increment\"\n ? \"Make the key `type: \\\"number\\\"`, or use `isId: \\\"uuid\\\"` for a string key.\"\n : \"Make the key `type: \\\"string\\\"`, or use `isId: \\\"increment\\\"` for a number key.\")\n );\n }\n\n if (isId === \"cuid\") {\n throw new Error(\n `Property \"${propName}\" of collection \"${collection.slug ?? collection.name ?? \"(unnamed)\"}\" ` +\n \"uses `isId: \\\"cuid\\\"`, which Postgres cannot honour: the generated default calls a `cuid()` \" +\n \"function that Rebase has never created, so every insert relying on it fails. \" +\n \"Use `isId: \\\"uuid\\\"`, or give the strategy as SQL — ``isId: \\\"sql`my_id()`\\\"`` — and create that \" +\n \"function in a migration.\"\n );\n }\n\n // Any other string is a raw SQL default. Written either bare\n // (`gen_random_uuid()::text`) or in the documented template form\n // (``sql`gen_random_uuid()::text` ``); the wrapper is markup, not SQL.\n return { kind: \"sql\", expression: sqlExpressionText(isId) };\n};\n\n/**\n * The SQL inside a template-form expression (``sql`now()` `` → `now()`); a\n * bare expression is returned as it is.\n */\nexport const sqlExpressionText = (value: string): string =>\n value.startsWith(\"sql`\") && value.endsWith(\"`\") && value.length >= 5\n ? value.substring(4, value.length - 1)\n : value;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,qBAAqB,UAAkB,SAAmC;CACnF,IAAI,QAAQ,gBAAgB,QAAQ,OAAO,KAAK,eAAe,UAC3D,OAAO,KAAK;CAEhB,OAAO,YAAY,QAAQ;AAC/B;;AAGA,IAAM,qBAAqB,eACvB,OAAO,QAAQ,WAAW,cAAc,CAAC,CAAC,CAAC,CAAC,QACvC,GAAG,UAAU,QAAQ,OAAO,SAAS,YAAY,UAAU,QAAQ,QAAS,KAA4B,IAAI,CACjH;;;;;;;;;AAUJ,IAAa,2BAA2B,eACpC,kBAAkB,UAAU,CAAC,CAAC,KAAK,CAAC,UAAU,IAAI;;;;;;;;;;;;;;AAoCtD,IAAa,qBAAqB,YAA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js";
|
|
4
4
|
import { h as searchIndexStatements, n as SEARCH_TEXT_FN, r as SEARCH_UNACCENT_FN, u as searchColumnStamps } from "./search-column-BM-GV6vH.js";
|
|
5
|
-
import { n as extractPgError } from "./pg-error-utils-
|
|
5
|
+
import { n as extractPgError } from "./pg-error-utils-BueZEJ0S.js";
|
|
6
6
|
import { u as vectorIndexStatement } from "./vector-index-DsQ3V2d2.js";
|
|
7
7
|
import { _ as sortIndexSpecs, l as collectionIndexStatement } from "./source-fZb92pN8.js";
|
|
8
|
-
import { a as triggerStatements, i as SET_UPDATED_AT_FN, r as quoteSqlLiteral } from "./plan-schema-
|
|
9
|
-
import { n as renderEnableRls, r as renderPgType, s as renderPrimaryKeyConstraint, t as renderColumnDefinition } from "./render-ddl-
|
|
10
|
-
import { a as isLockTimeout, c as resolveBootLockOptions, l as sleep, o as isMultiStatementRefusal, r as atomicBatch } from "./boot-ddl-
|
|
8
|
+
import { a as triggerStatements, i as SET_UPDATED_AT_FN, r as quoteSqlLiteral } from "./plan-schema-YagMlmNE.js";
|
|
9
|
+
import { n as renderEnableRls, r as renderPgType, s as renderPrimaryKeyConstraint, t as renderColumnDefinition } from "./render-ddl-D5jeXKR-.js";
|
|
10
|
+
import { a as isLockTimeout, c as resolveBootLockOptions, l as sleep, o as isMultiStatementRefusal, r as atomicBatch } from "./boot-ddl-yukSebLA.js";
|
|
11
11
|
import { logger } from "@rebasepro/server";
|
|
12
12
|
//#region src/schema/column-type-drift.ts
|
|
13
13
|
/**
|
|
@@ -1048,4 +1048,4 @@ function scheduleDeferredIndexBuild(openSession, indexes, options = {}) {
|
|
|
1048
1048
|
//#endregion
|
|
1049
1049
|
export { assertSafeIdentifier as a, helperFunctionKey as c, HELPER_FUNCTIONS as i, columnTypeDriftMessage as l, buildDeferredIndexes as n, describeHelperFunction as o, deferred_index_build_exports as r, diffPlanAgainstCatalogue as s, TABLE_BUSY_REASON as t, typesAgree as u };
|
|
1050
1050
|
|
|
1051
|
-
//# sourceMappingURL=deferred-index-build-
|
|
1051
|
+
//# sourceMappingURL=deferred-index-build-DRnoMq-O.js.map
|