Skip to content

Use explicit foreign key names for Ci::Build

Marius Bobin requested to merge mb-ci-builds-explicit-foreign-key-names into master

What does this MR do and why?

This change is needed for the Rails 7 upgrade: !90907 (merged)

Rails 6 uses active_record.name.foreign_key to compute the foreign key name:

        def derive_foreign_key
          if belongs_to?
            "#{name}_id"
          elsif options[:as]
            "#{options[:as]}_id"
          else
            active_record.name.foreign_key
          end
        end

but in Rails 7 it was changed to: active_record.model_name.to_s.foreign_key

        def derive_foreign_key
          if belongs_to?
            "#{name}_id"
          elsif options[:as]
            "#{options[:as]}_id"
          else
            active_record.model_name.to_s.foreign_key
          end
        end

For ci_builds we're changing model_name to Job and all foreign keys will be job_id unless explicitly set.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Marius Bobin

Merge request reports