Commit a9af4491 authored by Krasimir Angelov's avatar Krasimir Angelov

Merge branch '353350-constraints-on-title-for-sprints' into 'master'

Remove non-null and uniqueness constraints for title from sprints

See merge request gitlab-org/gitlab!82169
parents ff0f7dc0 444a02c3
# frozen_string_literal: true
class RemoveNotNullContraintOnTitleFromSprints < Gitlab::Database::Migration[1.0]
enable_lock_retries!
def up
change_column_null :sprints, :title, true
end
def down
execute <<~SQL
UPDATE sprints SET title = id WHERE title IS NULL
SQL
change_column_null :sprints, :title, false
end
end
# frozen_string_literal: true
class RemoveUniqueIndexForSprintsOnIterationsCadenceIdAndTitle < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
INDEX_NAME = 'index_sprints_on_iterations_cadence_id_and_title'
def up
remove_concurrent_index_by_name :sprints, INDEX_NAME
end
def down
add_concurrent_index :sprints, [:iterations_cadence_id, :title], name: INDEX_NAME, unique: true
end
end
# frozen_string_literal: true
class RemoveUniqueIndexForSprintsOnProjectIdAndTitle < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
INDEX_NAME = 'index_sprints_on_project_id_and_title'
def up
remove_concurrent_index_by_name :sprints, INDEX_NAME
end
def down
add_concurrent_index :sprints, [:project_id, :title], where: "project_id IS NOT NULL", name: INDEX_NAME, unique: true
end
end
ba2bae8d9561eeab907ecf30664a593bdf93ab1041453f93794bf0be4464e92c
\ No newline at end of file
7394be90999876473cfe39c38e72f21c7bb36a5038300d6fe1354f15f3d77e21
\ No newline at end of file
a9aace14f847412c2af03cc6de61616a0f48d32d0fd24b25f6b1f85513c87139
\ No newline at end of file
......@@ -20651,7 +20651,7 @@ CREATE TABLE sprints (
group_id bigint,
iid integer NOT NULL,
cached_markdown_version integer,
title text NOT NULL,
title text,
title_html text,
description text,
description_html text,
......@@ -29065,12 +29065,8 @@ CREATE INDEX index_sprints_on_due_date ON sprints USING btree (due_date);
CREATE INDEX index_sprints_on_group_id ON sprints USING btree (group_id);
CREATE UNIQUE INDEX index_sprints_on_iterations_cadence_id_and_title ON sprints USING btree (iterations_cadence_id, title);
CREATE UNIQUE INDEX index_sprints_on_project_id_and_iid ON sprints USING btree (project_id, iid);
CREATE UNIQUE INDEX index_sprints_on_project_id_and_title ON sprints USING btree (project_id, title) WHERE (project_id IS NOT NULL);
CREATE INDEX index_sprints_on_title ON sprints USING btree (title);
CREATE INDEX index_sprints_on_title_trigram ON sprints USING gin (title gin_trgm_ops);
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe RemoveNotNullContraintOnTitleFromSprints, :migration, schema: 20220304052335 do
let(:migration) { described_class.new }
let(:namespaces) { table(:namespaces) }
let(:sprints) { table(:sprints) }
let(:iterations_cadences) { table(:iterations_cadences) }
let!(:group) { namespaces.create!(name: 'foo', path: 'foo') }
let!(:cadence) { iterations_cadences.create!(group_id: group.id, title: "cadence 1") }
let!(:iteration1) { sprints.create!(id: 1, title: 'a', group_id: group.id, iterations_cadence_id: cadence.id, start_date: Date.new(2021, 11, 1), due_date: Date.new(2021, 11, 5), iid: 1) }
describe '#down' do
it "removes null titles by setting them with ids" do
migration.up
iteration2 = sprints.create!(id: 2, title: nil, group_id: group.id, iterations_cadence_id: cadence.id, start_date: Date.new(2021, 12, 1), due_date: Date.new(2021, 12, 5), iid: 2)
migration.down
expect(iteration1.reload.title).to eq 'a'
expect(iteration2.reload.title).to eq '2'
end
end
end
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