Add user to testrun

* We want to identify a user that has triggered a testrun. Previously (in regular operation), only submission author who were regular users were able to start a testrun. Now, we want to prepare a future where submission authors are programming groups. Still, a testrun is triggered by an individual user and not a group.
* Further, this commit fixes some missing foreign key constrains.
This commit is contained in:
Sebastian Serth
2023-08-20 17:59:24 +02:00
committed by Sebastian Serth
parent e3603758ef
commit be4f2b790d
12 changed files with 61 additions and 15 deletions

View File

@ -0,0 +1,8 @@
# frozen_string_literal: true
class RequireContributorOnSubmission < ActiveRecord::Migration[7.0]
def change
change_column_null :submissions, :contributor_id, false
change_column_null :submissions, :contributor_type, false
end
end

View File

@ -0,0 +1,8 @@
# frozen_string_literal: true
class RequireSubmissionOnTestrun < ActiveRecord::Migration[7.0]
def change
change_column_null :testruns, :submission_id, false
add_foreign_key :testruns, :submissions
end
end

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
class AddUserToTestrun < ActiveRecord::Migration[7.0]
def change
add_reference :testruns, :user, polymorphic: true, index: true
up_only do
# Since we do not have programming groups, we can assume that the user who triggered a testrun is the same as the author of the corresponding submission.
# For programming groups, this assumption is not valid (the author of a submission would the group, whereas an individual user would trigger the testrun).
execute <<~SQL.squish
UPDATE testruns
SET user_id = submissions.contributor_id,
user_type = submissions.contributor_type
FROM submissions
WHERE submissions.id = testruns.submission_id;
SQL
end
change_column_null :testruns, :user_id, false
change_column_null :testruns, :user_type, false
end
end