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
- Run GDK locally
- Go to one of the seeded projects or groups
- Create an issue/epic/MR
- Add an image/file either to the new issue/epic/MR or in a comment
- Using
rails c
- Run
Upload.last.uploaded_by_user_id
and confirm theuploaded_by_user_id
is set - Run
Upload.last.uploaded_by_user
to confirm thebelongs_to
relationship works - Run
User.find(Upload.last.uploaded_by_user_id).uploads
to confirm thehas_many
relationship works - etc...
- Run
[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