Method: AddRodauthTables#change

Defined in:
lib/osso/db/migrate/20201023142158_add_rodauth_tables.rb

#changeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/osso/db/migrate/20201023142158_add_rodauth_tables.rb', line 6

def change
  enable_extension "citext"

  create_table :accounts, id: :uuid do |t|
    t.citext :email, null: false, index: { unique: true, where: "status_id IN (1, 2)" }
    t.integer :status_id, null: false, default: 1
    t.string :role, null: false, default: 'admin'
    t.string :oauth_client_id, null: true, index: true
  end

  create_table :account_password_hashes, id: :uuid do |t|
    t.foreign_key :accounts, column: :id
    t.string :password_hash, null: false
  end

  Rodauth.create_database_authentication_functions(DB, table_name: "account_password_hashes")

  # Used by the password reset feature
  create_table :account_password_reset_keys, id: :uuid do |t|
    t.foreign_key :accounts, column: :id
    t.string :key, null: false
    t.datetime :deadline, null: false
    t.datetime :email_last_sent, null: false, default: -> { "CURRENT_TIMESTAMP" }
  end

  # Used by the account verification feature
  create_table :account_verification_keys, id: :uuid do |t|
    t.string :key, null: false
    t.datetime :requested_at, null: false, default: -> { "CURRENT_TIMESTAMP" }
    t.datetime :email_last_sent, null: false, default: -> { "CURRENT_TIMESTAMP" }
  end

  add_reference :account_verification_keys, :account, type: :uuid, index: true

  # Used by the remember me feature
  create_table :account_remember_keys, id: :uuid do |t|
    t.foreign_key :accounts, column: :id
    t.string :key, null: false
    t.datetime :deadline, null: false
  end
end