class ChangeTagSimilaritiesToCompositePk < ActiveRecord::Migration[8.0]
  def up
    execute <<~SQL
      ALTER TABLE
        tag_similarities
          MODIFY COLUMN id BIGINT NOT NULL
      ;
    SQL

    execute <<~SQL
      ALTER TABLE
        tag_similarities
          DROP PRIMARY KEY
      ;
    SQL

    remove_column :tag_similarities, :id

    execute <<~SQL
      ALTER TABLE
        tag_similarities
          ADD PRIMARY KEY (tag_id, target_tag_id)
      ;
    SQL
  end

  def down
    execute <<~SQL
      ALTER TABLE
        tag_similarities
          DROP PRIMARY KEY
      ;
    SQL

    execute <<~SQL
      ALTER TABLE
        tag_similarities
          ADD COLUMN id BIGINT NOT NULL AUTO_INCREMENT FIRST
        , ADD PRIMARY KEY (id)
      ;
    SQL
  end
end
