diff --git a/README.md b/README.md index f3f462d..f63715f 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,29 @@ docker exec -it procurement-postgres psql -U postgres -d procurement --- +## Restoring the demo data (for the team) + +The databases are **not** in git — Docker volumes hold the data. To let +everyone see the same system state, the repo ships exact database dumps in +`backups/` (taken 2026-09-02). After a fresh boot: + +```powershell +powershell -ExecutionPolicy Bypass -File .\backups\restore.ps1 # Windows +bash backups/restore.sh # Linux / Git Bash +``` + +This **replaces all data** in the `procurement` and `casdoor` databases with +the committed state (users + roles, projects, warehouses, quotes with +receipts, inventory rows, Casdoor org/app/users). To create a fresh dump of +your own current state: + +```powershell +docker compose stop api casdoor +docker exec procurement-postgres pg_dump -U postgres -d procurement -Fc > backups/procurement.dump # (Git Bash: use -f inside the container + docker cp) +docker exec procurement-postgres pg_dump -U postgres -d casdoor -Fc > backups/casdoor.dump +docker compose start casdoor api +``` + ## Common operations ```powershell diff --git a/backups/casdoor.dump b/backups/casdoor.dump new file mode 100644 index 0000000..e7b5e86 Binary files /dev/null and b/backups/casdoor.dump differ diff --git a/backups/procurement.dump b/backups/procurement.dump new file mode 100644 index 0000000..fc2bae1 Binary files /dev/null and b/backups/procurement.dump differ diff --git a/backups/restore.ps1 b/backups/restore.ps1 new file mode 100644 index 0000000..e47149b --- /dev/null +++ b/backups/restore.ps1 @@ -0,0 +1,44 @@ +# ============================================================ +# Restore the committed demo-state dumps (backups/*.dump) into +# the running stack. REPLACES all data in the `procurement` and +# `casdoor` databases — run it on a fresh boot or when you want +# to reset to the exact committed state. +# +# powershell -ExecutionPolicy Bypass -File .\backups\restore.ps1 +# ============================================================ + +$ErrorActionPreference = "Stop" +$here = Split-Path -Parent $MyInvocation.MyCommand.Path +Set-Location (Join-Path $here "..") + +Write-Host "" +Write-Host "Restoring demo data — this REPLACES the current DB content!" -ForegroundColor Yellow + +docker compose ps postgres | Select-String "healthy" | Out-Null +if ($LASTEXITCODE -ne 0) { + Write-Host "postgres is not healthy — run 'docker compose up -d' first." -ForegroundColor Red + exit 1 +} + +Write-Host "Stopping api + casdoor (they hold DB connections)..." -ForegroundColor Cyan +docker compose stop api casdoor +if ($LASTEXITCODE -ne 0) { exit 1 } + +Write-Host "Restoring procurement DB..." -ForegroundColor Cyan +docker cp "backups\procurement.dump" procurement-postgres:/tmp/procurement.dump +docker exec procurement-postgres pg_restore -U postgres -d procurement --clean --if-exists --single-transaction /tmp/procurement.dump +if ($LASTEXITCODE -ne 0) { Write-Host "procurement restore FAILED" -ForegroundColor Red; exit 1 } + +Write-Host "Restoring casdoor DB..." -ForegroundColor Cyan +docker cp "backups\casdoor.dump" procurement-postgres:/tmp/casdoor.dump +docker exec procurement-postgres pg_restore -U postgres -d casdoor --clean --if-exists --single-transaction /tmp/casdoor.dump +if ($LASTEXITCODE -ne 0) { Write-Host "casdoor restore FAILED" -ForegroundColor Red; exit 1 } + +Write-Host "Starting services..." -ForegroundColor Cyan +docker compose start casdoor api +if ($LASTEXITCODE -ne 0) { exit 1 } + +Write-Host "" +Write-Host "Restore complete." -ForegroundColor Green +Write-Host "App : http://localhost" -ForegroundColor Green +Write-Host "Casdoor : http://localhost:8080 (admin / 123)" -ForegroundColor Green diff --git a/backups/restore.sh b/backups/restore.sh new file mode 100644 index 0000000..e1837a5 --- /dev/null +++ b/backups/restore.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Restore the committed demo-state dumps (backups/*.dump) into the running +# stack (Linux/macOS/Git Bash). REPLACES all data in the `procurement` and +# `casdoor` databases. +# +# bash backups/restore.sh +set -euo pipefail +cd "$(dirname "$0")/.." + +echo "Stopping api + casdoor (they hold DB connections)..." +docker compose stop api casdoor + +echo "Restoring procurement DB..." +docker cp backups/procurement.dump procurement-postgres:/tmp/procurement.dump +docker exec procurement-postgres pg_restore -U postgres -d procurement --clean --if-exists --single-transaction /tmp/procurement.dump + +echo "Restoring casdoor DB..." +docker cp backups/casdoor.dump procurement-postgres:/tmp/casdoor.dump +docker exec procurement-postgres pg_restore -U postgres -d casdoor --clean --if-exists --single-transaction /tmp/casdoor.dump + +echo "Starting services..." +docker compose start casdoor api + +echo "" +echo "Restore complete." +echo "App : http://localhost" +echo "Casdoor : http://localhost:8080 (admin / 123)"