about summary refs log tree commit diff
path: root/db/migrate/20211231080958_add_category_to_reports.rb
blob: c2b495c6354509cbc87ff01783d17628fec8bc2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require Rails.root.join('lib', 'mastodon', 'migration_helpers')

class AddCategoryToReports < ActiveRecord::Migration[6.1]
  include Mastodon::MigrationHelpers

  disable_ddl_transaction!

  def up
    safety_assured { add_column_with_default :reports, :category, :int, default: 0, allow_null: false }
    add_column :reports, :action_taken_at, :datetime
    add_column :reports, :rule_ids, :bigint, array: true
    safety_assured { execute 'UPDATE reports SET action_taken_at = updated_at WHERE action_taken = TRUE' }
  end

  def down
    safety_assured { execute 'UPDATE reports SET action_taken = TRUE WHERE action_taken_at IS NOT NULL' }
    remove_column :reports, :category
    remove_column :reports, :action_taken_at
    remove_column :reports, :rule_ids
  end
end