Skip to content

Commit

Permalink
AO3-5995 Add boolean column named spam to comments table (#4499)
Browse files Browse the repository at this point in the history
* add spam column to comments table

* hound

* default: 0 to default:false
  • Loading branch information
saltlas authored Dec 3, 2023
1 parent 7a90d55 commit dafb762
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions db/migrate/20230418074141_add_spam_to_comments.rb
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

0 comments on commit dafb762

Please sign in to comment.