tabletop-companion/db/migrate/20240612145451_create_count...

21 lines
675 B
Ruby

# frozen_string_literal: true
class CreateCounters < ActiveRecord::Migration[7.1]
def change
create_table :counters do |t|
t.string :name, null: false
t.string :slug, null: false
t.integer :value, null: false, default: 0
t.belongs_to :character_sheet_section, null: false, foreign_key: true
t.timestamps
end
add_check_constraint :counters, "length(name) <= 100", name: "chk_counter_name_max_length"
add_check_constraint :counters, "length(slug) <= 100", name: "chk_counter_slug_max_length"
add_index :counters, :slug, unique: true
add_index :counters, [ :name, :character_sheet_section_id ], unique: true
end
end