Bhima is a free, open source accounting and hospital information management system (HIMS) tailored for rural hospitals in Africa. We are an international team based in the Democratic Republic of the Congo.
This page provides notes on how upgrades to BHIMA work. Note that these steps are quite manual, and we would like to automate them in the future.
BHIMA uses git tags to tag changes on the master branch and Github Releases to cut releases. The latest version is always the latest tag/release on git and Github respectively. The latest release is always available from the link https://github.com/Third-Culture-Software/bhima/releases/latest
.
While git effectively manages changes with code, some changes require changes to underlying production data - for example, adding a column to a database table, reassigning foreign keys, etc. These changes are kept in the server/models/migrations/
directory in the BHIMA repository. Within this directory are a series of folders, named in the form v.old.release-v.new.release
. They contain a single SQL file (generally called migrate.sql
) that is needed to upgrade from v.old.release
to v.new.release
. For example, the file v1.12.1-v1.13.0/migrate.sql
would migrate the database from version 1.12.1
to version 1.13.0
.
New changes (e.g. unreleased changes) are kept in server/models/migrations/next/
folder. In preparation for a new release, these changes are combined and renamed into the format v.old-release-v.new-release
described above.
Note: not all releases require changes to data structures. Therefore, not all version changes will have an associated migrate.sql
file.
When upgrading from an old version to a new version, it is important to run all migrate.sql
files in order from the oldest to the newest. Unfortunately, once in a these files fail on a production database where changes were made without checking into the source code the data structure. Please let us know if you find that.
Changes to stored procedures, triggers, and functions are not tracked in migration scripts. This is because they are due to frequent change and are already stored in the server/models
directory. Therefore, it is sufficient to simply rebuild them from source.
To help with this operation, BHIMA provides a migration helper script that can be invoked with npm run migrate
. This script does several things:
migration-$DATABASE.sql
filewhere $DATABASE
is the name of the production database. Now that the data is written out, it is can be run on the production database with the command mysql $DATABASE < migration-$DATABASE.sql
. As with all operations on production databases, always take a backup snapshot first.
As mentioned above, releases are managed on Github. There are two ways to obtain the latest release - either by downloading a zipped directory from Github or using git to pull the latest changes and check out the latest tag. If you have deployed from Digital Ocean, the deployment was made via zip download and you must use that method. Most development deployments are made with git and simply checking out the latest version is sufficient.
The basic steps to upgrade now are:
npm install
to upgrade dependencies.NODE_ENV=production npm run build
to compile the latest client-side codenpm run migrate
to create the migration script.mysql $DATABASE < migration-$DATABASE.sql
as described above.This should complete the steps to upgrading an existing BHIMA installation.