Skip to content

Commit b589db0

Browse files
clean up logging
1 parent 599a5f8 commit b589db0

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

Generic-POC-Flyway-Commands/fullFlywayPOCSetupAndRun.ps1

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Set parameters
2-
$overWriteProject = $false # Set to true to delete and recreate the project folder. Can be useful when configuring from scratch.
2+
$overWriteProject = $true # Set to true to delete and recreate the project folder. Can be useful when configuring from scratch.
33
$databaseType = "SqlServer" # alt values: SqlServer Oracle PostgreSql MySql
44
# connection string to prodlike database
55
# This POC will create a dev, test, shadow DB - this name will be in the root of all subsequent names
@@ -15,6 +15,7 @@ $projectName = "$baseDBName"
1515
$projectPath = "."
1616
# Backup as Baseline path - must be accessible by DB server - leave empty if not needed
1717
$backupPath = "C:\\Program Files\\Microsoft SQL Server\\MSSQL13.MSSQLSERVER\\MSSQL\\Backup\\NewWorldDB_Dev.bak" # eg C:\\Program Files\\Microsoft SQL Server\\MSSQL13.MSSQLSERVER\\MSSQL\\Backup\\Northwind.bak
18+
$workingDir = "$projectPath\$projectName"
1819

1920
# Set the schemas value
2021
$Schemas = @("") # can be empty for SqlServer
@@ -28,8 +29,8 @@ $shadowUrl = ""
2829

