Commit cd0b50a2 authored by David Fernandez's avatar David Fernandez

Merge branch '321917_introduce_info_column_for_the_security_scans_table' into 'master'

Add info column into security_scans table

See merge request gitlab-org/gitlab!55983
parents 4fc571e0 b4dc6647
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "Security::Scan#info schema",
"description": "The schema validates the content of the Security::Scan#info attribute",
"additionalProperties": false,
"properties": {
"errors": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"type",
"message"
]
}
}
}
}
---
title: "Introduce `info` column for the `security_scans` table"
merge_request: 55983
author:
type: added
# frozen_string_literal: true
class AddInfoColumnIntoSecurityScansTable < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column :security_scans, :info, :jsonb, null: false, default: {}
end
end
a81f3555d0e1159569687d4967edcd2b5706cdafd5defb8dc725e295eb969861
\ No newline at end of file
......@@ -17244,7 +17244,8 @@ CREATE TABLE security_scans (
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
build_id bigint NOT NULL,
scan_type smallint NOT NULL
scan_type smallint NOT NULL,
info jsonb DEFAULT '{}'::jsonb NOT NULL
);
CREATE SEQUENCE security_scans_id_seq
......@@ -8,6 +8,7 @@ module Security
validates :build_id, presence: true
validates :scan_type, presence: true
validates :info, json_schema: { filename: 'security_scan_info', draft: 7 }
belongs_to :build, class_name: 'Ci::Build'
......
......@@ -12,6 +12,28 @@ RSpec.describe Security::Scan do
describe 'validations' do
it { is_expected.to validate_presence_of(:build_id) }
it { is_expected.to validate_presence_of(:scan_type) }
describe 'info' do
let(:scan) { build(:security_scan, info: info) }
subject { scan.errors.details[:info] }
before do
scan.validate
end
context 'when the value for info field is valid' do
let(:info) { { errors: [{ type: 'Foo', message: 'Message' }] } }
it { is_expected.to be_empty }
end
context 'when the value for info field is invalid' do
let(:info) { { errors: [{ type: 'Foo' }] } }
it { is_expected.not_to be_empty }
end
end
end
describe '#project' do
......
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