-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutobaseline.ps1
54 lines (42 loc) · 1.81 KB
/
Autobaseline.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Set the working folder path
$workingFolderPath = "C:\WorkingFolders\test"
# Set the database type and database connection properties
$databaseType = "Oracle" # alt values: SqlServer Oracle PostgreSql
$Url = "jdbc:oracle:thin:@//localhost:1521/Dev1"
$User = "UserName"
$Password = "Password"
# Set the schemas value
$schemas = @("SchemaName") # can be empty for SqlServer
# Set the artifact and migration paths
$artifactPath = Join-Path $workingFolderPath "artifact.zip"
$migrationPath = Join-Path $workingFolderPath "migrations"
# Create a project
flyway-dev init -n Autobaseline -p $workingFolderPath --database-type $databaseType --i-agree-to-the-eula
# Read the JSON file
$jsonPath = Join-Path $workingFolderPath "flyway-dev.json"
$json = Get-Content -Path $jsonPath | ConvertFrom-Json
# Add a new key-value pair to the JSON
$newKey= "schemas"
$newValue = $schemas
$json | Add-Member -MemberType NoteProperty -Name $newKey -Value $newValue
$devDB = @{
"connectionProvider" = @{
"type" = "UsernamePassword"
"url" = "some-url"
}
}
$json | Add-Member -MemberType NoteProperty -Name "developmentDatabase" -Value $devDB
# Write out the updated JSON
$json | ConvertTo-Json | Set-Content -Path $jsonPath
# Get the differences from Production
$diffOptions = @{
"url" = $Url
"user" = $User
"password" = $Password
"token" = $null
"schemas" = $schemas
"resolverProperties" = @()
}
$diffOptions | ConvertTo-Json | flyway-dev diff -p $workingFolderPath -a $artifactPath --from Target --to Empty --output json --i-agree-to-the-eula
# Generate the baseline from all differences
flyway-dev take -p $workingFolderPath -a $artifactPath --i-agree-to-the-eula | flyway-dev generate -p $workingFolderPath -a $artifactPath -o $migrationPath --name 'B1__script.sql' --versioned-only --i-agree-to-the-eula