Skip to content

Add and set uploaded_by_user_id on Upload records

What does this MR do and why?

Implements https://gitlab.com/gitlab-org/gitlab/-/issues/469183

Adds a new uploaded_by_user_id column to uploads and sets it to the ID of the current user when uploading a file via a controller using the UploadActions concern.

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

N/A

How to set up and validate locally

  1. Run GDK locally
  2. Go to one of the seeded projects or groups
  3. Create an issue/epic/MR
  4. Add an image/file either to the new issue/epic/MR or in a comment
  5. Using rails c
    1. Run Upload.last.uploaded_by_user_id and confirm the uploaded_by_user_id is set
    2. Run Upload.last.uploaded_by_user to confirm the belongs_to relationship works
    3. Run User.find(Upload.last.uploaded_by_user_id).uploads to confirm the has_many relationship works
    4. etc...
[1] pry(main)> Upload.last.uploaded_by_user_id
  Upload Load (0.5ms)  SELECT "uploads".* FROM "uploads" ORDER BY "uploads"."id" DESC LIMIT 1
=> 1
[2] pry(main)> Upload.last.uploaded_by_user.username
  Upload Load (0.4ms)  SELECT "uploads".* FROM "uploads" ORDER BY "uploads"."id" DESC LIMIT 1
  User Load (1.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
=> "root"
[3] pry(main)> User.find(1).uploads.first.id
  User Load (0.8ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  Upload Load (0.3ms)  SELECT "uploads".* FROM "uploads" WHERE "uploads"."uploaded_by_user_id" = 1 ORDER BY "uploads"."id" ASC LIMIT 1
=> 64

Merge request reports