-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AO3-5995 Add boolean column named spam to comments table (#4499)
* add spam column to comments table * hound * default: 0 to default:false
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
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,49 @@ | ||
class AddSpamToComments < ActiveRecord::Migration[6.0] | ||
def up | ||
if Rails.env.staging? || Rails.env.production? | ||
database = Comment.connection.current_database | ||
|
||
puts <<~PTOSC | ||
Schema Change Command: | ||
pt-online-schema-change D=#{database},t=comments \\ | ||
--alter "ADD COLUMN spam BOOLEAN NOT NULL DEFAULT 0" \\ | ||
--no-drop-old-table \\ | ||
-uroot --ask-pass --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 \\ | ||
--execute | ||
Table Deletion Command: | ||
DROP TABLE IF EXISTS `#{database}`.`_comments_old`; | ||
PTOSC | ||
else | ||
add_column :comments, :spam, :boolean, default: false, null: false | ||
end | ||
end | ||
|
||
def down | ||
if Rails.env.staging? || Rails.env.production? | ||
database = Comment.connection.current_database | ||
|
||
puts <<~PTOSC | ||
Schema Change Command: | ||
pt-online-schema-change D=#{database},t=comments \\ | ||
--alter "DROP COLUMN spam" \\ | ||
--no-drop-old-table \\ | ||
-uroot --ask-pass --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 \\ | ||
--execute | ||
Table Deletion Command: | ||
DROP TABLE IF EXISTS `#{database}`.`_comments_old`; | ||
PTOSC | ||
else | ||
remove_column :comments, :spam | ||
end | ||
end | ||
end |