forked from turimbar1/flyway-example-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffScript.sh
More file actions
62 lines (47 loc) · 2.41 KB
/
DiffScript.sh
File metadata and controls
62 lines (47 loc) · 2.41 KB
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
55
56
57
58
59
60
61
62
#!/bin/bash
set -euo pipefail
# Point to where flyway dev is
# If you didn't create the entrypoint script you may need to invoke flyway dev through dotnet
# e.g. /opt/flyway-desktop/dotnet/dotnet /opt/flyway-desktop/flyway-dev/flyway-dev.dll
#flyway-dev() {
# /opt/flyway-desktop/flyway-dev.sh --i-agree-to-the-eula "$@"
#}
# Set the working folder path
WorkingFolderPath=~/.
#Set the environment (eg Dev, QA, Test) database connection properties
Url="jdbc:oracle:thin:@//localhost:1521/Dev1"
User="HR"
Password="Password"
Schemas='"HR"' # May be '' for SqlServer or '"Schema1", "Schema2"' for Oracle
# Set the shadow (empty) database connection properties
ShadowUrl="jdbc:oracle:thin:@//localhost:1521/Dev1"
ShadowUser="HR"
ShadowPassword="Password"
# Set the paths
ArtifactPath="/tmp/artifact.zip"
ProjectPath="$WorkingFolderPath/flyway.toml"
MigrationPath="$WorkingFolderPath/migrations"
# schema model diffs
DiffOptions=$(cat <<-END
{ "url": "$Url", "user": "$User", "password": "$Password", "schemas": [$Schemas], "resolverProperties": [] }
END
)
ShadowDiffOptions=$(cat <<-END
{ "url": "$ShadowUrl", "user": "$ShadowUser", "password": "$ShadowPassword", "schemas": [$Schemas], "resolverProperties": [] }
END
)
echo "$DiffOptions" \
| flyway-dev diff -p "$ProjectPath" -a "$ArtifactPath" --from Target --to SchemaModel --i-agree-to-the-eula
#apply to schema model
flyway-dev take -p "$ProjectPath" -a "$ArtifactPath" --i-agree-to-the-eula \
| flyway-dev apply -p "$ProjectPath" -a "$ArtifactPath" --i-agree-to-the-eula
#deploy migrations to shadow
flyway clean migrate info -url="$ShadowUrl" -user="$ShadowUser" -password="$ShadowPassword" -workingDirectory="$WorkingFolderPath" -cleanDisabled="false" -schemas="$Schemas" -baselinOnMigrate="true"
#diff between schema model and shadow/migrations scripts
echo "$ShadowDiffOptions" \
| flyway-dev diff -p "$ProjectPath" -a "$ArtifactPath" --from SchemaModel --to Target --i-agree-to-the-eula
# Generate the diff script between baseline and this environment
flyway-dev take -p "$ProjectPath" -a "$ArtifactPath" --i-agree-to-the-eula \
| flyway-dev generate -p "$ProjectPath" -a "$ArtifactPath" -o "$MigrationPath" --i-agree-to-the-eula
#mark scripts as deployed to target environment
# flyway migrate info -skipExecutingMigrations="true" -url="$Url" -user="$User" -password="$Password" -workingDirectory="$WorkingFolderPath" -cleanDisabled="false" -schemas="$Schemas" -baselinOnMigrate="true"