From dafb7621d4b6013a87fc7a08dcd1684c40038745 Mon Sep 17 00:00:00 2001 From: salt <60383410+saltlas@users.noreply.github.com> Date: Sun, 3 Dec 2023 17:22:08 +1300 Subject: [PATCH] AO3-5995 Add boolean column named spam to comments table (#4499) * add spam column to comments table * hound * default: 0 to default:false --- .../20230418074141_add_spam_to_comments.rb | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 db/migrate/20230418074141_add_spam_to_comments.rb diff --git a/db/migrate/20230418074141_add_spam_to_comments.rb b/db/migrate/20230418074141_add_spam_to_comments.rb new file mode 100644 index 00000000000..82dd6c334c4 --- /dev/null +++ b/db/migrate/20230418074141_add_spam_to_comments.rb @@ -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