From 3ad84420bd882f983c2f9b605e7a68f5bdf95f5c Mon Sep 17 00:00:00 2001 From: cloudhead Date: Mon, 18 Nov 2024 12:27:07 +0100 Subject: [PATCH] cli: Implement `rad cob migrate` Adds the new `migrate` sub-command to migrate the COB database. Checks for version when opening the COBs database and suggests the command on out of date version. Also adds the 2nd migration to the COBs cache, which updates the patch JSON schema. --- radicle-cli/examples/rad-cob-migrate.md | 24 +++ radicle-cli/src/commands/clone.rs | 5 +- radicle-cli/src/commands/cob.rs | 117 +++++++---- radicle-cli/src/commands/inbox.rs | 9 +- radicle-cli/src/commands/issue.rs | 5 +- radicle-cli/src/commands/issue/cache.rs | 4 +- radicle-cli/src/commands/patch.rs | 4 +- radicle-cli/src/commands/patch/archive.rs | 7 +- radicle-cli/src/commands/patch/assign.rs | 3 +- radicle-cli/src/commands/patch/cache.rs | 3 +- radicle-cli/src/commands/patch/checkout.rs | 3 +- radicle-cli/src/commands/patch/comment.rs | 4 +- radicle-cli/src/commands/patch/delete.rs | 3 +- radicle-cli/src/commands/patch/diff.rs | 4 +- radicle-cli/src/commands/patch/edit.rs | 4 +- radicle-cli/src/commands/patch/label.rs | 7 +- radicle-cli/src/commands/patch/list.rs | 4 +- radicle-cli/src/commands/patch/ready.rs | 7 +- radicle-cli/src/commands/patch/redact.rs | 4 +- radicle-cli/src/commands/patch/resolve.rs | 5 +- radicle-cli/src/commands/patch/review.rs | 3 +- radicle-cli/src/commands/patch/show.rs | 4 +- radicle-cli/src/commands/patch/update.rs | 4 +- radicle-cli/src/commands/stats.rs | 5 +- radicle-cli/src/terminal.rs | 1 + radicle-cli/src/terminal/cob.rs | 113 ++++++++++ radicle-cli/tests/commands.rs | 19 ++ radicle-node/src/runtime.rs | 13 +- radicle-node/src/test/environment.rs | 8 +- radicle-remote-helper/src/lib.rs | 38 +++- radicle-remote-helper/src/list.rs | 3 +- radicle-remote-helper/src/push.rs | 18 +- radicle-tools/src/rad-merge.rs | 3 +- radicle/src/cob/cache.rs | 195 ++++++++++++------ radicle/src/cob/cache/migrations.rs | 2 + radicle/src/cob/cache/migrations/2.rs | 132 ++++++++++++ .../cache/migrations/samples/patch.v1.json | 179 ++++++++++++++++ .../cache/migrations/samples/patch.v2.json | 165 +++++++++++++++ radicle/src/cob/issue/cache.rs | 6 +- radicle/src/cob/patch.rs | 6 +- radicle/src/cob/patch/cache.rs | 8 +- radicle/src/profile.rs | 67 +++--- 42 files changed, 1013 insertions(+), 205 deletions(-) create mode 100644 radicle-cli/examples/rad-cob-migrate.md create mode 100644 radicle-cli/src/terminal/cob.rs create mode 100644 radicle/src/cob/cache/migrations.rs create mode 100644 radicle/src/cob/cache/migrations/2.rs create mode 100644 radicle/src/cob/cache/migrations/samples/patch.v1.json create mode 100644 radicle/src/cob/cache/migrations/samples/patch.v2.json diff --git a/radicle-cli/examples/rad-cob-migrate.md b/radicle-cli/examples/rad-cob-migrate.md new file mode 100644 index 00000000..05c8adbe --- /dev/null +++ b/radicle-cli/examples/rad-cob-migrate.md @@ -0,0 +1,24 @@ +``` (fail) +$ rad patch list +✗ Error: collaborative objects database is out of date +✗ Hint: run `rad cob migrate` to update your database +``` + +``` (fail) +$ rad issue list +✗ Error: collaborative objects database is out of date +✗ Hint: run `rad cob migrate` to update your database +``` + +``` +$ rad cob migrate +✓ Migration [..]/[..] in progress.. (100%) +✓ Migrated collaborative objects database successfully (version = [..]) +``` + +``` +$ rad issue list +Nothing to show. +$ rad patch list +Nothing to show. +``` diff --git a/radicle-cli/src/commands/clone.rs b/radicle-cli/src/commands/clone.rs index e9fa8eee..2284cb41 100644 --- a/radicle-cli/src/commands/clone.rs +++ b/radicle-cli/src/commands/clone.rs @@ -9,7 +9,6 @@ use radicle::issue::cache::Issues as _; use radicle::patch::cache::Patches as _; use thiserror::Error; -use radicle::cob::migrate; use radicle::git::raw; use radicle::identity::doc; use radicle::identity::doc::{DocError, RepoId}; @@ -183,8 +182,8 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { info.push([term::format::bold(proj.name()).into()]); info.push([term::format::italic(proj.description()).into()]); - let issues = profile.issues(&repo, migrate::ignore)?.counts()?; - let patches = profile.patches(&repo, migrate::ignore)?.counts()?; + let issues = term::cob::issues(&profile, &repo)?.counts()?; + let patches = term::cob::patches(&profile, &repo)?.counts()?; info.push([term::Line::spaced([ term::format::tertiary(issues.open).into(), diff --git a/radicle-cli/src/commands/cob.rs b/radicle-cli/src/commands/cob.rs index 02c4bc74..2f4f2aab 100644 --- a/radicle-cli/src/commands/cob.rs +++ b/radicle-cli/src/commands/cob.rs @@ -5,7 +5,6 @@ use anyhow::anyhow; use chrono::prelude::*; use nonempty::NonEmpty; use radicle::cob; -use radicle::cob::migrate; use radicle::cob::Op; use radicle::identity::Identity; use radicle::issue::cache::Issues; @@ -27,14 +26,16 @@ pub const HELP: Help = Help { Usage rad cob [