diff --git a/data/drafts.db b/data/drafts.db index 3965e61..2485f1e 100644 Binary files a/data/drafts.db and b/data/drafts.db differ diff --git a/scripts/db-export.sh b/scripts/db-export.sh new file mode 100755 index 0000000..fceff8e --- /dev/null +++ b/scripts/db-export.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Export drafts.db as compressed SQL dump for portable sharing. +# Usage: scripts/db-export.sh [output_path] + +set -euo pipefail + +DB="data/drafts.db" +OUT="${1:-data/drafts.sql.gz}" + +if [[ ! -f "$DB" ]]; then + echo "Error: $DB not found" >&2 + exit 1 +fi + +echo "Exporting $DB → $OUT" +sqlite3 "$DB" .dump | gzip -9 > "$OUT" + +SIZE=$(du -h "$OUT" | cut -f1) +TABLES=$(sqlite3 "$DB" "SELECT count(*) FROM sqlite_master WHERE type='table';") +echo "Done: $SIZE ($TABLES tables)" diff --git a/scripts/db-import.sh b/scripts/db-import.sh new file mode 100755 index 0000000..0c90a5c --- /dev/null +++ b/scripts/db-import.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Import SQL dump into drafts.db, replacing existing data. +# Usage: scripts/db-import.sh [input_path] + +set -euo pipefail + +DB="data/drafts.db" +IN="${1:-data/drafts.sql.gz}" + +if [[ ! -f "$IN" ]]; then + echo "Error: $IN not found" >&2 + exit 1 +fi + +if [[ -f "$DB" ]]; then + BACKUP="data/drafts.db.bak.$(date +%s)" + echo "Backing up existing DB → $BACKUP" + cp "$DB" "$BACKUP" + rm "$DB" +fi + +echo "Importing $IN → $DB" +gunzip -c "$IN" | sqlite3 "$DB" + +ROWS=$(sqlite3 "$DB" "SELECT count(*) FROM drafts;") +echo "Done: $ROWS drafts restored"