-
Notifications
You must be signed in to change notification settings - Fork 2
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
Chore/1876 rebase pending revisions #1882
Merged
+1,615
−28
Merged
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
52baf12
chore: add jsonb minus
mikevespi 39b47cd
chore: rework setup for commit_form_change_internal
mikevespi 921f579
chore: pass correct arguments to commit form change internal
mikevespi 983ad50
chore: rebase changes made in pending form change on top of the commi…
mikevespi 34c77b9
chore: handle the merging of form changes when another project revisi…
mikevespi 9e5ee2f
test: initial tests for concurrent revisions merging
mikevespi 52e2301
test: test the updates of the simple forms in commit_form_change_inte…
mikevespi 6a1bcad
chore: fix revert sqitch function
mikevespi 371807f
chore: fix signature in rever
mikevespi ac8c74d
chore: explicitly drop the old function signature
mikevespi e83dfee
test: add create and mutual update tests
mikevespi 29afc50
chore: explicitly drop other function signature in revert file
mikevespi d4d974e
chore: fix db deploy
mikevespi d8f52b0
chore: switch test check from form change to project table, fc tested…
mikevespi bbddafc
test: explicit argument list in function should exist test
mikevespi e461f80
test: typecast values in test resturn
mikevespi 1723f74
chore: fix quotes in pg test
mikevespi c51a4c3
chore: handle the new commit_form_change_internal args in commit_form…
mikevespi 1b0669b
test: test the case when the commiting fc has made changes but the pe…
mikevespi 8527c05
test: test that attachments are handled correctly when concurrent rev…
mikevespi c23fe07
chore: set the previous_form_change_id on pending form changes
mikevespi a16a838
test: check previous_form_change_id and form_data_record_id on create…
mikevespi 5739bdf
test: add separate test for checking create on contacts
mikevespi df054fb
chore: handle the various cases for creating form changes in concurre…
mikevespi f26b393
chore: remove unnecessary comment
mikevespi d7f47ed
test: cleanup assertions and add testing for creating a funding agree…
mikevespi 8ecb312
chore: cast incremented indices in form data back to jsonb
mikevespi 34cada4
test: prep for the restof the create tests
mikevespi 6ad612d
test: add contacts to use as managers
mikevespi e1152b0
docs: add start of concurrent revision handling documentation
mikevespi d99a18e
docs: update concurrent revision doc
mikevespi 68b0b93
chore: address PR comments
mikevespi ee1108e
chore: set the operation of pending form changes to update when commi…
mikevespi 15e9846
test: add tests for adding project_managers with pending revision
mikevespi fd25539
test: tests for adding reporting requirements in both committing and …
mikevespi 90550cf
chore: fix update previous_form_change_id scope in commit_form_change…
mikevespi ef243d8
chore: remove redundant limit 1
mikevespi f9d8947
chore: added comments for clarity
mikevespi bf476bf
chore: updated function comment to be more accurate
mikevespi c728566
test: update the milestone concurrent revision tests
mikevespi bb2240f
test: move concurrent revision tests to a separate file and add conta…
mikevespi 3a96df5
test: add directory of tests related to concurrent revisions and upda…
mikevespi c69066b
chore: when committing archives something that pending has updated ch…
mikevespi 0a7101d
chore: remove test file that whose tests have been distributed to mor…
mikevespi 85ce6b4
chore: clean out unrelated items from test
mikevespi 5c1c620
chore: cleanup commit_form_change_internal
mikevespi 3a592c8
chore: fix contact index clashes from happening when both committing …
mikevespi 94b1142
test: fix contact scenarios in concurrent revision test
mikevespi 59d154d
test: add emission_intensity and funding_parameter tests
mikevespi f15e533
test: confirm form_data_record_ids are being set in concurrent create…
mikevespi 1a2ac24
test: add tests for concurrent revisions that discard form changes
mikevespi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Handling of Concurrent Revisions | ||
|
||
The purpose of this document is to outline how we allow concurrent revisions to be made to a proeject. | ||
|
||
## Introduction | ||
|
||
By "concurrent revisions" we are referring to the ability for two discrete sets of changes to a project to exist at the same time. In CIF, we limit the number of concurrent revisions on any given project to be two: one "Amendment", and one "General Revision". While this was never intended to be a functionality of CIF, a new user flow was introduced that required it. As such, the approach taken is more of an adaptaion of the existing CIF architecture (which is described in `docs/dbRecordsHistory.md`) than an architecture designed to handle concurrency. The result is that any divergence from the original architecture pre-concureency also appears in the concurrent behaviour. For example, project contacts are handled using a different pattern than the project form in the original architecture, therfore they behave differently from the genral pattern in the concurrent approach as well. | ||
|
||
### Terminology | ||
|
||
There are three terms we need to use to identify the three `form_change` records in question: "committing", "pending", and "original parent". I'll use the more common scenario to outline the terminology used throughout this document. | ||
An Amendment is opened on a project, and left open while it is being negotiated. While it is open, a General Revision is opened on that same project, a small change is made, and the revision is committed. The point in time of the General Revision being committed is where the terminology gets its roots. In this example, the General Revision is **committing**, the still-open amendment is **pending**, and the parent revision of the Amendment is the **original parent**. | ||
|
||
## Approach | ||
|
||
A solution that would allow us to handle concurrency without user input on conflict resolution was needed. To achieve this, the approach taken is comparable to a git rebase. When committing and pending are in conflict, the changes made in pending are applied on top of the committing form change, as if the committing `form_change` were the original parent of the pending `form_change`. While users commit on a `project_revision` level, the change propogates down to the `form_change` level, so when we're talking about this here it is at the `form_change` granularity, and the heart it takes place in the function `cif.commit_form_change_internal`. | ||
|
||
One of the ways our various forms can be categorized would be: | ||
|
||
- forms a project can have at most one of (`funding_parameter_EP`, `funding_parameter_IA`, `emission_intensity`, `project_summary_report`) | ||
- 'project_contact' are either primary or secondary, and have a `contactIndex` | ||
- 'project_manager' are categorized by `projectManagerLabelId` | ||
- 'reporting_requirement' have a `reportingRequirementIndex` based on the `json_schema_name` | ||
|
||
Form changes can have an operation of `create`, `update`, or `archive`, each of which need to be handled for all of the above categories. This results in several unique cases, which have been explained case-by-case using in-line in the `commit_form_change_internal` where they have more context. | ||
|
||
After each of the following cases, the `previous_form_change_id` of the pending `form_change` is set to be the id of the committing `form_change`, which leaves every form change with a `previous_form_change_id` of the **last commit** corresponding `form_change`, while preserving the option of a full history by maintaining accurate `created_at`, `updated_at`, and `archived_at` values for all `form_change`. | ||
|
||
### Create (the general approach) | ||
|
||
If the committing project revision creates a form change that does not exist in the pending revision, for example adding a milestone, then the form needs to be created in the pending revision. In cases such as contacts which have a `contactIndex` associated with them, the index needs to be determined by the existing indices in the pending revision. This will allow the indices to stay sequential if other items were added or removed in the pending revision. | ||
|
||
### Update | ||
|
||
1. If the committing form change contains the same data as the pending's original parent, then no change to the pending data is needed. | ||
2. If the committing and pending form changes both have changes from the pending form change's parent, then set the pending form change's new_form_data to be the committing form change's, plus the changes made in the penging form change. The result is what would the data would have been if the pending form change had the committing as it's parent, similar to a git rebase. | ||
3. If the pending form change hasn't made any changes since its creation, but the committing form change has, set the pending form change's new_form_data to be the committing form change's, as it is the latest information. | ||
|
||
### Archive (the general approach) | ||
|
||
If the committing `form_change` is being archived, the pending form change can simply be deleted as it never would have been created in the first place had the committing project revision been the original parent of the pending revision. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-- Deploy cif:functions/jsonb_minus to pg | ||
|
||
begin; | ||
-- A note on the functionality: | ||
-- If a key is present in the subtrahend but not the minuend, it will not appear in the result set. | ||
-- {"a": 1, "b": 3} - {"a": 1, "b": 2, "c": 3} = {"b": 3} | ||
-- If however a key is present in the minuend but not the subtrahend, it will appear in the result set with its value. | ||
-- {"a": 1, "b": 3, "c": 3} - {"a": 1, "b": 2} = {"b": 3, "c": 3} | ||
|
||
-- This behaviour fits our needs at the time of writing this, so the additional complexity of handling the other cases is not needed. | ||
|
||
|
||
create or replace function cif.jsonb_minus(minuend jsonb, subtrahend jsonb) | ||
returns jsonb as | ||
$$ | ||
declare | ||
difference jsonb; | ||
begin | ||
select jsonb_object_agg(key, value) into strict difference | ||
from ( | ||
select * from jsonb_each($1) | ||
except select * from jsonb_each($2) | ||
) as temp; | ||
|
||
return difference; | ||
end | ||
$$ language plpgsql volatile; | ||
|
||
comment on function cif.pending_new_form_change_for_table(text) is | ||
'returns list of key-value pairs present in the first argument but not the second argument'; | ||
commit; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- Deploy cif:mutations/commit_form_change to pg | ||
-- requires: tables/form_change | ||
|
||
begin; | ||
|
||
create or replace function cif.commit_form_change(row_id int, form_change_patch cif.form_change) | ||
returns cif.form_change as $$ | ||
begin | ||
|
||
update cif.form_change set | ||
new_form_data = coalesce(form_change_patch.new_form_data, new_form_data), | ||
validation_errors = coalesce(form_change_patch.validation_errors, validation_errors) | ||
where id=row_id; | ||
|
||
return (select cif_private.commit_form_change_internal((select row(form_change.*)::cif.form_change from cif.form_change where id = row_id))); | ||
end; | ||
$$ language plpgsql volatile; | ||
|
||
grant execute on function cif.commit_form_change to cif_internal, cif_external, cif_admin; | ||
|
||
comment on function cif.commit_form_change is 'Custom mutation to commit a form_change record via the API. Only used for records that are independent of a project such as the lists of contacts and operators.'; | ||
|
||
commit; |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
It would be fun for this one (but just fun, not that we have to do it here) to declare the
-
operator for the jsonb type with this functionhttps://www.postgresql.org/docs/current/sql-createoperator.html
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.
It would! This is cool I didn't know that you could add them like this