diff --git a/scripts/1_fetch_prod_db.ps1 b/scripts/1_fetch_prod_db.ps1 new file mode 100644 index 00000000..47835c40 --- /dev/null +++ b/scripts/1_fetch_prod_db.ps1 @@ -0,0 +1,31 @@ +$pwd = pwd +foreach ($line in Get-Content $PSScriptRoot\..\back\.env.prod) { + $args = $line -split "=" + If ($args[0] -And !$args[0].StartsWith("#")) { + $cmd = '$env:' + $args[0].Trim('"') + '="' + $args[1].Trim('"') + '"' + Invoke-Expression $cmd + } +} + +$filename = ("geoshop.backup") +$dumpFile = ("{0}\{1}"-f $PSScriptRoot, $filename) + +$previous_PGPASSWORD = $env:PGPASSWORD +$env:PGPASSWORD = $env:PGPOSTGRESPASSWORD + +If (Test-Path $dumpFile) { + Remove-Item $dumpFile +} + +pg_dump -U postgres -F c -n $env:PGSCHEMA -b -f $dumpFile $env:PGDATABASE + +If (Test-Path $dumpFile) { + psql -U postgres -h localhost -d geoshop -c "DROP SCHEMA IF EXISTS old_$env:PGSCHEMA CASCADE;" + psql -U postgres -h localhost -d geoshop -c "ALTER SCHEMA $env:PGSCHEMA RENAME TO old_$env:PGSCHEMA;" + pg_restore -U postgres -h localhost -F c -d geoshop $dumpFile +} Else { + Write-Host "$(Get-Date -Format g) pg_restore has not been done" +} +$env:PGPASSWORD = $previous_PGPASSWORD + +cd $pwd diff --git a/scripts/2_deploy_prepub_for_tests.ps1 b/scripts/2_deploy_prepub_for_tests.ps1 new file mode 100644 index 00000000..95a08508 --- /dev/null +++ b/scripts/2_deploy_prepub_for_tests.ps1 @@ -0,0 +1,31 @@ +$pwd = pwd +foreach ($line in Get-Content $PSScriptRoot\..\back\.env.prepub) { + $args = $line -split "=" + If ($args[0] -And !$args[0].StartsWith("#")) { + $cmd = '$env:' + $args[0].Trim('"') + '="' + $args[1].Trim('"') + '"' + Invoke-Expression $cmd + } +} + +$filename = ("geoshop_local.backup") +$dumpFile = ("{0}\{1}"-f $PSScriptRoot, $filename) + +$previous_PGPASSWORD = $env:PGPASSWORD +$env:PGPASSWORD = $env:PGPOSTGRESPASSWORD + +If (Test-Path $dumpFile) { + Remove-Item $dumpFile +} + +pg_dump -h localhost -U postgres -F c -n $env:PGSCHEMA -b -f $dumpFile geoshop + +If (Test-Path $dumpFile) { + psql -U postgres -c "DROP SCHEMA IF EXISTS old_$env:PGSCHEMA CASCADE;" + psql -U postgres -c "ALTER SCHEMA $env:PGSCHEMA RENAME TO old_$env:PGSCHEMA;" + pg_restore -U postgres -F c -d $env:PGDATABASE $dumpFile +} Else { + Write-Host "$(Get-Date -Format g) pg_restore has not been done" +} +$env:PGPASSWORD = $previous_PGPASSWORD + +cd $pwd