diff --git a/Gemfile b/Gemfile index 9236d99478e..4cc989816b0 100644 --- a/Gemfile +++ b/Gemfile @@ -113,6 +113,9 @@ gem 'kgio', '2.10.0' # TODO: AO3-6297 Update the download code so we can remove mimemagic. gem "mimemagic", "0.3.10" +# Library for helping run pt-online-schema-change commands: +gem "departure", "~> 6.5" + group :test do gem "rspec-rails", "~> 4.0.1" gem 'pickle' diff --git a/Gemfile.lock b/Gemfile.lock index 420e80799d3..4959418eebd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -205,6 +205,10 @@ GEM database_cleaner-core (2.0.1) delorean (2.1.0) chronic + departure (6.5.0) + activerecord (>= 5.2.0, < 7.1, != 7.0.0) + mysql2 (>= 0.4.0, <= 0.5.5) + railties (>= 5.2.0, < 7.1, != 7.0.0) devise (4.8.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -624,6 +628,7 @@ DEPENDENCIES dalli database_cleaner delorean + departure (~> 6.5) devise devise-async elasticsearch (= 7.17.1) diff --git a/config/config.yml b/config/config.yml index 6625b10062e..e52da538648 100644 --- a/config/config.yml +++ b/config/config.yml @@ -518,3 +518,14 @@ WRANGLING_REPORT_LIMIT: 1000 # After this window, all comments are disabled. Setting this value to # something below 1 -- or commenting it out -- will turn off comment disabling. ADMIN_POST_COMMENTING_EXPIRATION_DAYS: 14 + +# The arguments to pass to pt-online-schema-change: +PERCONA_ARGS: > + --chunk-size=5k + --max-flow-ctl 0 + --pause-file /tmp/pauseme + --max-load Threads_running=15 + --critical-load Threads_running=100 + --set-vars innodb_lock_wait_timeout=2 + --alter-foreign-keys-method=auto + --no-check-unique-key-change diff --git a/config/initializers/departure.rb b/config/initializers/departure.rb new file mode 100644 index 00000000000..f201a5630d4 --- /dev/null +++ b/config/initializers/departure.rb @@ -0,0 +1,10 @@ +Departure.configure do |config| + # Disable departure by default. To use pt-online-schema-change for a + # migration, call + # uses_departure! if Rails.env.staging? || Rails.env.production? + # in the migration file. + config.enabled_by_default = false + + # Set the arguments based on the config file: + config.global_percona_args = ArchiveConfig.PERCONA_ARGS.squish +end diff --git a/db/migrate/20230610162442_add_indices_to_tag_set_associations.rb b/db/migrate/20230610162442_add_indices_to_tag_set_associations.rb new file mode 100644 index 00000000000..be9ff0658a9 --- /dev/null +++ b/db/migrate/20230610162442_add_indices_to_tag_set_associations.rb @@ -0,0 +1,14 @@ +class AddIndicesToTagSetAssociations < ActiveRecord::Migration[6.1] + uses_departure! if Rails.env.staging? || Rails.env.production? + + def change + change_table :tag_set_associations do |t| + t.index :tag_id + t.index :parent_tag_id + + t.index [:owned_tag_set_id, :parent_tag_id, :tag_id], + name: :index_tag_set_associations_on_tag_set_and_parent_and_tag, + unique: true + end + end +end