about summary refs log tree commit diff stats
path: root/db/migrate/20180129213822_create_pokeviewer_pokedex_entries.rb
blob: 8456456977ad2f440d873bfe7ecdd31e02c7327c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class CreatePokeviewerPokedexEntries < ActiveRecord::Migration[5.1]
  def change
    create_table :pokeviewer_pokedex_entries do |t|
      t.references :trainer, null: true
      t.references :species, null: true
      t.boolean :caught, null: true, default: false

      t.timestamps
    end

    add_foreign_key :pokeviewer_pokedex_entries, :pokeviewer_trainers,
      column: :trainer_id

    add_foreign_key :pokeviewer_pokedex_entries, :pokeviewer_species,
      column: :species_id

    add_index :pokeviewer_pokedex_entries, [:trainer_id, :species_id],
      unique: true
  end
end