Commit 7ed6a71e authored by Sean McGivern's avatar Sean McGivern

Merge branch '201925-update-database-columns-to-match-vulnerability-code-changes' into 'master'

Rename columns in vulnerabilities table to match new states

See merge request gitlab-org/gitlab!25609
parents 46eb6ce2 86b5340b
# frozen_string_literal: true
class RenameClosedAtToDismissedAtInVulnerabilities < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
rename_column_concurrently :vulnerabilities, :closed_at, :dismissed_at
end
def down
undo_rename_column_concurrently :vulnerabilities, :closed_at, :dismissed_at
end
end
# frozen_string_literal: true
class RenameClosedByToDismissedByInVulnerabilities < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
rename_column_concurrently :vulnerabilities, :closed_by_id, :dismissed_by_id
end
def down
undo_rename_column_concurrently :vulnerabilities, :closed_by_id, :dismissed_by_id
end
end
# frozen_string_literal: true
class CleanupClosedAtRenameInVulnerabilities < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
cleanup_concurrent_column_rename :vulnerabilities, :closed_at, :dismissed_at
end
def down
undo_cleanup_concurrent_column_rename :vulnerabilities, :closed_at, :dismissed_at
end
end
# frozen_string_literal: true
class CleanupClosedByRenameInVulnerabilities < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
cleanup_concurrent_column_rename :vulnerabilities, :closed_by_id, :dismissed_by_id
end
def down
undo_cleanup_concurrent_column_rename :vulnerabilities, :closed_by_id, :dismissed_by_id
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_02_24_163804) do ActiveRecord::Schema.define(version: 2020_02_26_162723) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm" enable_extension "pg_trgm"
...@@ -4356,8 +4356,6 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do ...@@ -4356,8 +4356,6 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do
t.text "description_html" t.text "description_html"
t.bigint "start_date_sourcing_milestone_id" t.bigint "start_date_sourcing_milestone_id"
t.bigint "due_date_sourcing_milestone_id" t.bigint "due_date_sourcing_milestone_id"
t.bigint "closed_by_id"
t.datetime_with_timezone "closed_at"
t.integer "state", limit: 2, default: 1, null: false t.integer "state", limit: 2, default: 1, null: false
t.integer "severity", limit: 2, null: false t.integer "severity", limit: 2, null: false
t.boolean "severity_overridden", default: false t.boolean "severity_overridden", default: false
...@@ -4369,9 +4367,11 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do ...@@ -4369,9 +4367,11 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do
t.integer "cached_markdown_version" t.integer "cached_markdown_version"
t.bigint "confirmed_by_id" t.bigint "confirmed_by_id"
t.datetime_with_timezone "confirmed_at" t.datetime_with_timezone "confirmed_at"
t.datetime_with_timezone "dismissed_at"
t.bigint "dismissed_by_id"
t.index ["author_id"], name: "index_vulnerabilities_on_author_id" t.index ["author_id"], name: "index_vulnerabilities_on_author_id"
t.index ["closed_by_id"], name: "index_vulnerabilities_on_closed_by_id"
t.index ["confirmed_by_id"], name: "index_vulnerabilities_on_confirmed_by_id" t.index ["confirmed_by_id"], name: "index_vulnerabilities_on_confirmed_by_id"
t.index ["dismissed_by_id"], name: "index_vulnerabilities_on_dismissed_by_id"
t.index ["due_date_sourcing_milestone_id"], name: "index_vulnerabilities_on_due_date_sourcing_milestone_id" t.index ["due_date_sourcing_milestone_id"], name: "index_vulnerabilities_on_due_date_sourcing_milestone_id"
t.index ["epic_id"], name: "index_vulnerabilities_on_epic_id" t.index ["epic_id"], name: "index_vulnerabilities_on_epic_id"
t.index ["last_edited_by_id"], name: "index_vulnerabilities_on_last_edited_by_id" t.index ["last_edited_by_id"], name: "index_vulnerabilities_on_last_edited_by_id"
...@@ -5026,8 +5026,8 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do ...@@ -5026,8 +5026,8 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do
add_foreign_key "vulnerabilities", "milestones", name: "fk_131d289c65", on_delete: :nullify add_foreign_key "vulnerabilities", "milestones", name: "fk_131d289c65", on_delete: :nullify
add_foreign_key "vulnerabilities", "projects", name: "fk_efb96ab1e2", on_delete: :cascade add_foreign_key "vulnerabilities", "projects", name: "fk_efb96ab1e2", on_delete: :cascade
add_foreign_key "vulnerabilities", "users", column: "author_id", name: "fk_b1de915a15", on_delete: :nullify add_foreign_key "vulnerabilities", "users", column: "author_id", name: "fk_b1de915a15", on_delete: :nullify
add_foreign_key "vulnerabilities", "users", column: "closed_by_id", name: "fk_cf5c60acbf", on_delete: :nullify
add_foreign_key "vulnerabilities", "users", column: "confirmed_by_id", name: "fk_959d40ad0a", on_delete: :nullify add_foreign_key "vulnerabilities", "users", column: "confirmed_by_id", name: "fk_959d40ad0a", on_delete: :nullify
add_foreign_key "vulnerabilities", "users", column: "dismissed_by_id", name: "fk_725465b774", on_delete: :nullify
add_foreign_key "vulnerabilities", "users", column: "last_edited_by_id", name: "fk_1302949740", on_delete: :nullify add_foreign_key "vulnerabilities", "users", column: "last_edited_by_id", name: "fk_1302949740", on_delete: :nullify
add_foreign_key "vulnerabilities", "users", column: "resolved_by_id", name: "fk_76bc5f5455", on_delete: :nullify add_foreign_key "vulnerabilities", "users", column: "resolved_by_id", name: "fk_76bc5f5455", on_delete: :nullify
add_foreign_key "vulnerabilities", "users", column: "updated_by_id", name: "fk_7ac31eacb9", on_delete: :nullify add_foreign_key "vulnerabilities", "users", column: "updated_by_id", name: "fk_7ac31eacb9", on_delete: :nullify
......
...@@ -20,7 +20,7 @@ class Vulnerability < ApplicationRecord ...@@ -20,7 +20,7 @@ class Vulnerability < ApplicationRecord
belongs_to :updated_by, class_name: 'User' belongs_to :updated_by, class_name: 'User'
belongs_to :last_edited_by, class_name: 'User' belongs_to :last_edited_by, class_name: 'User'
belongs_to :resolved_by, class_name: 'User' belongs_to :resolved_by, class_name: 'User'
belongs_to :closed_by, class_name: 'User' belongs_to :dismissed_by, class_name: 'User'
belongs_to :confirmed_by, class_name: 'User' belongs_to :confirmed_by, class_name: 'User'
has_many :findings, class_name: 'Vulnerabilities::Occurrence', inverse_of: :vulnerability has_many :findings, class_name: 'Vulnerabilities::Occurrence', inverse_of: :vulnerability
......
...@@ -23,7 +23,7 @@ module Vulnerabilities ...@@ -23,7 +23,7 @@ module Vulnerabilities
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
@vulnerability.update(state: Vulnerability.states[:dismissed], closed_by: @user, closed_at: Time.current) @vulnerability.update(state: Vulnerability.states[:dismissed], dismissed_by: @user, dismissed_at: Time.current)
end end
@vulnerability @vulnerability
......
---
title: Rename close_{at,by} to dismissed_{at,by} in Vulnerabilities
merge_request: 25609
author: Michał Zając
type: other
...@@ -890,7 +890,7 @@ module EE ...@@ -890,7 +890,7 @@ module EE
expose :updated_by_id expose :updated_by_id
expose :last_edited_by_id expose :last_edited_by_id
expose :resolved_by_id expose :resolved_by_id
expose :closed_by_id expose :dismissed_by_id
expose :start_date expose :start_date
expose :due_date expose :due_date
...@@ -899,7 +899,7 @@ module EE ...@@ -899,7 +899,7 @@ module EE
expose :updated_at expose :updated_at
expose :last_edited_at expose :last_edited_at
expose :resolved_at expose :resolved_at
expose :closed_at expose :dismissed_at
end end
class VulnerabilityRelatedIssue < ::API::Entities::IssueBasic class VulnerabilityRelatedIssue < ::API::Entities::IssueBasic
......
...@@ -21,7 +21,7 @@ FactoryBot.define do ...@@ -21,7 +21,7 @@ FactoryBot.define do
trait :dismissed do trait :dismissed do
state { Vulnerability.states[:dismissed] } state { Vulnerability.states[:dismissed] }
closed_at { Time.current } dismissed_at { Time.current }
end end
trait :confirmed do trait :confirmed do
......
...@@ -36,7 +36,7 @@ describe Vulnerability do ...@@ -36,7 +36,7 @@ describe Vulnerability do
it { is_expected.to belong_to(:updated_by).class_name('User') } it { is_expected.to belong_to(:updated_by).class_name('User') }
it { is_expected.to belong_to(:last_edited_by).class_name('User') } it { is_expected.to belong_to(:last_edited_by).class_name('User') }
it { is_expected.to belong_to(:resolved_by).class_name('User') } it { is_expected.to belong_to(:resolved_by).class_name('User') }
it { is_expected.to belong_to(:closed_by).class_name('User') } it { is_expected.to belong_to(:dismissed_by).class_name('User') }
it { is_expected.to belong_to(:confirmed_by).class_name('User') } it { is_expected.to belong_to(:confirmed_by).class_name('User') }
it { is_expected.to have_many(:findings).class_name('Vulnerabilities::Occurrence').dependent(false) } it { is_expected.to have_many(:findings).class_name('Vulnerabilities::Occurrence').dependent(false) }
......
...@@ -199,7 +199,7 @@ describe API::Vulnerabilities do ...@@ -199,7 +199,7 @@ describe API::Vulnerabilities do
expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee') expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee')
expect(vulnerability.reload).to( expect(vulnerability.reload).to(
have_attributes(state: 'dismissed', closed_by: user, closed_at: be_like_time(Time.current))) have_attributes(state: 'dismissed', dismissed_by: user, dismissed_at: be_like_time(Time.current)))
expect(vulnerability.findings).to all have_vulnerability_dismissal_feedback expect(vulnerability.findings).to all have_vulnerability_dismissal_feedback
end end
end end
......
...@@ -26,7 +26,7 @@ describe Vulnerabilities::DismissService do ...@@ -26,7 +26,7 @@ describe Vulnerabilities::DismissService do
dismiss_vulnerability dismiss_vulnerability
expect(vulnerability.reload).to( expect(vulnerability.reload).to(
have_attributes(state: 'dismissed', closed_by: user, closed_at: be_like_time(Time.current))) have_attributes(state: 'dismissed', dismissed_by: user, dismissed_at: be_like_time(Time.current)))
expect(vulnerability.findings).to all have_vulnerability_dismissal_feedback expect(vulnerability.findings).to all have_vulnerability_dismissal_feedback
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment