summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-03-23 11:55:43 +0100
committerJames Lopez <james@jameslopez.es>2016-03-23 11:55:43 +0100
commit8da04f6b64884c642e8e4b630a30e6400e47b09e (patch)
treee1464f08ac8dc74f4dd32e01c436a5e928e95356 /db
parent46346caf5ba5af7ad9af6913e479f301a3ff2d2d (diff)
downloadgitlab-ce-8da04f6b64884c642e8e4b630a30e6400e47b09e.tar.gz
refactored migration a bit and fixed a few problems. Also added some logging
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb36
1 files changed, 23 insertions, 13 deletions
diff --git a/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb b/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb
index 4ca245035d3..3d97a66c0ff 100644
--- a/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb
+++ b/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb
@@ -10,31 +10,41 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
end
def up
- process_projects_with_wrong_url
- process_bitbucket_projects
+ say("Encrypting and migrating project import credentials...")
+
+ say("Projects and Github projects with a wrong URL")
+ in_transaction { process_projects_with_wrong_url }
+
+ say("Migrating bitbucket credentials...")
+ in_transaction { process_bitbucket_projects }
end
def process_projects_with_wrong_url
- projects_with_wrong_import_url do |project|
+ projects_with_wrong_import_url.each do |project|
import_url = Gitlab::ImportUrl.new(project["import_url"])
- ActiveRecord::Base.transaction do
- update_import_url(import_url, project)
- update_import_data(import_url, project)
- end
+ update_import_url(import_url, project)
+ update_import_data(import_url, project)
end
end
def process_bitbucket_projects
- bitbucket_projects_with_wrong_import_url do |bitbucket_data|
- data = bitbucket_data['data']
- data_hash = YAML::load(data)
- if data_hash && data_hash['bb_session']
+ bitbucket_projects_with_wrong_import_url.each do |bitbucket_data|
+ data_hash = YAML::load(bitbucket_data['data']) if bitbucket_data['data']
+ if defined?(data_hash) && data_hash && data_hash['bb_session']
update_import_data_for_bitbucket(data_hash, bitbucket_data['id'])
end
end
end
+ def in_transaction
+ say_with_time("Processing new transaction...") do
+ ActiveRecord::Base.transaction do
+ yield
+ end
+ end
+ end
+
def update_import_data(import_url, project)
fake_import_data = FakeProjectImportData.new
fake_import_data.credentials = import_url.credentials
@@ -60,8 +70,8 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
%( INSERT into project_import_data (encrypted_credentials, project_id, encrypted_credentials_iv, encrypted_credentials_salt) VALUES ( #{quote(fake_import_data.encrypted_credentials)}, '#{project_id}', #{quote(fake_import_data.encrypted_credentials_iv)}, #{quote(fake_import_data.encrypted_credentials_salt)}))
end
- def update_import_data_sql(id, fake_import_data)
- %( UPDATE project_import_data SET encrypted_credentials = #{quote(fake_import_data.encrypted_credentials)}, encrypted_credentials_iv = #{quote(fake_import_data.encrypted_credentials_iv)}, encrypted_credentials_salt = #{quote(fake_import_data.encrypted_credentials_salt)} WHERE id = '#{id}')
+ def update_import_data_sql(id, fake_import_data, data = 'NULL')
+ %( UPDATE project_import_data SET encrypted_credentials = #{quote(fake_import_data.encrypted_credentials)}, encrypted_credentials_iv = #{quote(fake_import_data.encrypted_credentials_iv)}, encrypted_credentials_salt = #{quote(fake_import_data.encrypted_credentials_salt)}, data = #{data} WHERE id = '#{id}')
end
#Github projects with token, and any user:password@ based URL