Set project_id for existing orphaned packages dependencies
Context
We're preparing the packages_dependencies
for adding the sharding key project_id
.
In Set project_id when creating Packages::Dependency (!161039 - merged) we added the changes to set project_id
for new dependencies, and in Add migration to backfill project_id for packag... (!161798 - merged) to backfill project_id
for existing dependencies that have the linked packages dependency links where we can use project_id
.
Now we got the case when orphaned packages dependencies (the dependencies that don't have any linked dependency links) and should be removed with the Packages::Cleanup::DeleteOrphanedDependenciesWorker
, in the meantime becoming used by newly uploaded packages and dependency links, and thus becoming not orphaned, but without project_id
.
What does this MR do and why?
This MR changes the Packages::CreateDependencyService
service to set project_id
for existing orphaned packages dependencies, when they're re-used.
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
No.
How to set up and validate locally
-
Create orphaned dependency without
project
usingrails console
FactoryBot.create(:packages_dependency, name: 'axios', version_pattern: '^1.7.5' project: nil)
Note: note down the ID, we'll need it on the verification step.
-
Create a new npm package that uses axios@1.7.5
npm init # Now edit package's name (if needed) and add authentication to `.nmprc` [docs](https://docs.gitlab.com/ee/user/packages/npm_registry/#publishing-a-package-via-the-command-line) # Install dependency and publish a package to the registry. npm i axios@1.7.5 npm publish
-
Verify that previously orphaned dependency now has
project_id
set.Packages::Dependency.find(dependency_id)
Related to #465276 (closed)