Commit 7a4f9639 authored by Jarka Košanová's avatar Jarka Košanová

Add migrations to wrap iterations to cadences

- create iteration_cadences table
- add association to iterations
- add migration to wrap existing iterations under cadences
parent 78341adb
# frozen_string_literal: true
class CreateIterationCadence < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
create_table_with_constraints :iteration_cadences do |t|
t.references :group, null: false, foreign_key: { to_table: :namespaces, on_delete: :cascade }
t.timestamps_with_timezone null: false
t.date :start_date, null: false
t.date :last_run_date
t.integer :duration_in_weeks
t.integer :iterations_in_advance
t.boolean :active, default: true, null: false
t.boolean :automatic, default: true, null: false
t.text :title, null: false
t.text_limit :title, 255
end
end
def down
drop_table :iteration_cadences if table_exists?(:iteration_cadences)
end
end
# frozen_string_literal: true
class AddIterationCadenceToSprints < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
INDEX_NAME = 'index_sprints_iteration_cadence_id'
def up
add_column :sprints, :iteration_cadence_id, :integer unless column_exists?(:sprints, :iteration_cadence_id)
add_concurrent_index :sprints, :iteration_cadence_id, name: INDEX_NAME
add_concurrent_foreign_key :sprints, :iteration_cadences, column: :iteration_cadence_id, on_delete: :cascade
end
def down
remove_column :sprints, :iteration_cadence_id if column_exists?(:sprints, :iteration_cadence_id)
end
end
# frozen_string_literal: true
class ScheduleSetDefaultIterationCadences < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
BATCH_SIZE = 1_000
DELAY_INTERVAL = 2.minutes.to_i
MIGRATION_CLASS = 'SetDefaultIterationCadences'
class Iteration < ActiveRecord::Base # rubocop:disable Style/Documentation
include EachBatch
self.table_name = 'sprints'
end
disable_ddl_transaction!
def up
Iteration.select(:group_id).distinct.each_batch(of: BATCH_SIZE, column: :group_id) do |batch, index|
group_ids = batch.pluck(:group_id)
migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, group_ids)
end
end
def down
# Not needed
end
end
6488e3542276042f302d79533e3e84c43a4ef471535137bcef11e73a0e4d961f
\ No newline at end of file
7be98c4f62df9fd837f7a547916dd5481c0b4da2d4fc6680b104b2a998be1eed
\ No newline at end of file
26bf4abb73a53f71fbcb8b5cd1ae1e1539ec59e7052b3bbed95ab1de3fda3de7
\ No newline at end of file
...@@ -13544,6 +13544,30 @@ CREATE TABLE issues_self_managed_prometheus_alert_events ( ...@@ -13544,6 +13544,30 @@ CREATE TABLE issues_self_managed_prometheus_alert_events (
updated_at timestamp with time zone NOT NULL updated_at timestamp with time zone NOT NULL
); );
CREATE TABLE iteration_cadences (
id bigint NOT NULL,
group_id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
start_date date NOT NULL,
last_run_date date,
duration_in_weeks integer,
iterations_in_advance integer,
active boolean DEFAULT true NOT NULL,
automatic boolean DEFAULT true NOT NULL,
title text NOT NULL,
CONSTRAINT check_6b6fe7cdea CHECK ((char_length(title) <= 255))
);
CREATE SEQUENCE iteration_cadences_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE iteration_cadences_id_seq OWNED BY iteration_cadences.id;
CREATE TABLE jira_connect_installations ( CREATE TABLE jira_connect_installations (
id bigint NOT NULL, id bigint NOT NULL,
client_key character varying, client_key character varying,
...@@ -17356,6 +17380,7 @@ CREATE TABLE sprints ( ...@@ -17356,6 +17380,7 @@ CREATE TABLE sprints (
description text, description text,
description_html text, description_html text,
state_enum smallint DEFAULT 1 NOT NULL, state_enum smallint DEFAULT 1 NOT NULL,
iteration_cadence_id integer,
CONSTRAINT sprints_must_belong_to_project_or_group CHECK ((((project_id <> NULL::bigint) AND (group_id IS NULL)) OR ((group_id <> NULL::bigint) AND (project_id IS NULL)))), CONSTRAINT sprints_must_belong_to_project_or_group CHECK ((((project_id <> NULL::bigint) AND (group_id IS NULL)) OR ((group_id <> NULL::bigint) AND (project_id IS NULL)))),
CONSTRAINT sprints_title CHECK ((char_length(title) <= 255)) CONSTRAINT sprints_title CHECK ((char_length(title) <= 255))
); );
...@@ -19067,6 +19092,8 @@ ALTER TABLE ONLY issue_user_mentions ALTER COLUMN id SET DEFAULT nextval('issue_ ...@@ -19067,6 +19092,8 @@ ALTER TABLE ONLY issue_user_mentions ALTER COLUMN id SET DEFAULT nextval('issue_
ALTER TABLE ONLY issues ALTER COLUMN id SET DEFAULT nextval('issues_id_seq'::regclass); ALTER TABLE ONLY issues ALTER COLUMN id SET DEFAULT nextval('issues_id_seq'::regclass);
ALTER TABLE ONLY iteration_cadences ALTER COLUMN id SET DEFAULT nextval('iteration_cadences_id_seq'::regclass);
ALTER TABLE ONLY jira_connect_installations ALTER COLUMN id SET DEFAULT nextval('jira_connect_installations_id_seq'::regclass); ALTER TABLE ONLY jira_connect_installations ALTER COLUMN id SET DEFAULT nextval('jira_connect_installations_id_seq'::regclass);
ALTER TABLE ONLY jira_connect_subscriptions ALTER COLUMN id SET DEFAULT nextval('jira_connect_subscriptions_id_seq'::regclass); ALTER TABLE ONLY jira_connect_subscriptions ALTER COLUMN id SET DEFAULT nextval('jira_connect_subscriptions_id_seq'::regclass);
...@@ -20361,6 +20388,9 @@ ALTER TABLE ONLY issues_prometheus_alert_events ...@@ -20361,6 +20388,9 @@ ALTER TABLE ONLY issues_prometheus_alert_events
ALTER TABLE ONLY issues_self_managed_prometheus_alert_events ALTER TABLE ONLY issues_self_managed_prometheus_alert_events
ADD CONSTRAINT issues_self_managed_prometheus_alert_events_pkey PRIMARY KEY (issue_id, self_managed_prometheus_alert_event_id); ADD CONSTRAINT issues_self_managed_prometheus_alert_events_pkey PRIMARY KEY (issue_id, self_managed_prometheus_alert_event_id);
ALTER TABLE ONLY iteration_cadences
ADD CONSTRAINT iteration_cadences_pkey PRIMARY KEY (id);
ALTER TABLE ONLY sprints ALTER TABLE ONLY sprints
ADD CONSTRAINT iteration_start_and_due_daterange_group_id_constraint EXCLUDE USING gist (group_id WITH =, daterange(start_date, due_date, '[]'::text) WITH &&) WHERE ((group_id IS NOT NULL)); ADD CONSTRAINT iteration_start_and_due_daterange_group_id_constraint EXCLUDE USING gist (group_id WITH =, daterange(start_date, due_date, '[]'::text) WITH &&) WHERE ((group_id IS NOT NULL));
...@@ -22440,6 +22470,8 @@ CREATE INDEX index_issues_on_updated_at ON issues USING btree (updated_at); ...@@ -22440,6 +22470,8 @@ CREATE INDEX index_issues_on_updated_at ON issues USING btree (updated_at);
CREATE INDEX index_issues_on_updated_by_id ON issues USING btree (updated_by_id) WHERE (updated_by_id IS NOT NULL); CREATE INDEX index_issues_on_updated_by_id ON issues USING btree (updated_by_id) WHERE (updated_by_id IS NOT NULL);
CREATE INDEX index_iteration_cadences_on_group_id ON iteration_cadences USING btree (group_id);
CREATE UNIQUE INDEX index_jira_connect_installations_on_client_key ON jira_connect_installations USING btree (client_key); CREATE UNIQUE INDEX index_jira_connect_installations_on_client_key ON jira_connect_installations USING btree (client_key);
CREATE INDEX index_jira_connect_subscriptions_on_namespace_id ON jira_connect_subscriptions USING btree (namespace_id); CREATE INDEX index_jira_connect_subscriptions_on_namespace_id ON jira_connect_subscriptions USING btree (namespace_id);
...@@ -23428,6 +23460,8 @@ CREATE UNIQUE INDEX index_sop_configs_on_project_id ON security_orchestration_po ...@@ -23428,6 +23460,8 @@ CREATE UNIQUE INDEX index_sop_configs_on_project_id ON security_orchestration_po
CREATE UNIQUE INDEX index_sop_configs_on_security_policy_management_project_id ON security_orchestration_policy_configurations USING btree (security_policy_management_project_id); CREATE UNIQUE INDEX index_sop_configs_on_security_policy_management_project_id ON security_orchestration_policy_configurations USING btree (security_policy_management_project_id);
CREATE INDEX index_sprints_iteration_cadence_id ON sprints USING btree (iteration_cadence_id);
CREATE INDEX index_sprints_on_description_trigram ON sprints USING gin (description gin_trgm_ops); CREATE INDEX index_sprints_on_description_trigram ON sprints USING gin (description gin_trgm_ops);
CREATE INDEX index_sprints_on_due_date ON sprints USING btree (due_date); CREATE INDEX index_sprints_on_due_date ON sprints USING btree (due_date);
...@@ -24694,6 +24728,9 @@ ALTER TABLE ONLY project_group_links ...@@ -24694,6 +24728,9 @@ ALTER TABLE ONLY project_group_links
ALTER TABLE ONLY epics ALTER TABLE ONLY epics
ADD CONSTRAINT fk_dccd3f98fc FOREIGN KEY (assignee_id) REFERENCES users(id) ON DELETE SET NULL; ADD CONSTRAINT fk_dccd3f98fc FOREIGN KEY (assignee_id) REFERENCES users(id) ON DELETE SET NULL;
ALTER TABLE ONLY sprints
ADD CONSTRAINT fk_de14ba038f FOREIGN KEY (iteration_cadence_id) REFERENCES iteration_cadences(id) ON DELETE CASCADE;
ALTER TABLE ONLY analytics_devops_adoption_segment_selections ALTER TABLE ONLY analytics_devops_adoption_segment_selections
ADD CONSTRAINT fk_ded7fe0344 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE; ADD CONSTRAINT fk_ded7fe0344 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
...@@ -25087,6 +25124,9 @@ ALTER TABLE ONLY packages_debian_group_component_files ...@@ -25087,6 +25124,9 @@ ALTER TABLE ONLY packages_debian_group_component_files
ALTER TABLE ONLY boards_epic_board_labels ALTER TABLE ONLY boards_epic_board_labels
ADD CONSTRAINT fk_rails_2bedeb8799 FOREIGN KEY (label_id) REFERENCES labels(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_2bedeb8799 FOREIGN KEY (label_id) REFERENCES labels(id) ON DELETE CASCADE;
ALTER TABLE ONLY iteration_cadences
ADD CONSTRAINT fk_rails_2cbf3ce526 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY onboarding_progresses ALTER TABLE ONLY onboarding_progresses
ADD CONSTRAINT fk_rails_2ccfd420cc FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_2ccfd420cc FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
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