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

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

    remove_column :post_similarities, :id

    execute <<~SQL
      ALTER TABLE
        post_similarities
          ADD PRIMARY KEY (post_id, target_post_id)
      ;
    SQL
  end

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

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