Merge branch 'ac-namespaces-stats-no-coalesce' into 'master'
Remove nils from project_statistics.packages_size See merge request gitlab-org/gitlab-ce!28400
This commit is contained in:
commit
fa32ae5d61
|
@ -48,7 +48,7 @@ class ProjectStatistics < ApplicationRecord
|
||||||
|
|
||||||
# older migrations fail due to non-existent attribute without this
|
# older migrations fail due to non-existent attribute without this
|
||||||
def packages_size
|
def packages_size
|
||||||
has_attribute?(:packages_size) ? super.to_i : 0
|
has_attribute?(:packages_size) ? super : 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_storage_size
|
def update_storage_size
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Forbid NULL in project_statistics.packages_size
|
||||||
|
merge_request: 28400
|
||||||
|
author:
|
||||||
|
type: other
|
|
@ -0,0 +1,24 @@
|
||||||
|
# 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
|
|
@ -1744,7 +1744,7 @@ ActiveRecord::Schema.define(version: 20190527194900) do
|
||||||
t.bigint "repository_size", default: 0, null: false
|
t.bigint "repository_size", default: 0, null: false
|
||||||
t.bigint "lfs_objects_size", default: 0, null: false
|
t.bigint "lfs_objects_size", default: 0, null: false
|
||||||
t.bigint "build_artifacts_size", default: 0, null: false
|
t.bigint "build_artifacts_size", default: 0, null: false
|
||||||
t.bigint "packages_size"
|
t.bigint "packages_size", default: 0, null: false
|
||||||
t.bigint "wiki_size"
|
t.bigint "wiki_size"
|
||||||
t.index ["namespace_id"], name: "index_project_statistics_on_namespace_id", using: :btree
|
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
|
t.index ["project_id"], name: "index_project_statistics_on_project_id", unique: true, using: :btree
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
# 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
|
Loading…
Reference in New Issue