diff options
author | Stan Hu <stanhu@gmail.com> | 2018-01-18 00:38:46 +0300 |
---|---|---|
committer | Ian Baum <ibaum@gitlab.com> | 2018-01-29 21:00:58 +0300 |
commit | f76c0cd173cfc49de77b2e14bf266cfdac183583 (patch) | |
tree | d0fc6c17c58ae9c28e5658051b2644b49cffe708 /db | |
parent | 8f0f79f6a596a6156003a2039daaf3762aa03886 (diff) |
Merge branch 'fj-42112-fix-deploy-keys-migration-mysql' into 'master'
Fix bug in security release with deploy keys migration
See merge request gitlab-org/gitlab-ce!16531
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20171215113714_populate_can_push_from_deploy_keys_projects.rb | 48 | ||||
-rw-r--r-- | db/post_migrate/20171215121205_post_populate_can_push_from_deploy_keys_projects.rb | 48 |
2 files changed, 68 insertions, 28 deletions
diff --git a/db/migrate/20171215113714_populate_can_push_from_deploy_keys_projects.rb b/db/migrate/20171215113714_populate_can_push_from_deploy_keys_projects.rb index ec0427a8e5a..680855af945 100644 --- a/db/migrate/20171215113714_populate_can_push_from_deploy_keys_projects.rb +++ b/db/migrate/20171215113714_populate_can_push_from_deploy_keys_projects.rb @@ -6,6 +6,8 @@ class PopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration # Set this constant to true if this migration requires downtime. DOWNTIME = false + DATABASE_NAME = Gitlab::Database.database_name + disable_ddl_transaction! class DeploysKeyProject < ActiveRecord::Base @@ -18,13 +20,22 @@ class PopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration DeploysKeyProject.each_batch(of: 10_000) do |batch| start_id, end_id = batch.pluck('MIN(id), MAX(id)').first - execute <<-EOF - UPDATE deploy_keys_projects - SET can_push = keys.can_push - FROM keys - WHERE deploy_key_id = keys.id - AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} - EOF + if Gitlab::Database.mysql? + execute <<-EOF.strip_heredoc + UPDATE deploy_keys_projects, #{DATABASE_NAME}.keys + SET deploy_keys_projects.can_push = #{DATABASE_NAME}.keys.can_push + WHERE deploy_keys_projects.deploy_key_id = #{DATABASE_NAME}.keys.id + AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} + EOF + else + execute <<-EOF.strip_heredoc + UPDATE deploy_keys_projects + SET can_push = keys.can_push + FROM keys + WHERE deploy_key_id = keys.id + AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} + EOF + end end end @@ -32,13 +43,22 @@ class PopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration DeploysKeyProject.each_batch(of: 10_000) do |batch| start_id, end_id = batch.pluck('MIN(id), MAX(id)').first - execute <<-EOF - UPDATE keys - SET can_push = deploy_keys_projects.can_push - FROM deploy_keys_projects - WHERE deploy_keys_projects.deploy_key_id = keys.id - AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} - EOF + if Gitlab::Database.mysql? + execute <<-EOF.strip_heredoc + UPDATE deploy_keys_projects, #{DATABASE_NAME}.keys + SET #{DATABASE_NAME}.keys.can_push = deploy_keys_projects.can_push + WHERE deploy_keys_projects.deploy_key_id = #{DATABASE_NAME}.keys.id + AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} + EOF + else + execute <<-EOF.strip_heredoc + UPDATE keys + SET can_push = deploy_keys_projects.can_push + FROM deploy_keys_projects + WHERE deploy_keys_projects.deploy_key_id = keys.id + AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} + EOF + end end end end diff --git a/db/post_migrate/20171215121205_post_populate_can_push_from_deploy_keys_projects.rb b/db/post_migrate/20171215121205_post_populate_can_push_from_deploy_keys_projects.rb index 05d236f8e96..3a5850df3db 100644 --- a/db/post_migrate/20171215121205_post_populate_can_push_from_deploy_keys_projects.rb +++ b/db/post_migrate/20171215121205_post_populate_can_push_from_deploy_keys_projects.rb @@ -5,6 +5,8 @@ class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers DOWNTIME = false + DATABASE_NAME = Gitlab::Database.database_name + disable_ddl_transaction! class DeploysKeyProject < ActiveRecord::Base @@ -17,13 +19,22 @@ class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration DeploysKeyProject.each_batch(of: 10_000) do |batch| start_id, end_id = batch.pluck('MIN(id), MAX(id)').first - execute <<-EOF - UPDATE deploy_keys_projects - SET can_push = keys.can_push - FROM keys - WHERE deploy_key_id = keys.id - AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} - EOF + if Gitlab::Database.mysql? + execute <<-EOF.strip_heredoc + UPDATE deploy_keys_projects, #{DATABASE_NAME}.keys + SET deploy_keys_projects.can_push = #{DATABASE_NAME}.keys.can_push + WHERE deploy_keys_projects.deploy_key_id = #{DATABASE_NAME}.keys.id + AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} + EOF + else + execute <<-EOF.strip_heredoc + UPDATE deploy_keys_projects + SET can_push = keys.can_push + FROM keys + WHERE deploy_key_id = keys.id + AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} + EOF + end end end @@ -31,13 +42,22 @@ class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration DeploysKeyProject.each_batch(of: 10_000) do |batch| start_id, end_id = batch.pluck('MIN(id), MAX(id)').first - execute <<-EOF - UPDATE keys - SET can_push = deploy_keys_projects.can_push - FROM deploy_keys_projects - WHERE deploy_keys_projects.deploy_key_id = keys.id - AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} - EOF + if Gitlab::Database.mysql? + execute <<-EOF.strip_heredoc + UPDATE deploy_keys_projects, #{DATABASE_NAME}.keys + SET #{DATABASE_NAME}.keys.can_push = deploy_keys_projects.can_push + WHERE deploy_keys_projects.deploy_key_id = #{DATABASE_NAME}.keys.id + AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} + EOF + else + execute <<-EOF.strip_heredoc + UPDATE keys + SET can_push = deploy_keys_projects.can_push + FROM deploy_keys_projects + WHERE deploy_keys_projects.deploy_key_id = keys.id + AND deploy_keys_projects.id BETWEEN #{start_id} AND #{end_id} + EOF + end end end end |