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 | |
parent | 7a22a5891129716808206535770032baa69cd07d (diff) | |
download | gitlab-ce-986f470d40a3ed993bb6b2c2115a05c24eb575fa.tar.gz |
Improve migration robustness and speed.
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20180223120443_create_user_contributed_projects_table.rb | 2 | ||||
-rw-r--r-- | db/post_migrate/20180223124427_build_user_contributed_projects_table.rb | 10 | ||||
-rw-r--r-- | db/schema.rb | 2 |
3 files changed, 10 insertions, 4 deletions
diff --git a/db/migrate/20180223120443_create_user_contributed_projects_table.rb b/db/migrate/20180223120443_create_user_contributed_projects_table.rb index bbd39da14bd..2f7b6c578c3 100644 --- a/db/migrate/20180223120443_create_user_contributed_projects_table.rb +++ b/db/migrate/20180223120443_create_user_contributed_projects_table.rb @@ -9,8 +9,6 @@ class CreateUserContributedProjectsTable < ActiveRecord::Migration create_table :user_contributed_projects, id: false do |t| t.references :user, null: false t.references :project, null: false - - t.index [:user_id, :project_id], unique: true end add_concurrent_foreign_key :user_contributed_projects, :users, column: :user_id, on_delete: :cascade 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 diff --git a/db/schema.rb b/db/schema.rb index 4b1508e350c..8366957f691 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1820,7 +1820,7 @@ ActiveRecord::Schema.define(version: 20180304204842) do t.integer "project_id", null: false end - add_index "user_contributed_projects", ["user_id", "project_id"], name: "index_user_contributed_projects_on_user_id_and_project_id", unique: true, using: :btree + add_index "user_contributed_projects", ["project_id", "user_id"], name: "index_user_contributed_projects_on_project_id_and_user_id", unique: true, using: :btree create_table "user_custom_attributes", force: :cascade do |t| t.datetime_with_timezone "created_at", null: false |