Commit a0d4f383 authored by syasonik's avatar syasonik

Add model for tracking published issues

To support an ability to publish status page issues
at a user's discretion, we want to store whether an
issue has been published. This adds a table and model
to represent a published incident.
parent 2bf71184
---
title: Add table for tracking issues published to status page
merge_request: 29994
author:
type: added
# frozen_string_literal: true
class CreateStatusPagePublishedIncidents < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
create_table :status_page_published_incidents do |t|
t.timestamps_with_timezone null: false
t.references :issue, null: false, index: { unique: true }, foreign_key: { on_delete: :cascade }
end
end
end
def down
drop_table :status_page_published_incidents
end
end
......@@ -6098,6 +6098,22 @@ CREATE SEQUENCE public.sprints_id_seq
ALTER SEQUENCE public.sprints_id_seq OWNED BY public.sprints.id;
CREATE TABLE public.status_page_published_incidents (
id bigint NOT NULL,
issue_id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL
);
CREATE SEQUENCE public.status_page_published_incidents_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.status_page_published_incidents_id_seq OWNED BY public.status_page_published_incidents.id;
CREATE TABLE public.status_page_settings (
project_id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
......@@ -7618,6 +7634,8 @@ ALTER TABLE ONLY public.spam_logs ALTER COLUMN id SET DEFAULT nextval('public.sp
ALTER TABLE ONLY public.sprints ALTER COLUMN id SET DEFAULT nextval('public.sprints_id_seq'::regclass);
ALTER TABLE ONLY public.status_page_published_incidents ALTER COLUMN id SET DEFAULT nextval('public.status_page_published_incidents_id_seq'::regclass);
ALTER TABLE ONLY public.status_page_settings ALTER COLUMN project_id SET DEFAULT nextval('public.status_page_settings_project_id_seq'::regclass);
ALTER TABLE ONLY public.subscriptions ALTER COLUMN id SET DEFAULT nextval('public.subscriptions_id_seq'::regclass);
......@@ -8547,6 +8565,9 @@ ALTER TABLE ONLY public.spam_logs
ALTER TABLE ONLY public.sprints
ADD CONSTRAINT sprints_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.status_page_published_incidents
ADD CONSTRAINT status_page_published_incidents_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.status_page_settings
ADD CONSTRAINT status_page_settings_pkey PRIMARY KEY (project_id);
......@@ -10375,6 +10396,8 @@ CREATE INDEX index_sprints_on_title ON public.sprints USING btree (title);
CREATE INDEX index_sprints_on_title_trigram ON public.sprints USING gin (title public.gin_trgm_ops);
CREATE UNIQUE INDEX index_status_page_published_incidents_on_issue_id ON public.status_page_published_incidents USING btree (issue_id);
CREATE INDEX index_status_page_settings_on_project_id ON public.status_page_settings USING btree (project_id);
CREATE INDEX index_subscriptions_on_project_id ON public.subscriptions USING btree (project_id);
......@@ -11668,6 +11691,9 @@ ALTER TABLE ONLY public.dependency_proxy_group_settings
ALTER TABLE ONLY public.group_deploy_tokens
ADD CONSTRAINT fk_rails_61a572b41a FOREIGN KEY (group_id) REFERENCES public.namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.status_page_published_incidents
ADD CONSTRAINT fk_rails_61e5493940 FOREIGN KEY (issue_id) REFERENCES public.issues(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.deployment_clusters
ADD CONSTRAINT fk_rails_6359a164df FOREIGN KEY (deployment_id) REFERENCES public.deployments(id) ON DELETE CASCADE;
......@@ -13417,6 +13443,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200415161021
20200415161206
20200415192656
20200416005331
20200416111111
20200416120128
20200416120354
......
......@@ -39,6 +39,8 @@ module EE
end
end
has_one :status_page_published_incident, class_name: 'StatusPage::PublishedIncident', inverse_of: :issue
has_and_belongs_to_many :self_managed_prometheus_alert_events, join_table: :issues_self_managed_prometheus_alert_events
has_and_belongs_to_many :prometheus_alert_events, join_table: :issues_prometheus_alert_events
has_many :prometheus_alerts, through: :prometheus_alert_events
......
# frozen_string_literal: true
module StatusPage
# Corresponds to an issue which has been published to a
# status-page app's AWS bucket.
class PublishedIncident < ApplicationRecord
self.table_name = "status_page_published_incidents"
belongs_to :issue, inverse_of: :status_page_published_incident
validates :issue, presence: true
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :status_page_published_incident, class: '::StatusPage::PublishedIncident' do
issue
end
end
......@@ -178,6 +178,7 @@ describe Issue do
it { is_expected.to have_many(:related_vulnerabilities).through(:vulnerability_links).source(:vulnerability) }
it { is_expected.to belong_to(:promoted_to_epic).class_name('Epic') }
it { is_expected.to have_many(:resource_weight_events) }
it { is_expected.to have_one(:status_page_published_incident) }
describe 'versions.most_recent' do
it 'returns the most recent version' do
......
# frozen_string_literal: true
require 'spec_helper'
describe StatusPage::PublishedIncident do
describe 'associations' do
it { is_expected.to belong_to(:issue).inverse_of(:status_page_published_incident) }
end
describe 'validation' do
it { is_expected.to validate_presence_of(:issue) }
end
end
......@@ -41,6 +41,7 @@ issues:
- user_mentions
- system_note_metadata
- alert_management_alert
- status_page_published_incident
events:
- author
- project
......@@ -636,3 +637,5 @@ epic_issue:
system_note_metadata:
- note
- description_version
status_page_published_incident:
- issue
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