Commit 2dafb6f9 authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Create foreign key constraints in seperate migrations

To comply with the style guides at Gitlab.
parent 94d5d2bb
...@@ -8,9 +8,9 @@ class CreateSecurityFindingsTable < ActiveRecord::Migration[6.0] ...@@ -8,9 +8,9 @@ class CreateSecurityFindingsTable < ActiveRecord::Migration[6.0]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
create_table :security_findings, id: :bigserial do |t| create_table :security_findings, if_not_exists: true do |t|
t.references :scan, null: false, foreign_key: { to_table: :security_scans, on_delete: :cascade } t.references :scan, null: false
t.references :scanner, null: false, foreign_key: { to_table: :vulnerability_scanners, on_delete: :cascade } t.references :scanner, null: false
t.integer :severity, limit: 2, index: true, null: false t.integer :severity, limit: 2, index: true, null: false
t.integer :confidence, limit: 2, index: true, null: false t.integer :confidence, limit: 2, index: true, null: false
t.text :project_fingerprint, index: true, null: false t.text :project_fingerprint, index: true, null: false
......
# frozen_string_literal: true
class AddForeignKeyOnScanIdToSecurityScans < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
add_foreign_key :security_findings, :security_scans, column: :scan_id, on_delete: :cascade # rubocop:disable Migration/AddConcurrentForeignKey
end
end
def down
with_lock_retries do
remove_foreign_key :security_findings, column: :scan_id
end
end
end
# frozen_string_literal: true
class AddForeignKeyOnScannerIdToVulnerabilityScanners < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
add_foreign_key :security_findings, :vulnerability_scanners, column: :scanner_id, on_delete: :cascade # rubocop:disable Migration/AddConcurrentForeignKey
end
end
def down
with_lock_retries do
remove_foreign_key :security_findings, column: :scanner_id
end
end
end
b3ee994231a8da694dbcda227b37e19a2112be666648d918425b064ec19d239e
\ No newline at end of file
b575558752206149171a05231e4167e1ac3e1295f76d800edfe3d61c1b996b52
\ No newline at end of file
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