-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TRUNK-6058 : added script to generate liquibase snapshots automatically
TRUNK-6058 : kill the process after installation completing TRUNK-6058 : added logs TRUNK-6058 : remove drop database process TRUNK-6058 : delete installation.properties file TRUNK-6058 : remove unwanted line
- Loading branch information
Showing
2 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/bin/bash | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at http:https://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
# the terms of the Healthcare Disclaimer located at http:https://openmrs.org/license. | ||
# | ||
# Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
# graphic logo is a trademark of OpenMRS Inc. | ||
# | ||
|
||
|
||
function generate_liquibase_snapshots_and_update() { | ||
cd liquibase/ | ||
. scripts/create_liquibase_snapshots.sh "${1}" "${2}" | ||
. scripts/fix_liquibase_snapshots.sh | ||
cd .. | ||
} | ||
|
||
function move_updated_snapshots() { | ||
mv liquibase/snapshots/liquibase-core-data-UPDATED-SNAPSHOT.xml api/src/main/resources/org/openmrs/liquibase/snapshots/core-data/"liquibase-core-data-$openmrs_version.x.xml" | ||
mv liquibase/snapshots/liquibase-schema-only-UPDATED-SNAPSHOT.xml api/src/main/resources/org/openmrs/liquibase/snapshots/schema-only/"liquibase-schema-only-$openmrs_version.x.xml" | ||
} | ||
|
||
function create_new_liquibase_update_file() { | ||
new_liquibase_file="liquibase-update-to-latest-${new_openmrs_version}.x.xml" | ||
cp "api/src/main/resources/liquibase-update-to-latest-template.xml" "api/src/main/resources/org/openmrs/liquibase/updates/$new_liquibase_file" | ||
|
||
database_updater_class="api/src/test/java/org/openmrs/util/DatabaseUpdaterDatabaseIT.java" | ||
variable_name="CHANGE_SET_COUNT_FOR_GREATER_THAN_2_1_X" | ||
|
||
# Increase the variable value by 1 | ||
sed -i "s/\($variable_name *= *\)[0-9]\+/\1$(( $(grep -o "$variable_name *= *[0-9]\+" "$database_updater_class" | awk '{print $NF}') + 1 ))/" "$database_updater_class" | ||
|
||
insert_line=" <include file=\"org/openmrs/liquibase/updates/$new_liquibase_file\"/>" | ||
sed -i -e '$!N;$!N;$i\'"$insert_line" "api/src/main/resources/liquibase-update-to-latest-from-1.9.x.xml" | ||
|
||
} | ||
|
||
function update_log_files_with_new_snapshots() { | ||
sed -i 's/\(<include file="org\/openmrs\/liquibase\/snapshots\/schema-only\/liquibase-schema-only-\)\([^"]*\)\.x\.xml"\/>/\1'"$openmrs_version"'\.x.xml"\/>/' "api/src/main/resources/liquibase-schema-only.xml" | ||
sed -i 's/\(<include file="org\/openmrs\/liquibase\/snapshots\/core-data\/liquibase-core-data-\)\([^"]*\)\.x\.xml"\/>/\1'"$openmrs_version"'\.x.xml"\/>/' "api/src/main/resources/liquibase-core-data.xml" | ||
sed -i 's/\(<include file="org\/openmrs\/liquibase\/updates\/liquibase-update-to-latest-\)\([^"]*\)\.x\.xml"\/>/\1'"${new_openmrs_version}"'\.x.xml"\/>/' "api/src/main/resources/liquibase-update-to-latest.xml" | ||
} | ||
|
||
function update_snapshot_tests() { | ||
change_log_java_file="api/src/main/java/org/openmrs/liquibase/ChangeLogVersions.java" | ||
|
||
# Use grep to check if the version already exists in the lists | ||
if ! grep -q "${openmrs_version}" "$change_log_java_file"; then | ||
# Add the new version to the lists in the Java class | ||
sed -i '/private static final List<String> SNAPSHOT_VERSIONS = Arrays.asList(/s/);/,\ "'"${openmrs_version}"'"\);/' "$change_log_java_file" | ||
fi | ||
|
||
if ! grep -q "${new_openmrs_version}" "$change_log_java_file"; then | ||
sed -i '/private static final List<String> UPDATE_VERSIONS = Arrays.asList(/s/);/,\ "'"${new_openmrs_version}"'"\);/' "$change_log_java_file" | ||
fi | ||
} | ||
|
||
function test_liquibase_snapshots() { | ||
cd liquibase/ | ||
. scripts/test_liquibase_snapshots.sh "${1}" "${2}" | ||
cd .. | ||
} | ||
|
||
function echo_usage() { | ||
echo "usage: . liquibase/scripts/create_liquibase_snapshots.sh <username> <password>" | ||
} | ||
|
||
project_version=$(grep -m 1 '<version>' pom.xml | sed -n 's/.*<version>\(.*\)<\/version>.*/\1/p') | ||
openmrs_version=$(echo $project_version | sed "s/\([0-9]*\.[0-9]*\)\..*/\1/") | ||
new_openmrs_version=$(echo "$openmrs_version + 0.1" | bc -l) | ||
|
||
if [ "${1}" == "" ] || [ "${2}" == "" ]; then | ||
echo_usage | ||
else | ||
echo "[INFO] generate liquibase snapshots" | ||
generate_liquibase_snapshots_and_update "${1}" "${2}" | ||
echo "[INFO] move updated snapshot files" | ||
move_updated_snapshots | ||
echo "[INFO] create new liquibase updated snapshots file" | ||
create_new_liquibase_update_file | ||
echo "[INFO] update the log files with new snapshot version" | ||
update_log_files_with_new_snapshots | ||
echo "[INFO] update the tests with new snapshot version" | ||
update_snapshot_tests | ||
echo "[INFO] generate liquibase snapshots successfully" | ||
fi | ||
|