diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 12:09:17 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 12:09:17 +0000 |
commit | cd52759ee33051b8ad7b88b02ba7954e4fad7018 (patch) | |
tree | f1096c68e457aef7f5201acd16e4a751ff538026 /db | |
parent | 18f7828977b74bf6e5153594a098ef90e773b3b7 (diff) | |
download | gitlab-ce-cd52759ee33051b8ad7b88b02ba7954e4fad7018.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
16 files changed, 163 insertions, 14 deletions
diff --git a/db/fixtures/development/11_keys.rb b/db/fixtures/development/11_keys.rb index eeee2388d01..958d999f475 100644 --- a/db/fixtures/development/11_keys.rb +++ b/db/fixtures/development/11_keys.rb @@ -5,9 +5,9 @@ require './spec/support/sidekiq_middleware' # gitlab-shell path set (yet) we need to disable this for these fixtures. Sidekiq::Testing.disable! do Gitlab::Seeder.quiet do - # We want to run `add_to_shell` immediately instead of after the commit, so + # We want to run `add_to_authorized_keys` immediately instead of after the commit, so # that it falls under `Sidekiq::Testing.disable!`. - Key.skip_callback(:commit, :after, :add_to_shell) + Key.skip_callback(:commit, :after, :add_to_authorized_keys) User.not_mass_generated.first(10).each do |user| key = "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt#{user.id + 100}6k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" @@ -18,7 +18,7 @@ Sidekiq::Testing.disable! do ) Sidekiq::Worker.skipping_transaction_check do - key.add_to_shell + key.add_to_authorized_keys end print '.' diff --git a/db/migrate/20200203025400_default_lock_version_to_zero_for_merge_requests.rb b/db/migrate/20200203025400_default_lock_version_to_zero_for_merge_requests.rb index c0c58cfa3a7..8e48490af77 100644 --- a/db/migrate/20200203025400_default_lock_version_to_zero_for_merge_requests.rb +++ b/db/migrate/20200203025400_default_lock_version_to_zero_for_merge_requests.rb @@ -9,9 +9,15 @@ class DefaultLockVersionToZeroForMergeRequests < ActiveRecord::Migration[6.0] # Set this constant to true if this migration requires downtime. DOWNTIME = false - def change + def up with_lock_retries do change_column_default :merge_requests, :lock_version, from: nil, to: 0 end end + + def down + with_lock_retries do + change_column_default :merge_requests, :lock_version, from: 0, to: nil + end + end end diff --git a/db/migrate/20200203025602_default_lock_version_to_zero_for_issues.rb b/db/migrate/20200203025602_default_lock_version_to_zero_for_issues.rb index 72c265fdf38..1265de70728 100644 --- a/db/migrate/20200203025602_default_lock_version_to_zero_for_issues.rb +++ b/db/migrate/20200203025602_default_lock_version_to_zero_for_issues.rb @@ -9,9 +9,15 @@ class DefaultLockVersionToZeroForIssues < ActiveRecord::Migration[6.0] # Set this constant to true if this migration requires downtime. DOWNTIME = false - def change + def up with_lock_retries do change_column_default :issues, :lock_version, from: nil, to: 0 end end + + def down + with_lock_retries do + change_column_default :issues, :lock_version, from: 0, to: nil + end + end end diff --git a/db/migrate/20200203025619_default_lock_version_to_zero_for_epics.rb b/db/migrate/20200203025619_default_lock_version_to_zero_for_epics.rb index f44cfd07ee2..b2af8cbe707 100644 --- a/db/migrate/20200203025619_default_lock_version_to_zero_for_epics.rb +++ b/db/migrate/20200203025619_default_lock_version_to_zero_for_epics.rb @@ -9,9 +9,15 @@ class DefaultLockVersionToZeroForEpics < ActiveRecord::Migration[6.0] # Set this constant to true if this migration requires downtime. DOWNTIME = false - def change + def up with_lock_retries do change_column_default :epics, :lock_version, from: nil, to: 0 end end + + def down + with_lock_retries do + change_column_default :epics, :lock_version, from: 0, to: nil + end + end end diff --git a/db/migrate/20200203025744_default_lock_version_to_zero_for_ci_builds.rb b/db/migrate/20200203025744_default_lock_version_to_zero_for_ci_builds.rb index feda8c36947..f40bf7d6309 100644 --- a/db/migrate/20200203025744_default_lock_version_to_zero_for_ci_builds.rb +++ b/db/migrate/20200203025744_default_lock_version_to_zero_for_ci_builds.rb @@ -9,9 +9,15 @@ class DefaultLockVersionToZeroForCiBuilds < ActiveRecord::Migration[6.0] # Set this constant to true if this migration requires downtime. DOWNTIME = false - def change + def up with_lock_retries do change_column_default :ci_builds, :lock_version, from: nil, to: 0 end end + + def down + with_lock_retries do + change_column_default :ci_builds, :lock_version, from: 0, to: nil + end + end end diff --git a/db/migrate/20200203025801_default_lock_version_to_zero_for_ci_stages.rb b/db/migrate/20200203025801_default_lock_version_to_zero_for_ci_stages.rb index b825c4ff1c4..fd3194a742a 100644 --- a/db/migrate/20200203025801_default_lock_version_to_zero_for_ci_stages.rb +++ b/db/migrate/20200203025801_default_lock_version_to_zero_for_ci_stages.rb @@ -9,9 +9,15 @@ class DefaultLockVersionToZeroForCiStages < ActiveRecord::Migration[6.0] # Set this constant to true if this migration requires downtime. DOWNTIME = false - def change + def up with_lock_retries do change_column_default :ci_stages, :lock_version, from: nil, to: 0 end end + + def down + with_lock_retries do + change_column_default :ci_stages, :lock_version, from: 0, to: nil + end + end end diff --git a/db/migrate/20200203025821_default_lock_version_to_zero_for_ci_pipelines.rb b/db/migrate/20200203025821_default_lock_version_to_zero_for_ci_pipelines.rb index 6c4c84cb7e7..6b4568cc7e8 100644 --- a/db/migrate/20200203025821_default_lock_version_to_zero_for_ci_pipelines.rb +++ b/db/migrate/20200203025821_default_lock_version_to_zero_for_ci_pipelines.rb @@ -9,9 +9,15 @@ class DefaultLockVersionToZeroForCiPipelines < ActiveRecord::Migration[6.0] # Set this constant to true if this migration requires downtime. DOWNTIME = false - def change + def up with_lock_retries do change_column_default :ci_pipelines, :lock_version, from: nil, to: 0 end end + + def down + with_lock_retries do + change_column_default :ci_pipelines, :lock_version, from: 0, to: nil + end + end end diff --git a/db/migrate/20200207062728_add_default_branch_protection_to_namespaces.rb b/db/migrate/20200207062728_add_default_branch_protection_to_namespaces.rb index c21cac307f9..6eb650e6b6a 100644 --- a/db/migrate/20200207062728_add_default_branch_protection_to_namespaces.rb +++ b/db/migrate/20200207062728_add_default_branch_protection_to_namespaces.rb @@ -5,9 +5,15 @@ class AddDefaultBranchProtectionToNamespaces < ActiveRecord::Migration[6.0] DOWNTIME = false - def change + def up with_lock_retries do add_column :namespaces, :default_branch_protection, :integer, limit: 2 end end + + def down + with_lock_retries do + remove_column :namespaces, :default_branch_protection + end + end end diff --git a/db/migrate/20200222055543_add_confidential_to_note.rb b/db/migrate/20200222055543_add_confidential_to_note.rb index 03173f63a03..d7bf64dca44 100644 --- a/db/migrate/20200222055543_add_confidential_to_note.rb +++ b/db/migrate/20200222055543_add_confidential_to_note.rb @@ -4,9 +4,15 @@ class AddConfidentialToNote < ActiveRecord::Migration[6.0] DOWNTIME = false - def change + def up with_lock_retries do add_column :notes, :confidential, :boolean end end + + def down + with_lock_retries do + remove_column :notes, :confidential + end + end end diff --git a/db/migrate/20200227165129_create_user_details.rb b/db/migrate/20200227165129_create_user_details.rb index 14403824abc..fe9f23fcb21 100644 --- a/db/migrate/20200227165129_create_user_details.rb +++ b/db/migrate/20200227165129_create_user_details.rb @@ -5,7 +5,7 @@ class CreateUserDetails < ActiveRecord::Migration[6.0] DOWNTIME = false - def change + def up with_lock_retries do create_table :user_details, id: false do |t| t.references :user, index: false, foreign_key: { on_delete: :cascade }, null: false, primary_key: true @@ -15,4 +15,10 @@ class CreateUserDetails < ActiveRecord::Migration[6.0] add_index :user_details, :user_id, unique: true end + + def down + with_lock_retries do + drop_table :user_details + end + end end diff --git a/db/migrate/20200304121828_add_ci_sources_project_pipeline_foreign_key.rb b/db/migrate/20200304121828_add_ci_sources_project_pipeline_foreign_key.rb index db78d9594b0..d5b0af41d4a 100644 --- a/db/migrate/20200304121828_add_ci_sources_project_pipeline_foreign_key.rb +++ b/db/migrate/20200304121828_add_ci_sources_project_pipeline_foreign_key.rb @@ -5,9 +5,15 @@ class AddCiSourcesProjectPipelineForeignKey < ActiveRecord::Migration[6.0] DOWNTIME = false - def change + def up with_lock_retries do add_foreign_key :ci_sources_projects, :ci_pipelines, column: :pipeline_id, on_delete: :cascade # rubocop:disable Migration/AddConcurrentForeignKey end end + + def down + with_lock_retries do + remove_foreign_key :ci_sources_projects, :ci_pipelines, column: :pipeline_id + end + end end diff --git a/db/migrate/20200304121844_add_ci_sources_project_source_project_foreign_key.rb b/db/migrate/20200304121844_add_ci_sources_project_source_project_foreign_key.rb index 88bf835b9f1..4f679bef85e 100644 --- a/db/migrate/20200304121844_add_ci_sources_project_source_project_foreign_key.rb +++ b/db/migrate/20200304121844_add_ci_sources_project_source_project_foreign_key.rb @@ -5,9 +5,15 @@ class AddCiSourcesProjectSourceProjectForeignKey < ActiveRecord::Migration[6.0] DOWNTIME = false - def change + def up with_lock_retries do add_foreign_key :ci_sources_projects, :projects, column: :source_project_id, on_delete: :cascade # rubocop:disable Migration/AddConcurrentForeignKey end end + + def down + with_lock_retries do + remove_foreign_key :ci_sources_projects, :projects, column: :source_project_id + end + end end diff --git a/db/post_migrate/20200211155000_cleanup_empty_merge_request_mentions.rb b/db/post_migrate/20200211155000_cleanup_empty_merge_request_mentions.rb new file mode 100644 index 00000000000..e90d192388b --- /dev/null +++ b/db/post_migrate/20200211155000_cleanup_empty_merge_request_mentions.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class CleanupEmptyMergeRequestMentions < ActiveRecord::Migration[5.2] + DOWNTIME = false + BATCH_SIZE = 1_000 + + class MergeRequestUserMention < ActiveRecord::Base + include EachBatch + + self.table_name = 'merge_request_user_mentions' + end + + def up + # cleanup merge request user mentions with no actual mentions, + # re https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24586#note_285982468 + MergeRequestUserMention + .where(mentioned_users_ids: nil) + .where(mentioned_groups_ids: nil) + .where(mentioned_projects_ids: nil).each_batch(of: BATCH_SIZE) do |batch| + batch.delete_all + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20200211155100_add_temporary_merge_request_with_mentions_index.rb b/db/post_migrate/20200211155100_add_temporary_merge_request_with_mentions_index.rb new file mode 100644 index 00000000000..5b25f29d5f7 --- /dev/null +++ b/db/post_migrate/20200211155100_add_temporary_merge_request_with_mentions_index.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddTemporaryMergeRequestWithMentionsIndex < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_CONDITION = "description like '%@%' OR title like '%@%'" + INDEX_NAME = 'merge_request_mentions_temp_index' + + disable_ddl_transaction! + + def up + # create temporary index for notes with mentions, may take well over 1h + add_concurrent_index(:merge_requests, :id, where: INDEX_CONDITION, name: INDEX_NAME) + end + + def down + remove_concurrent_index(:merge_requests, :id, where: INDEX_CONDITION, name: INDEX_NAME) + end +end diff --git a/db/post_migrate/20200211155539_migrate_merge_request_mentions_to_db.rb b/db/post_migrate/20200211155539_migrate_merge_request_mentions_to_db.rb new file mode 100644 index 00000000000..b622badb561 --- /dev/null +++ b/db/post_migrate/20200211155539_migrate_merge_request_mentions_to_db.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class MigrateMergeRequestMentionsToDb < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + DELAY = 3.minutes.to_i + BATCH_SIZE = 1_000 + MIGRATION = 'UserMentions::CreateResourceUserMention' + + JOIN = "LEFT JOIN merge_request_user_mentions on merge_requests.id = merge_request_user_mentions.merge_request_id" + QUERY_CONDITIONS = "(description like '%@%' OR title like '%@%') AND merge_request_user_mentions.merge_request_id IS NULL" + + disable_ddl_transaction! + + class MergeRequest < ActiveRecord::Base + include EachBatch + + self.table_name = 'merge_requests' + end + + def up + MergeRequest + .joins(JOIN) + .where(QUERY_CONDITIONS) + .each_batch(of: BATCH_SIZE) do |batch, index| + range = batch.pluck(Arel.sql('MIN(merge_requests.id)'), Arel.sql('MAX(merge_requests.id)')).first + migrate_in(index * DELAY, MIGRATION, ['MergeRequest', JOIN, QUERY_CONDITIONS, false, *range]) + end + end + + def down + # no-op + end +end diff --git a/db/schema.rb b/db/schema.rb index 52bb18dda68..4e885ce7dc2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2634,6 +2634,7 @@ ActiveRecord::Schema.define(version: 2020_03_11_165635) do t.index ["head_pipeline_id"], name: "index_merge_requests_on_head_pipeline_id" t.index ["id", "merge_jid"], name: "idx_merge_requests_on_id_and_merge_jid", where: "((merge_jid IS NOT NULL) AND (state_id = 4))" t.index ["id", "merge_jid"], name: "index_merge_requests_on_id_and_merge_jid", where: "((merge_jid IS NOT NULL) AND ((state)::text = 'locked'::text))" + t.index ["id"], name: "merge_request_mentions_temp_index", where: "((description ~~ '%@%'::text) OR ((title)::text ~~ '%@%'::text))" t.index ["latest_merge_request_diff_id"], name: "index_merge_requests_on_latest_merge_request_diff_id" t.index ["lock_version"], name: "index_merge_requests_on_lock_version", where: "(lock_version IS NULL)" t.index ["merge_user_id"], name: "index_merge_requests_on_merge_user_id", where: "(merge_user_id IS NOT NULL)" |