3ef4f74b1a
This adds counters for build artifacts and LFS objects, and moves the preexisting repository_size and commit_count from the projects table into a new project_statistics table. The counters are displayed in the administration area for projects and groups, and also available through the API for admins (on */all) and normal users (on */owned) The statistics are updated through ProjectCacheWorker, which can now do more granular updates with the new :statistics argument.
23 lines
858 B
Ruby
23 lines
858 B
Ruby
class MigrateProjectStatistics < ActiveRecord::Migration
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
DOWNTIME = true
|
|
DOWNTIME_REASON = 'Removes two columns from the projects table'
|
|
|
|
def up
|
|
# convert repository_size in float (megabytes) to integer (bytes),
|
|
# initialize total storage_size with repository_size
|
|
execute <<-EOF
|
|
INSERT INTO project_statistics (project_id, namespace_id, commit_count, storage_size, repository_size)
|
|
SELECT id, namespace_id, commit_count, (repository_size * 1024 * 1024), (repository_size * 1024 * 1024) FROM projects
|
|
EOF
|
|
|
|
remove_column :projects, :repository_size
|
|
remove_column :projects, :commit_count
|
|
end
|
|
|
|
def down
|
|
add_column_with_default :projects, :repository_size, :float, default: 0.0
|
|
add_column_with_default :projects, :commit_count, :integer, default: 0
|
|
end
|
|
end
|