Commit 0adf9f76 authored by Sean Arnold's avatar Sean Arnold Committed by Matthias Käppler

Add alert metric image table and basic model

Changelog: added
parent b1072b3f
# frozen_string_literal: true
class CreateAlertManagementAlertMetricImages < Gitlab::Database::Migration[1.0]
def up
create_table :alert_management_alert_metric_images do |t|
t.references :alert, null: false, index: true, foreign_key: { to_table: :alert_management_alerts, on_delete: :cascade }
t.timestamps_with_timezone
t.integer :file_store, limit: 2
t.text :file, limit: 255, null: false
t.text :url, limit: 255
t.text :url_text, limit: 128
end
end
def down
drop_table :alert_management_alert_metric_images, if_exists: true
end
end
41b67585574f6309d8e32fe695e65fc43f15f6738db713c1a11e04558a5ec515
\ No newline at end of file
......@@ -9917,6 +9917,29 @@ CREATE SEQUENCE alert_management_alert_assignees_id_seq
ALTER SEQUENCE alert_management_alert_assignees_id_seq OWNED BY alert_management_alert_assignees.id;
CREATE TABLE alert_management_alert_metric_images (
id bigint NOT NULL,
alert_id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
file_store smallint,
file text NOT NULL,
url text,
url_text text,
CONSTRAINT check_2587666252 CHECK ((char_length(url_text) <= 128)),
CONSTRAINT check_4d811d9007 CHECK ((char_length(url) <= 255)),
CONSTRAINT check_70fafae519 CHECK ((char_length(file) <= 255))
);
CREATE SEQUENCE alert_management_alert_metric_images_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE alert_management_alert_metric_images_id_seq OWNED BY alert_management_alert_metric_images.id;
CREATE TABLE alert_management_alert_user_mentions (
id bigint NOT NULL,
alert_management_alert_id bigint NOT NULL,
......@@ -21495,6 +21518,8 @@ ALTER TABLE ONLY agent_project_authorizations ALTER COLUMN id SET DEFAULT nextva
ALTER TABLE ONLY alert_management_alert_assignees ALTER COLUMN id SET DEFAULT nextval('alert_management_alert_assignees_id_seq'::regclass);
ALTER TABLE ONLY alert_management_alert_metric_images ALTER COLUMN id SET DEFAULT nextval('alert_management_alert_metric_images_id_seq'::regclass);
ALTER TABLE ONLY alert_management_alert_user_mentions ALTER COLUMN id SET DEFAULT nextval('alert_management_alert_user_mentions_id_seq'::regclass);
ALTER TABLE ONLY alert_management_alerts ALTER COLUMN id SET DEFAULT nextval('alert_management_alerts_id_seq'::regclass);
......@@ -22865,6 +22890,9 @@ ALTER TABLE ONLY agent_project_authorizations
ALTER TABLE ONLY alert_management_alert_assignees
ADD CONSTRAINT alert_management_alert_assignees_pkey PRIMARY KEY (id);
ALTER TABLE ONLY alert_management_alert_metric_images
ADD CONSTRAINT alert_management_alert_metric_images_pkey PRIMARY KEY (id);
ALTER TABLE ONLY alert_management_alert_user_mentions
ADD CONSTRAINT alert_management_alert_user_mentions_pkey PRIMARY KEY (id);
......@@ -25402,6 +25430,8 @@ CREATE INDEX index_alert_assignees_on_alert_id ON alert_management_alert_assigne
CREATE UNIQUE INDEX index_alert_assignees_on_user_id_and_alert_id ON alert_management_alert_assignees USING btree (user_id, alert_id);
CREATE INDEX index_alert_management_alert_metric_images_on_alert_id ON alert_management_alert_metric_images USING btree (alert_id);
CREATE INDEX index_alert_management_alerts_on_domain ON alert_management_alerts USING btree (domain);
CREATE INDEX index_alert_management_alerts_on_environment_id ON alert_management_alerts USING btree (environment_id) WHERE (environment_id IS NOT NULL);
......@@ -30470,6 +30500,9 @@ ALTER TABLE ONLY container_repositories
ALTER TABLE ONLY clusters_applications_jupyter
ADD CONSTRAINT fk_rails_331f0aff78 FOREIGN KEY (oauth_application_id) REFERENCES oauth_applications(id) ON DELETE SET NULL;
ALTER TABLE ONLY alert_management_alert_metric_images
ADD CONSTRAINT fk_rails_338e55b408 FOREIGN KEY (alert_id) REFERENCES alert_management_alerts(id) ON DELETE CASCADE;
ALTER TABLE ONLY suggestions
ADD CONSTRAINT fk_rails_33b03a535c FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
# frozen_string_literal: true
module AlertManagement
class MetricImage < ApplicationRecord
self.table_name = 'alert_management_alert_metric_images'
belongs_to :alert, class_name: 'AlertManagement::Alert', foreign_key: 'alert_id', inverse_of: :metric_images
validates :file, presence: true
validates :url, length: { maximum: 255 }, public_url: { allow_blank: true }
validates :url_text, length: { maximum: 128 }
end
end
......@@ -9,6 +9,7 @@ module EE
include AfterCommitQueue
has_many :pending_escalations, class_name: 'IncidentManagement::PendingEscalations::Alert', foreign_key: :alert_id, inverse_of: :alert
has_many :metric_images, class_name: '::AlertManagement::MetricImage'
after_create do |alert|
run_after_commit { alert.trigger_auto_rollback }
......
......@@ -64,6 +64,7 @@ class License < ApplicationRecord
EEP_FEATURES = EES_FEATURES + EEP_FEATURES_WITH_USAGE_PING + %i[
adjourned_deletion_for_projects_and_groups
admin_audit_log
alert_metric_upload
auditor_user
blocking_merge_requests
board_assignee_lists
......
# frozen_string_literal: true
FactoryBot.define do
factory :alert_metric_image, class: 'AlertManagement::MetricImage' do
association :alert, factory: :alert_management_alert
url { generate(:url) }
trait :local do
file_store { ObjectStorage::Store::LOCAL }
end
after(:build) do |image|
image.file = fixture_file_upload('spec/fixtures/rails_sample.jpg', 'image/jpg')
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AlertManagement::MetricImage do
subject { build(:alert_metric_image) }
describe 'associations' do
it { is_expected.to belong_to(:alert) }
end
describe 'validations' do
it { is_expected.to be_valid }
it { is_expected.to validate_presence_of(:file) }
it { is_expected.to validate_length_of(:url).is_at_most(255) }
it { is_expected.to validate_length_of(:url_text).is_at_most(128) }
end
end
......@@ -4,6 +4,7 @@ agent_group_authorizations: :gitlab_main
agent_project_authorizations: :gitlab_main
alert_management_alert_assignees: :gitlab_main
alert_management_alerts: :gitlab_main
alert_management_alert_metric_images: :gitlab_main
alert_management_alert_user_mentions: :gitlab_main
alert_management_http_integrations: :gitlab_main
allowed_email_domains: :gitlab_main
......
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