-
Notifications
You must be signed in to change notification settings - Fork 490
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
Prevent no impact updates from creating version - sql #2519
Merged
apurvabhaleMS
merged 16 commits into
main
from
personal/apurvabhale/prevent-no-impact-updates-from-creating-version-sql
Apr 7, 2022
Merged
Prevent no impact updates from creating version - sql #2519
apurvabhaleMS
merged 16 commits into
main
from
personal/apurvabhale/prevent-no-impact-updates-from-creating-version-sql
Apr 7, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…prevent-no-impact-updates-from-creating-version-sql # Conflicts: # test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/UpdateTests.cs # test/Microsoft.Health.Fhir.Shared.Tests.Integration/Persistence/FhirStorageTests.cs
src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Sprocs/UpsertResource_7.sql
Show resolved
Hide resolved
src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Sprocs/UpsertResource_7.sql
Outdated
Show resolved
Hide resolved
src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Sprocs/UpsertResource_7.sql
Outdated
Show resolved
Hide resolved
…prevent-no-impact-updates-from-creating-version-sql
src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Sprocs/UpsertResource_7.sql
Outdated
Show resolved
Hide resolved
SergeyGaluzo
previously approved these changes
Mar 26, 2022
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.
feordin
previously approved these changes
Mar 30, 2022
…prevent-no-impact-updates-from-creating-version-sql
…prevent-no-impact-updates-from-creating-version-sql # Conflicts: # src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Migrations/29.diff.sql # src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Migrations/29.sql # src/Microsoft.Health.Fhir.SqlServer/Features/Schema/SchemaVersionConstants.cs
…ating-version-sql' of https://github.com/microsoft/fhir-server into personal/apurvabhale/prevent-no-impact-updates-from-creating-version-sql # Conflicts: # src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Migrations/29.diff.sql # src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Migrations/29.sql
83b8a21
…prevent-no-impact-updates-from-creating-version-sql
…prevent-no-impact-updates-from-creating-version-sql # Conflicts: # src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
…rverFhirDataStore
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
LTA-Thinking
approved these changes
Apr 7, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Area-SQL
Area related to the SQL Server data provider
Azure API for FHIR
Label denotes that the issue or PR is relevant to the Azure API for FHIR
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
If a user updates a record that already exists and nothing has changed in the content, then the user should get a 200 but nothing should update the record. Updated UpsertAsync method to add validations in the code instead of in UpsertResource SP and check the existing resource rawData with new resource rawData by ignoring meta.versionId and meta.lastUpdated. If its an absolute match then we simply return Ok with existing resource information without updating VersionId and lastUpdated. If the strings do not match then we proceed with further steps of creating a new version.
Current login -
Inside a transaction in SP
Updated logic -
In code -
Loop to continue below transaction when the resource is updated by the time we reach the SP
Read the latest resource info
Validate
Parse, Replace, and Compare resource content with old and new data
If match return OK with existing resource
If do not match then calls SP with compared version
In SP transaction
Notes -
IsMetaSet
Can this be possible ?
"meta": {
"lastUpdated": "2022-03-23T00:03:05.378+00:00",
"versionId": "1"
} => "meta" : {,}
"meta":{"lastUpdated":"2022-03-23T00:03:05.378+00:00"} => "meta" : {}
Above comparison will fail, but this should not happen. Generally we set lastUpdated and versionId both in a meta depending on the flag keepMeta which is set by canUpdateCreate (UpdateCreate from capability statement)
- True = all good
- False = Shouldn't be set to false and not toggled**
We are forming versionId and lastUpdated strings to use String.Replace on raw resource data. Forming lastUpdated with a valid date format is little tricky. We set the value of lastUpdated by using ToString("o") which formats the datetimeoffset to Formats to 2022-03-09T01:40:52.0690000+02:00. String serializer converts this to 2022-03-09T01:40:52.069+02:00 and saves it.
In C#, millisecond value can range from [0 to 999]. Below are some useful examples of how date is stored in rawResource data in DB.
0000000+ -> +, 0010000+ -> 001+, 0100000+ -> 01+, 0180000+ -> 018+, 1000000 -> 1+, 1100000+ -> 11+, 1010000+ -> 101+
Related issues
Addresses 89485
Testing
Manual testing
Updated existing tests
Additional tests to cover duplicate data do not creates a new version
If metadata has other properties which were changed during the update then new version should be created
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)