-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TRUNK-6058 : Create CI Process to create liquibase snapshots #4474
base: master
Are you sure you want to change the base?
Conversation
@ManojLL as per this https://wiki.openmrs.org/display/docs/Pull+Request+Tips you need to transition the JIRA ticket state to indicate that you are waiting for review. |
Are you able to run this on our bamboo CI server? |
This has not integrate with CI process yet, I just need to review my work and then we can run this in CI process. |
How will you know that it works if you have not tested it out? |
@dkayiwa here are the steps to generate liquilbase snapshot automatically
|
Don't i need to set some sort of permissions to make the script an executable? |
# Change directory to the 'webapp' folder | ||
cd webapp | ||
|
||
# Remove the ~/.OpenMRS directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really want to remove the .OpenMRS folder and i lose my existing OpenMRS installation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I was thinking about,
I just trying to automate the snapshot generating steps mentioned here. However, we can not drop existing can't delete our current production-level database and application while doing this. so alter this scrip to generate the snapshots without dropping current database and existing application data and this worked successfully and generate liquibase snapshots without any issue.
I'm not quite sure about the generated snapshots are the same when using these two methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your script wipes out all the existing data that existing openmrs instances store in the application data directory. Can you avoid that?
install_method=auto | ||
connection.url=jdbc:mysql:https://localhost:3306/@DBNAME@?autoReconnect=true&sessionVariables=default_storage_engine=InnoDB&useUnicode=true&characterEncoding=UTF-8 | ||
connection.driver_class=com.mysql.cj.jdbc.Driver | ||
connection.username=root |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the instructions you gave, i do not see how the username and password is passed over.
No wonder i got Access denied for user 'root'@'localhost' (using password: YES)
when i tried to run this in spite of the fact that i supplied a correct username and password.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized I missed mentioning a couple of instructions earlier, my bad!
I alter the script, so if this works fine we do not meed to run the installation process again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized I missed mentioning a couple of instructions earlier, my bad!
So where are you putting the instructions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ManojLL did you see the above question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is where I put the instructions for run the script. what I forgot to mention is chmod +x <path to script>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not keep instructions in a github comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you address the above comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkayiwa Do I need to update liquibase read me file with the instructions ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkayiwa I added the instructions to the Readme.md
file.
Can we also avoid running the tests? yes we can , when make a release we run the tests so I think we do not need to run the test again in the script. |
So can you make the necessary changes? |
Update the script to generate snapshot without dropping the existing database. |
@ManojLL is this still Draft? |
} | ||
|
||
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/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why for some you are using capital letters and then others lower case? openMRS_version
vs new_openmrs_version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason to name like this, I will correct the variable names
|
||
# Update the version in openmrs_version.txt only if it's a new version | ||
if [ "${openMRS_version}" != "${new_openmrs_version}" ]; then | ||
sed -i "s/\(openmrs_version.txt=\).*/\1${new_openmrs_version}.0-SNAPSHOT/" "liquibase/scripts/fix_liquibase_snapshots.sh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you really test the line above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not required now, missed to remove this line from the script when ,I will remove these lines
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we explicitly using 2.1.x here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to the steps mentioned here, we are copying the liquibase-updates template and rename it to current version. That template file contains change set as below (this include a comment),
<changeSet id="42ddb873-f064-4418-a6c0-6c09426c4832" author="wschlegel"> <comment>Empty change set for integration tests.</comment> </changeSet>
So when adding a new change-set we need to increase the CHANGE_SET_COUNT_FOR_GREATER_THAN_2_1_X
value by one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the current version is not 2.1.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when adding new changeset
in a new version which is greater than 2.1, we should increase this CHANGE_SET_COUNT_FOR_GREATER_THAN_2_1_X
value by the number of newly added changesets.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using 1.9.x here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the liquibase snapshot update version is above 1.9.x , we add that names in this file. This also mentioned in here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the documentation that you referenced above, isn't 1.9.x just an example. Where the actual value depends on the current version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file called liquibase-update-to-latest-from-1.9.x.xml is used for integration tests. When we make a new snapshot, we create a file for the next snapshot version using the format liquibase-update-.x.xml. After creating this new file, we need to add its path to the liquibase-update-to-latest-from-1.9.x.xml file.
#### step 2 - run the script `openmrs/liquibase/scripts/generate_liquilbase_snapshots.sh`: | ||
Run the following commands to generate the Liquibase snapshots automatically, where username and password refer to a MySQL user: | ||
|
||
. liquibase/scripts/generate_liquibase_snapshots.sh <username> <password> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After running this script, can you list the files which will get created and their output locations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkayiwa I updated the read.me file by adding the details of created and updated files, along with their output locations.
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 TRUNK-6058 : remove unwanted line TRUNK-6058 : update script TRUNK-6058 : update script TRUNK-6058 : update script TRUNK-6058 : update script TRUNK-6058 : change project version TRUNK-6058 : change project version TRUNK-6058: fixed the new version issue when generating liquibase snapshots TRUNK-6058: fixed the new version issue when generating liquibase snapshots TRUNK-6058: added instructions to run the script TRUNK-6058: update the Read.me file
Description of what I changed
I write a script to automate the liquibase snapshot generating process
Issue I worked on
see https://issues.openmrs.org/browse/TRUNK-6058
Checklist: I completed these to help reviewers :)
My IDE is configured to follow the code style of this project.
No? Unsure? -> configure your IDE, format the code and add the changes with
git add . && git commit --amend
I have added tests to cover my changes. (If you refactored
existing code that was well tested you do not have to add tests)
No? -> write tests and add them to this commit
git add . && git commit --amend
I ran
mvn clean package
right before creating this pull request andadded all formatting changes to my commit.
No? -> execute above command
All new and existing tests passed.
No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.
My pull request is based on the latest changes of the master branch.
No? Unsure? -> execute command
git pull --rebase upstream master