Exclude package-less nuget symbols from queries & unique index
What does this MR do and why?
-
Update the unique index on
packages_nuget_symbols
'ssignature
&file_path
columns to exclude the rows whosepackage_id
is null. When a row has itspackage_id
as null, it means that the parent package got deleted, and this row will be picked up by the cleanup worker and then destroyed too.Accordingly, we want to exclude those orphan rows from the unique index, so that users can create new records even if the orphan duplicate ones are still existent in the table.
-
Update the
.find_by_signature_and_file_and_checksum
method to also exclude the orphan (package_id
= nil) rows from the finder query. -
Add tests for the changes.
References
Please include cross links to any resources that are relevant to this MR This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
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
In rails console:
# stub file upload
def fixture_file_upload(*args, **kwargs)
Rack::Test::UploadedFile.new(*args, **kwargs)
end
# create an orphan symbol
orphan_symbol = FactoryBot.create(:nuget_symbol, :orphan)
# creating another non-orohan symbol should succeed. On master, this will fail because the uniqne index doesn't take into account the orphan rows
symbol = FactoryBot.create(:nuget_symbol, signature: orphan_symbol.signature, file_path: orphan_symbol.file_path)
Related to #503682 (closed)