-
Notifications
You must be signed in to change notification settings - Fork 37
TAN-5720 Inconsistent custom fields ordering (Part 2) #12401
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
base: master
Are you sure you want to change the base?
TAN-5720 Inconsistent custom fields ordering (Part 2) #12401
Conversation
|
| add_index :custom_fields, :ordering, | ||
| unique: true, | ||
| where: 'resource_id IS NULL', | ||
| algorithm: :concurrently |
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.
Learn something every day. Did not know that you could have a conditional on an index
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.
Is it needed though? Does the first index not create an index on [null, 1] for example?
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.
@jamesspeake Apparently uniqueness does not apply to null values. Duplicates like [null, 1] and [null, 1] will be allowed if we would make one index. That's why a separate index is needed to deal with the registration forms.
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.
Generally looks fine, but have a question about the update_all endpoint. I just want to be sure. Happy to talk through if you want
| update_statements! field, statements_params, errors, index if statements_params | ||
| relate_map_config_to_field(field, field_params, errors, index) | ||
| field.set_list_position(index) | ||
| field.move_to_bottom |
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.
Does this work fine where new fields are added in the middle of the form? I have it in my mind that we changed update_all a while back so that it was not making updates to every field, every time. ie the next statements on line 152, 155
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.
@jamesspeake I wasn't aware of this change. Will do more testing around these cases (new field in the middle and the other field) and will likely use a different method to insert at that position. But it would have to be a different method because set_list_position will temporarily have two fields with the same ordering.
One fix to rule them all.
There was a lot of code spread around the code base that attempted to fix this bug, but the issue remained. Adding a unique constraint on the database level should fix this once and for all.
Ideally we should do this for all ordering columns we have today.
This task will be ran before releasing:
This flow was tested thoroughly on a snapshot of the Benelux cluster.
Changelog
Fixed