Module: Gitlab::Database::MigrationHelpers::CascadingNamespaceSettings

Includes:
Gitlab::Database::MigrationHelpers
Defined in:
lib/gitlab/database/migration_helpers/cascading_namespace_settings.rb

Constant Summary

Constants included from Gitlab::Database::MigrationHelpers

DEFAULT_TIMESTAMP_COLUMNS, MAX_IDENTIFIER_NAME_LENGTH

Constants included from DynamicModelHelpers

DynamicModelHelpers::BATCH_SIZE

Constants included from Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers

Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers::BATCH_CLASS_NAME, Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers::BATCH_MIN_DELAY, Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers::BATCH_MIN_VALUE, Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers::BATCH_SIZE, Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers::SUB_BATCH_SIZE

Constants included from Gitlab::Database::Migrations::BackgroundMigrationHelpers

Gitlab::Database::Migrations::BackgroundMigrationHelpers::BATCH_SIZE, Gitlab::Database::Migrations::BackgroundMigrationHelpers::JOB_BUFFER_SIZE

Instance Method Summary collapse

Methods included from Gitlab::Database::MigrationHelpers

#add_check_constraint, #add_column_with_default, #add_concurrent_foreign_key, #add_concurrent_index, #add_not_null_constraint, #add_text_limit, #add_timestamps_with_timezone, #backfill_conversion_of_integer_to_bigint, #backfill_iids, #change_column_type_concurrently, #check_constraint_exists?, #check_constraint_name, #check_not_null_constraint_exists?, #check_text_limit_exists?, #check_trigger_permissions!, #cleanup_concurrent_column_rename, #cleanup_concurrent_column_type_change, #column_for, #concurrent_foreign_key_name, #convert_to_bigint_column, #copy_check_constraints, #copy_foreign_keys, #copy_indexes, #create_extension, #create_or_update_plan_limit, #create_table_with_constraints, #define_batchable_model, #disable_statement_timeout, #drop_extension, #each_batch, #each_batch_range, #ensure_batched_background_migration_is_finished, #false_value, #foreign_key_exists?, #foreign_keys_for, #index_exists_by_name?, #index_invalid?, #indexes_for, #initialize_conversion_of_integer_to_bigint, #install_rename_triggers, #postgres_exists_by_name?, #remove_check_constraint, #remove_concurrent_index, #remove_concurrent_index_by_name, #remove_foreign_key_if_exists, #remove_foreign_key_without_error, #remove_not_null_constraint, #remove_rename_triggers, #remove_text_limit, #remove_timestamps, #rename_column_concurrently, #rename_constraint, #rename_trigger_name, #replace_sql, #restore_conversion_of_integer_to_bigint, #revert_backfill_conversion_of_integer_to_bigint, #revert_initialize_conversion_of_integer_to_bigint, #sidekiq_queue_length, #sidekiq_queue_migrate, #true_value, #undo_change_column_type_concurrently, #undo_cleanup_concurrent_column_rename, #undo_cleanup_concurrent_column_type_change, #undo_rename_column_concurrently, #update_column_in_batches, #validate_check_constraint, #validate_foreign_key, #validate_not_null_constraint, #validate_text_limit, #with_lock_retries

Methods included from AsyncIndexes::MigrationHelpers

#async_index_creation_available?, #prepare_async_index, #unprepare_async_index, #unprepare_async_index_by_name

Methods included from RenameTableHelpers

#finalize_table_rename, #rename_table_safely, #undo_finalize_table_rename, #undo_rename_table_safely

Methods included from DynamicModelHelpers

#define_batchable_model, #each_batch, #each_batch_range

Methods included from Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers

#queue_batched_background_migration

Methods included from Gitlab::Database::Migrations::BackgroundMigrationHelpers

#delete_job_tracking, #delete_queued_jobs, #finalize_background_migration, #migrate_in, #queue_background_migration_jobs_by_range_at_intervals, #requeue_background_migration_jobs_by_range_at_intervals

Instance Method Details

#add_cascading_namespace_setting(setting_name, type, **options) ⇒ Object

Creates the four required columns that constitutes a single cascading namespace settings attribute. This helper is only appropriate if the setting is not already present as a non-cascading attribute.

Creates the `setting_name` column along with the `lock_setting_name` column in both `namespace_settings` and `application_settings`.

This helper is not reversible and must be defined in conjunction with `remove_cascading_namespace_setting` in separate up and down directions.

setting_name - The name of the cascading attribute - same as defined

in `NamespaceSetting` with the `cascading_attr` method.

type - The column type for the setting itself (:boolean, :integer, etc.) options - Standard Rails column options hash. Accepts keys such as

`null` and `default`.

`null` and `default` options will only be applied to the `application_settings` column. In most cases, a non-null default value should be specified.


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gitlab/database/migration_helpers/cascading_namespace_settings.rb', line 27

def add_cascading_namespace_setting(setting_name, type, **options)
  lock_column_name = "lock_#{setting_name}".to_sym

  check_cascading_namespace_setting_consistency(setting_name, lock_column_name)

  namespace_options = options.merge(null: true, default: nil)

  add_column(:namespace_settings, setting_name, type, **namespace_options)
  add_column(:namespace_settings, lock_column_name, :boolean, default: false, null: false)

  add_column(:application_settings, setting_name, type, **options)
  add_column(:application_settings, lock_column_name, :boolean, default: false, null: false)
end

#remove_cascading_namespace_setting(setting_name) ⇒ Object


41
42
43
44
45
46
47
48
49
# File 'lib/gitlab/database/migration_helpers/cascading_namespace_settings.rb', line 41

def remove_cascading_namespace_setting(setting_name)
  lock_column_name = "lock_#{setting_name}".to_sym

  remove_column(:namespace_settings, setting_name) if column_exists?(:namespace_settings, setting_name)
  remove_column(:namespace_settings, lock_column_name) if column_exists?(:namespace_settings, lock_column_name)

  remove_column(:application_settings, setting_name) if column_exists?(:application_settings, setting_name)
  remove_column(:application_settings, lock_column_name) if column_exists?(:application_settings, lock_column_name)
end