Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ManojLL
Copy link
Contributor

@ManojLL ManojLL commented Nov 30, 2023

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 and
    added 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

@ManojLL
Copy link
Contributor Author

ManojLL commented Nov 30, 2023

@dkayiwa @ibacher could you please review this work?

@dkayiwa
Copy link
Member

dkayiwa commented Dec 1, 2023

@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.

@dkayiwa
Copy link
Member

dkayiwa commented Dec 1, 2023

Are you able to run this on our bamboo CI server?

@ManojLL
Copy link
Contributor Author

ManojLL commented Dec 2, 2023

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.

@ManojLL ManojLL marked this pull request as draft December 2, 2023 05:30
@dkayiwa
Copy link
Member

dkayiwa commented Dec 2, 2023

How will you know that it works if you have not tested it out?

@ManojLL
Copy link
Contributor Author

ManojLL commented Dec 7, 2023

@dkayiwa here are the steps to generate liquilbase snapshot automatically

  1. set ENV variable called OPENMRS_INSTALLATION_SCRIPT
    export OPENMRS_INSTALLATION_SCRIPT=<path to openmrs-core folder>/liquibase/scripts/installation.properties
  2. run the script, username and passowrd refer to a MySQL user:
    cd <path to openmrs-core folder>
    . liquibase/scripts/generate_liquibase_snapshots.sh <username> <password>

@dkayiwa
Copy link
Member

dkayiwa commented Dec 7, 2023

Don't i need to set some sort of permissions to make the script an executable?
Can we also avoid running the tests?

# Change directory to the 'webapp' folder
cd webapp

# Remove the ~/.OpenMRS directory
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@dkayiwa dkayiwa Dec 7, 2023

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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

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>.

Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

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 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. 😊

Copy link
Contributor Author

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.

@ManojLL
Copy link
Contributor Author

ManojLL commented Dec 7, 2023

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.

@dkayiwa
Copy link
Member

dkayiwa commented Dec 7, 2023

So can you make the necessary changes?

@ManojLL
Copy link
Contributor Author

ManojLL commented Dec 8, 2023

So can you make the necessary changes?

Update the script to generate snapshot without dropping the existing database.

@dkayiwa
Copy link
Member

dkayiwa commented Dec 8, 2023

@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/")
Copy link
Member

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

Copy link
Contributor Author

@ManojLL ManojLL Dec 8, 2023

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"
Copy link
Member

@dkayiwa dkayiwa Dec 8, 2023

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?

Copy link
Contributor Author

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

@ManojLL ManojLL marked this pull request as ready for review December 8, 2023 14:57
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"
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.?

Copy link
Contributor Author

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"
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

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>
Copy link
Member

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?

Copy link
Contributor Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants