# DBAOps Sovereign™ — Run Database Migration
# Requires: SQL Server + SOVEREIGN_DB_CONNECTION in .env

$ErrorActionPreference = "Stop"
$root = (Get-Item $PSScriptRoot).Parent.FullName
Set-Location $root

if (-not (Test-Path "src\api\node_modules")) {
    Write-Host "Installing API dependencies..." -ForegroundColor Yellow
    Set-Location src\api
    npm install
    Set-Location $root
}

Write-Host "Running SovereignRepository migration..." -ForegroundColor Cyan
Set-Location src\api
node scripts/migrate.js
Set-Location $root

Write-Host "Migration complete." -ForegroundColor Green
