diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-02-28 16:19:43 +0100 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-03-06 12:53:14 +0100 |
commit | 986f470d40a3ed993bb6b2c2115a05c24eb575fa (patch) | |
tree | 6e6fba32d3cd6928311a433dda899122b79634a9 /db/post_migrate | |
parent | 7a22a5891129716808206535770032baa69cd07d (diff) | |
download | gitlab-ce-986f470d40a3ed993bb6b2c2115a05c24eb575fa.tar.gz |
Improve migration robustness and speed.
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20180223124427_build_user_contributed_projects_table.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/db/post_migrate/20180223124427_build_user_contributed_projects_table.rb b/db/post_migrate/20180223124427_build_user_contributed_projects_table.rb index 40049d4ab65..ede130a3fbf 100644 --- a/db/post_migrate/20180223124427_build_user_contributed_projects_table.rb +++ b/db/post_migrate/20180223124427_build_user_contributed_projects_table.rb @@ -12,10 +12,14 @@ class BuildUserContributedProjectsTable < ActiveRecord::Migration else MysqlStrategy.new end.up + + add_concurrent_index :user_contributed_projects, [:project_id, :user_id], unique: true end def down execute "TRUNCATE user_contributed_projects" + + remove_concurrent_index_by_name :user_contributed_projects, 'index_user_contributed_projects_on_project_id_and_user_id' end private @@ -24,7 +28,7 @@ class BuildUserContributedProjectsTable < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers BATCH_SIZE = 100_000 - SLEEP_TIME = 30 + SLEEP_TIME = 5 def up with_index(:events, [:author_id, :project_id], name: 'events_user_contributions_temp', where: 'project_id IS NOT NULL') do @@ -44,10 +48,14 @@ class BuildUserContributedProjectsTable < ActiveRecord::Migration records += result.cmd_tuples Rails.logger.info "Building user_contributed_projects table, batch ##{iteration} complete, created #{records} overall" Kernel.sleep(SLEEP_TIME) if result.cmd_tuples > 0 + rescue ActiveRecord::InvalidForeignKey => e + Rails.logger.info "Retry on InvalidForeignKey: #{e}" + retry end while result.cmd_tuples > 0 end execute "ANALYZE user_contributed_projects" + end private |