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
9d2753db
Commit
9d2753db
authored
May 17, 2019
by
Alessio Caiazza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove nils from project_statistics.packages_size
Now it defaults to 0
parent
c145e7f2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
2 deletions
+66
-2
app/models/project_statistics.rb
app/models/project_statistics.rb
+1
-1
changelogs/unreleased/ac-namespaces-stats-no-coalesce.yml
changelogs/unreleased/ac-namespaces-stats-no-coalesce.yml
+5
-0
db/migrate/20190516155724_change_packages_size_defaults_in_project_statistics.rb
...24_change_packages_size_defaults_in_project_statistics.rb
+24
-0
db/schema.rb
db/schema.rb
+1
-1
spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb
...ange_packages_size_defaults_in_project_statistics_spec.rb
+35
-0
No files found.
app/models/project_statistics.rb
View file @
9d2753db
...
...
@@ -48,7 +48,7 @@ class ProjectStatistics < ApplicationRecord
# older migrations fail due to non-existent attribute without this
def
packages_size
has_attribute?
(
:packages_size
)
?
super
.
to_i
:
0
has_attribute?
(
:packages_size
)
?
super
:
0
end
def
update_storage_size
...
...
changelogs/unreleased/ac-namespaces-stats-no-coalesce.yml
0 → 100644
View file @
9d2753db
---
title
:
Forbid NULL in project_statistics.packages_size
merge_request
:
28400
author
:
type
:
other
db/migrate/20190516155724_change_packages_size_defaults_in_project_statistics.rb
0 → 100644
View file @
9d2753db
# frozen_string_literal: true
class
ChangePackagesSizeDefaultsInProjectStatistics
<
ActiveRecord
::
Migration
[
5.1
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
change_column_default
:project_statistics
,
:packages_size
,
0
update_column_in_batches
(
:project_statistics
,
:packages_size
,
0
)
do
|
table
,
query
|
query
.
where
(
table
[
:packages_size
].
eq
(
nil
))
end
change_column_null
:project_statistics
,
:packages_size
,
false
end
def
down
change_column_null
:project_statistics
,
:packages_size
,
true
change_column_default
:project_statistics
,
:packages_size
,
nil
end
end
db/schema.rb
View file @
9d2753db
...
...
@@ -2496,7 +2496,7 @@ ActiveRecord::Schema.define(version: 20190528173628) do
t
.
bigint
"build_artifacts_size"
,
default:
0
,
null:
false
t
.
bigint
"shared_runners_seconds"
,
default:
0
,
null:
false
t
.
datetime
"shared_runners_seconds_last_reset"
t
.
bigint
"packages_size"
t
.
bigint
"packages_size"
,
default:
0
,
null:
false
t
.
bigint
"wiki_size"
t
.
index
[
"namespace_id"
],
name:
"index_project_statistics_on_namespace_id"
,
using: :btree
t
.
index
[
"project_id"
],
name:
"index_project_statistics_on_project_id"
,
unique:
true
,
using: :btree
...
...
spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb
0 → 100644
View file @
9d2753db
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20190516155724_change_packages_size_defaults_in_project_statistics.rb'
)
describe
ChangePackagesSizeDefaultsInProjectStatistics
,
:migration
do
let
(
:project_statistics
)
{
table
(
:project_statistics
)
}
let
(
:projects
)
{
table
(
:projects
)
}
it
'removes null packages_size'
do
stats_to_migrate
=
10
stats_to_migrate
.
times
do
|
i
|
p
=
projects
.
create!
(
name:
"project
#{
i
}
"
,
namespace_id:
1
)
project_statistics
.
create!
(
project_id:
p
.
id
,
namespace_id:
p
.
namespace_id
)
end
expect
{
migrate!
}
.
to
change
{
ProjectStatistics
.
where
(
packages_size:
nil
).
count
}
.
from
(
stats_to_migrate
)
.
to
(
0
)
end
it
'defaults packages_size to 0'
do
project
=
projects
.
create!
(
name:
'a new project'
,
namespace_id:
2
)
stat
=
project_statistics
.
create!
(
project_id:
project
.
id
,
namespace_id:
project
.
namespace_id
)
expect
(
stat
.
packages_size
).
to
be_nil
migrate!
stat
.
reload
expect
(
stat
.
packages_size
).
to
eq
(
0
)
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