Skip to content

Commit

Permalink
user tests scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
maltaesousa committed Mar 31, 2021
1 parent 715f7fb commit a36a352
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/1_fetch_prod_db.ps1
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions scripts/2_deploy_prepub_for_tests.ps1
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a36a352

Please sign in to comment.