-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fi-2084 Load resources from JSONs instead of initdb.sql #129
Conversation
Looks like I may need to add something that prevents it from loading the resources when running tests |
d9d5abb
to
4446e11
Compare
Since we are cleaning things up a bit, would it make sense to rename the transaction files, which are now UUIDs, to something more descriptive like |
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.
Now that the resources live in src
, docker has to redo the java build whenever the data changes. It would be really great if they could get added to the image after the java build so that the docker rebuilds are fast when no actual source is changing.
Also, I now see some errors that aren't present on main
when running the g10 tests with US Core 6 against this branch.
Update: migrated the files back out of |
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 think something is wrong with your local g10 setup, as this and prod both pass for me.
README.md
Outdated
@@ -21,7 +21,7 @@ Note that sometimes on the initial start up, the database initialization might c | |||
You can delete the server's data by stopping the containers with `docker-compose down` and then running `docker volume rm inferno-reference-server_fhir-pgdata` to remove the existing volume. Note that the default data will be reloaded when starting the containers. | |||
|
|||
|
|||
The database will be initially populated by the default initdb.sql script. To update the default initial data with the data in the current db container, run `docker-compose exec db pg_dump -U postgres postgres > initdb.sql` | |||
The database will be initially populated with the resources in `src/main/resources/fhir_resources`. If the server contains any `Patient` resources this process will be skipped, but you can force loading the files in this folder by setting the `FORCE_LOAD_RESOURCES` environment variable to `true`. Note that if the default files are still present this will result in duplicate data being populated. |
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.
Here and below need to be updated since they're no longer in src/main/resources
.
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.
"Note that if the default files are still present this will result in duplicate data being populated." What are the "default files"?
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.
"default files" meant the original 3 files in the ./resources
folder, the 2 patient bundles and the Group. I wasn't sure how much anybody besides us actually uses and configures this server, so the instruction or even that whole "FORCE_LOAD_RESOURCES" feature may be unnecessary. I can think of other wording
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.
So that means "additional" resources can be add into "src/main/resources/fhir_resources". Is that correct?
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 that's a good point. I should be more clear about that too. How's this?
The database will be initially populated with the resources in
./resources/
the next time the server starts. This folder by default contains 3 files, but you can add additional files in the form of transaction Bundles or individual resources, or you can remove the original files to start with an empty server.
If the server contains anyPatient
resources the initial loading process will be skipped, but you can force loading the files in this folder by setting theFORCE_LOAD_RESOURCES
environment variable totrue
. Note that if the original files are re-loaded in this way, this will result in duplicate data being populated.
Tested with US Core 3.1.0, 4.0.0, 5.0.1, and 6.1.0. Test results are as expected. Wait for tx.fhir.org to be back online for US Core 7 testing. Will raise separate ticket(s) for US Core 7 issues. Approved |
Summary
This change addresses a major pain point in updating the data on the reference server by removing initdb.sql and loading resources from JSON files instead.
This change is based heavily on Gravity-SDOHCC/gravity-sdoh-ehr-server#7 and Steve's prior work in #93
New behavior
Ultimately from an end-user perspective this should have 0 impact. The changes should only be apparent to developers, when we want to add/change the data.
Instead of reading DB state from an sql file, this now reads and loads resources from JSON files. Files should only be loaded when the server is empty, but this can be overriden with an env var.
IMPORTANT: Changes to HAPI's ID settings mean that the DB must be cleared out before this is run. You can't use an existing DB with this code, otherwise you will see very strange behavior (ex
GET Patient/85
might return an error along the lines of "Resource Patient/42 is not known") If that's a concern I can look into ways to detect when the server is in that invalid state and have it fail to start with a useful error.Code changes
./us-core-resources
to./src/main/resources
which allows them to be read in the same way even if the code is run as a standalone java app or as a WAR file. The files were already transaction Bundles with PUTs for the Patient resources, so no changes were made. I added a file for the Group resource since it was missingMitreJpaServer
actually loads the resources at startup. Note theloadResources
function takes a Path, so we could theoretically allow for configuring the location to read from, but I didn't feel like that was necessary here.initdb.sql
means the docker configuration can be simplified - we no longer need a custom docker image, we can just use the postgres base image that our image was based off.Testing guidance
Patient/85
,Patient/355
, andGroup/1a
. Are there any presets anywhere that might reference other fixed IDs?docker volume rm inferno-reference-server_fhir-pgdata
), or delete any local DB you may have