-
Notifications
You must be signed in to change notification settings - Fork 10
/
runCreateFastRefreshModule.sh
executable file
·192 lines (122 loc) · 6.67 KB
/
runCreateFastRefreshModule.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#! /bin/bash
. ./module_set_variables.sh
echo "INFO: Set variables" >> $LOG_FILE
echo "INFO: LOG_FILE parameter set to $LOG_FILE" >> $LOG_FILE
echo "INFO: MODULEOWNER parameter set to $MODULEOWNER" >> $LOG_FILE
echo "INFO: PGUSERNAME parameter set to $PGUSERNAME" >> $LOG_FILE
echo "INFO: HOSTNAME parameter set to $HOSTNAME" >> $LOG_FILE
echo "INFO: PORT parameter set to $PORT" >> $LOG_FILE
echo "INFO: DBNAME parameter set to $DBNAME" >> $LOG_FILE
echo "INFO: MODULE_HOME parameter set to $MODULE_HOME" >> $LOG_FILE
echo "INFO: INSTALL_TYPE parameter set to $INSTALL_TYPE" >> $LOG_FILE
if [ "$INSTALL_TYPE" == "FULL" ]; then
echo "INFO: Fast Refresh Module FULL Install started at `date`" >> $LOG_FILE
elif [ "$INSTALL_TYPE" == "UPDATE" ]; then
echo "INFO: Fast Refresh Module UPDATE patch started at `date`" >> $LOG_FILE
fi
chmod 771 -R $MODULE_HOME/
export PATCHVERSION="$(cat $MODULE_HOME/read_my_version.txt)"
export PATCHVERSION=$(echo $PATCHVERSION | tr -d ' ')
echo "Patch version: $PATCHVERSION" >> $LOG_FILE
function fullbuildcompatibility
{
echo "INFO: Run $MODULEOWNER full build compatibility script" >> $LOG_FILE
echo "INFO: Connect to postgres database $DBNAME via PSQL session" >> $LOG_FILE
psql --host=$HOSTNAME --port=$PORT --username=$MODULEOWNER --dbname=$DBNAME -v ON_ERROR_STOP=1 -v MODULE_HOME=$MODULE_HOME -v MODULEOWNER=$MODULEOWNER << EOFB >> $LOG_FILE 2>&1
\i :MODULE_HOME/BuildScripts/fullBuildCompatibility.sql;
\q
EOFB
exitcode=$?
if [ $exitcode != 0 ]; then
exit 1
fi
}
function versioncontrol
{
echo "INFO: Run $MODULEOWNER version control script" >> $LOG_FILE
echo "INFO: Connect to postgres database $DBNAME via PSQL session" >> $LOG_FILE
psql --host=$HOSTNAME --port=$PORT --username=$MODULEOWNER --dbname=$DBNAME -v ON_ERROR_STOP=1 -v MODULE_HOME=$MODULE_HOME -v MODULEOWNER=$MODULEOWNER -v PATCHVERSION=$PATCHVERSION << EOFV >> $LOG_FILE 2>&1
\i :MODULE_HOME/UpdateScripts/V704_create_table_pgmviews_version_control.sql;
\i :MODULE_HOME/BuildScripts/versionCompatibility.sql;
\q
EOFV
exitcode=$?
if [ $exitcode != 0 ]; then
exit 1
fi
}
if [ "$INSTALL_TYPE" == "FULL" ]; then
echo "INFO: Run $MODULEOWNER schema build script" >> $LOG_FILE
echo "INFO: Connect to postgres database $DBNAME via PSQL session" >> $LOG_FILE
psql --host=$HOSTNAME --port=$PORT --username=$PGUSERNAME --dbname=$DBNAME -v MODULE_HOME=$MODULE_HOME -v MODULEOWNERPASS=$MODULEOWNERPASS -v MODULEOWNER=$MODULEOWNER -v PGUSERNAME=$PGUSERNAME -v DBNAME=$DBNAME -v HOSTNAME=$HOSTNAME -v PORT=$PORT << EOF1 >> $LOG_FILE 2>&1
\i :MODULE_HOME/BuildScripts/createModuleOwnerSchema.sql;
\q
EOF1
echo "INFO: Run Cron setup script" >> $LOG_FILE
echo "INFO: Connect to postgres database via PSQL session" >> $LOG_FILE
psql --host=$HOSTNAME --port=$PORT --username=$PGUSERNAME --dbname=postgres -v MODULE_HOME=$MODULE_HOME -v MODULEOWNERPASS=$MODULEOWNERPASS -v MODULEOWNER=$MODULEOWNER << EOF2 >> $LOG_FILE 2>&1
\i :MODULE_HOME/BuildScripts/createCronSetup.sql;
\q
EOF2
PGPASSWORD=$MODULEOWNERPASS
fullbuildcompatibility
versioncontrol
echo "INFO: Run $MODULEOWNER schema object build scripts" >> $LOG_FILE
echo "INFO: Connect to postgres database $DBNAME via PSQL session" >> $LOG_FILE
psql --host=$HOSTNAME --port=$PORT --username=$MODULEOWNER --dbname=$DBNAME -v MODULE_HOME=$MODULE_HOME -v MODULEOWNERPASS=$MODULEOWNERPASS -v MODULEOWNER=$MODULEOWNER -v HOSTNAME=$HOSTNAME -v PORT=$PORT << EOF3 >> $LOG_FILE 2>&1
SET search_path = :MODULEOWNER,catalog,public;
-- Used to run materialized view build insert in parallel sessions
CREATE SERVER IF NOT EXISTS pgmv\$cron_instance FOREIGN DATA WRAPPER postgres_fdw options ( dbname 'postgres', port :'PORT', host :'HOSTNAME', connect_timeout '2', keepalives_count '5' );
CREATE USER MAPPING IF NOT EXISTS for :MODULEOWNER SERVER pgmv\$cron_instance OPTIONS (user :'MODULEOWNER', password :'MODULEOWNERPASS');
GRANT USAGE ON FOREIGN SERVER pgmv\$cron_instance TO :MODULEOWNER;
\i :MODULE_HOME/BuildScripts/mvTypes.sql;
\i :MODULE_HOME/BuildScripts/mvConstants.sql;
\i :MODULE_HOME/BuildScripts/mvSimpleFunctions.sql;
\i :MODULE_HOME/BuildScripts/mvComplexFunctions.sql;
\i :MODULE_HOME/BuildScripts/mvApplicationFunctions.sql;
\i :MODULE_HOME/BuildScripts/mvTriggerFunction.sql;
\q
EOF3
elif [ "$INSTALL_TYPE" == "UPDATE" ]; then
touch $MODULE_HOME/fast_refresh_module_update_patch_objects.sql
chmod 771 $MODULE_HOME/fast_refresh_module_update_patch_objects.sql
truncate -s 0 $MODULE_HOME/fast_refresh_module_update_patch_objects.sql
ls $MODULE_HOME/UpdateScripts/*.sql | sort -V | while IFS= read -r file; do
UPDATE_SCRIPTS_SQL=$(echo "\\i $file;")$'\n'
echo $UPDATE_SCRIPTS_SQL >> $MODULE_HOME/fast_refresh_module_update_patch_objects.sql
done
UPDATE_FUNCTIONS=$(echo "\\i $MODULE_HOME/BuildScripts/mvTypes.sql;")$'\n'
echo $UPDATE_FUNCTIONS >> $MODULE_HOME/fast_refresh_module_update_patch_objects.sql
UPDATE_FUNCTIONS=$(echo "\\i $MODULE_HOME/BuildScripts/mvConstants.sql;")$'\n'
echo $UPDATE_FUNCTIONS >> $MODULE_HOME/fast_refresh_module_update_patch_objects.sql
UPDATE_FUNCTIONS=$(echo "\\i $MODULE_HOME/BuildScripts/mvSimpleFunctions.sql;")$'\n'
echo $UPDATE_FUNCTIONS >> $MODULE_HOME/fast_refresh_module_update_patch_objects.sql
UPDATE_FUNCTIONS=$(echo "\\i $MODULE_HOME/BuildScripts/mvComplexFunctions.sql;")$'\n'
echo $UPDATE_FUNCTIONS >> $MODULE_HOME/fast_refresh_module_update_patch_objects.sql
UPDATE_FUNCTIONS=$(echo "\\i $MODULE_HOME/BuildScripts/mvApplicationFunctions.sql;")$'\n'
echo $UPDATE_FUNCTIONS >> $MODULE_HOME/fast_refresh_module_update_patch_objects.sql
psql --host=$HOSTNAME --port=$PORT --username=$PGUSERNAME --dbname=postgres -v MODULE_HOME=$MODULE_HOME -v MODULEOWNERPASS=$MODULEOWNERPASS -v MODULEOWNER=$MODULEOWNER << EOF4 >> $LOG_FILE 2>&1
\i :MODULE_HOME/BuildScripts/createCronSetup.sql;
\q
EOF4
PGPASSWORD=$MODULEOWNERPASS
versioncontrol
echo "INFO: Run $MODULEOWNER schema UPDATE patch scripts" >> $LOG_FILE
echo "INFO: Connect to postgres database $DBNAME via PSQL session" >> $LOG_FILE
psql --host=$HOSTNAME --port=$PORT --username=$MODULEOWNER --dbname=$DBNAME -v MODULE_HOME=$MODULE_HOME -v MODULEOWNERPASS=$MODULEOWNERPASS -v MODULEOWNER=$MODULEOWNER -v HOSTNAME=$HOSTNAME -v PORT=$PORT << EOF5 >> $LOG_FILE 2>&1
SET search_path = :MODULEOWNER,catalog,public;
\i :MODULE_HOME/fast_refresh_module_update_patch_objects.sql;
EOF5
fi
$MODULE_HOME/module_error_chks.sh
echo "Check log file - $LOG_FILE"
exitcode=$?
if [ $exitcode != 0 ]; then
exit 1
fi
if [ "$INSTALL_TYPE" == "FULL" ]; then
echo "INFO: Fast Refresh Module FULL Install finished at `date`" >> $LOG_FILE
elif [ "$INSTALL_TYPE" == "UPDATE" ]; then
echo "INFO: Fast Refresh Module UPDATE patch finished at `date`" >> $LOG_FILE
fi
exit