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

Couch to SQL forms & cases: add system for encoding diffs in patch forms #27327

Merged
merged 5 commits into from
Apr 30, 2020

Conversation

millerdev
Copy link
Contributor

@millerdev millerdev commented Apr 30, 2020

This is a powerful new feature that allows us to automatically "patch" a SQL case to a state that as closely as possible resembles the state of the Couch case. All patched diffs are encoded in the patch form for future reference (at least until the form is removed). Patch forms can be archived to effectively to revert the patch.

Review by commit 🐡

Diffs that cannot be patched are now preserved in patch forms, allowing migrations with these diffs to be safely committed without losing information. It may be necessary in the future to build tools to extract the diff data from patch forms if it is ever needed.
Case properties that are missing in Couch but present in SQL are often the result of a form that should have been, but for some reason was not, applied to the Couch case. Often it will be applied if the Couch case is rebuilt.
@millerdev millerdev added the product/invisible Change has no end-user visible impact label Apr 30, 2020
"""
diffs = [diff_to_json(d) for d in sorted(case.diffs, key=lambda d: d.path)]
data = {"case_id": case.case_id, "diffs": diffs}
return f"<diff>{escape(json.dumps(data))}</diff>"
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think about a slightly more expressive name for this block, like <case_migration_diff>

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'm not excited about changing it at this point because some of these forms already exist on prod, and I'd rather not have to check for two different names in places that extract diff data. The form XMLNS is http://commcarehq.org/couch-to-sql/patch-case-diff, which clearly indicates it's related to Couch-to-SQL case diffs.

@millerdev
Copy link
Contributor Author

Build failed right at the end, and the failure is unrelated to this PR.

@millerdev millerdev merged commit d8332de into master Apr 30, 2020
@millerdev millerdev deleted the dm/couch2sql-next branch April 30, 2020 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product/invisible Change has no end-user visible impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants