Commit db1c7c80 authored by Jan Provaznik's avatar Jan Provaznik

Added models for epic board and epic board labels

This is similar to issue board labels.
parent f506606f
---
title: Added epic boards and epic board labels tables
merge_request: 48658
author:
type: added
# frozen_string_literal: true
class AddEpicBoards < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
with_lock_retries do
create_table :boards_epic_boards do |t|
t.boolean :hide_backlog_list, default: false, null: false
t.boolean :hide_closed_list, default: false, null: false
t.references :group, index: true, foreign_key: { to_table: :namespaces, on_delete: :cascade }, null: false
t.timestamps_with_timezone
t.text :name, default: 'Development', null: false
end
end
add_text_limit :boards_epic_boards, :name, 255
end
def down
with_lock_retries do
drop_table :boards_epic_boards
end
end
end
# frozen_string_literal: true
class AddEpicBoardLabels < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
with_lock_retries do
create_table :boards_epic_board_labels do |t|
t.references :epic_board, index: true, foreign_key: { to_table: :boards_epic_boards, on_delete: :cascade }, null: false
t.references :label, index: true, foreign_key: { on_delete: :cascade }, null: false
end
end
end
def down
with_lock_retries do
drop_table :boards_epic_board_labels
end
end
end
a68c609800f5bdb0a77e39f706b410477493e7b7db3af11e4b2a67534df31079
\ No newline at end of file
65935afe9b4ad195aaf31cddb915dcd62b23674e278e93ce7ff9b4ae98e32331
\ No newline at end of file
...@@ -9849,6 +9849,41 @@ CREATE TABLE boards ( ...@@ -9849,6 +9849,41 @@ CREATE TABLE boards (
hide_closed_list boolean DEFAULT false NOT NULL hide_closed_list boolean DEFAULT false NOT NULL
); );
CREATE TABLE boards_epic_board_labels (
id bigint NOT NULL,
epic_board_id bigint NOT NULL,
label_id bigint NOT NULL
);
CREATE SEQUENCE boards_epic_board_labels_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE boards_epic_board_labels_id_seq OWNED BY boards_epic_board_labels.id;
CREATE TABLE boards_epic_boards (
id bigint NOT NULL,
hide_backlog_list boolean DEFAULT false NOT NULL,
hide_closed_list boolean DEFAULT false NOT NULL,
group_id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
name text DEFAULT 'Development'::text NOT NULL,
CONSTRAINT check_bcbbffe601 CHECK ((char_length(name) <= 255))
);
CREATE SEQUENCE boards_epic_boards_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE boards_epic_boards_id_seq OWNED BY boards_epic_boards.id;
CREATE TABLE boards_epic_user_preferences ( CREATE TABLE boards_epic_user_preferences (
id bigint NOT NULL, id bigint NOT NULL,
board_id bigint NOT NULL, board_id bigint NOT NULL,
...@@ -17876,6 +17911,10 @@ ALTER TABLE ONLY board_user_preferences ALTER COLUMN id SET DEFAULT nextval('boa ...@@ -17876,6 +17911,10 @@ ALTER TABLE ONLY board_user_preferences ALTER COLUMN id SET DEFAULT nextval('boa
ALTER TABLE ONLY boards ALTER COLUMN id SET DEFAULT nextval('boards_id_seq'::regclass); ALTER TABLE ONLY boards ALTER COLUMN id SET DEFAULT nextval('boards_id_seq'::regclass);
ALTER TABLE ONLY boards_epic_board_labels ALTER COLUMN id SET DEFAULT nextval('boards_epic_board_labels_id_seq'::regclass);
ALTER TABLE ONLY boards_epic_boards ALTER COLUMN id SET DEFAULT nextval('boards_epic_boards_id_seq'::regclass);
ALTER TABLE ONLY boards_epic_user_preferences ALTER COLUMN id SET DEFAULT nextval('boards_epic_user_preferences_id_seq'::regclass); ALTER TABLE ONLY boards_epic_user_preferences ALTER COLUMN id SET DEFAULT nextval('boards_epic_user_preferences_id_seq'::regclass);
ALTER TABLE ONLY broadcast_messages ALTER COLUMN id SET DEFAULT nextval('broadcast_messages_id_seq'::regclass); ALTER TABLE ONLY broadcast_messages ALTER COLUMN id SET DEFAULT nextval('broadcast_messages_id_seq'::regclass);
...@@ -18904,6 +18943,12 @@ ALTER TABLE ONLY board_project_recent_visits ...@@ -18904,6 +18943,12 @@ ALTER TABLE ONLY board_project_recent_visits
ALTER TABLE ONLY board_user_preferences ALTER TABLE ONLY board_user_preferences
ADD CONSTRAINT board_user_preferences_pkey PRIMARY KEY (id); ADD CONSTRAINT board_user_preferences_pkey PRIMARY KEY (id);
ALTER TABLE ONLY boards_epic_board_labels
ADD CONSTRAINT boards_epic_board_labels_pkey PRIMARY KEY (id);
ALTER TABLE ONLY boards_epic_boards
ADD CONSTRAINT boards_epic_boards_pkey PRIMARY KEY (id);
ALTER TABLE ONLY boards_epic_user_preferences ALTER TABLE ONLY boards_epic_user_preferences
ADD CONSTRAINT boards_epic_user_preferences_pkey PRIMARY KEY (id); ADD CONSTRAINT boards_epic_user_preferences_pkey PRIMARY KEY (id);
...@@ -20523,6 +20568,12 @@ CREATE INDEX index_board_user_preferences_on_user_id ON board_user_preferences U ...@@ -20523,6 +20568,12 @@ CREATE INDEX index_board_user_preferences_on_user_id ON board_user_preferences U
CREATE UNIQUE INDEX index_board_user_preferences_on_user_id_and_board_id ON board_user_preferences USING btree (user_id, board_id); CREATE UNIQUE INDEX index_board_user_preferences_on_user_id_and_board_id ON board_user_preferences USING btree (user_id, board_id);
CREATE INDEX index_boards_epic_board_labels_on_epic_board_id ON boards_epic_board_labels USING btree (epic_board_id);
CREATE INDEX index_boards_epic_board_labels_on_label_id ON boards_epic_board_labels USING btree (label_id);
CREATE INDEX index_boards_epic_boards_on_group_id ON boards_epic_boards USING btree (group_id);
CREATE INDEX index_boards_epic_user_preferences_on_board_id ON boards_epic_user_preferences USING btree (board_id); CREATE INDEX index_boards_epic_user_preferences_on_board_id ON boards_epic_user_preferences USING btree (board_id);
CREATE UNIQUE INDEX index_boards_epic_user_preferences_on_board_user_epic_unique ON boards_epic_user_preferences USING btree (board_id, user_id, epic_id); CREATE UNIQUE INDEX index_boards_epic_user_preferences_on_board_user_epic_unique ON boards_epic_user_preferences USING btree (board_id, user_id, epic_id);
...@@ -23842,6 +23893,9 @@ ALTER TABLE ONLY group_group_links ...@@ -23842,6 +23893,9 @@ ALTER TABLE ONLY group_group_links
ALTER TABLE ONLY geo_repository_updated_events ALTER TABLE ONLY geo_repository_updated_events
ADD CONSTRAINT fk_rails_2b70854c08 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_2b70854c08 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY boards_epic_board_labels
ADD CONSTRAINT fk_rails_2bedeb8799 FOREIGN KEY (label_id) REFERENCES labels(id) ON DELETE CASCADE;
ALTER TABLE ONLY protected_branch_unprotect_access_levels ALTER TABLE ONLY protected_branch_unprotect_access_levels
ADD CONSTRAINT fk_rails_2d2aba21ef FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_2d2aba21ef FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
...@@ -24247,6 +24301,9 @@ ALTER TABLE ONLY slack_integrations ...@@ -24247,6 +24301,9 @@ ALTER TABLE ONLY slack_integrations
ALTER TABLE ONLY custom_emoji ALTER TABLE ONLY custom_emoji
ADD CONSTRAINT fk_rails_745925b412 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_745925b412 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY boards_epic_board_labels
ADD CONSTRAINT fk_rails_7471128a8e FOREIGN KEY (epic_board_id) REFERENCES boards_epic_boards(id) ON DELETE CASCADE;
ALTER TABLE ONLY dast_site_profiles ALTER TABLE ONLY dast_site_profiles
ADD CONSTRAINT fk_rails_747dc64abc FOREIGN KEY (dast_site_id) REFERENCES dast_sites(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_747dc64abc FOREIGN KEY (dast_site_id) REFERENCES dast_sites(id) ON DELETE CASCADE;
...@@ -24331,6 +24388,9 @@ ALTER TABLE ONLY clusters_applications_crossplane ...@@ -24331,6 +24388,9 @@ ALTER TABLE ONLY clusters_applications_crossplane
ALTER TABLE ONLY packages_package_file_build_infos ALTER TABLE ONLY packages_package_file_build_infos
ADD CONSTRAINT fk_rails_871ca3ae21 FOREIGN KEY (package_file_id) REFERENCES packages_package_files(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_871ca3ae21 FOREIGN KEY (package_file_id) REFERENCES packages_package_files(id) ON DELETE CASCADE;
ALTER TABLE ONLY boards_epic_boards
ADD CONSTRAINT fk_rails_874c573878 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_runner_namespaces ALTER TABLE ONLY ci_runner_namespaces
ADD CONSTRAINT fk_rails_8767676b7a FOREIGN KEY (runner_id) REFERENCES ci_runners(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_8767676b7a FOREIGN KEY (runner_id) REFERENCES ci_runners(id) ON DELETE CASCADE;
......
# frozen_string_literal: true
module Boards
def self.table_name_prefix
'boards_'
end
end
# frozen_string_literal: true
module Boards
class EpicBoard < ApplicationRecord
belongs_to :group, optional: false, inverse_of: :epic_boards
has_many :epic_board_labels, foreign_key: :epic_board_id, inverse_of: :epic_board
validates :name, length: { maximum: 255 }
end
end
# frozen_string_literal: true
module Boards
class EpicBoardLabel < ApplicationRecord
belongs_to :epic_board, optional: false, inverse_of: :epic_board_labels
belongs_to :label, optional: false, inverse_of: :epic_board_labels
end
end
...@@ -18,6 +18,7 @@ module EE ...@@ -18,6 +18,7 @@ module EE
add_authentication_token_field :saml_discovery_token, unique: false, token_generator: -> { Devise.friendly_token(8) } add_authentication_token_field :saml_discovery_token, unique: false, token_generator: -> { Devise.friendly_token(8) }
has_many :epics has_many :epics
has_many :epic_boards, class_name: 'Boards::EpicBoard', inverse_of: :group
has_one :saml_provider has_one :saml_provider
has_many :scim_identities has_many :scim_identities
......
...@@ -7,6 +7,10 @@ module EE ...@@ -7,6 +7,10 @@ module EE
SCOPED_LABEL_SEPARATOR = '::' SCOPED_LABEL_SEPARATOR = '::'
SCOPED_LABEL_PATTERN = /^.*#{SCOPED_LABEL_SEPARATOR}/.freeze SCOPED_LABEL_PATTERN = /^.*#{SCOPED_LABEL_SEPARATOR}/.freeze
prepended do
has_many :epic_board_labels, class_name: 'Boards::EpicBoardLabel', inverse_of: :label
end
def scoped_label? def scoped_label?
SCOPED_LABEL_PATTERN.match?(name) SCOPED_LABEL_PATTERN.match?(name)
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Boards::EpicBoardLabel do
describe 'associations' do
it { is_expected.to belong_to(:epic_board).required.inverse_of(:epic_board_labels) }
it { is_expected.to belong_to(:label).required.inverse_of(:epic_board_labels) }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Boards::EpicBoard do
describe 'associations' do
it { is_expected.to belong_to(:group).required.inverse_of(:epic_boards) }
it { is_expected.to have_many(:epic_board_labels).inverse_of(:epic_board) }
end
describe 'validations' do
it { is_expected.to validate_length_of(:name).is_at_most(255) }
end
end
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Label do RSpec.describe Label do
describe 'associations' do
it { is_expected.to have_many(:epic_board_labels).inverse_of(:label) }
end
describe '#scoped_label?' do describe '#scoped_label?' do
context 'with scoped_labels available' do context 'with scoped_labels available' do
before do before do
......
...@@ -22,6 +22,8 @@ RSpec.describe Group do ...@@ -22,6 +22,8 @@ RSpec.describe Group do
it { is_expected.to have_one(:group_wiki_repository) } it { is_expected.to have_one(:group_wiki_repository) }
it { is_expected.to belong_to(:push_rule) } it { is_expected.to belong_to(:push_rule) }
it { is_expected.to have_many(:saml_group_links) } it { is_expected.to have_many(:saml_group_links) }
it { is_expected.to have_many(:epics) }
it { is_expected.to have_many(:epic_boards).inverse_of(:group) }
it_behaves_like 'model with wiki' do it_behaves_like 'model with wiki' do
let(:container) { create(:group, :nested, :wiki_repo) } let(:container) { create(:group, :nested, :wiki_repo) }
......
...@@ -86,6 +86,7 @@ label: ...@@ -86,6 +86,7 @@ label:
- issues - issues
- merge_requests - merge_requests
- priorities - priorities
- epic_board_labels
milestone: milestone:
- group - group
- project - project
......
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