class CreateUserThemeSlots < ActiveRecord::Migration[8.0]
  def change
    create_table :user_theme_slots do |t|
      t.references :user, null: false, foreign_key: true
      t.string :base_theme, null: false
      t.integer :slot_no, null: false
      t.json :tokens, null: false
      t.timestamps
    end

    add_index :user_theme_slots,
              [:user_id, :base_theme, :slot_no],
              unique: true,
              name: 'index_user_theme_slots_on_user_theme_and_slot'
    add_check_constraint :user_theme_slots,
                         "base_theme IN ('light', 'dark')",
                         name: 'user_theme_slots_base_theme_valid'
    add_check_constraint :user_theme_slots,
                         'slot_no BETWEEN 1 AND 3',
                         name: 'user_theme_slots_slot_no_valid'
  end
end
