feat(db): add database backup/restore tooling

- tooling/db-backup: copies shared settledreach.db to docs/backups/
  for git tracking (main branch only)
- tooling/db-install: restores from backup for new clones
- make db-backup / make db-install Makefile targets
- worktree-update skill runs make db-backup after merges on main

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-12 16:54:21 +01:00
co-authored by Claude Opus 4.6
parent 0784d484c4
commit 60ca9d951c
6 changed files with 73 additions and 1 deletions
+12
View File
@@ -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
+13 -1
View File
@@ -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:
View File
Binary file not shown.
+23
View File
@@ -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"
+25
View File
@@ -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"