@somewhere-cloud/cli 0.38.173 → 0.38.174

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.38.174
4
+
5
+ - Restore a database from a history point with explicit confirmation of the app and point.
6
+
3
7
  ## 0.38.173
4
8
 
5
9
  - Deploy preserves text and binary file bytes and explains when to use file storage.
@@ -87396,9 +87396,9 @@ function registerDb(program2) {
87396
87396
  process.exit(1);
87397
87397
  }
87398
87398
  });
87399
- db.command("restore-points").description("List database restore points (project owner only)").option("--project <id>", "Project ID (defaults to .somewhere.json)").option("--take", "Take a restore point now").option("--delete <id>", "Delete one restore point now").option("--json", "Print the API response as JSON").action(async (opts) => {
87400
- if (opts.take && opts.delete) {
87401
- error("Use --take or --delete, not both.");
87399
+ db.command("restore-points").description("List database restore points (project owner only)").option("--project <id>", "Project ID (defaults to .somewhere.json)").option("--take", "Take a restore point now").option("--delete <id>", "Delete one restore point now").option("--restore <id>", "Inspect or restore a database history point").option("--confirm-app <name>", "Confirm the exact app name. Members, groups and roles return to the saved moment.").option("--json", "Print the API response as JSON").action(async (opts) => {
87400
+ if ([opts.take, opts.delete, opts.restore].filter(Boolean).length > 1 || opts.confirmApp && !opts.restore) {
87401
+ error("Choose one action. --confirm-app requires --restore.");
87402
87402
  process.exit(1);
87403
87403
  }
87404
87404
  let projectId = opts.project;
@@ -87413,6 +87413,28 @@ function registerDb(program2) {
87413
87413
  const size = /* @__PURE__ */ __name((n) => n >= 1e6 ? `${(n / 1e6).toFixed(1)} MB` : `${Math.max(1, Math.round(n / 1e3))} KB`, "size");
87414
87414
  const client = new ApiClient(getToken());
87415
87415
  try {
87416
+ if (opts.restore) {
87417
+ if (opts.confirmApp && !opts.json) {
87418
+ info("Restoring returns the app\u2019s members, groups and roles to the recorded moment. People removed since then will have access again; remove them again after the restore. Completion can take a minute while cached sign-ins expire.");
87419
+ }
87420
+ const result = await client.call("POST", `/db/restore-points/${encodeURIComponent(opts.restore)}/restore`, {
87421
+ project_id: projectId,
87422
+ ...opts.confirmApp ? { confirm: { app: opts.confirmApp, point: opts.restore } } : {}
87423
+ }, void 0, opts.confirmApp ? { timeoutMs: 24e4 } : void 0);
87424
+ if (opts.json) {
87425
+ printJson(result);
87426
+ return;
87427
+ }
87428
+ if (result.confirmed) {
87429
+ success(`Database restored. Undo point: ${result.undo_point_id}.`);
87430
+ return;
87431
+ }
87432
+ info(result.warning);
87433
+ for (const moment of result.moments)
87434
+ info(`${moment.plane}: ${moment.at}`);
87435
+ info(`Confirm app "${result.app}" and point ${result.point_id} before ${result.expires_at}. Repeat with --confirm-app and the exact app name to restore.`);
87436
+ return;
87437
+ }
87416
87438
  if (opts.take) {
87417
87439
  const spinner = opts.json ? null : ora("Taking a restore point\u2026").start();
87418
87440
  let point = (await client.call("POST", "/db/restore-points", { project_id: projectId })).restore_point;
@@ -87461,6 +87483,8 @@ function registerDb(program2) {
87461
87483
  printJson(r);
87462
87484
  return;
87463
87485
  }
87486
+ if (r.restore)
87487
+ info(`${r.restore.point_id}: ${r.restore.message}`);
87464
87488
  if (!r.restore_points.length) {
87465
87489
  info(dim(`No restore points yet. Take one now with \`${cliInvocation()} db restore-points --take\`; the platform also takes them before deploys that change the database (when it can finish within the deploy's wait) and daily when the data changed.`));
87466
87490
  return;