@prenta/cli 0.17.0 → 0.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,8 @@ import { dirname, join, resolve } from 'node:path'
19
19
  import { createBlobStore, DEFAULT_BACKUP_PREFIX, type BlobModule } from '../backup/blob-store.js'
20
20
  import {
21
21
  BLOB_AUTH_HINT,
22
+ DEFAULT_EXCLUDED_EXTENSIONS,
23
+ EXCLUDE_EXTENSIONS_NONE,
22
24
  EXIT_FAILED,
23
25
  EXIT_OK,
24
26
  EXIT_PRECONDITION,
@@ -28,6 +30,7 @@ import {
28
30
  isPostgresUrl,
29
31
  resolveBlobAuth,
30
32
  resolveDatabaseUrl,
33
+ resolveExcludedExtensions,
31
34
  } from '../backup/common.js'
32
35
  import { BackupKeyError, encryptFile, parseBackupKey } from '../backup/crypto.js'
33
36
  import {
@@ -63,6 +66,8 @@ export interface DbBackupOptions {
63
66
  initWorkflow?: boolean
64
67
  force?: boolean
65
68
  allowLocal?: boolean
69
+ /** Repeatable `--exclude-extension`; `none` anywhere excludes nothing. */
70
+ excludeExtension?: readonly string[]
66
71
  }
67
72
 
68
73
  export interface DbBackupDeps {
@@ -190,6 +195,9 @@ export async function runDbBackup(opts: DbBackupOptions, deps: DbBackupDeps): Pr
190
195
  }
191
196
 
192
197
  // 6. Dump → encrypt → manifest.
198
+ const excludedExtensions = resolveExcludedExtensions(
199
+ opts.excludeExtension ?? DEFAULT_EXCLUDED_EXTENSIONS,
200
+ )
193
201
  const stamp = stampFor(startedAt)
194
202
  const outDir = resolve(deps.cwd, opts.out ?? join(tmpdir(), 'prenta-backups'))
195
203
  await mkdir(outDir, { recursive: true })
@@ -201,7 +209,7 @@ export async function runDbBackup(opts: DbBackupOptions, deps: DbBackupDeps): Pr
201
209
  let sizeBytes: number
202
210
  try {
203
211
  deps.log.info(`Dumping ${redactUrl(resolved.url)} with pg_dump ${pgDump.version}…`)
204
- await runPgDump(resolved.url, rawDump, deps.spawnImpl, env)
212
+ await runPgDump(resolved.url, rawDump, excludedExtensions, deps.spawnImpl, env)
205
213
  await encryptFile(rawDump, dumpPath, key)
206
214
  sizeBytes = (await stat(dumpPath)).size
207
215
  const sha256 = await sha256File(dumpPath)
@@ -212,6 +220,7 @@ export async function runDbBackup(opts: DbBackupOptions, deps: DbBackupDeps): Pr
212
220
  sizeBytes,
213
221
  sha256,
214
222
  tables,
223
+ excludedExtensions,
215
224
  })
216
225
  await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`)
217
226
  } catch (err) {
@@ -291,6 +300,15 @@ export async function runDbBackup(opts: DbBackupOptions, deps: DbBackupDeps): Pr
291
300
  return EXIT_OK
292
301
  }
293
302
 
303
+ /**
304
+ * Commander collector for the repeatable `--exclude-extension`. The first
305
+ * occurrence replaces the default list rather than appending to it, so
306
+ * `--exclude-extension none` really means "exclude nothing".
307
+ */
308
+ function collectExcludeExtension(value: string, previous: readonly string[]): string[] {
309
+ return previous === DEFAULT_EXCLUDED_EXTENSIONS ? [value] : [...previous, value]
310
+ }
311
+
294
312
  function parseRetention(value: string): number {
295
313
  const n = Number(value)
296
314
  if (!Number.isFinite(n)) throw new Error(`--retention-days expects a number, got "${value}".`)
@@ -325,6 +343,12 @@ export function registerDbBackupCommand(program: Command, deps?: DbBackupDeps):
325
343
  )
326
344
  .option('--prefix <path>', 'Blob pathname prefix', DEFAULT_BACKUP_PREFIX)
327
345
  .option('--allow-local', 'Allow a localhost / 127.0.0.1 database URL')
346
+ .option(
347
+ '--exclude-extension <name>',
348
+ `Platform-managed extension to keep out of the dump so it restores into stock PostgreSQL (repeatable; "${EXCLUDE_EXTENSIONS_NONE}" excludes nothing, for a dump that only ever goes back to the same platform)`,
349
+ collectExcludeExtension,
350
+ DEFAULT_EXCLUDED_EXTENSIONS,
351
+ )
328
352
  .option('--json', 'Print a machine-readable JSON summary')
329
353
  .option('--init-workflow', `Write ${DB_BACKUP_WORKFLOW_PATH} into this repo and exit`)
330
354
  .option('--force', 'Overwrite an existing workflow file (with --init-workflow)')
@@ -242,7 +242,7 @@ export async function runDbRestore(
242
242
  // URL is judged on its own: the guard is blind only when none of them parses.
243
243
  const envUrls: Array<{ name: 'DIRECT_DATABASE_URL' | 'DATABASE_URL'; url: string }> = []
244
244
  for (const name of ['DIRECT_DATABASE_URL', 'DATABASE_URL'] as const) {
245
- const url = env[name]
245
+ const url = env[name]?.trim()
246
246
  if (url) envUrls.push({ name, url })
247
247
  }
248
248
  const comparable = envUrls.filter((e) => databaseIdentity(e.url) !== null)
@@ -441,6 +441,17 @@ export async function runDbRestore(
441
441
  }
442
442
  deps.log.success('pg_restore completed.')
443
443
 
444
+ // Older manifests predate the key; only say something when there is
445
+ // something to say. The source database had these extensions installed,
446
+ // the dump deliberately does not carry them (they are managed by the
447
+ // platform it ran on), and a fresh non-Prisma target therefore has none.
448
+ const excluded = manifest?.excludedExtensions ?? []
449
+ if (excluded.length > 0) {
450
+ deps.log.info(
451
+ `The source database had platform-managed extension(s) excluded from this dump: ${excluded.join(', ')}. They are installed and owned by the managed host, so nothing is missing on that platform; on a stock PostgreSQL server they simply do not exist. Nothing to do unless your own schema starts depending on one.`,
452
+ )
453
+ }
454
+
444
455
  // Post-restore counts.
445
456
  const tables: DbRestoreTableReport[] = (manifest?.tables ?? []).map((t) => ({
446
457
  schema: t.schema,