53 lines
2.4 KiB
PowerShell
53 lines
2.4 KiB
PowerShell
# Patch E:\wwwroot\.env resource names to inquiry_robot*
|
|
$ErrorActionPreference = "Stop"
|
|
$envFile = "E:\wwwroot\.env"
|
|
if (-not (Test-Path $envFile)) { throw "missing $envFile" }
|
|
$c = [System.IO.File]::ReadAllText($envFile)
|
|
$c2 = $c
|
|
$c2 = $c2 -replace 'MYSQL_DB=ytd_test','MYSQL_DB=inquiry_robot'
|
|
$c2 = $c2 -replace 'MYSQL_USER=ytd_test','MYSQL_USER=inquiry_robot'
|
|
$c2 = $c2 -replace '3306/ytd_test\?','3306/inquiry_robot?'
|
|
$c2 = $c2 -replace 'PG_DATABASE=ytd_test_runtime','PG_DATABASE=inquiry_robot_runtime'
|
|
$c2 = $c2 -replace 'PG_USER=ytd_test_runtime','PG_USER=inquiry_robot_runtime'
|
|
$c2 = $c2 -replace 'REDIS_KEY_PREFIX=ytd:test:','REDIS_KEY_PREFIX=inquiry_robot:'
|
|
$c2 = $c2 -replace 'OBJECT_STORAGE_BUCKET=ytd-test','OBJECT_STORAGE_BUCKET=inquiry_robot'
|
|
if ($c2 -eq $c) {
|
|
Write-Output "NO_CHANGE_OR_ALREADY"
|
|
} else {
|
|
Copy-Item $envFile "$envFile.bak-before-inquiry-robot-rename" -Force
|
|
[System.IO.File]::WriteAllText($envFile, $c2)
|
|
Write-Output "ENV_PATCHED"
|
|
}
|
|
# also patch agent current .env if present
|
|
$agentEnv = "E:\wwwroot\agent\current\.env"
|
|
if (Test-Path $agentEnv) {
|
|
$a = [System.IO.File]::ReadAllText($agentEnv)
|
|
$a2 = $a
|
|
$a2 = $a2 -replace 'MYSQL_DB=ytd_test','MYSQL_DB=inquiry_robot'
|
|
$a2 = $a2 -replace 'MYSQL_USER=ytd_test','MYSQL_USER=inquiry_robot'
|
|
$a2 = $a2 -replace '3306/ytd_test\?','3306/inquiry_robot?'
|
|
$a2 = $a2 -replace 'PG_DATABASE=ytd_test_runtime','PG_DATABASE=inquiry_robot_runtime'
|
|
$a2 = $a2 -replace 'PG_USER=ytd_test_runtime','PG_USER=inquiry_robot_runtime'
|
|
$a2 = $a2 -replace 'REDIS_KEY_PREFIX=ytd:test:','REDIS_KEY_PREFIX=inquiry_robot:'
|
|
$a2 = $a2 -replace 'OBJECT_STORAGE_BUCKET=ytd-test','OBJECT_STORAGE_BUCKET=inquiry_robot'
|
|
if ($a2 -ne $a) {
|
|
[System.IO.File]::WriteAllText($agentEnv, $a2)
|
|
Write-Output "AGENT_ENV_PATCHED"
|
|
}
|
|
}
|
|
$intent = @{
|
|
cutoverTarget = "replace-yutongda"
|
|
deployRoot = "E:\wwwroot"
|
|
resourceNamespace = "inquiry_robot"
|
|
mysqlDb = "inquiry_robot"
|
|
pgDatabase = "inquiry_robot_runtime"
|
|
redisKeyPrefix = "inquiry_robot:"
|
|
objectStorageBucket = "inquiry_robot"
|
|
phase = "P0-isolation-until-ready"
|
|
updatedAt = (Get-Date).ToString("o")
|
|
} | ConvertTo-Json
|
|
Set-Content "E:\wwwroot\ops\cutover-intent.json" -Value $intent -Encoding UTF8
|
|
# verify without dumping secrets
|
|
Select-String -Path $envFile -Pattern 'MYSQL_DB=|PG_DATABASE=|REDIS_KEY_PREFIX=|OBJECT_STORAGE_BUCKET=' | ForEach-Object { $_.Line.Trim() }
|
|
Write-Output "DONE"
|