diff --git a/.claude/skills/worktree-update/SKILL.md b/.claude/skills/worktree-update/SKILL.md index 0dcea4479..403b2e1c3 100644 --- a/.claude/skills/worktree-update/SKILL.md +++ b/.claude/skills/worktree-update/SKILL.md @@ -88,6 +88,18 @@ continue to the next branch. The user must resolve before proceeding. After all merges, show the final state with `git log --oneline -N` (where N covers the new commits). +#### Backup the shared database + +After successful merges on main, snapshot the database for git tracking: + +```bash +make db-backup +``` + +This copies the shared `settledreach.db` (in the parent directory) to +`docs/backups/settledreach.db.backup`. Stage and commit it with the merge +if the file changed. + ### 2b. Not on `main` — merge main into current branch ```bash diff --git a/Makefile b/Makefile index d799989bc..e9950d5b6 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ GODOT := $(shell command -v godot4 2>/dev/null || command -v godot 2>/dev/null) .PHONY: help setup build client server test lint ci ci-client ci-server clean \ - decisions-sync decisions-coverage decisions-active decisions-orphan + decisions-sync decisions-coverage decisions-active decisions-orphan \ + db-backup db-install # --- Configuration --- @@ -22,6 +23,9 @@ help: @echo " make ci-server Run server CI checks" @echo " make clean Remove build artifacts and caches" @echo "" + @echo " make db-backup Backup shared database to git (main only)" + @echo " make db-install Restore shared database from backup" + @echo "" @echo " make decisions-sync Sync decisions/*.md into SQLite" @echo " make decisions-coverage Decision-to-ticket coverage by domain" @echo " make decisions-active List active decisions" @@ -101,6 +105,14 @@ ci-server: lint-server build-server test-server ci-client: lint-client build-client test-client +# --- Database --- + +db-backup: + @tooling/db-backup + +db-install: + @tooling/db-install + # --- Decisions --- decisions-sync: diff --git a/docs/backups/.gitkeep b/docs/backups/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/docs/backups/settledreach.db.backup b/docs/backups/settledreach.db.backup new file mode 100644 index 000000000..55171851c Binary files /dev/null and b/docs/backups/settledreach.db.backup differ diff --git a/tooling/db-backup b/tooling/db-backup new file mode 100755 index 000000000..9911f5040 --- /dev/null +++ b/tooling/db-backup @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# Copy the shared database into git-tracked docs/backups/ for disaster recovery. +# Only runs on the main branch — called via `make db-backup`. +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +WORKTREE_ROOT="$(dirname "$SCRIPT_DIR")" +DB_PATH="$(dirname "$WORKTREE_ROOT")/settledreach.db" +BACKUP_PATH="$WORKTREE_ROOT/docs/backups/settledreach.db.backup" + +branch="$(git -C "$WORKTREE_ROOT" branch --show-current)" +if [ "$branch" != "main" ]; then + echo "error: db-backup only runs on the main branch (currently on '$branch')" >&2 + exit 1 +fi + +if [ ! -f "$DB_PATH" ]; then + echo "error: shared database not found at $DB_PATH" >&2 + exit 1 +fi + +cp "$DB_PATH" "$BACKUP_PATH" +echo "ok: backed up $(du -h "$BACKUP_PATH" | cut -f1) to docs/backups/settledreach.db.backup" diff --git a/tooling/db-install b/tooling/db-install new file mode 100755 index 000000000..ec90d8b80 --- /dev/null +++ b/tooling/db-install @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Restore the shared database from the git-tracked backup. +# Use after cloning or when the shared database is missing. +# Called via `make db-install`. +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +WORKTREE_ROOT="$(dirname "$SCRIPT_DIR")" +DB_PATH="$(dirname "$WORKTREE_ROOT")/settledreach.db" +BACKUP_PATH="$WORKTREE_ROOT/docs/backups/settledreach.db.backup" + +if [ -f "$DB_PATH" ]; then + echo "error: shared database already exists at $DB_PATH" >&2 + echo " delete it first if you want to restore from backup" >&2 + exit 1 +fi + +if [ ! -f "$BACKUP_PATH" ]; then + echo "error: backup not found at $BACKUP_PATH" >&2 + echo " run 'make db-backup' on the main branch first" >&2 + exit 1 +fi + +cp "$BACKUP_PATH" "$DB_PATH" +echo "ok: restored $(du -h "$DB_PATH" | cut -f1) to $DB_PATH"