-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutobaseline.sh
155 lines (55 loc) · 3.13 KB
/
Autobaseline.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
########### To generate new baseline and schema-model, update WorkingFolderPath to a new location may be something with app name,Url,Password, Schemas
set -euo pipefail
# Set the working folder path
export DOTNET_ROOT=/opt/ddl_automation/OEL8/flyway-desktop-7.6.2/dotnet
export PATH=${PATH}:/etc:/usr/lib:/usr/lib64:/usr/local/bin:/sys_bckup/reel/bin:/usr/etc:/usr/bin/X11:/etc/conf/bin:/oracle/local/bin:/opt/ddl_automation/OEL8/flyway-10.17.1:/opt/ddl_automation/instantclient_19_15:/opt/ddl_automation/OEL8/flyway-desktop-7.6.2/flyway-dev:/opt/ddl_automation/OEL8/flyway-desktop-7.6.2/dotnet
export PROGRAM=$1
echo $PROGRAM
export CRQ=$2
echo $CRQ
# Set the working folder path
WorkingFolderPath="/ddl_automation/Automated_Onboarding/"$PROGRAM"/$CRQ/Baselinemodel"
export DBTYPE=$3
echo $DBTYPE
export DBBASELINEURL=$4
echo $DBBASELINEURL
export DBUSER=$5
echo $DBUSER
export DBPWD=$6
echo $DBPWD
export SCHEMAS=$7
echo $SCHEMAS
# Set the database type and database connection properties
DatabaseType="$DBTYPE" # alt values: SqlServer Oracle PostgreSql
#Url="jdbc:oracle:thin:@//x0stl11-scan.mastercard.int:1527/PDBCDPCS01S"
Url="$DBBASELINEURL"
User="$DBUSER"
Password="$DBPWD"
Schemas="$SCHEMAS" # May be '' for SqlServer or '"Schema1", "Schema2"' for Oracle
echo $SCHEMAS
# Set the paths
ArtifactPath="$WorkingFolderPath/artifact.zip"
ProjectPath="$WorkingFolderPath/flyway.toml"
MigrationPath="$WorkingFolderPath/migrations"
# Create a project
flyway-dev init -n Autobaseline -p "$WorkingFolderPath" --database-type "$DatabaseType" --i-agree-to-the-eula
echo -e "\n\n[environments.development]\nurl = \"some-url\"\nschemas = [$Schemas]"" >> "$ProjectPath"
echo -e "\n\n[environments.target]\nurl = "$Url"\nschemas = [$Schemas]\nuser = "$User"\npassword = "$Password"" >> "$ProjectPath"
sed -i 's/includeStoragePartitioning = false/includeStoragePartitioning = true/g' "$ProjectPath"
sed -i 's/ignoreSupplementalLogGroups = false/ignoreSupplementalLogGroups = true/g' "$ProjectPath"
sed -i 's/ignorePermissions = true/ignorePermissions = false/g' "$ProjectPath"
# schema model diffs
###DiffOptions=$(cat <<-END
###{ "url": "$Url", "user": "$User", "password": "$Password", "schemas": [$Schemas], "resolverProperties": [] }
###END
###)
flyway-dev diff -p "$ProjectPath" -a "$ArtifactPath" --targetId target --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
flyway-dev diff -p "$ProjectPath" -a "$ArtifactPath" --targetId target --from Target --to Empty --i-agree-to-the-eula
# Generate the baseline from all differences
flyway-dev take -p "$ProjectPath" -a "$ArtifactPath" --i-agree-to-the-eula \
| flyway-dev generate -p "$ProjectPath" -a "$ArtifactPath" -o "$MigrationPath" --name 'B1__script.sql' --versioned-only --i-agree-to-the-eula
echo -e "\n[flyway.oracle]\nsqlplus = true" >> "$ProjectPath"