2016-06-09 08:39:16 -04:00
# rubocop:disable all
2014-05-02 09:05:08 -04:00
class MigrateRepoSize < ActiveRecord :: Migration
2016-09-14 14:15:28 -04:00
DOWNTIME = false
2014-05-02 09:05:08 -04:00
def up
2016-04-18 10:42:26 -04:00
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' ] || ''
2016-09-14 14:15:28 -04:00
repos_path = Gitlab . config . gitlab_shell [ 'repos_path' ] || Gitlab . config . repositories . storages . default
path = File . join ( repos_path , namespace_path , project [ 'project_path' ] + '.git' )
2016-04-18 10:42:26 -04:00
2014-05-02 09:05:08 -04:00
begin
2016-04-18 10:42:26 -04:00
repo = Gitlab :: Git :: Repository . new ( path )
if repo . empty?
2014-05-02 09:05:08 -04:00
print '-'
else
2016-04-18 10:42:26 -04:00
size = repo . size
2014-05-02 09:05:08 -04:00
print '.'
2016-04-18 10:42:26 -04:00
execute ( " UPDATE projects SET repository_size = #{ size } WHERE id = #{ id } " )
2014-05-02 09:05:08 -04:00
end
2016-04-18 10:42:26 -04:00
rescue = > e
puts " \n Failed to update project #{ id } : #{ e } "
2014-05-02 09:05:08 -04:00
end
end
2016-04-18 10:42:26 -04:00
puts " \n Done "
2014-05-02 09:05:08 -04:00
end
def down
end
end