Make plan_limits.repository_size nullable

What does this MR do and why?

We need to make plan_limits.repository_size accepts nil values for 2 reasons:

  1. To act in accordance with application_settings.repository_size_limit, namespaces.repository_size_limit, and projects.repository_size_limit, which all are nullable
  2. Because the current business logic is:
    • if nil it means that there's no limit set
    • if 0 it's limitless
    • if > 0 then the limit is the number set.

The hierarchy will be as follows: projects.repository_size_limit > namespaces.repository_size_limit > plan_limits.repository_size > application_settings.repository_size_limit

So if a limit is set at a lower level (e.g. project) it takes precedence over the upper levels. In order for plan_limits.repository_size to participate in this hierarchy it needs to accept null values

References

Please include cross links to any resources that are relevant to this MR This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Migrations

Up

bundle exec rails db:migrate VERSION=20241106163530
DEPRECATION WARNING: Support for Rails versions < 7.1 is deprecated and will be removed from ViewComponent 4.0.0 (ViewComponent v4 will remove support for Rails versions < 7.1 no earlier than April 1, 2025) (called from <main> at /Users/sheldonled/projects/gitlab/gdk/gitlab/config/environment.rb:7)
main: == [advisory_lock_connection] object_id: 129480, pg_backend_pid: 4820
main: == 20241106163530 AllowNullForPlanLimitsRepositorySize: migrating =============
main: -- change_column_null(:plan_limits, :repository_size, true)
main:    -> 0.0023s
main: == 20241106163530 AllowNullForPlanLimitsRepositorySize: migrated (0.0063s) ====

main: == [advisory_lock_connection] object_id: 129480, pg_backend_pid: 4820
bundle exec rails db:migrate VERSION=20241106163630
DEPRECATION WARNING: Support for Rails versions < 7.1 is deprecated and will be removed from ViewComponent 4.0.0 (ViewComponent v4 will remove support for Rails versions < 7.1 no earlier than April 1, 2025) (called from <main> at /Users/sheldonled/projects/gitlab/gdk/gitlab/config/environment.rb:7)
main: == [advisory_lock_connection] object_id: 129500, pg_backend_pid: 8257
main: == 20241106163630 UpdateDefaultPlanLimitsRepositorySize: migrating ============
main: -- change_column_default(:plan_limits, :repository_size, {:from=>0, :to=>nil})
main:    -> 0.0526s
main: == 20241106163630 UpdateDefaultPlanLimitsRepositorySize: migrated (0.0596s) ===

main: == [advisory_lock_connection] object_id: 129500, pg_backend_pid: 8257
bundle exec rails db:migrate VERSION=20241106163900
DEPRECATION WARNING: Support for Rails versions < 7.1 is deprecated and will be removed from ViewComponent 4.0.0 (ViewComponent v4 will remove support for Rails versions < 7.1 no earlier than April 1, 2025) (called from <main> at /Users/sheldonled/projects/gitlab/gdk/gitlab/config/environment.rb:7)
main: == [advisory_lock_connection] object_id: 129500, pg_backend_pid: 8995
main: == 20241106163900 SetExistingPlanLimitsRepositorySizeToNull: migrating ========
main: -- execute("UPDATE plan_limits SET repository_size = NULL WHERE repository_size = 0")
main:    -> 0.0029s
main: == 20241106163900 SetExistingPlanLimitsRepositorySizeToNull: migrated (0.0099s)

main: == [advisory_lock_connection] object_id: 129500, pg_backend_pid: 8995
gitlabhq_development=# \d+ plan_limits
                                                                                       Table "public.plan_limits"
                        Column                         |           Type           | Collation | Nullable |                 Default                 | Storage  | Compression | Stats target | Description
-------------------------------------------------------+--------------------------+-----------+----------+-----------------------------------------+----------+-------------+--------------+-------------
...
repository_size                                       | bigint                   |           |          |                                         | plain    |             |              |
...

Down

rails db:migrate:down:main VERSION=20241106163900
DEPRECATION WARNING: Support for Rails versions < 7.1 is deprecated and will be removed from ViewComponent 4.0.0 (ViewComponent v4 will remove support for Rails versions < 7.1 no earlier than April 1, 2025) (called from <main> at /Users/sheldonled/projects/gitlab/gdk/gitlab/config/environment.rb:7)
main: == [advisory_lock_connection] object_id: 129040, pg_backend_pid: 13061
main: == 20241106163900 SetExistingPlanLimitsRepositorySizeToNull: reverting ========
main: -- execute("UPDATE plan_limits SET repository_size = 0 WHERE repository_size IS NULL")
main:    -> 0.0049s
main: == 20241106163900 SetExistingPlanLimitsRepositorySizeToNull: reverted (0.2730s)

main: == [advisory_lock_connection] object_id: 129040, pg_backend_pid: 13061
rails db:migrate:down:main VERSION=20241106163630
DEPRECATION WARNING: Support for Rails versions < 7.1 is deprecated and will be removed from ViewComponent 4.0.0 (ViewComponent v4 will remove support for Rails versions < 7.1 no earlier than April 1, 2025) (called from <main> at /Users/sheldonled/projects/gitlab/gdk/gitlab/config/environment.rb:7)
main: == [advisory_lock_connection] object_id: 129040, pg_backend_pid: 16482
main: == 20241106163630 UpdateDefaultPlanLimitsRepositorySize: reverting ============
main: -- change_column_default(:plan_limits, :repository_size, {:from=>nil, :to=>0})
main:    -> 0.0569s
main: == 20241106163630 UpdateDefaultPlanLimitsRepositorySize: reverted (0.0636s) ===

main: == [advisory_lock_connection] object_id: 129040, pg_backend_pid: 16482
bundle exec rails db:migrate:down:main VERSION=20241106163530
DEPRECATION WARNING: Support for Rails versions < 7.1 is deprecated and will be removed from ViewComponent 4.0.0 (ViewComponent v4 will remove support for Rails versions < 7.1 no earlier than April 1, 2025) (called from <main> at /Users/sheldonled/projects/gitlab/gdk/gitlab/config/environment.rb:7)
main: == [advisory_lock_connection] object_id: 129080, pg_backend_pid: 23792
main: == 20241106163530 AllowNullForPlanLimitsRepositorySize: reverting =============
main: -- change_column_null(:plan_limits, :repository_size, false)
main:    -> 0.0019s
main: == 20241106163530 AllowNullForPlanLimitsRepositorySize: reverted (0.0072s) ====

main: == [advisory_lock_connection] object_id: 129080, pg_backend_pid: 23792
                        Column                         |           Type           | Collation | Nullable |                 Default                 | Storage  | Compression | Stats target | Description
-------------------------------------------------------+--------------------------+-----------+----------+-----------------------------------------+----------+-------------+--------------+-------------
...
repository_size                                       | bigint                   |           | not null | 0                                       | plain    |             |              |
...

How to set up and validate locally

  1. Open rails console:
    1. Check that the limit yields 0
      Group.find(35).actual_plan.actual_limits.repository_size
      => 0
  2. Now run the migrations rails db:migrate
  3. Open rails console again
    1. Check that the limit yields nil
      Group.find(35).actual_plan.actual_limits.repository_size
      => nil
Edited by Sheldon Led

Merge request reports

Loading