summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-28 18:08:35 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-28 18:08:35 +0000
commit6315ed9630fb1c6ade3114beb762cd1568d79219 (patch)
tree2a5d31936d09c14420c8f4c8bd752e268f0eb19f /db
parentfedf978f9aa1909ed7bb3fad767ad120a1c6bd7b (diff)
downloadgitlab-ce-6315ed9630fb1c6ade3114beb762cd1568d79219.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20190416185130_add_merge_train_enabled_to_ci_cd_settings.rb6
-rw-r--r--db/migrate/20200117194830_add_iid_to_operations_feature_flags.rb13
-rw-r--r--db/migrate/20200117194840_add_index_on_operations_feature_flags_iid.rb17
-rw-r--r--db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb36
-rw-r--r--db/post_migrate/20191115115522_migrate_epic_notes_mentions_to_db.rb45
-rw-r--r--db/post_migrate/20191128162854_drop_project_ci_cd_settings_merge_trains_enabled.rb2
-rw-r--r--db/post_migrate/20200117194850_backfill_operations_feature_flags_iid.rb24
-rw-r--r--db/post_migrate/20200117194900_delete_internal_ids_where_feature_flags_usage.rb19
-rw-r--r--db/schema.rb3
9 files changed, 163 insertions, 2 deletions
diff --git a/db/migrate/20190416185130_add_merge_train_enabled_to_ci_cd_settings.rb b/db/migrate/20190416185130_add_merge_train_enabled_to_ci_cd_settings.rb
index e6427534310..55ef3c79f3f 100644
--- a/db/migrate/20190416185130_add_merge_train_enabled_to_ci_cd_settings.rb
+++ b/db/migrate/20190416185130_add_merge_train_enabled_to_ci_cd_settings.rb
@@ -7,9 +7,13 @@ class AddMergeTrainEnabledToCiCdSettings < ActiveRecord::Migration[5.1]
disable_ddl_transaction!
+ # rubocop:disable Migration/UpdateLargeTable
+ # rubocop:disable Migration/AddColumnWithDefault
def up
- add_column_with_default :project_ci_cd_settings, :merge_trains_enabled, :boolean, default: false, allow_null: false # rubocop:disable Migration/AddColumnWithDefault
+ add_column_with_default :project_ci_cd_settings, :merge_trains_enabled, :boolean, default: false, allow_null: false
end
+ # rubocop:enable Migration/UpdateLargeTable
+ # rubocop:enable Migration/AddColumnWithDefault
def down
remove_column :project_ci_cd_settings, :merge_trains_enabled
diff --git a/db/migrate/20200117194830_add_iid_to_operations_feature_flags.rb b/db/migrate/20200117194830_add_iid_to_operations_feature_flags.rb
new file mode 100644
index 00000000000..b18d9788b9f
--- /dev/null
+++ b/db/migrate/20200117194830_add_iid_to_operations_feature_flags.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddIidToOperationsFeatureFlags < ActiveRecord::Migration[5.2]
+ DOWNTIME = false
+
+ def up
+ add_column :operations_feature_flags, :iid, :integer
+ end
+
+ def down
+ remove_column :operations_feature_flags, :iid
+ end
+end
diff --git a/db/migrate/20200117194840_add_index_on_operations_feature_flags_iid.rb b/db/migrate/20200117194840_add_index_on_operations_feature_flags_iid.rb
new file mode 100644
index 00000000000..67dedb56ec1
--- /dev/null
+++ b/db/migrate/20200117194840_add_index_on_operations_feature_flags_iid.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexOnOperationsFeatureFlagsIid < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :operations_feature_flags, [:project_id, :iid], unique: true
+ end
+
+ def down
+ remove_concurrent_index :operations_feature_flags, [:project_id, :iid]
+ end
+end
diff --git a/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb b/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb
new file mode 100644
index 00000000000..97f2e568a7e
--- /dev/null
+++ b/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class MigrateEpicMentionsToDb < ActiveRecord::Migration[5.2]
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ DELAY = 2.minutes.to_i
+ BATCH_SIZE = 10000
+ MIGRATION = 'UserMentions::CreateResourceUserMention'
+
+ JOIN = "LEFT JOIN epic_user_mentions on epics.id = epic_user_mentions.epic_id"
+ QUERY_CONDITIONS = "(description like '%@%' OR title like '%@%') AND epic_user_mentions.epic_id is null"
+
+ class Epic < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'epics'
+ end
+
+ def up
+ return unless Gitlab.ee?
+
+ Epic
+ .joins(JOIN)
+ .where(QUERY_CONDITIONS)
+ .each_batch(of: BATCH_SIZE) do |batch, index|
+ range = batch.pluck(Arel.sql('MIN(epics.id)'), Arel.sql('MAX(epics.id)')).first
+ BackgroundMigrationWorker.perform_in(index * DELAY, MIGRATION, ['Epic', JOIN, QUERY_CONDITIONS, false, *range])
+ end
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20191115115522_migrate_epic_notes_mentions_to_db.rb b/db/post_migrate/20191115115522_migrate_epic_notes_mentions_to_db.rb
new file mode 100644
index 00000000000..e0b3c36b57d
--- /dev/null
+++ b/db/post_migrate/20191115115522_migrate_epic_notes_mentions_to_db.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class MigrateEpicNotesMentionsToDb < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ DELAY = 2.minutes.to_i
+ BATCH_SIZE = 10000
+ MIGRATION = 'UserMentions::CreateResourceUserMention'
+
+ INDEX_NAME = 'epic_mentions_temp_index'
+ INDEX_CONDITION = "note LIKE '%@%'::text AND notes.noteable_type = 'Epic'"
+ QUERY_CONDITIONS = "#{INDEX_CONDITION} AND epic_user_mentions.epic_id IS NULL"
+ JOIN = 'LEFT JOIN epic_user_mentions ON notes.id = epic_user_mentions.note_id'
+
+ class Note < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'notes'
+ end
+
+ def up
+ return unless Gitlab.ee?
+
+ # create temporary index for notes with mentions, may take well over 1h
+ add_concurrent_index(:notes, :id, where: INDEX_CONDITION, name: INDEX_NAME)
+
+ Note
+ .joins(JOIN)
+ .where(QUERY_CONDITIONS)
+ .each_batch(of: BATCH_SIZE) do |batch, index|
+ range = batch.pluck(Arel.sql('MIN(notes.id)'), Arel.sql('MAX(notes.id)')).first
+ BackgroundMigrationWorker.perform_in(index * DELAY, MIGRATION, ['Epic', JOIN, QUERY_CONDITIONS, true, *range])
+ end
+ end
+
+ def down
+ # no-op
+ # temporary index is to be dropped in a different migration in an upcoming release:
+ # https://gitlab.com/gitlab-org/gitlab/issues/196842
+ end
+end
diff --git a/db/post_migrate/20191128162854_drop_project_ci_cd_settings_merge_trains_enabled.rb b/db/post_migrate/20191128162854_drop_project_ci_cd_settings_merge_trains_enabled.rb
index df5c6c8f6cc..c2e6792e611 100644
--- a/db/post_migrate/20191128162854_drop_project_ci_cd_settings_merge_trains_enabled.rb
+++ b/db/post_migrate/20191128162854_drop_project_ci_cd_settings_merge_trains_enabled.rb
@@ -12,6 +12,6 @@ class DropProjectCiCdSettingsMergeTrainsEnabled < ActiveRecord::Migration[5.2]
end
def down
- add_column_with_default :project_ci_cd_settings, :merge_trains_enabled, :boolean, default: false, allow_null: true
+ add_column_with_default :project_ci_cd_settings, :merge_trains_enabled, :boolean, default: false, allow_null: true # rubocop:disable Migration/UpdateLargeTable
end
end
diff --git a/db/post_migrate/20200117194850_backfill_operations_feature_flags_iid.rb b/db/post_migrate/20200117194850_backfill_operations_feature_flags_iid.rb
new file mode 100644
index 00000000000..bc97bd6062d
--- /dev/null
+++ b/db/post_migrate/20200117194850_backfill_operations_feature_flags_iid.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class BackfillOperationsFeatureFlagsIid < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ ###
+ # This should update about 700 rows on gitlab.com
+ # Execution time is predicted to take less than a second based on #database-lab results
+ # https://gitlab.com/gitlab-org/gitlab/merge_requests/22175#migration-performance
+ ###
+ def up
+ execute('LOCK operations_feature_flags IN ACCESS EXCLUSIVE MODE')
+
+ backfill_iids('operations_feature_flags')
+
+ change_column_null :operations_feature_flags, :iid, false
+ end
+
+ def down
+ change_column_null :operations_feature_flags, :iid, true
+ end
+end
diff --git a/db/post_migrate/20200117194900_delete_internal_ids_where_feature_flags_usage.rb b/db/post_migrate/20200117194900_delete_internal_ids_where_feature_flags_usage.rb
new file mode 100644
index 00000000000..0cf1ab03622
--- /dev/null
+++ b/db/post_migrate/20200117194900_delete_internal_ids_where_feature_flags_usage.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class DeleteInternalIdsWhereFeatureFlagsUsage < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ sql = <<~SQL
+ DELETE FROM internal_ids WHERE usage = 6
+ SQL
+
+ execute(sql)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index e4ec6e55fa6..f48ead215bc 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -2778,6 +2778,7 @@ ActiveRecord::Schema.define(version: 2020_01_27_090233) do
t.index ["commit_id"], name: "index_notes_on_commit_id"
t.index ["created_at"], name: "index_notes_on_created_at"
t.index ["discussion_id"], name: "index_notes_on_discussion_id"
+ t.index ["id"], name: "epic_mentions_temp_index", where: "((note ~~ '%@%'::text) AND ((noteable_type)::text = 'Epic'::text))"
t.index ["line_code"], name: "index_notes_on_line_code"
t.index ["note"], name: "index_notes_on_note_trigram", opclass: :gin_trgm_ops, using: :gin
t.index ["noteable_id", "noteable_type"], name: "index_notes_on_noteable_id_and_noteable_type"
@@ -2881,6 +2882,8 @@ ActiveRecord::Schema.define(version: 2020_01_27_090233) do
t.datetime_with_timezone "updated_at", null: false
t.string "name", null: false
t.text "description"
+ t.integer "iid", null: false
+ t.index ["project_id", "iid"], name: "index_operations_feature_flags_on_project_id_and_iid", unique: true
t.index ["project_id", "name"], name: "index_operations_feature_flags_on_project_id_and_name", unique: true
end