2024-05-26 10:45:10 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-04-14 10:10:10 +00:00
|
|
|
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
|