2016-06-16 23:09:34 +05:30
# rubocop:disable all
2014-09-02 18:07:02 +05:30
class MigrateRepoSize < ActiveRecord :: Migration
2016-09-29 09:46:39 +05:30
DOWNTIME = false
2014-09-02 18:07:02 +05:30
def up
2016-06-02 11:05:42 +05:30
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' ] || ''
2017-08-17 22:00:37 +05:30
path = File . join ( namespace_path , project [ 'project_path' ] + '.git' )
2016-06-02 11:05:42 +05:30
2014-09-02 18:07:02 +05:30
begin
2018-03-17 18:26:18 +05:30
repo = Gitlab :: Git :: Repository . new ( 'default' , path , '' )
2016-06-02 11:05:42 +05:30
if repo . empty?
2014-09-02 18:07:02 +05:30
print '-'
else
2016-06-02 11:05:42 +05:30
size = repo . size
2014-09-02 18:07:02 +05:30
print '.'
2016-06-02 11:05:42 +05:30
execute ( " UPDATE projects SET repository_size = #{ size } WHERE id = #{ id } " )
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
rescue = > e
puts " \n Failed to update project #{ id } : #{ e } "
2014-09-02 18:07:02 +05:30
end
end
2016-06-02 11:05:42 +05:30
puts " \n Done "
2014-09-02 18:07:02 +05:30
end
def down
end
end