@batadata/cli 0.2.8 → 0.2.9
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/commands/powdb.js +57 -2
- package/package.json +1 -1
package/dist/commands/powdb.js
CHANGED
|
@@ -3,6 +3,7 @@ import * as path from "node:path";
|
|
|
3
3
|
import { api, apiError } from "../api.js";
|
|
4
4
|
import { requireToken, isJsonMode, loadConfig } from "../config.js";
|
|
5
5
|
import { colors, log, json, spinner, heading, table } from "../utils/logger.js";
|
|
6
|
+
import { confirmDestructive } from "../utils/prompts.js";
|
|
6
7
|
import { emitError, isRetryable } from "../utils/errors.js";
|
|
7
8
|
import { resolveProjectId, resolveBranchId } from "../link.js";
|
|
8
9
|
// PowQL reserved words a column/table name must not collide with. Mirrors the
|
|
@@ -860,7 +861,57 @@ async function powdbLifecycle(action, args) {
|
|
|
860
861
|
return;
|
|
861
862
|
}
|
|
862
863
|
log();
|
|
863
|
-
|
|
864
|
+
const ver = res.data.server_version;
|
|
865
|
+
log(` ${colors.green(">")} ${colors.cyan(projectId)} ${colors.dim("engine=powdb state=")}${res.data.state}${ver ? colors.dim(" server=") + ver : ""}`);
|
|
866
|
+
log();
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* `bata powdb upgrade --to <version>` — pin the project's server to a new
|
|
870
|
+
* engine version. Server-side this is park→backup→flip→wake→verify with
|
|
871
|
+
* automatic rollback to the pre-upgrade backup on failure. Storage-format
|
|
872
|
+
* releases (0.11+) make a verified upgrade a ONE-WAY door once new-format
|
|
873
|
+
* data is written, so this always confirms unless --yes/--json.
|
|
874
|
+
*/
|
|
875
|
+
async function powdbUpgrade(args) {
|
|
876
|
+
const token = requireToken();
|
|
877
|
+
const jsonMode = isJsonMode();
|
|
878
|
+
let toVersion;
|
|
879
|
+
const rest = [];
|
|
880
|
+
for (let i = 0; i < args.length; i++) {
|
|
881
|
+
const a = args[i];
|
|
882
|
+
if (a === "--to")
|
|
883
|
+
toVersion = args[++i];
|
|
884
|
+
else if (a.startsWith("--to="))
|
|
885
|
+
toVersion = a.slice("--to=".length);
|
|
886
|
+
else
|
|
887
|
+
rest.push(a);
|
|
888
|
+
}
|
|
889
|
+
const positional = rest.find((a) => !a.startsWith("-"));
|
|
890
|
+
const projectId = powdbProjectFlag(rest) ?? positional ?? resolvePowdbProject(rest);
|
|
891
|
+
if (!toVersion || !/^\d+\.\d+\.\d+$/.test(toVersion)) {
|
|
892
|
+
emitError("MISSING_ARG", "A target version is required.", "Usage: bata powdb upgrade --to <x.y.z> [--project <id>]");
|
|
893
|
+
}
|
|
894
|
+
const ok = await confirmDestructive(`Upgrade ${colors.cyan(projectId)} to powdb-server ${colors.cyan(toVersion)}? A format-changing release cannot be downgraded once new data is written.`);
|
|
895
|
+
if (!ok) {
|
|
896
|
+
log(" Aborted.");
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
const s = jsonMode ? null : spinner(`Upgrading ${projectId} to ${toVersion} (park -> backup -> flip -> wake -> verify)`);
|
|
900
|
+
const res = await api.post(`/v1/powdb/${encodeURIComponent(projectId)}/upgrade`, { to_version: toVersion }, token);
|
|
901
|
+
s?.stop();
|
|
902
|
+
if (!res.ok) {
|
|
903
|
+
emitError(res.status === 404 ? "NOT_FOUND"
|
|
904
|
+
: res.status === 401 || res.status === 403 ? "INVALID_KEY"
|
|
905
|
+
: res.status >= 500 || res.status === 0 ? "API_UNAVAILABLE"
|
|
906
|
+
: "CLI_ERROR", apiError(res, "PowDB upgrade failed (instance rolled back to its pre-upgrade state)"), "");
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
if (jsonMode) {
|
|
910
|
+
json({ project_id: projectId, ...res.data });
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
log();
|
|
914
|
+
log(` ${colors.green(">")} ${colors.cyan(projectId)} upgraded to powdb-server ${colors.cyan(res.data.server_version)} ${colors.dim("(verified)")}`);
|
|
864
915
|
log();
|
|
865
916
|
}
|
|
866
917
|
// ─── Help + dispatch ──────────────────────────────────────────────────────────
|
|
@@ -883,6 +934,8 @@ function powdbHelp() {
|
|
|
883
934
|
log(` ${colors.cyan("status")} Show the server state (running | parked) [--project <id>]`);
|
|
884
935
|
log(` ${colors.cyan("park")} Scale the server to zero (WAL is durable) [--project <id>]`);
|
|
885
936
|
log(` ${colors.cyan("wake")} Start a parked server (~tens of ms) [--project <id>]`);
|
|
937
|
+
log(` ${colors.cyan("upgrade")} Pin the server to a new engine version --to <x.y.z> [--project <id>]`);
|
|
938
|
+
log(` ${colors.dim(" park -> backup -> flip -> wake -> verify, auto-rollback on failure")}`);
|
|
886
939
|
log();
|
|
887
940
|
log(` ${colors.dim("Options (pull):")}`);
|
|
888
941
|
log(` ${colors.dim("--project <id> override the linked/default project")}`);
|
|
@@ -918,10 +971,12 @@ export async function handlePowdb(args) {
|
|
|
918
971
|
return powdbLifecycle("park", args.slice(1));
|
|
919
972
|
case "wake":
|
|
920
973
|
return powdbLifecycle("wake", args.slice(1));
|
|
974
|
+
case "upgrade":
|
|
975
|
+
return powdbUpgrade(args.slice(1));
|
|
921
976
|
case undefined:
|
|
922
977
|
powdbHelp();
|
|
923
978
|
return;
|
|
924
979
|
default:
|
|
925
|
-
emitError("INVALID_FLAG", `Unknown subcommand: powdb ${sub}`, "Available: pull, query, exec, status, park, wake. Run `bata powdb --help`.");
|
|
980
|
+
emitError("INVALID_FLAG", `Unknown subcommand: powdb ${sub}`, "Available: pull, query, exec, status, park, wake, upgrade. Run `bata powdb --help`.");
|
|
926
981
|
}
|
|
927
982
|
}
|