doc/development/application_settings.md
This document provides a development guide for contributors to add application settings to GitLab.
Application settings are stored in the application_settings table. Each setting has its own column and there should only be one row.
GitLab Duo-related applications settings are stored in a different table.
First of all, you have to decide if it is necessary to add an application setting. Consider our configuration principles when adding a new setting.
We prefer saving the related application settings in a single JSONB column to avoid making the application_settings
table wider. Also, adding a new setting to an existing column doesn't require a database review so it saves time.
To add a new setting, you have to:
rate_limits
in the ApplicationSetting model.rate_limits validator.application_settings table to store, see this merge request for reference.ApplicationSettingImplementation#defaults, if the setting has a default value.ApplicationSetting model.scripts/cells/application-settings-analysis.rb script to generate a definition YAML file at config/application_setting_columns/*.yml and update the documentation file at
cells/application_settings_analysis, based on db/structure.sql and the API documentation. After the definition file is created, ensure you set the
clusterwide key to true or false in it. Setting clusterwide: true means that the attribute values are copied from the leader cell to other cells
in the context of Cells architecture. In most cases, clusterwide: false is preferable.class AddNewSetting < Gitlab::Database::Migration[2.1]
disable_ddl_transaction!
def up
with_lock_retries do
add_column :application_settings, :new_setting, :text, if_not_exists: true
end
add_text_limit :application_settings, :new_setting, 255
end
def down
with_lock_retries do
remove_column :application_settings, :new_setting, if_exists: true
end
end
end
validates :new_setting,
length: { maximum: 255, message: N_('is too long (maximum is %{count} characters)') },
allow_blank: true
To migrate a column to JSONB, add the new setting under the JSONB accessor.
You must follow the process for dropping columns to remove the original column. This a required multi-milestone process that involves:
[!warning] Dropping the original column before ignoring it in the model can cause problems with zero-downtime migrations.
When migrating settings to JSONB columns with jsonb_accessor defaults,
remove them from ApplicationSettingImplementation.defaults because
JSONB accessors take precedence over the defaults method.
We have several instance-wide GitLab Duo settings in the application_settings table. These include duo_features_enabled (boolean), duo_workflow (jsonb), and duo_chat (jsonb).
At some point, we realized it was simpler to add new instance-wide settings to a different table. Going forward, any new GitLab Duo-related instance-wide settings should be added to the ai_settings table.
For GitLab Duo settings at the group or project level, there is also a namespace_ai_settings table.
The cascading settings framework assumes that the instance-wide setting is on the application_settings table and that group and project settings are on namespace_settings and project_settings, respectively. If you are considering adding a cascading setting for GitLab Duo, that may be a good reason to use application_settings instead of ai_settings.