Module: Gitlab::Database::MigrationHelpers::Swapping
- Includes:
- V2, SchemaHelpers
- Included in:
- PartitioningMigrationHelpers::ForeignKeyHelpers, PartitioningMigrationHelpers::IndexHelpers
- Defined in:
- lib/gitlab/database/migration_helpers/swapping.rb
Constant Summary
Constants included from Gitlab::Database::MigrationHelpers
DEFAULT_TIMESTAMP_COLUMNS, ENFORCE_INITIALIZE_ALL_INT_IDS_FROM_MILESTONE, INTEGER_IDS_YET_TO_INITIALIZED_TO_BIGINT_FILE_PATH, PENDING_INT_IDS_ERROR_MSG, TABLE_INT_IDS_YAML_FILE_COMMENT
Constants included from DynamicModelHelpers
DynamicModelHelpers::BATCH_SIZE
Constants included from Gitlab::Database::Migrations::RedisHelpers
Gitlab::Database::Migrations::RedisHelpers::SCAN_START_CURSOR
Constants included from Gitlab::Database::Migrations::SidekiqHelpers
Gitlab::Database::Migrations::SidekiqHelpers::DEFAULT_MAX_ATTEMPTS, Gitlab::Database::Migrations::SidekiqHelpers::DEFAULT_TIMES_IN_A_ROW
Constants included from Gitlab::Database::Migrations::ConstraintsHelpers
Gitlab::Database::Migrations::ConstraintsHelpers::MAX_IDENTIFIER_NAME_LENGTH
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::EARLY_FINALIZATION_ERROR, Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers::ENFORCE_EARLY_FINALIZATION_FROM_VERSION, Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers::MIGRATION_NOT_FOUND_MESSAGE, Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers::MINIMUM_PAUSE_MS, Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers::NonExistentMigrationError, Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers::SUB_BATCH_SIZE
Instance Method Summary collapse
- #swap_columns(table, column1, column2) ⇒ Object
- #swap_columns_default(table, column1, column2) ⇒ Object
- #swap_foreign_keys(table, foreign_key1, foreign_key2) ⇒ Object
- #swap_indexes(table, index1, index2, schema: nil) ⇒ Object
Methods included from V2
#cleanup_concurrent_column_rename, #create_table, #rename_column_concurrently, #rename_index_with_schema, #truncate_tables!, #undo_cleanup_concurrent_column_rename, #undo_rename_column_concurrently, #with_lock_retries
Methods included from Gitlab::Database::MigrationHelpers
#add_concurrent_index, #add_primary_key_using_index, #add_sequence, #add_timestamps_with_timezone, #backfill_conversion_of_integer_to_bigint, #backfill_iids, #change_column_type_concurrently, #check_trigger_permissions!, #cleanup_concurrent_column_rename, #cleanup_concurrent_column_type_change, #cleanup_conversion_of_integer_to_bigint, #column_for, #convert_to_bigint_column, #copy_foreign_keys, #copy_indexes, #create_or_update_plan_limit, #define_batchable_model, #drop_sequence, #each_batch, #each_batch_range, #ensure_backfill_conversion_of_integer_to_bigint_is_finished, #false_value, #foreign_keys_for, #index_exists_by_name?, #index_invalid?, #indexes_for, #initialize_conversion_of_integer_to_bigint, #install_rename_triggers, #install_sharding_key_assignment_trigger, #lock_tables, #remove_column_default, #remove_concurrent_index, #remove_concurrent_index_by_name, #remove_rename_triggers, #remove_sharding_key_assignment_trigger, #remove_timestamps, #rename_column_concurrently, #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, #swap_primary_key, #table_integer_ids, #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
Methods included from PartitionHelpers
#partition?, #table_partitioned?
Methods included from WraparoundVacuumHelpers
#check_if_wraparound_in_progress
Methods included from AsyncConstraints::MigrationHelpers
#prepare_async_check_constraint_validation, #prepare_async_foreign_key_validation, #prepare_partitioned_async_check_constraint_validation, #prepare_partitioned_async_foreign_key_validation, #unprepare_async_check_constraint_validation, #unprepare_async_foreign_key_validation, #unprepare_partitioned_async_check_constraint_validation, #unprepare_partitioned_async_foreign_key_validation
Methods included from AsyncIndexes::MigrationHelpers
#async_index_creation_available?, #prepare_async_index, #prepare_async_index_from_sql, #prepare_async_index_removal, #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 FeatureFlagMigratorHelpers
#down_migrate_to_jsonb_setting, #down_migrate_to_setting, #up_migrate_to_jsonb_setting, #up_migrate_to_setting
Methods included from DynamicModelHelpers
define_batchable_model, #each_batch, #each_batch_range
Methods included from Gitlab::Database::Migrations::ForeignKeyHelpers
#add_concurrent_foreign_key, #concurrent_foreign_key_name, #foreign_key_exists?, #remove_foreign_key_if_exists, #remove_foreign_key_without_error, #validate_foreign_key
Methods included from Gitlab::Database::Migrations::LockRetriesHelpers
Methods included from Gitlab::Database::Migrations::TimeoutHelpers
Methods included from Gitlab::Database::Migrations::RedisHelpers
Methods included from Gitlab::Database::Migrations::SidekiqHelpers
#migrate_across_instance, #migrate_within_instance, #sidekiq_queue_migrate, #sidekiq_remove_jobs
Methods included from Gitlab::Database::Migrations::ExtensionHelpers
#create_extension, #drop_extension
Methods included from Gitlab::Database::Migrations::ConstraintsHelpers
#add_check_constraint, #add_multi_column_not_null_constraint, #add_not_null_constraint, #add_text_limit, #check_constraint_exists?, check_constraint_exists?, #check_constraint_name, #check_not_null_constraint_exists?, #check_text_limit_exists?, #copy_check_constraints, #drop_constraint, #remove_check_constraint, #remove_multi_column_not_null_constraint, #remove_not_null_constraint, #remove_text_limit, #rename_constraint, #switch_constraint_names, #text_limit_name, #validate_check_constraint, #validate_check_constraint_name!, #validate_multi_column_not_null_constraint, #validate_not_null_constraint, #validate_text_limit
Methods included from Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers
#delete_batched_background_migration, #ensure_batched_background_migration_is_finished, #finalize_batched_background_migration, #gitlab_schema_from_context, #queue_batched_background_migration
Methods included from Gitlab::Database::Migrations::ReestablishedConnectionStack
#with_restored_connection_stack
Methods included from SchemaHelpers
#assert_not_in_transaction_block, #create_comment, #create_trigger, #create_trigger_function, #drop_function, #drop_trigger, #find_all_id_columns_sql, #function_exists?, #object_name, #reset_all_trigger_functions, #reset_trigger_function, #tmp_table_name, #trigger_exists?
Instance Method Details
#swap_columns(table, column1, column2) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/gitlab/database/migration_helpers/swapping.rb', line 10 def swap_columns(table, column1, column2) ::Gitlab::Database::Migrations::SwapColumns.new( migration_context: self, table: table, column1: column1, column2: column2 ).execute end |
#swap_columns_default(table, column1, column2) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/gitlab/database/migration_helpers/swapping.rb', line 19 def swap_columns_default(table, column1, column2) ::Gitlab::Database::Migrations::SwapColumnsDefault.new( migration_context: self, table: table, column1: column1, column2: column2 ).execute end |
#swap_foreign_keys(table, foreign_key1, foreign_key2) ⇒ Object
28 29 30 31 32 |
# File 'lib/gitlab/database/migration_helpers/swapping.rb', line 28 def swap_foreign_keys(table, foreign_key1, foreign_key2) rename_constraint(table, foreign_key1, :temp_name_for_renaming) rename_constraint(table, foreign_key2, foreign_key1) rename_constraint(table, :temp_name_for_renaming, foreign_key2) end |
#swap_indexes(table, index1, index2, schema: nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gitlab/database/migration_helpers/swapping.rb', line 34 def swap_indexes(table, index1, index2, schema: nil) identifier = "index_#{index1}_on_#{table}" # Check Gitlab::Database::MigrationHelpers#concurrent_foreign_key_name() # for info on why we use a hash hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10) temp_index = "temp_#{hashed_identifier}" rename_index_with_schema(table, index1, temp_index, schema: schema) rename_index_with_schema(table, index2, index1, schema: schema) rename_index_with_schema(table, temp_index, index2, schema: schema) end |