Add module to resolve aliases for SourceUserPlaceholderReference
requested to merge 467522-add-aliasing-for-table-of-placeholder-contribution-details-to-make-resilient-to-pg-schema into master
What does this MR do and why?
As discussed in #467522 (closed), data in Import::SourceUserPlaceholderReference
can get outdated if models or columns get renamed. So we should be able to handle that.
This MR adds a PlaceholderReferenceAliasResolver
which is in charge of keeping track of the aliases and fetching the correct model names and columns if there are changes.
Explanation of a couple decisions:
- I did not need to add tests to ensure that the model names are valid, as these are real constants now and not strings. So Ruby will complain as soon as we remove the old models
- We discussed an issue where a model is deleted and reintroduced at a future date: In this case, the old alias will still exist, so when the dev tries to add it again for the new model, Ruby will complain about a duplicate key in the hash. This will prompt them to fix the code as discussed to handle this odd case.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Run the following in a Rails console:
[3] pry(main)> Import::PlaceholderReferenceAliasResolver.aliased_model("Note")
=> Note(note: text, noteable_type: string, author_id: integer, created_at: datetime, updated_at: datetime, project_id: integer, attachment: string, line_code: string, commit_id: string, noteable_id: integer, system: boolean, st_diff: text, updated_by_id: integer, type: string, position: text, original_position: text, resolved_at: datetime, resolved_by_id: integer, discussion_id: string, note_html: text, cached_markdown_version: integer, change_position: text, resolved_by_push: boolean, review_id: integer, confidential: boolean, last_edited_at: timestamptz, internal: boolean, id: integer, namespace_id: integer, imported_from: integer)
[4] pry(main)> Import::PlaceholderReferenceAliasResolver.aliased_column("Note", "author_id")
=> "author_id"
[5] pry(main)>
Related to #467522 (closed)
Edited by Keeyan Nejad