Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a5520fa5
Commit
a5520fa5
authored
Apr 18, 2019
by
Alessio Caiazza
Committed by
Stan Hu
May 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backfill ProjectStatisics packages_size
parent
174f4598
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
0 deletions
+73
-0
ee/db/post_migrate/20190418132125_populate_project_statistics_packages_size.rb
...190418132125_populate_project_statistics_packages_size.rb
+36
-0
ee/spec/migrations/populate_project_statistics_packages_size_spec.rb
...rations/populate_project_statistics_packages_size_spec.rb
+37
-0
No files found.
ee/db/post_migrate/20190418132125_populate_project_statistics_packages_size.rb
0 → 100644
View file @
a5520fa5
# frozen_string_literal: true
class
PopulateProjectStatisticsPackagesSize
<
ActiveRecord
::
Migration
[
5.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
stats_ids
=
ProjectStatistics
.
joins
(
project:
{
packages: :package_files
}).
distinct
.
select
(
:id
)
packages_size
=
Arel
.
sql
(
'(SELECT SUM(size) FROM packages_package_files '
\
'JOIN packages_packages ON packages_packages.id = packages_package_files.package_id '
\
'WHERE packages_packages.project_id = project_statistics.project_id)'
)
update_column_in_batches
(
:project_statistics
,
:packages_size
,
packages_size
)
do
|
table
,
query
|
query
.
where
(
table
[
:id
].
in
(
stats_ids
))
end
storage_size
=
Arel
.
sql
(
'(repository_size + lfs_objects_size + build_artifacts_size + COALESCE(packages_size, 0))'
)
update_column_in_batches
(
:project_statistics
,
:storage_size
,
storage_size
)
do
|
table
,
query
|
query
.
where
(
table
[
:id
].
in
(
stats_ids
))
end
end
def
down
storage_size
=
Arel
.
sql
(
'(repository_size + lfs_objects_size + build_artifacts_size)'
)
update_column_in_batches
(
:project_statistics
,
:storage_size
,
storage_size
)
do
|
table
,
query
|
query
.
where
(
table
[
:packages_size
].
gt
(
0
))
end
update_column_in_batches
(
:project_statistics
,
:packages_size
,
nil
)
end
end
ee/spec/migrations/populate_project_statistics_packages_size_spec.rb
0 → 100644
View file @
a5520fa5
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'ee'
,
'db'
,
'post_migrate'
,
'20190418132125_populate_project_statistics_packages_size.rb'
)
describe
PopulateProjectStatisticsPackagesSize
,
:migration
do
let
(
:project_statistics
)
{
table
(
:project_statistics
)
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:packages
)
{
table
(
:packages_packages
)
}
let
(
:package_files
)
{
table
(
:packages_package_files
)
}
let
(
:file_size
)
{
1
.
kilobyte
}
let
(
:repo_size
)
{
2
.
megabytes
}
let
(
:lfs_size
)
{
3
.
gigabytes
}
let
(
:artifacts_size
)
{
4
.
terabytes
}
let
(
:storage_size
)
{
repo_size
+
lfs_size
+
artifacts_size
}
let
(
:namespace
)
{
namespaces
.
create
(
name:
'foo'
,
path:
'foo'
)
}
let
(
:package
)
{
packages
.
create!
(
project_id:
project
.
id
,
name:
'a package'
,
package_type:
1
)
}
let
(
:project
)
{
projects
.
create!
(
namespace_id:
namespace
.
id
)
}
let!
(
:statistics
)
{
project_statistics
.
create!
(
project_id:
project
.
id
,
namespace_id:
namespace
.
id
,
storage_size:
storage_size
,
repository_size:
repo_size
,
lfs_objects_size:
lfs_size
,
build_artifacts_size:
artifacts_size
)
}
let!
(
:package_file
)
{
package_files
.
create!
(
package_id:
package
.
id
,
file:
'a file.txt'
,
file_name:
'a file.txt'
,
size:
file_size
)}
it
'backfills ProjectStatistics packages_size'
do
expect
{
migrate!
}
.
to
change
{
statistics
.
reload
.
packages_size
}
.
from
(
nil
).
to
(
file_size
)
end
it
'updates ProjectStatistics storage_size'
do
expect
{
migrate!
}
.
to
change
{
statistics
.
reload
.
storage_size
}
.
by
(
file_size
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment