Skip to content

Commit

Permalink
AO3-6212 AO3-6573 Add indices to tag_set_associations, and add the de…
Browse files Browse the repository at this point in the history
…parture gem to make future migrations easier. (#4528)

* AO3-6212 Add indices to tag_set_associations.

Also introduces the departure gem, to make future migrations easier.

* AO3-6212 Use the right environment check.

* AO3-6212 Indentation.

* AO3-6212 - Add no-check-unique-key-change to default options.
  • Loading branch information
tickinginstant authored Aug 13, 2023
1 parent f34ff6c commit 6504b0b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -624,6 +628,7 @@ DEPENDENCIES
dalli
database_cleaner
delorean
departure (~> 6.5)
devise
devise-async
elasticsearch (= 7.17.1)
Expand Down
11 changes: 11 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions config/initializers/departure.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions db/migrate/20230610162442_add_indices_to_tag_set_associations.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6504b0b

Please sign in to comment.