diff options
author | Robert Speicher <robert@gitlab.com> | 2016-04-18 18:51:51 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-04-18 18:51:51 +0000 |
commit | 007a683f9ccf49ac537761cdd1a83e62220294d8 (patch) | |
tree | 3dfa5fb66bd197f2847fa548468598a1cd60504a | |
parent | bd65a2f6b2e8c5a41be4bdbc8f802f1b5815b253 (diff) | |
parent | f30053ba608ccc7a9edc8ca720ba09ab15a8f1f5 (diff) | |
download | gitlab-ce-007a683f9ccf49ac537761cdd1a83e62220294d8.tar.gz |
Merge branch 'fix-migrate-repo-size-migration' into 'master'
Use raw SQL commands for 20140502125220 MigrateRepoSize
Partial fix for #15210
See merge request !3789
-rw-r--r-- | db/migrate/20140502125220_migrate_repo_size.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/db/migrate/20140502125220_migrate_repo_size.rb b/db/migrate/20140502125220_migrate_repo_size.rb index eed6d366814..efdf53112fd 100644 --- a/db/migrate/20140502125220_migrate_repo_size.rb +++ b/db/migrate/20140502125220_migrate_repo_size.rb @@ -1,19 +1,26 @@ class MigrateRepoSize < ActiveRecord::Migration def up - Project.reset_column_information - Project.find_each(batch_size: 500) do |project| + 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'] || '' + path = File.join(Gitlab.config.gitlab_shell.repos_path, namespace_path, project['project_path'] + '.git') + begin - if project.empty_repo? + repo = Gitlab::Git::Repository.new(path) + if repo.empty? print '-' else - project.update_repository_size + size = repo.size print '.' + execute("UPDATE projects SET repository_size = #{size} WHERE id = #{id}") end - rescue - print 'F' + rescue => e + puts "\nFailed to update project #{id}: #{e}" end end - puts 'Done' + puts "\nDone" end def down |