Commit 414ae564 authored by Stan Hu's avatar Stan Hu

Fix namespace statistics migration failure

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/79657 modified
`NamespaceStatistics` to use a new database column
(`dependency_proxy_size`) in the `before_save` callback. However,
migration tests that roll back to an older schema value previously
would fail since the column did not exist.

To mitigate this issue, we now check for the existence of the column
before attempting to use it.
parent 32a93d55
...@@ -29,6 +29,10 @@ class NamespaceStatistics < ApplicationRecord # rubocop:disable Gitlab/Namespace ...@@ -29,6 +29,10 @@ class NamespaceStatistics < ApplicationRecord # rubocop:disable Gitlab/Namespace
end end
def update_storage_size def update_storage_size
# This prevents failures with older database schemas, such as those
# in migration specs.
return unless self.class.database.cached_column_exists?(:dependency_proxy_size)
self.storage_size = dependency_proxy_size self.storage_size = dependency_proxy_size
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment