diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-03-01 15:42:04 +0100 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-03-06 12:53:14 +0100 |
commit | 43b74afd8656df8228c19d5e5e6aee9f87abc244 (patch) | |
tree | c1f4a7b09d53af65ed13774e30f2a27be38c8052 /db/post_migrate | |
parent | 986f470d40a3ed993bb6b2c2115a05c24eb575fa (diff) | |
download | gitlab-ce-43b74afd8656df8228c19d5e5e6aee9f87abc244.tar.gz |
Rename to UserInteractedProjects.
This is to avoid a mix-up with the existing concept of 'user
contributions'. See `User#contributed_projects` or
`Event#contributions`.
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20180223124427_build_user_interacted_projects_table.rb (renamed from db/post_migrate/20180223124427_build_user_contributed_projects_table.rb) | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/db/post_migrate/20180223124427_build_user_contributed_projects_table.rb b/db/post_migrate/20180223124427_build_user_interacted_projects_table.rb index ede130a3fbf..0992509c629 100644 --- a/db/post_migrate/20180223124427_build_user_contributed_projects_table.rb +++ b/db/post_migrate/20180223124427_build_user_interacted_projects_table.rb @@ -1,4 +1,4 @@ -class BuildUserContributedProjectsTable < ActiveRecord::Migration +class BuildUserInteractedProjectsTable < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers # Set this constant to true if this migration requires downtime. @@ -13,13 +13,13 @@ class BuildUserContributedProjectsTable < ActiveRecord::Migration MysqlStrategy.new end.up - add_concurrent_index :user_contributed_projects, [:project_id, :user_id], unique: true + add_concurrent_index :user_interacted_projects, [:project_id, :user_id], unique: true end def down - execute "TRUNCATE user_contributed_projects" + execute "TRUNCATE user_interacted_projects" - remove_concurrent_index_by_name :user_contributed_projects, 'index_user_contributed_projects_on_project_id_and_user_id' + remove_concurrent_index_by_name :user_interacted_projects, 'index_user_interacted_projects_on_project_id_and_user_id' end private @@ -31,22 +31,22 @@ class BuildUserContributedProjectsTable < ActiveRecord::Migration SLEEP_TIME = 5 def up - with_index(:events, [:author_id, :project_id], name: 'events_user_contributions_temp', where: 'project_id IS NOT NULL') do + with_index(:events, [:author_id, :project_id], name: 'events_user_interactions_temp', where: 'project_id IS NOT NULL') do iteration = 0 records = 0 begin - Rails.logger.info "Building user_contributed_projects table, batch ##{iteration}" + Rails.logger.info "Building user_interacted_projects table, batch ##{iteration}" result = execute <<~SQL - INSERT INTO user_contributed_projects (user_id, project_id) + INSERT INTO user_interacted_projects (user_id, project_id) SELECT e.user_id, e.project_id FROM (SELECT DISTINCT author_id AS user_id, project_id FROM events WHERE project_id IS NOT NULL) AS e - LEFT JOIN user_contributed_projects ucp USING (user_id, project_id) + LEFT JOIN user_interacted_projects ucp USING (user_id, project_id) WHERE ucp.user_id IS NULL LIMIT #{BATCH_SIZE} SQL iteration += 1 records += result.cmd_tuples - Rails.logger.info "Building user_contributed_projects table, batch ##{iteration} complete, created #{records} overall" + Rails.logger.info "Building user_interacted_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}" @@ -54,7 +54,7 @@ class BuildUserContributedProjectsTable < ActiveRecord::Migration end while result.cmd_tuples > 0 end - execute "ANALYZE user_contributed_projects" + execute "ANALYZE user_interacted_projects" end @@ -73,10 +73,10 @@ class BuildUserContributedProjectsTable < ActiveRecord::Migration def up execute <<~SQL - INSERT INTO user_contributed_projects (user_id, project_id) + INSERT INTO user_interacted_projects (user_id, project_id) SELECT e.user_id, e.project_id FROM (SELECT DISTINCT author_id AS user_id, project_id FROM events WHERE project_id IS NOT NULL) AS e - LEFT JOIN user_contributed_projects ucp USING (user_id, project_id) + LEFT JOIN user_interacted_projects ucp USING (user_id, project_id) WHERE ucp.user_id IS NULL SQL end |