2930
# Initialize project - create folders and flyway.toml - delete existing project folder if exists
3031
# For project setup, it can be helpful to overwrite as configuration may change. Set $overWriteProject = $true to force recreation
31-
if ($overWriteProject -or -not (Test-Path -Path "$projectPath\$projectName")) {
32-
if (Test-Path -Path "$projectPath\$projectName") {
32+
if ($overWriteProject -or -not (Test-Path -Path "$workingDir")) {
33+
if (Test-Path -Path "$workingDir") {
3334
Remove-Item -Path $projectName -Recurse -Force
3435
}
3536
Set-Location $projectPath
@@ -154,17 +155,17 @@ Read-Host "Press Enter when ready to capture your changes in the schema model an
154155
$scriptName = "Jira123_YourDescription"
155156

156157
#Syncs the Schema Model folder with the provided Source URL
157-
flyway diff model "-workingDirectory=$projectPath" "-diff.source=dev" "-diff.target=schemaModel" "-environments.dev.url=$devDBConnectionString" 2>&1 | Where-Object { $_ -notmatch 'Database: jdbc:' -and $_ -notmatch 'ERROR: Skipping filesystem location:' }
158+
flyway diff model "-workingDirectory=$workingDir" "-diff.source=dev" "-diff.target=schemaModel" "-environments.dev.url=$devDBConnectionString" 2>&1 | Where-Object { $_ -notmatch 'Database: jdbc:' -and $_ -notmatch 'ERROR: Skipping filesystem location:' }
158159
#Generated a new migration script by comparing the Schema Model folder to Build Url after it's been brought to current version.
159-
flyway diff generate "-workingDirectory=$projectPath" "-diff.source=schemaModel" "-diff.target=migrations" "-generate.types=versioned,undo" "-generate.description=$scriptName" "-diff.buildEnvironment=shadow" "-environments.shadow.url=$shadowUrl" 2>&1 | Where-Object { $_ -notmatch 'Database: jdbc:' -and $_ -notmatch 'ERROR: Skipping filesystem location:' }
160+
flyway diff generate "-workingDirectory=$workingDir" "-diff.source=schemaModel" "-diff.target=migrations" "-generate.types=versioned,undo" "-generate.description=$scriptName" "-diff.buildEnvironment=shadow" "-environments.shadow.url=$shadowUrl" 2>&1 | Where-Object { $_ -notmatch 'Database: jdbc:' -and $_ -notmatch 'ERROR: Skipping filesystem location:' }
160161

161162
Write-Host "`n========================================" -ForegroundColor Cyan
162163
Write-Host "DEPLOYMENT: Deploy to Test Database ($testUrl)" -ForegroundColor Yellow -BackgroundColor DarkBlue
163164
Write-Host "========================================" -ForegroundColor Cyan
164165
Write-Host "You are about to deploy changes to the test DB." -ForegroundColor White
165-
Read-Host "Press Enter to run flyway migrate -workingDirectory=$projectPath -environment=test -saveSnapshot=true"
166+
Read-Host "Press Enter to run flyway migrate -workingDirectory=$workingDir -environment=test -saveSnapshot=true"
166167

167-
flyway migrate -workingDirectory="$projectPath" -environment=test -saveSnapshot=true 2>&1 | Where-Object { $_ -notmatch 'Database: jdbc:' -and $_ -notmatch 'ERROR: Skipping filesystem location:' }
168+
flyway migrate -workingDirectory="$workingDir" -environment=test -saveSnapshot=true 2>&1 | Where-Object { $_ -notmatch 'Database: jdbc:' -and $_ -notmatch 'ERROR: Skipping filesystem location:' }
168169

169170
Write-Host "`n========================================" -ForegroundColor Cyan
170171
Write-Host "REVIEW: Check Deployment Results" -ForegroundColor Yellow -BackgroundColor DarkBlue
@@ -179,9 +180,9 @@ Write-Host "`n========================================" -ForegroundColor Cyan
179180
Write-Host "INFO: View Deployment History" -ForegroundColor Yellow -BackgroundColor DarkBlue
180181
Write-Host "========================================" -ForegroundColor Cyan
181182
Write-Host "You can run 'flyway info' from the command line to see the deployment history." -ForegroundColor White
182-
Read-Host "Press Enter to run flyway info -workingDirectory=$projectPath -environment=test"
183+
Read-Host "Press Enter to run flyway info -workingDirectory=$workingDir -environment=test"
183184

184-
flyway info -workingDirectory="$projectPath" -environment=test 2>&1 | Where-Object { $_ -notmatch 'Database: jdbc:' -and $_ -notmatch 'ERROR: Skipping filesystem location:' }
185+
flyway info -workingDirectory="$workingDir" -environment=test 2>&1 | Where-Object { $_ -notmatch 'Database: jdbc:' -and $_ -notmatch 'ERROR: Skipping filesystem location:' }
185186

186187
Write-Host "`n========================================" -ForegroundColor Cyan
187188
Write-Host "DRIFT DETECTION: Learn More" -ForegroundColor Yellow -BackgroundColor DarkBlue
@@ -191,10 +192,10 @@ Write-Host "Learn more at: " -ForegroundColor White -NoNewline
191192
Write-Host "Drift Detection Tutorial" -ForegroundColor Cyan
192193
Write-Host "https://documentation.red-gate.com/fd/tutorial-drift-report-for-deployments-using-embedded-snapshot-317493682.html" -ForegroundColor Blue
193194
Read-Host "For drift to show up, you need to manually make a change to a target database outside of using Flyway. Make a schema change manually to $testUrl."
194-
Read-Host "Press Enter to execute flyway check -drift -code -dryrun -environment=$test -check.code.failOnError=false -check.failOnDrift=false -check.deployedSnapshot=snapshothistory:current -workingDirectory=$projectPath"
195+
Read-Host "Press Enter to execute flyway check -drift -code -dryrun -environment=$test -check.code.failOnError=false -check.failOnDrift=false -check.deployedSnapshot=snapshothistory:current -workingDirectory=$workingDir"
195196

196197

197-
flyway check -drift -code -dryrun -environment=$test -check.code.failOnError=false -check.failOnDrift=false -check.deployedSnapshot=snapshothistory:current -workingDirectory="$projectPath"
198+
flyway check -drift -code -dryrun -environment=$test -check.code.failOnError=false -check.failOnDrift=false -check.deployedSnapshot=snapshothistory:current -workingDirectory="$workingDir"
198199

199200

200201
# # Variables to be changed by user

0 commit comments

Comments
 (0)