class CreateBoardMemberships < ActiveRecord::Migration[8.1]
  def change
    create_table :board_memberships do |t|
      t.integer :board_id, null: false
      t.integer :participant_id, null: false
      t.datetime :joined_at, null: false
      t.datetime :left_at
      t.integer :last_read_post_id

      t.timestamps
    end

    add_index :board_memberships, :board_id
    add_index :board_memberships, :participant_id
    add_index :board_memberships, [ :board_id, :participant_id ], unique: true
    add_foreign_key :board_memberships, :boards
    add_foreign_key :board_memberships, :participants
  end
end
