-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix migrations task for country petition journals
A `TRUNCATE` followed by an `INSERT ... FROM` doesn't really work that well on a busy site like the petitions website because new journals will start to appear before the `INSERT` completes. Fix this by doing it in Ruby and locking the journals before calculating the signatures. To do this in a performant manner we need an index on the petition_id and location_code for the signatures table. We need to do this concurrently otherwise it will block writes to the table, preventing anyone from signing any petitions.
- Loading branch information
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
db/migrate/20160217192016_add_location_code_index_to_country_petition_journal.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class AddLocationCodeIndexToCountryPetitionJournal < ActiveRecord::Migration | ||
disable_ddl_transaction! | ||
|
||
def up | ||
unless index_exists?(:signatures, [:petition_id, :location_code]) | ||
add_index :signatures, [:petition_id, :location_code], algorithm: :concurrently | ||
end | ||
end | ||
|
||
def down | ||
if index_exists?(:signatures, [:petition_id, :location_code]) | ||
remove_index :signatures, [:petition_id, :location_code] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters