class CreateGekanatorGames < ActiveRecord::Migration[8.0]
  def change
    create_table :gekanator_games do |t|
      t.references :user, null: false, foreign_key: true
      t.references :guessed_post, null: false, foreign_key: { to_table: :posts }
      t.references :correct_post, null: false, foreign_key: { to_table: :posts }
      t.boolean :won, null: false
      t.integer :question_count, null: false
      t.json :answers, null: false

      t.timestamps
    end

    add_check_constraint :gekanator_games,
                         'question_count >= 0',
                         name: 'chk_gekanator_games_question_count_nonnegative'
  end
end
