-
Notifications
You must be signed in to change notification settings - Fork 160
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
fail the schema-update if there are existing Evidence or EvidenceVariable resource instances #3681
Comments
Implementation tips: Add a new version to FhirSchemaVersion:
In com.ibm.fhir.schema.app.Main, see the method:
Before the
The checkIfDataExistsForV0030 should only be called if the current schema is less before V0030:
There are a number of example DAO command implementations you can use as the basic for the TableHasData class. GetXXLogicalResourceNeedsMigration is a good example. The SQL statement you'll want to be executing is as simple as:
Obviously the table name ( |
Because the table name is a parameter to the DAO command class, we should check it is a valid name (secure programming). DataDefinitionUtil has a couple of methods to support this. The simplest would be:
in the constructor. |
Unit testing this particular case is a bit more involved. The schema migration tests currently don't take into account any of the migration steps we apply in the Main class. So in this instance, it is probably reasonable to not bother with "migration" at all, and simply just test the DAO:
This unit test will be in fhir-persistence-schema, which means you don't have access to the fhir-persistence-jdbc layer, so you need to create the resource record yourself using a plain insert:
The v_logical_resource_id value could probably be just 1. Theoretically it should be assigned the next val from fhir_sequence, but for this test case I don't think it matters. |
Oh, because your DAO should be generic, it doesn't matter if you test Evidence or Observation. In this case because our tests currently use Observation, just go with that. |
Unfortunately because we're not unit-testing the data migration logic contained in the Main class, this means that we won't have a unit test to check the schema version (< V0030) logic. We may have to check this with inspection and QA. |
…r EvidenceVariable resource instances Signed-off-by: Prasanna Hegde <prasanna.hegde1@ibm.com>
Signed-off-by: Prasanna Hegde <prasanna.hegde1@ibm.com>
Signed-off-by: Prasanna Hegde <prasanna.hegde1@ibm.com>
#3830) * issue #3681 - fail the schema-update if there are existing Evidence or EvidenceVariable resource instances Signed-off-by: Prasanna Hegde <prasanna.hegde1@ibm.com> * issue #3681 - fixed review comments Signed-off-by: Prasanna Hegde <prasanna.hegde1@ibm.com> * issue #3681 - fixed java doc review comments Signed-off-by: Prasanna Hegde <prasanna.hegde1@ibm.com>
the schema upgrade is split into multiple transactions, so we need to move the check to the beginning to avoid complicated rollback logic |
Signed-off-by: Prasanna Hegde <prasanna.hegde1@ibm.com>
Signed-off-by: Prasanna Hegde <prasanna.hegde1@ibm.com>
issue #3681 - moved checkIfDataExistsForV0030 method call
QA: Using a schema which contains tables for Evidence and EvidenceVariable, I manually inserted row into one of evidence_logical_resources or evidencevariable_logical_resources, for example:
Also, we need to manipulate the whole_schema_version to a prior value so that we don't bypass everything:
Running first with an evidence row, we see:
Then the same with an evidencevariable_logical_resources record:
After deleting the offending record, the schema update completes successfully:
|
Is your feature request related to a problem? Please describe.
Evidence and EvidenceVariable are the two resource types in R4B where a valid R4 instance is basically guaranteed not to parse.
That means that, after migration to our 5.0.0, certain interactions could blow up on any existing resources of this type in the db.
Describe the solution you'd like
To avoid a big surprise down-the-line, I think it would be better just to fail the schema-upgrade in cases where there is data in the Evidence_RESOURCES or EvidenceVariable_RESOURCES tables.
Describe alternatives you've considered
Provide steps to patch the old Evidence and EvidenceVariable resources instead
Acceptance Criteria
GIVEN a 4.11.1 schema with Evidence or EvidenceVariable resources
WHEN 5.0.0-SNAPSHOT schema upgrade is applied
THEN the upgrade is aborted
AND there is a useful error message near the bottom of the output
AND no other schema changes were applied
GIVEN a 4.11.1 schema with no Evidence or EvidenceVariable resources
WHEN 5.0.0-SNAPSHOT schema upgrade is applied
THEN the schema upgrade is successful
Additional context
EvidenceVariable too?
The text was updated successfully, but these errors were encountered: