# OPC # 0004: One-time migration — make postgres-data and minio-data external volumes # Run this ONCE before doing `docker compose up -d` with the updated docker-compose.yml. # Safe to run while containers are stopped. Do NOT run while containers are running. # # Usage: # cd OPC/scripts # .\create-external-volumes.ps1 $ErrorActionPreference = "Stop" function Migrate-Volume($composeName, $externalName) { Write-Host "`nMigrating: $composeName -> $externalName" -ForegroundColor Cyan $existing = docker volume ls --format "{{.Name}}" | Where-Object { $_ -eq $externalName } if ($existing) { Write-Host " Volume '$externalName' already exists — skipping copy." -ForegroundColor Yellow return } # Check source exists $source = docker volume ls --format "{{.Name}}" | Where-Object { $_ -eq $composeName } if (-not $source) { Write-Host " Source volume '$composeName' not found — creating empty external volume." -ForegroundColor Yellow docker volume create $externalName | Out-Null return } # Create external volume docker volume create $externalName | Out-Null Write-Host " Created '$externalName'" # Copy data using a temporary alpine container docker run --rm ` -v "${composeName}:/from" ` -v "${externalName}:/to" ` alpine sh -c "cd /from && cp -a . /to" Write-Host " Data copied." -ForegroundColor Green } # The compose project name prefixes anonymous volumes as "clarity-platform_" Migrate-Volume "clarity-platform_postgres-data" "postgres-data" Migrate-Volume "clarity-platform_minio-data" "minio-data" Write-Host "`nDone. You can now run: docker compose up -d" -ForegroundColor Green Write-Host "The old 'clarity-platform_postgres-data' and 'clarity-platform_minio-data' volumes can be removed with 'docker volume rm' once you've verified everything is working."