Commit 57112dfb authored by Marius Bobin's avatar Marius Bobin Committed by Kamil Trzciński

Assign plan_id when building a new plan limit

Using `PlanLimits.new` fails because the `plan_id` FK is not set.
We were also directing users to use `Plan.default.limits` which can be
nil if there are no limit records.
parent 1dfba3bc
...@@ -27,7 +27,7 @@ class Plan < ApplicationRecord ...@@ -27,7 +27,7 @@ class Plan < ApplicationRecord
end end
def actual_limits def actual_limits
self.limits || PlanLimits.new self.limits || self.build_limits
end end
def default? def default?
......
---
title: Assign plan_id when building a new plan limit
merge_request: 34845
author:
type: fixed
...@@ -77,10 +77,10 @@ To set this limit on a self-managed installation, run the following in the ...@@ -77,10 +77,10 @@ To set this limit on a self-managed installation, run the following in the
# Plan.default.create_limits! # Plan.default.create_limits!
# For project webhooks # For project webhooks
Plan.default.limits.update!(project_hooks: 100) Plan.default.actual_limits.update!(project_hooks: 100)
# For group webhooks # For group webhooks
Plan.default.limits.update!(group_hooks: 100) Plan.default.actual_limits.update!(group_hooks: 100)
``` ```
NOTE: **Note:** Set the limit to `0` to disable it. NOTE: **Note:** Set the limit to `0` to disable it.
...@@ -115,7 +115,7 @@ To set this limit on a self-managed installation, run the following in the ...@@ -115,7 +115,7 @@ To set this limit on a self-managed installation, run the following in the
# If limits don't exist for the default plan, you can create one with: # If limits don't exist for the default plan, you can create one with:
# Plan.default.create_limits! # Plan.default.create_limits!
Plan.default.limits.update!(offset_pagination_limit: 10000) Plan.default.actual_limits.update!(offset_pagination_limit: 10000)
``` ```
- **Default offset pagination limit:** 50000 - **Default offset pagination limit:** 50000
...@@ -149,7 +149,7 @@ To set this limit on a self-managed installation, run the following in the ...@@ -149,7 +149,7 @@ To set this limit on a self-managed installation, run the following in the
# If limits don't exist for the default plan, you can create one with: # If limits don't exist for the default plan, you can create one with:
# Plan.default.create_limits! # Plan.default.create_limits!
Plan.default.limits.update!(ci_active_jobs: 500) Plan.default.actual_limits.update!(ci_active_jobs: 500)
``` ```
NOTE: **Note:** Set the limit to `0` to disable it. NOTE: **Note:** Set the limit to `0` to disable it.
...@@ -171,7 +171,7 @@ To set this limit on a self-managed installation, run the following in the ...@@ -171,7 +171,7 @@ To set this limit on a self-managed installation, run the following in the
[GitLab Rails console](troubleshooting/debug.md#starting-a-rails-console-session): [GitLab Rails console](troubleshooting/debug.md#starting-a-rails-console-session):
```ruby ```ruby
Plan.default.limits.update!(ci_project_subscriptions: 500) Plan.default.actual_limits.update!(ci_project_subscriptions: 500)
``` ```
NOTE: **Note:** Set the limit to `0` to disable it. NOTE: **Note:** Set the limit to `0` to disable it.
...@@ -196,7 +196,7 @@ To set this limit on a self-managed installation, run the following in the ...@@ -196,7 +196,7 @@ To set this limit on a self-managed installation, run the following in the
[GitLab Rails console](troubleshooting/debug.md#starting-a-rails-console-session): [GitLab Rails console](troubleshooting/debug.md#starting-a-rails-console-session):
```ruby ```ruby
Plan.default.limits.update!(ci_pipeline_schedules: 100) Plan.default.actual_limits.update!(ci_pipeline_schedules: 100)
``` ```
### Number of instance level variables ### Number of instance level variables
...@@ -214,7 +214,7 @@ To update this limit to a new value on a self-managed installation, run the foll ...@@ -214,7 +214,7 @@ To update this limit to a new value on a self-managed installation, run the foll
[GitLab Rails console](troubleshooting/debug.md#starting-a-rails-console-session): [GitLab Rails console](troubleshooting/debug.md#starting-a-rails-console-session):
```ruby ```ruby
Plan.default.limits.update!(ci_instance_level_variables: 30) Plan.default.actual_limits.update!(ci_instance_level_variables: 30)
``` ```
## Instance monitoring and metrics ## Instance monitoring and metrics
......
...@@ -14,4 +14,16 @@ describe Plan do ...@@ -14,4 +14,16 @@ describe Plan do
end end
end end
end end
context 'when updating plan limits' do
let(:plan) { described_class.default }
it { expect(plan).to be_persisted }
it { expect(plan.actual_limits).not_to be_persisted }
it 'successfully updates the limits' do
expect(plan.actual_limits.update!(ci_instance_level_variables: 100)).to be_truthy
end
end
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