Replace `ci_commits.environment` with `ci_commits.environment_id` (`CI::Build#environment` is a string, but should be `belongs_to :environment`)
Description
Technical debt issue split out of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7983#note_20003983
A build belongs_to
an environment, and this relationship is needed to pass CI variables defined in the environment model over to the runner. However, the build already has an environment
attribute, which is a string containing the unexpanded environment name, so standard ActiveRecord associations could not be used. Instead, I created a persisted_environment
helper method that acts a bit like a belongs_to
association - but it's hardly ideal.
Proposal
- Add an
environment_id
column toci_commits
(this can be NULL) and populate it for builds whereenvironment
is set, following the current logic ofpersisted_environment
- Rename
ci_commits.environment
tounexpanded_environment_name
(or something similar), or eliminate it completely. - Replace
persisted_environment
withbelongs_to :environment