The databases live in Docker volumes (not in git), so teammates on a fresh boot saw an empty system. backups/procurement.dump + casdoor.dump are exact pg_dump snapshots of the current demo state (users/roles, projects, warehouses, quotes with receipts, inventory rows; Casdoor org/app/users); restore.ps1 / restore.sh replace both DBs with the committed state (--clean --if-exists, verified by a round-trip restore into throwaway DBs). README documents how to restore and how to take a fresh dump.
45 lines
2.1 KiB
PowerShell
45 lines
2.1 KiB
PowerShell
# ============================================================
|
|
# 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
|