gitlab-org--gitlab-foss/db/migrate/20140502125220_migrate_repo_size.rb
Alejandro Rodríguez 02bc717f34 Update references to deprecated repos_path configuration key to avoid
errors on updates from older versions
2016-09-14 21:19:24 -03:00

32 lines
995 B
Ruby

# rubocop:disable all
class MigrateRepoSize < ActiveRecord::Migration
DOWNTIME = false
def up
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_data.each do |project|
id = project['id']
namespace_path = project['namespace_path'] || ''
repos_path = Gitlab.config.gitlab_shell['repos_path'] || Gitlab.config.repositories.storages.default
path = File.join(repos_path, namespace_path, project['project_path'] + '.git')
begin
repo = Gitlab::Git::Repository.new(path)
if repo.empty?
print '-'
else
size = repo.size
print '.'
execute("UPDATE projects SET repository_size = #{size} WHERE id = #{id}")
end
rescue => e
puts "\nFailed to update project #{id}: #{e}"
end
end
puts "\nDone"
end
def down
end
end