diff options
author | Stan Hu <stanhu@gmail.com> | 2017-09-14 18:34:59 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-09-14 18:34:59 +0000 |
commit | 06b1e8ec9a0459f541c23027856df27e25940c01 (patch) | |
tree | 66a9cb5ee7f50fded51528af658a399322b93aa1 | |
parent | 66773772ed89de2808d8f452765f9497070d5e25 (diff) | |
parent | 9230caa907156354d6b9889eee1c4e30a4737471 (diff) | |
download | gitlab-ce-06b1e8ec9a0459f541c23027856df27e25940c01.tar.gz |
Merge branch 'ci-environment-status-performance' into 'master'
Constrain environment deployments to project IDs
Closes #36877
See merge request gitlab-org/gitlab-ce!14252
-rw-r--r-- | app/models/environment.rb | 5 | ||||
-rw-r--r-- | changelogs/unreleased/ci-environment-status-performance.yml | 5 | ||||
-rw-r--r-- | changelogs/unreleased/disallow-null-values-for-environments-project-id.yml | 5 | ||||
-rw-r--r-- | db/migrate/20170913131410_environments_project_id_not_null.rb | 16 | ||||
-rw-r--r-- | db/schema.rb | 4 |
5 files changed, 32 insertions, 3 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb index 9b05f8b1cd5..44e39e21442 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -6,7 +6,10 @@ class Environment < ActiveRecord::Base belongs_to :project, required: true, validate: true - has_many :deployments, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent + has_many :deployments, + -> (env) { where(project_id: env.project_id) }, + dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent + has_one :last_deployment, -> { order('deployments.id DESC') }, class_name: 'Deployment' before_validation :nullify_external_url diff --git a/changelogs/unreleased/ci-environment-status-performance.yml b/changelogs/unreleased/ci-environment-status-performance.yml new file mode 100644 index 00000000000..8812733b5a7 --- /dev/null +++ b/changelogs/unreleased/ci-environment-status-performance.yml @@ -0,0 +1,5 @@ +--- +title: Constrain environment deployments to project IDs +merge_request: +author: +type: other diff --git a/changelogs/unreleased/disallow-null-values-for-environments-project-id.yml b/changelogs/unreleased/disallow-null-values-for-environments-project-id.yml new file mode 100644 index 00000000000..f4a956e6724 --- /dev/null +++ b/changelogs/unreleased/disallow-null-values-for-environments-project-id.yml @@ -0,0 +1,5 @@ +--- +title: "Disallow NULL values for environments.project_id" +merge_request: +author: +type: other diff --git a/db/migrate/20170913131410_environments_project_id_not_null.rb b/db/migrate/20170913131410_environments_project_id_not_null.rb new file mode 100644 index 00000000000..d5404f8ede9 --- /dev/null +++ b/db/migrate/20170913131410_environments_project_id_not_null.rb @@ -0,0 +1,16 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class EnvironmentsProjectIdNotNull < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + change_column_null :environments, :project_id, false + end + + def down + change_column_null :environments, :project_id, true + end +end diff --git a/db/schema.rb b/db/schema.rb index 2149f5ad23d..dd0ef04788b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170905112933) do +ActiveRecord::Schema.define(version: 20170913131410) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -520,7 +520,7 @@ ActiveRecord::Schema.define(version: 20170905112933) do add_index "emails", ["user_id"], name: "index_emails_on_user_id", using: :btree create_table "environments", force: :cascade do |t| - t.integer "project_id" + t.integer "project_id", null: false t.string "name", null: false t.datetime "created_at" t.datetime "updated_at" |