class AddDeprecatedAtToTags < ActiveRecord::Migration[8.0]
  def up
    add_column :tags, :deprecated_at, :datetime, after: :category
    add_column :tag_versions, :deprecated_at, :datetime, after: :parent_tag_ids

    add_index :tags, :deprecated_at

    add_check_constraint :tags, "deprecated_at IS NULL OR category <> 'nico'",
                         name: 'chk_tags_deprecated_at_not_nico'
  end

  def down
    remove_check_constraint :tags, name: 'chk_tags_deprecated_at_not_nico'

    remove_index :tags, :deprecated_at

    remove_column :tag_versions, :deprecated_at, :datetime
    remove_column :tags, :deprecated_at
  end
end
