class CreateUsers < ActiveRecord::Migration[7.2]
  def change
    create_table :users do |t|
      t.string :email,           null: false, index: { unique: true }
      t.string :password_digest, null: false
      t.string :firstname
      t.string :lastname

      t.string :role, default: "user", index: true

      t.boolean :verified, null: false, default: false

      t.integer :customer_jobs_count, default: 0
      t.integer :operator_jobs_count, default: 0
      t.integer :created_jobs_count, default: 0
      t.integer :cashed_jobs_count, default: 0

      t.timestamps
    end
    add_foreign_key :jobs, :users, column: :customer_id
    add_foreign_key :jobs, :users, column: :operator_id
    add_foreign_key :jobs, :users, column: :creator_id
    add_foreign_key :jobs, :users, column: :cashier_id
  end
end
