This ticket involves changing the approach for persisting user versions. Currently, user_version of an attribute of a WorkVersion with a unique index on id, user_version. So, for example:
Work Version
user_version
1
2
1
3
4
2
In this case, user version 1 is work version 2 and user version 2 is work version 4.
In the new approach, every WorkVersion will have a user_version (except maybe the current draft).
Work Version
user_version
1
1
2
1
3
2
4
2
To find the Work Version for a user version, you find the highest WorkVersion with the user_version value. In this case, user version 1 is work version 2 and user version 2 is work version 4. (Though there aren't currently any features that require this.)
This means that discarding a draft doesn't require making any changes to user_version values. If WorkVersion 4 would be discarded then work version 3 would become user version 2:
Work Version
user_version
1
1
2
1
3
2
This also allows it to be determined which radio button to select when displaying the new version section:
When a draft WorkVersion is created, no radio button should be selected. While the user will have to make a choice before depositing, they can still save a draft without making a choice. No choice is represented by a null. Thus, if there is no user_version, select no radio buttons:
Work Version
user_version
1
1
2
1
3
2
4
If the user_version is the same as the last WorkVersion, then select the "No" radio:
Work Version
user_version
1
1
2
1
3
2
4
2
If the user_version is different than the last WorkVersion, then select the "Yes" radio:
Work Version
user_version
1
1
2
1
3
2
4
3
Thus, the work for this ticket includes (but may not be limited to):
Remove the unique index.
Populate user_version for existing WorkVersions. (The value is probably just 1.)
When creating a new WorkVersion, set user_version to nil, except the first WorkVersion which should be 1.
If feature flag is set, populate the version section radio button and version description field as described above.
If feature flag is set, when saving a WorkVersion, update the user_version based on the radio button. (If "yes", increment the user_version of the previous WorkVersion. If "no", use the user_version of the previous WorkVersion. If neither, set to nil.)
If the feature flag is not set, when saving a WorkVersion, set the user_version to the user_version of the previous WorkVersion.
Make sure that there are enough code comments and/or README docs to document this approach for our future selves.
This ticket involves changing the approach for persisting user versions. Currently, user_version of an attribute of a WorkVersion with a unique index on id, user_version. So, for example:
In this case, user version 1 is work version 2 and user version 2 is work version 4.
To find the Work Version for a user version, you find the highest WorkVersion with the user_version value. In this case, user version 1 is work version 2 and user version 2 is work version 4. (Though there aren't currently any features that require this.)
This means that discarding a draft doesn't require making any changes to user_version values. If WorkVersion 4 would be discarded then work version 3 would become user version 2:
This also allows it to be determined which radio button to select when displaying the new version section:![image](https://github.com/sul-dlss/happy-heron/assets/588335/7acc7992-d77a-4f67-b621-682a0ab6e9ad)
Thus, the work for this ticket includes (but may not be limited to):