tabletop-companion/db/migrate/20240413152553_create_users.rb

24 lines
832 B
Ruby

class CreateUsers < ActiveRecord::Migration[7.1]
def change
create_table :users do |t|
t.string :username, null: false, limit: 20
t.string :password_digest, null: false, limit: 200
t.string :email, null: false, limit: 100
t.string :first_name, null: false, limit: 50
t.string :last_name, null: false, limit: 50, default: ""
t.timestamps
end
add_index :users, :username, unique: true
add_index :users, :email, unique: true
add_check_constraint :users, "length(username) >= 3",
name: "chk_username_min_length"
add_check_constraint :users, "length(email) >= 5",
name: "chk_email_min_length"
add_check_constraint :users, "length(first_name) >= 1",
name: "chk_first_name_min_length"
end
end