Use raw SQL commands for 20140502125220 MigrateRepoSize

Partial fix for #15210
This commit is contained in:
Stan Hu 2016-04-18 07:42:26 -07:00
parent 70e6fa3106
commit f30053ba60
1 changed files with 14 additions and 7 deletions

View File

@ -1,19 +1,26 @@
class MigrateRepoSize < ActiveRecord::Migration class MigrateRepoSize < ActiveRecord::Migration
def up def up
Project.reset_column_information project_data = execute('SELECT projects.id, namespaces.path AS namespace_path, projects.path AS project_path FROM projects LEFT JOIN namespaces ON projects.namespace_id = namespaces.id')
Project.find_each(batch_size: 500) do |project|
project_data.each do |project|
id = project['id']
namespace_path = project['namespace_path'] || ''
path = File.join(Gitlab.config.gitlab_shell.repos_path, namespace_path, project['project_path'] + '.git')
begin begin
if project.empty_repo? repo = Gitlab::Git::Repository.new(path)
if repo.empty?
print '-' print '-'
else else
project.update_repository_size size = repo.size
print '.' print '.'
execute("UPDATE projects SET repository_size = #{size} WHERE id = #{id}")
end end
rescue rescue => e
print 'F' puts "\nFailed to update project #{id}: #{e}"
end end
end end
puts 'Done' puts "\nDone"
end end
def down def down