@rebasepro/server-postgres 0.13.1-canary.g18cfeb7 → 0.13.1-canary.g1bf9303
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/PostgresBootstrapper.d.ts +26 -0
- package/dist/auth/services.d.ts +21 -0
- package/dist/{auth-users-columns-Do9mw5Y5.js → auth-users-columns-BxT6FRyu.js} +819 -68
- package/dist/auth-users-columns-BxT6FRyu.js.map +1 -0
- package/dist/{backup-service-Bww-Lg0s.js → backup-service-BH0Dzo_h.js} +2 -3
- package/dist/{backup-service-Bww-Lg0s.js.map → backup-service-BH0Dzo_h.js.map} +1 -1
- package/dist/cli-helpers.d.ts +56 -0
- package/dist/cli-output.d.ts +34 -0
- package/dist/data-transformer.d.ts +7 -2
- package/dist/data_driver-ULAyJEi9.js +193 -0
- package/dist/data_driver-ULAyJEi9.js.map +1 -0
- package/dist/ensure-collection-policies-CP5_YttS.js +124 -0
- package/dist/ensure-collection-policies-CP5_YttS.js.map +1 -0
- package/dist/{ensure-collection-tables-DSIxvLLD.js → ensure-collection-tables-DWVISfcC.js} +119 -13
- package/dist/ensure-collection-tables-DWVISfcC.js.map +1 -0
- package/dist/index.es.js +998 -600
- package/dist/index.es.js.map +1 -1
- package/dist/{rls-bootstrap-sql-Bpv3nUZo.js → rls-bootstrap-sql-69hYT8nr.js} +2 -2
- package/dist/{rls-bootstrap-sql-Bpv3nUZo.js.map → rls-bootstrap-sql-69hYT8nr.js.map} +1 -1
- package/dist/rls-enforcement-Ct9ab42o.js +425 -0
- package/dist/rls-enforcement-Ct9ab42o.js.map +1 -0
- package/dist/schema/auth-schema.d.ts +102 -0
- package/dist/schema/doctor-policy-checks.d.ts +28 -0
- package/dist/schema/doctor.d.ts +41 -25
- package/dist/schema/ensure-collection-policies.d.ts +33 -9
- package/dist/schema/ensure-collection-tables.d.ts +60 -6
- package/dist/schema/generate-drizzle-schema-logic.d.ts +9 -1
- package/dist/schema/generate-postgres-ddl-logic.d.ts +48 -0
- package/dist/schema/search-column.d.ts +248 -0
- package/dist/security/rls-enforcement.d.ts +8 -3
- package/dist/services/FetchService.d.ts +24 -0
- package/dist/services/RelationService.d.ts +30 -0
- package/dist/services/collection-helpers.d.ts +26 -0
- package/dist/services/dataService.d.ts +3 -0
- package/dist/services/realtimeService.d.ts +139 -2
- package/dist/{src-C_wvdMnl.js → src-DCdn3Val.js} +35 -3
- package/dist/src-DCdn3Val.js.map +1 -0
- package/dist/utils/drizzle-conditions.d.ts +124 -2
- package/dist/{websocket-D0TBU3ia.js → websocket-C8ZqVBiV.js} +75 -18
- package/dist/websocket-C8ZqVBiV.js.map +1 -0
- package/package.json +6 -6
- package/src/PostgresBackendDriver.ts +7 -3
- package/src/PostgresBootstrapper.ts +95 -9
- package/src/auth/ensure-tables.ts +27 -5
- package/src/auth/services.ts +82 -5
- package/src/backup/backup-cli.ts +59 -57
- package/src/cli-errors.ts +6 -6
- package/src/cli-helpers.ts +110 -4
- package/src/cli-output.ts +43 -0
- package/src/cli.ts +210 -145
- package/src/collections/buildRegistry.ts +3 -1
- package/src/data-transformer.ts +107 -14
- package/src/history/ensure-history-table.ts +2 -2
- package/src/schema/auth-schema.ts +17 -1
- package/src/schema/doctor-cli.ts +14 -65
- package/src/schema/doctor-policy-checks.ts +105 -0
- package/src/schema/doctor.ts +149 -72
- package/src/schema/ensure-collection-policies.ts +99 -6
- package/src/schema/ensure-collection-tables.ts +286 -13
- package/src/schema/generate-drizzle-schema-logic.ts +126 -42
- package/src/schema/generate-drizzle-schema.ts +11 -10
- package/src/schema/generate-postgres-ddl-logic.ts +204 -10
- package/src/schema/generate-postgres-ddl.ts +38 -14
- package/src/schema/introspect-db-logic.ts +65 -33
- package/src/schema/introspect-db.ts +24 -24
- package/src/schema/search-column.ts +643 -0
- package/src/security/rls-enforcement.ts +9 -4
- package/src/services/FetchService.ts +229 -15
- package/src/services/PersistService.ts +24 -1
- package/src/services/RelationService.ts +119 -69
- package/src/services/cdc/trigger-cdc.ts +5 -1
- package/src/services/channel-history.ts +9 -3
- package/src/services/channel-presence.ts +10 -3
- package/src/services/collection-helpers.ts +54 -1
- package/src/services/dataService.ts +3 -0
- package/src/services/pg-notify-listener.ts +1 -1
- package/src/services/realtimeService.ts +347 -86
- package/src/utils/drizzle-conditions.ts +365 -23
- package/src/utils/pg-error-utils.ts +8 -3
- package/src/websocket.ts +113 -16
- package/dist/auth-users-columns-Do9mw5Y5.js.map +0 -1
- package/dist/ensure-collection-policies-DMUdRQdM.js +0 -57
- package/dist/ensure-collection-policies-DMUdRQdM.js.map +0 -1
- package/dist/ensure-collection-tables-DSIxvLLD.js.map +0 -1
- package/dist/policy-CPkCqVTz.js +0 -105
- package/dist/policy-CPkCqVTz.js.map +0 -1
- package/dist/src-C_wvdMnl.js.map +0 -1
- package/dist/websocket-D0TBU3ia.js.map +0 -1
package/src/cli.ts
CHANGED
|
@@ -5,6 +5,7 @@ import path from "path";
|
|
|
5
5
|
import fs from "fs";
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
7
|
import { logger } from "@rebasepro/server";
|
|
8
|
+
import { out, outWarn, outError } from "./cli-output";
|
|
8
9
|
import { formatRelativeTime } from "@rebasepro/utils";
|
|
9
10
|
import {
|
|
10
11
|
diagnoseMissingBin,
|
|
@@ -12,6 +13,10 @@ import {
|
|
|
12
13
|
getTableIncludes,
|
|
13
14
|
getDevDatabaseUrl,
|
|
14
15
|
ensureDevDatabaseExists,
|
|
16
|
+
applySearchDdl,
|
|
17
|
+
getSearchExcludes,
|
|
18
|
+
readSearchDdl,
|
|
19
|
+
seedDevDatabaseSearchHelpers,
|
|
15
20
|
getTableExcludes,
|
|
16
21
|
ExcludeIntrospectionError,
|
|
17
22
|
promptConfirm
|
|
@@ -37,7 +42,7 @@ async function loadEnv(): Promise<void> {
|
|
|
37
42
|
|
|
38
43
|
for (const p of envPaths) {
|
|
39
44
|
if (fs.existsSync(p)) {
|
|
40
|
-
const parsed = dotenv.config({ path: p });
|
|
45
|
+
const parsed = dotenv.config({ path: p, quiet: true });
|
|
41
46
|
if (parsed.parsed) {
|
|
42
47
|
for (const [key, val] of Object.entries(parsed.parsed)) {
|
|
43
48
|
if (process.env[key] === undefined) {
|
|
@@ -54,6 +59,13 @@ async function loadEnv(): Promise<void> {
|
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
export async function runPluginCommand(args: string[]) {
|
|
62
|
+
// Also set as an environment variable, not just per `config()` call: this
|
|
63
|
+
// command spawns `tsx` subprocesses (the schema generator, the DDL
|
|
64
|
+
// generator, doctor) that load `.env` themselves, and they inherit this.
|
|
65
|
+
// dotenv reads it before `options.quiet`; an explicit `false` still wins.
|
|
66
|
+
if (process.env.DOTENV_CONFIG_QUIET === undefined) {
|
|
67
|
+
process.env.DOTENV_CONFIG_QUIET = "true";
|
|
68
|
+
}
|
|
57
69
|
await loadEnv();
|
|
58
70
|
const domain = args[0]; // "db" or "schema"
|
|
59
71
|
const subcommand = args[1];
|
|
@@ -65,15 +77,22 @@ export async function runPluginCommand(args: string[]) {
|
|
|
65
77
|
} else if (domain === "doctor") {
|
|
66
78
|
await doctorPluginCommand(args);
|
|
67
79
|
} else {
|
|
68
|
-
|
|
80
|
+
outError(chalk.red(`Unknown domain command: ${domain}`));
|
|
69
81
|
process.exit(1);
|
|
70
82
|
}
|
|
71
83
|
}
|
|
72
84
|
|
|
85
|
+
/** The migration files on disk, sorted, or none if the directory is absent. */
|
|
86
|
+
function listMigrationFiles(): string[] {
|
|
87
|
+
const dir = path.resolve(process.cwd(), "drizzle", "migrations");
|
|
88
|
+
if (!fs.existsSync(dir)) return [];
|
|
89
|
+
return fs.readdirSync(dir).filter(f => f.endsWith(".sql")).sort();
|
|
90
|
+
}
|
|
91
|
+
|
|
73
92
|
async function dbCommand(subcommand: string, rawArgs: string[]): Promise<void> {
|
|
74
93
|
const VALID_ACTIONS = ["push", "generate", "migrate", "branch", "backup", "restore", "backups"];
|
|
75
94
|
if (!subcommand || !VALID_ACTIONS.includes(subcommand)) {
|
|
76
|
-
|
|
95
|
+
outError(chalk.red(`Unknown db command. Valid: ${VALID_ACTIONS.join(", ")}`));
|
|
77
96
|
process.exit(1);
|
|
78
97
|
}
|
|
79
98
|
|
|
@@ -106,17 +125,19 @@ async function dbCommand(subcommand: string, rawArgs: string[]): Promise<void> {
|
|
|
106
125
|
const collectionsPath = argsList["--collections"] || path.join("..", "config", "collections");
|
|
107
126
|
|
|
108
127
|
if (subcommand === "generate") {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
128
|
+
out("");
|
|
129
|
+
out(chalk.bold(" 📦 Rebase DB Generate"));
|
|
130
|
+
out(chalk.gray(" Step 1/2: Generating Drizzle schema & Postgres DDL from collections..."));
|
|
131
|
+
out("");
|
|
113
132
|
await schemaCommand("generate", rawArgs);
|
|
114
133
|
await generatePostgresDdlCommand(rawArgs);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
134
|
+
out("");
|
|
135
|
+
out(chalk.gray(" Step 2/2: Generating SQL migration files with Atlas..."));
|
|
136
|
+
out("");
|
|
118
137
|
const migrationName = argsList._[0] || "migration";
|
|
138
|
+
const migrationsBefore = listMigrationFiles();
|
|
119
139
|
await runAtlas("migrate", ["diff", migrationName, "--dir", "file://drizzle/migrations", "--to", "file://drizzle/schema.sql"], collectionsPath);
|
|
140
|
+
const wroteNewMigration = listMigrationFiles().length > migrationsBefore.length;
|
|
120
141
|
|
|
121
142
|
// Post-process the newest migration file
|
|
122
143
|
try {
|
|
@@ -137,6 +158,33 @@ async function dbCommand(subcommand: string, rawArgs: string[]): Promise<void> {
|
|
|
137
158
|
/CREATE SCHEMA (?!IF NOT EXISTS)("[^"]+");/g,
|
|
138
159
|
"CREATE SCHEMA IF NOT EXISTS $1;"
|
|
139
160
|
);
|
|
161
|
+
// Atlas never writes the search objects into a migration —
|
|
162
|
+
// it is not shown them — so a migration replayed against a
|
|
163
|
+
// fresh database would build every table except the part
|
|
164
|
+
// that makes search work. Appending, because these are
|
|
165
|
+
// `ALTER TABLE ... ADD COLUMN` over the tables the
|
|
166
|
+
// migration just created.
|
|
167
|
+
//
|
|
168
|
+
// Only into a migration Atlas just wrote. The file picked
|
|
169
|
+
// here is simply the newest one, which when there was no
|
|
170
|
+
// diff is a migration that has already run in production:
|
|
171
|
+
// editing it changes a hash Atlas has recorded, and the
|
|
172
|
+
// appended SQL would never be applied anywhere.
|
|
173
|
+
const searchContent = readSearchDdl();
|
|
174
|
+
if (searchContent && wroteNewMigration) {
|
|
175
|
+
migrationContent = `${migrationContent}\n\n${searchContent}`;
|
|
176
|
+
out(chalk.gray(" ✓ Appended search DDL to the migration"));
|
|
177
|
+
} else if (searchContent) {
|
|
178
|
+
// Reachable whenever a `search` block is the *only*
|
|
179
|
+
// thing that changed: Atlas cannot see one, so it finds
|
|
180
|
+
// nothing to diff and writes no file.
|
|
181
|
+
out(chalk.gray(
|
|
182
|
+
" ℹ Search DDL not written to a migration — this change produced none.\n" +
|
|
183
|
+
" It is applied by `rebase db push`, and at boot by the schema ensure.\n" +
|
|
184
|
+
" For a migration-only deployment, add drizzle/search.sql to a migration by hand."
|
|
185
|
+
));
|
|
186
|
+
}
|
|
187
|
+
|
|
140
188
|
fs.writeFileSync(newestMigrationFile, migrationContent, "utf-8");
|
|
141
189
|
|
|
142
190
|
// Append RLS policies, preceded by the RLS bootstrap so the
|
|
@@ -147,35 +195,35 @@ async function dbCommand(subcommand: string, rawArgs: string[]): Promise<void> {
|
|
|
147
195
|
if (fs.existsSync(policiesFile)) {
|
|
148
196
|
const policiesContent = fs.readFileSync(policiesFile, "utf-8");
|
|
149
197
|
fs.appendFileSync(newestMigrationFile, "\n\n" + RLS_BOOTSTRAP_SQL + "\n" + policiesContent);
|
|
150
|
-
|
|
198
|
+
out(chalk.gray(` ✓ Appended RLS policies to migration file: ${path.basename(newestMigrationFile)}`));
|
|
151
199
|
|
|
152
200
|
// Re-hash the migration directory
|
|
153
|
-
|
|
201
|
+
out(chalk.gray(" Re-hashing migration files..."));
|
|
154
202
|
await runAtlas("migrate", ["hash", "--dir", "file://drizzle/migrations"], collectionsPath);
|
|
155
|
-
|
|
203
|
+
out(chalk.gray(" ✓ Migration directory checksum updated successfully."));
|
|
156
204
|
}
|
|
157
205
|
}
|
|
158
206
|
}
|
|
159
207
|
} catch (err) {
|
|
160
|
-
|
|
208
|
+
outWarn(chalk.yellow(` ⚠️ Failed to append policies or re-hash migration: ${err instanceof Error ? err.message : String(err)}`));
|
|
161
209
|
}
|
|
162
210
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
211
|
+
out("");
|
|
212
|
+
out(` You can now run ${chalk.bold.green("rebase db migrate")} to apply the migrations to your database.`);
|
|
213
|
+
out("");
|
|
166
214
|
} else {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
215
|
+
out("");
|
|
216
|
+
out(chalk.bold(` 🗄️ Rebase DB ${subcommand.charAt(0).toUpperCase() + subcommand.slice(1)}`));
|
|
217
|
+
out("");
|
|
170
218
|
|
|
171
219
|
if (subcommand === "push") {
|
|
172
|
-
|
|
173
|
-
|
|
220
|
+
out(chalk.gray(" Step 1/3: Generating Drizzle schema & Postgres DDL from collections..."));
|
|
221
|
+
out("");
|
|
174
222
|
await schemaCommand("generate", rawArgs);
|
|
175
223
|
await generatePostgresDdlCommand(rawArgs);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
224
|
+
out("");
|
|
225
|
+
out(chalk.gray(" Step 2/3: Pushing schema to database with Atlas..."));
|
|
226
|
+
out("");
|
|
179
227
|
const databaseUrl = process.env.DATABASE_URL;
|
|
180
228
|
if (databaseUrl) {
|
|
181
229
|
await ensureAuthSchemaAndFunctions(databaseUrl);
|
|
@@ -200,19 +248,19 @@ async function dbCommand(subcommand: string, rawArgs: string[]): Promise<void> {
|
|
|
200
248
|
});
|
|
201
249
|
|
|
202
250
|
if (destructive.length > 0) {
|
|
203
|
-
|
|
204
|
-
|
|
251
|
+
outWarn(chalk.yellow(` ⚠️ This push includes ${destructive.length} destructive change(s) that will DESTROY data:`));
|
|
252
|
+
outWarn("");
|
|
205
253
|
for (const d of destructive) {
|
|
206
|
-
|
|
254
|
+
outWarn(chalk.red(` ${d.kind}: `) + chalk.gray(d.statement.replace(/\s+/g, " ")));
|
|
207
255
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
256
|
+
outWarn("");
|
|
257
|
+
outWarn(chalk.yellow(" Full planned changes:"));
|
|
258
|
+
outWarn(chalk.gray(plan.trim().split("\n").map((l) => ` ${l}`).join("\n")));
|
|
259
|
+
outWarn("");
|
|
212
260
|
|
|
213
261
|
if (decision === "refuse") {
|
|
214
|
-
|
|
215
|
-
|
|
262
|
+
outError(chalk.red(" ✗ Aborting: destructive changes require confirmation."));
|
|
263
|
+
outError(chalk.gray(" Re-run interactively, or pass --allow-destructive to proceed. Back up first: rebase db backup"));
|
|
216
264
|
process.exit(1);
|
|
217
265
|
}
|
|
218
266
|
if (decision === "confirm") {
|
|
@@ -220,26 +268,30 @@ async function dbCommand(subcommand: string, rawArgs: string[]): Promise<void> {
|
|
|
220
268
|
chalk.yellow(" Type 'yes' to apply these destructive changes (this cannot be undone): ")
|
|
221
269
|
);
|
|
222
270
|
if (!confirmed) {
|
|
223
|
-
|
|
271
|
+
out(chalk.gray(" Aborted. No changes were made."));
|
|
224
272
|
process.exit(1);
|
|
225
273
|
}
|
|
226
274
|
} else {
|
|
227
275
|
// decision === "apply" via --allow-destructive
|
|
228
|
-
|
|
276
|
+
outWarn(chalk.yellow(" Proceeding because --allow-destructive was passed."));
|
|
229
277
|
}
|
|
230
278
|
}
|
|
231
279
|
|
|
232
280
|
await runAtlas("schema", ["apply", "--to", "file://drizzle/schema.sql", "--auto-approve"], collectionsPath);
|
|
233
|
-
|
|
281
|
+
out("");
|
|
234
282
|
|
|
235
283
|
if (databaseUrl) {
|
|
236
284
|
await ensureAuthTables(databaseUrl, collectionsPath);
|
|
285
|
+
// After the tables exist and before the policies: the search
|
|
286
|
+
// column is `ALTER TABLE ... ADD COLUMN`, and a policy may
|
|
287
|
+
// reference the table it is added to.
|
|
288
|
+
await applySearchDdl(databaseUrl);
|
|
237
289
|
await applyPolicies(databaseUrl);
|
|
238
290
|
await reconcilePolicies(databaseUrl, collectionsPath);
|
|
239
291
|
await ensureRlsUserRole(databaseUrl);
|
|
240
292
|
await retireLegacyAuthSchema(databaseUrl);
|
|
241
293
|
} else {
|
|
242
|
-
|
|
294
|
+
outWarn(chalk.yellow(" ⚠️ DATABASE_URL not found in environment, skipping RLS policies application."));
|
|
243
295
|
}
|
|
244
296
|
} else if (subcommand === "migrate") {
|
|
245
297
|
const databaseUrl = process.env.DATABASE_URL;
|
|
@@ -254,9 +306,9 @@ async function dbCommand(subcommand: string, rawArgs: string[]): Promise<void> {
|
|
|
254
306
|
}
|
|
255
307
|
}
|
|
256
308
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
309
|
+
out("");
|
|
310
|
+
out(chalk.green(` ✓ rebase db ${subcommand} completed successfully.`));
|
|
311
|
+
out("");
|
|
260
312
|
}
|
|
261
313
|
}
|
|
262
314
|
|
|
@@ -279,7 +331,7 @@ async function ensureAuthSchemaAndFunctions(databaseUrl: string): Promise<void>
|
|
|
279
331
|
await client.end();
|
|
280
332
|
}
|
|
281
333
|
} catch (err) {
|
|
282
|
-
|
|
334
|
+
outWarn(chalk.yellow(` ⚠️ Failed to bootstrap the RLS helper functions: ${err instanceof Error ? err.message : String(err)}`));
|
|
283
335
|
}
|
|
284
336
|
}
|
|
285
337
|
|
|
@@ -316,7 +368,7 @@ async function ensureAuthTables(databaseUrl: string, collectionsPath: string): P
|
|
|
316
368
|
await client.end();
|
|
317
369
|
}
|
|
318
370
|
} catch (err) {
|
|
319
|
-
|
|
371
|
+
outWarn(chalk.yellow(` ⚠️ Failed to ensure framework auth tables: ${err instanceof Error ? err.message : String(err)}`));
|
|
320
372
|
}
|
|
321
373
|
}
|
|
322
374
|
|
|
@@ -347,7 +399,7 @@ async function ensureRlsUserRole(databaseUrl: string): Promise<void> {
|
|
|
347
399
|
} catch (err) {
|
|
348
400
|
// A module-resolution failure here is a build problem, not a database
|
|
349
401
|
// one, and it is exactly the case that used to produce the silent exit.
|
|
350
|
-
|
|
402
|
+
outError(chalk.red(
|
|
351
403
|
`\n ✗ Could not load the RLS provisioning module: ${err instanceof Error ? err.message : String(err)}`
|
|
352
404
|
));
|
|
353
405
|
return;
|
|
@@ -362,17 +414,17 @@ async function ensureRlsUserRole(databaseUrl: string): Promise<void> {
|
|
|
362
414
|
const posture = await rls.detectConnectionPosture(runSql);
|
|
363
415
|
if (posture.privileged) {
|
|
364
416
|
await rls.ensureAppRole(runSql, schemas);
|
|
365
|
-
|
|
417
|
+
out(chalk.gray(` ✓ RLS role "${rls.REBASE_USER_ROLE}" provisioned/refreshed.`));
|
|
366
418
|
}
|
|
367
419
|
} finally {
|
|
368
420
|
await client.end();
|
|
369
421
|
}
|
|
370
422
|
} catch (err) {
|
|
371
|
-
|
|
423
|
+
outError(chalk.red(
|
|
372
424
|
`\n ✗ The schema change was applied, but the "${rls.REBASE_USER_ROLE}" role could not be ` +
|
|
373
425
|
`provisioned: ${err instanceof Error ? err.message : String(err)}`
|
|
374
426
|
));
|
|
375
|
-
|
|
427
|
+
outError(chalk.gray(rls.appRoleSetupInstructions("your database user", schemas)));
|
|
376
428
|
}
|
|
377
429
|
}
|
|
378
430
|
|
|
@@ -394,8 +446,8 @@ async function retireLegacyAuthSchema(databaseUrl: string): Promise<void> {
|
|
|
394
446
|
await dropLegacyAuthSchema(
|
|
395
447
|
async (text) => (await client.query(text)).rows as Record<string, unknown>[],
|
|
396
448
|
{
|
|
397
|
-
info: (m) =>
|
|
398
|
-
warn: (m) =>
|
|
449
|
+
info: (m) => out(chalk.gray(` ${m}`)),
|
|
450
|
+
warn: (m) => outWarn(chalk.yellow(` ⚠️ ${m}`))
|
|
399
451
|
}
|
|
400
452
|
);
|
|
401
453
|
} finally {
|
|
@@ -411,8 +463,8 @@ async function applyPolicies(databaseUrl: string): Promise<void> {
|
|
|
411
463
|
const policiesPath = path.resolve(process.cwd(), "drizzle", "policies.sql");
|
|
412
464
|
if (!fs.existsSync(policiesPath)) return;
|
|
413
465
|
|
|
414
|
-
|
|
415
|
-
|
|
466
|
+
out(chalk.gray(" Step 3/3: Applying RLS policies to database..."));
|
|
467
|
+
out("");
|
|
416
468
|
|
|
417
469
|
const policiesContent = fs.readFileSync(policiesPath, "utf-8");
|
|
418
470
|
const { Client } = await import("pg");
|
|
@@ -420,16 +472,16 @@ async function applyPolicies(databaseUrl: string): Promise<void> {
|
|
|
420
472
|
await client.connect();
|
|
421
473
|
try {
|
|
422
474
|
await client.query(policiesContent);
|
|
423
|
-
|
|
475
|
+
out(chalk.green(" ✓ RLS policies applied successfully."));
|
|
424
476
|
} finally {
|
|
425
477
|
await client.end();
|
|
426
478
|
}
|
|
427
479
|
} catch (err) {
|
|
428
480
|
const hint = diagnoseDbError(err, databaseUrl);
|
|
429
481
|
if (hint) {
|
|
430
|
-
|
|
482
|
+
outError(hint);
|
|
431
483
|
} else {
|
|
432
|
-
|
|
484
|
+
outError(chalk.red(` ✗ Failed to apply RLS policies: ${err instanceof Error ? err.message : String(err)}`));
|
|
433
485
|
}
|
|
434
486
|
process.exit(1);
|
|
435
487
|
}
|
|
@@ -463,34 +515,34 @@ async function reconcilePolicies(databaseUrl: string, collectionsPath: string):
|
|
|
463
515
|
const { dropped, kept } = await dropOrphanedPolicies(client as never, drift, collections);
|
|
464
516
|
|
|
465
517
|
for (const p of dropped) {
|
|
466
|
-
|
|
518
|
+
out(chalk.gray(` ✓ Dropped superseded policy "${p.name}" on ${p.schema}.${p.table}`));
|
|
467
519
|
}
|
|
468
520
|
if (dropped.length > 0) {
|
|
469
|
-
|
|
521
|
+
out(chalk.green(` ✓ Removed ${dropped.length} superseded RLS ${dropped.length === 1 ? "policy" : "policies"}.`));
|
|
470
522
|
}
|
|
471
523
|
|
|
472
524
|
// Custom-named orphans are indistinguishable from policies someone
|
|
473
525
|
// wrote in SQL deliberately, so they are reported, never dropped.
|
|
474
526
|
if (kept.length > 0) {
|
|
475
|
-
|
|
527
|
+
outWarn(chalk.yellow(" ⚠️ Policies in the database that no collection describes:"));
|
|
476
528
|
for (const p of kept) {
|
|
477
|
-
|
|
529
|
+
outWarn(chalk.yellow(` • ${p.schema}.${p.table} → "${p.name}" (${p.command} TO ${p.roles.join(", ")})`));
|
|
478
530
|
}
|
|
479
|
-
|
|
531
|
+
outWarn(chalk.yellow(" These still grant access. Drop them by hand if they are stale."));
|
|
480
532
|
}
|
|
481
533
|
|
|
482
534
|
// Missing/diverged are not push's to fix, but staying silent about
|
|
483
535
|
// them is how a database ends up not matching its config.
|
|
484
536
|
const remaining = { ...drift, orphaned: kept };
|
|
485
537
|
if (hasDrift(remaining) && (remaining.missing.length > 0 || remaining.diverged.length > 0)) {
|
|
486
|
-
|
|
487
|
-
|
|
538
|
+
outWarn(chalk.yellow(" ⚠️ RLS policies do not match your collections:"));
|
|
539
|
+
outWarn(formatPolicyDrift({ ...remaining, orphaned: [] }));
|
|
488
540
|
}
|
|
489
541
|
} finally {
|
|
490
542
|
await client.end();
|
|
491
543
|
}
|
|
492
544
|
} catch (err) {
|
|
493
|
-
|
|
545
|
+
outWarn(chalk.yellow(` ⚠️ Could not reconcile RLS policies: ${err instanceof Error ? err.message : String(err)}`));
|
|
494
546
|
}
|
|
495
547
|
}
|
|
496
548
|
|
|
@@ -507,9 +559,9 @@ async function branchCommand(rawArgs: string[]): Promise<void> {
|
|
|
507
559
|
const dotenv = await import("dotenv");
|
|
508
560
|
const envPath = process.env.DOTENV_CONFIG_PATH;
|
|
509
561
|
if (envPath) {
|
|
510
|
-
dotenv.config({ path: envPath });
|
|
562
|
+
dotenv.config({ path: envPath, quiet: true });
|
|
511
563
|
} else {
|
|
512
|
-
dotenv.config();
|
|
564
|
+
dotenv.config({ quiet: true });
|
|
513
565
|
}
|
|
514
566
|
} catch {
|
|
515
567
|
// dotenv may not be installed
|
|
@@ -517,7 +569,7 @@ async function branchCommand(rawArgs: string[]): Promise<void> {
|
|
|
517
569
|
|
|
518
570
|
const databaseUrl = process.env.DATABASE_URL || process.env.ADMIN_CONNECTION_STRING;
|
|
519
571
|
if (!databaseUrl) {
|
|
520
|
-
|
|
572
|
+
outError(chalk.red("✗ DATABASE_URL is not set. Make sure your .env file is configured."));
|
|
521
573
|
process.exit(1);
|
|
522
574
|
}
|
|
523
575
|
|
|
@@ -541,8 +593,8 @@ max: 3 });
|
|
|
541
593
|
case "create": {
|
|
542
594
|
const name = rawArgs[3];
|
|
543
595
|
if (!name) {
|
|
544
|
-
|
|
545
|
-
|
|
596
|
+
outError(chalk.red("✗ Branch name is required."));
|
|
597
|
+
out(chalk.gray(" Usage: rebase db branch create <name> [--from <source>]"));
|
|
546
598
|
process.exit(1);
|
|
547
599
|
}
|
|
548
600
|
let source: string | undefined;
|
|
@@ -550,81 +602,81 @@ max: 3 });
|
|
|
550
602
|
if (fromIdx !== -1 && rawArgs[fromIdx + 1]) {
|
|
551
603
|
source = rawArgs[fromIdx + 1];
|
|
552
604
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
if (source)
|
|
557
|
-
|
|
605
|
+
out("");
|
|
606
|
+
out(chalk.bold(" 🌿 Creating database branch..."));
|
|
607
|
+
out(chalk.gray(` Name: ${name}`));
|
|
608
|
+
if (source) out(chalk.gray(` Source: ${source}`));
|
|
609
|
+
out("");
|
|
558
610
|
const branch = await branchService.createBranch(name, source ? { source } : undefined);
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
611
|
+
out(chalk.green(` ✓ Branch "${branch.name}" created successfully.`));
|
|
612
|
+
out(chalk.gray(` Database: rb_${branch.name}`));
|
|
613
|
+
out(chalk.gray(` Parent: ${branch.parentDatabase}`));
|
|
614
|
+
out("");
|
|
563
615
|
break;
|
|
564
616
|
}
|
|
565
617
|
|
|
566
618
|
case "list": {
|
|
567
619
|
const branches = await branchService.listBranches();
|
|
568
|
-
|
|
620
|
+
out("");
|
|
569
621
|
if (branches.length === 0) {
|
|
570
|
-
|
|
622
|
+
out(chalk.gray(" No branches found. Create one with: rebase db branch create <name>"));
|
|
571
623
|
} else {
|
|
572
|
-
|
|
573
|
-
|
|
624
|
+
out(chalk.bold(` 🌿 ${branches.length} branch(es):`));
|
|
625
|
+
out("");
|
|
574
626
|
for (const b of branches) {
|
|
575
627
|
const size = b.sizeBytes != null
|
|
576
628
|
? chalk.gray(` (${formatBytes(b.sizeBytes)})`)
|
|
577
629
|
: "";
|
|
578
630
|
const age = chalk.gray(` — created ${timeAgo(b.createdAt)}`);
|
|
579
|
-
|
|
580
|
-
|
|
631
|
+
out(` ${chalk.green("●")} ${chalk.bold(b.name)}${size}${age}`);
|
|
632
|
+
out(chalk.gray(` from ${b.parentDatabase}`));
|
|
581
633
|
}
|
|
582
634
|
}
|
|
583
|
-
|
|
635
|
+
out("");
|
|
584
636
|
break;
|
|
585
637
|
}
|
|
586
638
|
|
|
587
639
|
case "delete": {
|
|
588
640
|
const name = rawArgs[3];
|
|
589
641
|
if (!name) {
|
|
590
|
-
|
|
591
|
-
|
|
642
|
+
outError(chalk.red("✗ Branch name is required."));
|
|
643
|
+
out(chalk.gray(" Usage: rebase db branch delete <name>"));
|
|
592
644
|
process.exit(1);
|
|
593
645
|
}
|
|
594
|
-
|
|
595
|
-
|
|
646
|
+
out("");
|
|
647
|
+
out(chalk.bold(` 🗑️ Deleting branch "${name}"...`));
|
|
596
648
|
await branchService.deleteBranch(name);
|
|
597
|
-
|
|
598
|
-
|
|
649
|
+
out(chalk.green(` ✓ Branch "${name}" deleted.`));
|
|
650
|
+
out("");
|
|
599
651
|
break;
|
|
600
652
|
}
|
|
601
653
|
|
|
602
654
|
case "info": {
|
|
603
655
|
const name = rawArgs[3];
|
|
604
656
|
if (!name) {
|
|
605
|
-
|
|
606
|
-
|
|
657
|
+
outError(chalk.red("✗ Branch name is required."));
|
|
658
|
+
out(chalk.gray(" Usage: rebase db branch info <name>"));
|
|
607
659
|
process.exit(1);
|
|
608
660
|
}
|
|
609
661
|
const info = await branchService.getBranchInfo(name);
|
|
610
|
-
|
|
662
|
+
out("");
|
|
611
663
|
if (!info) {
|
|
612
|
-
|
|
664
|
+
outError(chalk.red(` ✗ Branch "${name}" not found.`));
|
|
613
665
|
} else {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
666
|
+
out(chalk.bold(` 🌿 Branch: ${info.name}`));
|
|
667
|
+
out(chalk.gray(` Database: rb_${info.name}`));
|
|
668
|
+
out(chalk.gray(` Parent: ${info.parentDatabase}`));
|
|
669
|
+
out(chalk.gray(` Created: ${info.createdAt.toISOString()}`));
|
|
618
670
|
if (info.sizeBytes != null) {
|
|
619
|
-
|
|
671
|
+
out(chalk.gray(` Size: ${formatBytes(info.sizeBytes)}`));
|
|
620
672
|
}
|
|
621
673
|
}
|
|
622
|
-
|
|
674
|
+
out("");
|
|
623
675
|
break;
|
|
624
676
|
}
|
|
625
677
|
|
|
626
678
|
default:
|
|
627
|
-
|
|
679
|
+
outError(chalk.red(`Unknown branch action: "${branchAction}".`));
|
|
628
680
|
printBranchHelp();
|
|
629
681
|
process.exit(1);
|
|
630
682
|
}
|
|
@@ -635,7 +687,7 @@ max: 3 });
|
|
|
635
687
|
}
|
|
636
688
|
|
|
637
689
|
function printBranchHelp() {
|
|
638
|
-
|
|
690
|
+
out(`
|
|
639
691
|
${chalk.bold("rebase db branch")} — Database branching commands
|
|
640
692
|
|
|
641
693
|
${chalk.green.bold("Usage")}
|
|
@@ -690,28 +742,28 @@ async function runAtlas(
|
|
|
690
742
|
// other — see `diagnoseMissingBin`. This used to say "Install it with:
|
|
691
743
|
// pnpm add -D @ariga/atlas" unconditionally, which is the exact command
|
|
692
744
|
// that produces the far more common of the two states.
|
|
693
|
-
|
|
745
|
+
outError(chalk.red("\n✗ The atlas binary is missing, so the schema cannot be applied.\n"));
|
|
694
746
|
|
|
695
747
|
if (diagnoseMissingBin("@ariga/atlas") === "build-script-blocked") {
|
|
696
|
-
|
|
697
|
-
|
|
748
|
+
outError(chalk.yellow(" @ariga/atlas IS installed — only its binary is missing.\n"));
|
|
749
|
+
outError(chalk.gray(
|
|
698
750
|
" It downloads that binary in a `preinstall` script, and pnpm 10+ does not\n" +
|
|
699
751
|
" run a dependency's scripts unless you allow it. The install still exits 0,\n" +
|
|
700
752
|
" so the only sign is `Ignored build scripts: @ariga/atlas` in its output.\n"
|
|
701
753
|
));
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
754
|
+
outError(" Fix it with either:\n");
|
|
755
|
+
outError(chalk.bold(" pnpm approve-builds\n"));
|
|
756
|
+
outError(" or, to record it in the project (what `rebase init` scaffolds):\n");
|
|
757
|
+
outError(chalk.bold(
|
|
706
758
|
" // package.json\n" +
|
|
707
759
|
" \"pnpm\": { \"onlyBuiltDependencies\": [\"@ariga/atlas\"] }\n"
|
|
708
760
|
));
|
|
709
|
-
|
|
761
|
+
outError(chalk.gray(" Then re-run `pnpm install`.\n"));
|
|
710
762
|
} else {
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
763
|
+
outError(chalk.gray(" It is not installed in this project.\n"));
|
|
764
|
+
outError(" Install it with:\n");
|
|
765
|
+
outError(chalk.bold(" pnpm add -D @ariga/atlas\n"));
|
|
766
|
+
outError(chalk.gray(
|
|
715
767
|
" If pnpm then reports `Ignored build scripts`, also run `pnpm approve-builds` —\n" +
|
|
716
768
|
" the package carries a `preinstall` script that fetches the binary.\n"
|
|
717
769
|
));
|
|
@@ -731,7 +783,7 @@ async function runAtlas(
|
|
|
731
783
|
|
|
732
784
|
for (const p of envPaths) {
|
|
733
785
|
if (fs.existsSync(p)) {
|
|
734
|
-
const parsed = dotenv.config({ path: p });
|
|
786
|
+
const parsed = dotenv.config({ path: p, quiet: true });
|
|
735
787
|
if (parsed.parsed) {
|
|
736
788
|
for (const [key, val] of Object.entries(parsed.parsed)) {
|
|
737
789
|
if (env[key] === undefined) {
|
|
@@ -748,7 +800,7 @@ async function runAtlas(
|
|
|
748
800
|
|
|
749
801
|
const databaseUrl = env.DATABASE_URL;
|
|
750
802
|
if (!databaseUrl) {
|
|
751
|
-
|
|
803
|
+
outError(chalk.red("✗ DATABASE_URL is not set. Make sure your .env file is configured."));
|
|
752
804
|
process.exit(1);
|
|
753
805
|
}
|
|
754
806
|
|
|
@@ -759,6 +811,9 @@ async function runAtlas(
|
|
|
759
811
|
|
|
760
812
|
const devDatabaseUrl = getDevDatabaseUrl(databaseUrl);
|
|
761
813
|
await ensureDevDatabaseExists(databaseUrl, devDatabaseUrl);
|
|
814
|
+
if (collectionsPath) {
|
|
815
|
+
await seedDevDatabaseSearchHelpers(devDatabaseUrl, collectionsPath);
|
|
816
|
+
}
|
|
762
817
|
|
|
763
818
|
// Atlas speaks libpq, which rejects the `sslmode=no-verify` that
|
|
764
819
|
// node-postgres accepts — see `forLibpq`. Rewritten only for the argv, so
|
|
@@ -785,6 +840,16 @@ async function runAtlas(
|
|
|
785
840
|
}
|
|
786
841
|
}
|
|
787
842
|
|
|
843
|
+
// Search objects are Rebase's, not Atlas's — on both paths. `schema apply`
|
|
844
|
+
// would drop them as absent from the desired state; `migrate diff` would
|
|
845
|
+
// write that same drop into the next migration file, where it would sit
|
|
846
|
+
// waiting to be applied later.
|
|
847
|
+
if (collectionsPath && (args.includes("apply") || args.includes("diff"))) {
|
|
848
|
+
for (const exc of await getSearchExcludes(collectionsPath)) {
|
|
849
|
+
atlasArgs.push("--exclude", exc);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
|
|
788
853
|
if (domain === "schema" && args.includes("apply") && collectionsPath) {
|
|
789
854
|
// Fail CLOSED: the exclude list is the only thing shielding
|
|
790
855
|
// non-collection tables from the auto-approved apply. If we can't
|
|
@@ -795,11 +860,11 @@ async function runAtlas(
|
|
|
795
860
|
excludes = await getTableExcludes(databaseUrl, collectionsPath);
|
|
796
861
|
} catch (err) {
|
|
797
862
|
if (err instanceof ExcludeIntrospectionError) {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
863
|
+
outError(chalk.red("\n✗ Aborting push: could not determine which tables to protect."));
|
|
864
|
+
outError(chalk.gray(` ${err.message}`));
|
|
865
|
+
outError(chalk.gray(" Refusing to apply — a partial exclude list could drop tables Rebase does not manage."));
|
|
801
866
|
const hint = diagnoseDbError(err.cause ?? err, databaseUrl);
|
|
802
|
-
if (hint)
|
|
867
|
+
if (hint) outError(hint);
|
|
803
868
|
process.exit(1);
|
|
804
869
|
}
|
|
805
870
|
throw err;
|
|
@@ -834,11 +899,11 @@ async function runAtlas(
|
|
|
834
899
|
try {
|
|
835
900
|
await subprocess;
|
|
836
901
|
} catch {
|
|
837
|
-
|
|
902
|
+
outError(chalk.red(`\n✗ atlas ${domain} ${args.join(" ")} failed.\n`));
|
|
838
903
|
// Surface actionable recovery guidance for recognized failures.
|
|
839
904
|
const hint = diagnoseDbError({ message: stderrText }, databaseUrl);
|
|
840
905
|
if (hint) {
|
|
841
|
-
|
|
906
|
+
outError(hint);
|
|
842
907
|
}
|
|
843
908
|
process.exit(1);
|
|
844
909
|
}
|
|
@@ -868,7 +933,7 @@ async function generatePostgresDdlCommand(rawArgs: string[]): Promise<void> {
|
|
|
868
933
|
const ddlScript = path.join(__cliDirname, "schema", "generate-postgres-ddl.ts");
|
|
869
934
|
const tsxBin = resolveLocalBin("tsx");
|
|
870
935
|
if (!tsxBin) {
|
|
871
|
-
|
|
936
|
+
outError(chalk.red("✗ Could not find tsx binary."));
|
|
872
937
|
process.exit(1);
|
|
873
938
|
}
|
|
874
939
|
|
|
@@ -889,7 +954,7 @@ async function generatePostgresDdlCommand(rawArgs: string[]): Promise<void> {
|
|
|
889
954
|
env: { ...process.env as Record<string, string> }
|
|
890
955
|
});
|
|
891
956
|
} catch (err: unknown) {
|
|
892
|
-
|
|
957
|
+
outError(chalk.red(`✗ Failed to run Postgres DDL generator: ${err instanceof Error ? err.message : String(err)}`));
|
|
893
958
|
process.exit(1);
|
|
894
959
|
}
|
|
895
960
|
}
|
|
@@ -948,23 +1013,23 @@ async function schemaStaleCommand(rawArgs: string[]): Promise<void> {
|
|
|
948
1013
|
|
|
949
1014
|
if (stale.length === 0) return;
|
|
950
1015
|
|
|
951
|
-
|
|
952
|
-
|
|
1016
|
+
out("");
|
|
1017
|
+
outWarn(chalk.yellow(
|
|
953
1018
|
` ⚠️ ${outputPath} names ${stale.length} foreign key(s) the way an earlier release did:`
|
|
954
1019
|
));
|
|
955
|
-
|
|
956
|
-
|
|
1020
|
+
out(chalk.gray(describeLegacyForeignKeyNames(stale)));
|
|
1021
|
+
out("");
|
|
957
1022
|
|
|
958
1023
|
if (!argsList["--fix"]) {
|
|
959
|
-
|
|
1024
|
+
outError(chalk.red(
|
|
960
1025
|
" The database column has already been renamed at boot, so the generated schema no " +
|
|
961
1026
|
"longer matches it and the server will refuse to start."
|
|
962
1027
|
));
|
|
963
|
-
|
|
1028
|
+
outError(chalk.red(" Run `rebase schema generate` to regenerate it."));
|
|
964
1029
|
process.exit(1);
|
|
965
1030
|
}
|
|
966
1031
|
|
|
967
|
-
|
|
1032
|
+
out(chalk.gray(" Regenerating the Drizzle schema so it matches..."));
|
|
968
1033
|
await schemaCommand("generate", ["schema", "generate", `--collections=${collectionsPath}`, `--output=${outputPath}`]);
|
|
969
1034
|
}
|
|
970
1035
|
|
|
@@ -994,13 +1059,13 @@ async function schemaCommand(subcommand: string, rawArgs: string[]): Promise<voi
|
|
|
994
1059
|
// If installed in node_modules, __cliDirname is node_modules/@rebasepro/server-postgres/dist or src.
|
|
995
1060
|
const generatorScript = path.join(__cliDirname, "schema", "generate-drizzle-schema.ts");
|
|
996
1061
|
if (!fs.existsSync(generatorScript)) {
|
|
997
|
-
|
|
1062
|
+
outError(chalk.red(`✗ Could not find generate-drizzle-schema.ts at ${generatorScript}`));
|
|
998
1063
|
process.exit(1);
|
|
999
1064
|
}
|
|
1000
1065
|
|
|
1001
1066
|
const tsxBin = resolveLocalBin("tsx");
|
|
1002
1067
|
if (!tsxBin) {
|
|
1003
|
-
|
|
1068
|
+
outError(chalk.red("✗ Could not find tsx binary."));
|
|
1004
1069
|
process.exit(1);
|
|
1005
1070
|
}
|
|
1006
1071
|
|
|
@@ -1008,9 +1073,9 @@ async function schemaCommand(subcommand: string, rawArgs: string[]): Promise<voi
|
|
|
1008
1073
|
const outputPath = argsList["--output"] || path.join("src", "schema.generated.ts");
|
|
1009
1074
|
const watch = argsList["--watch"] || false;
|
|
1010
1075
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1076
|
+
out("");
|
|
1077
|
+
out(chalk.bold(" 🔧 Rebase Schema Generator"));
|
|
1078
|
+
out("");
|
|
1014
1079
|
|
|
1015
1080
|
const cmdParts = [
|
|
1016
1081
|
tsxBin,
|
|
@@ -1029,7 +1094,7 @@ async function schemaCommand(subcommand: string, rawArgs: string[]): Promise<voi
|
|
|
1029
1094
|
env: { ...process.env as Record<string, string> }
|
|
1030
1095
|
});
|
|
1031
1096
|
} catch (err: unknown) {
|
|
1032
|
-
|
|
1097
|
+
outError(chalk.red(`✗ Failed to run schema generator: ${err instanceof Error ? err.message : String(err)}`));
|
|
1033
1098
|
process.exit(1);
|
|
1034
1099
|
}
|
|
1035
1100
|
} else if (subcommand === "introspect") {
|
|
@@ -1051,21 +1116,21 @@ async function schemaCommand(subcommand: string, rawArgs: string[]): Promise<voi
|
|
|
1051
1116
|
|
|
1052
1117
|
const introspectScript = path.join(__cliDirname, "schema", "introspect-db.ts");
|
|
1053
1118
|
if (!fs.existsSync(introspectScript)) {
|
|
1054
|
-
|
|
1119
|
+
outError(chalk.red(`✗ Could not find introspect-db.ts at ${introspectScript}`));
|
|
1055
1120
|
process.exit(1);
|
|
1056
1121
|
}
|
|
1057
1122
|
|
|
1058
1123
|
const tsxBin = resolveLocalBin("tsx");
|
|
1059
1124
|
if (!tsxBin) {
|
|
1060
|
-
|
|
1125
|
+
outError(chalk.red("✗ Could not find tsx binary."));
|
|
1061
1126
|
process.exit(1);
|
|
1062
1127
|
}
|
|
1063
1128
|
|
|
1064
1129
|
const outputPath = argsList["--output"] || argsList["--collections"] || path.join("..", "config", "collections");
|
|
1065
1130
|
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1131
|
+
out("");
|
|
1132
|
+
out(chalk.bold(" 🔍 Rebase Schema Introspector"));
|
|
1133
|
+
out("");
|
|
1069
1134
|
|
|
1070
1135
|
const cmdParts = [
|
|
1071
1136
|
tsxBin,
|
|
@@ -1082,11 +1147,11 @@ async function schemaCommand(subcommand: string, rawArgs: string[]): Promise<voi
|
|
|
1082
1147
|
env: { ...process.env as Record<string, string> }
|
|
1083
1148
|
});
|
|
1084
1149
|
} catch (err: unknown) {
|
|
1085
|
-
|
|
1150
|
+
outError(chalk.red(`✗ Failed to run schema introspector: ${err instanceof Error ? err.message : String(err)}`));
|
|
1086
1151
|
process.exit(1);
|
|
1087
1152
|
}
|
|
1088
1153
|
} else {
|
|
1089
|
-
|
|
1154
|
+
outError(chalk.red("Unknown schema command."));
|
|
1090
1155
|
process.exit(1);
|
|
1091
1156
|
}
|
|
1092
1157
|
}
|
|
@@ -1110,13 +1175,13 @@ async function doctorPluginCommand(rawArgs: string[]): Promise<void> {
|
|
|
1110
1175
|
|
|
1111
1176
|
const doctorScript = path.join(__cliDirname, "schema", "doctor-cli.ts");
|
|
1112
1177
|
if (!fs.existsSync(doctorScript)) {
|
|
1113
|
-
|
|
1178
|
+
outError(chalk.red(`✗ Could not find doctor.ts at ${doctorScript}`));
|
|
1114
1179
|
process.exit(1);
|
|
1115
1180
|
}
|
|
1116
1181
|
|
|
1117
1182
|
const tsxBin = resolveLocalBin("tsx");
|
|
1118
1183
|
if (!tsxBin) {
|
|
1119
|
-
|
|
1184
|
+
outError(chalk.red("✗ Could not find tsx binary."));
|
|
1120
1185
|
process.exit(1);
|
|
1121
1186
|
}
|
|
1122
1187
|
|