# frozen_string_literal: true

class AddDoneMetadataToUxToolkitChecklistItems < ActiveRecord::Migration[6.1]
  def up
    unless column_exists?(:ux_toolkit_checklist_items, :done_by_id)
      add_column :ux_toolkit_checklist_items, :done_by_id, :integer
      add_index :ux_toolkit_checklist_items, :done_by_id
    end

    return if column_exists?(:ux_toolkit_checklist_items, :done_at)

    add_column :ux_toolkit_checklist_items, :done_at, :datetime
  end

  def down
    remove_index :ux_toolkit_checklist_items, :done_by_id if index_exists?(:ux_toolkit_checklist_items, :done_by_id)
    remove_column :ux_toolkit_checklist_items, :done_by_id if column_exists?(:ux_toolkit_checklist_items, :done_by_id)
    remove_column :ux_toolkit_checklist_items, :done_at if column_exists?(:ux_toolkit_checklist_items, :done_at)
  end
end
