Problem creating separate tables for admin #50
-
Hi @janko, I'm trying to create a separate table for admins and I'm getting the following error:
(Please see the full logs below.) I've got
I created ALL the tables for class CreateAdminAccountTables < ActiveRecord::Migration[6.0]
def change
enable_extension "citext"
create_table :admin_accounts do |t|
t.citext :email, null: false, index: { unique: true, where: "status IN ('unverified', 'verified')" }
t.string :status, null: false, default: "unverified"
t.string :role, null: false, default: "admin"
end
# Used if storing password hashes in a separate table (default)
create_table :admin_account_password_hashes do |t|
t.foreign_key :admin_accounts, column: :id
t.string :password_hash, null: false
end
# Used by the password reset feature
create_table :admin_account_password_reset_keys do |t|
t.foreign_key :admin_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 :admin_account_verification_keys do |t|
t.foreign_key :admin_accounts, column: :id
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
# Used by the verify login change feature
create_table :admin_account_login_change_keys do |t|
t.foreign_key :admin_accounts, column: :id
t.string :key, null: false
t.string :login, null: false
t.datetime :deadline, null: false
end
# Used by the remember me feature
create_table :admin_account_remember_keys do |t|
t.foreign_key :admin_accounts, column: :id
t.string :key, null: false
t.datetime :deadline, null: false
end
end
end The problem is an insert into I searched the docs and issues about this, hoping that I needed to set the table names for the other tables needed like this in
But I couldn't find anything. Can you please let me what I'm missing or doing wrong? Thank you so much! Holden Full logs:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
For table name configuration methods I typically open the corresponding feature documentation and search for the term "table". In your case, the correct configuration would be: reset_password_table :admin_account_password_reset_keys
verify_account_table :admin_account_verification_keys
verify_login_change_table :admin_account_login_change_keys
remember_table :admin_account_remember_keys Note that in your case all table names are the default table names prefixed with methods.grep(/_table$/) do |table_method|
public_send(table_method) { :"admin_#{super()}" }
end |
Beta Was this translation helpful? Give feedback.
For table name configuration methods I typically open the corresponding feature documentation and search for the term "table". In your case, the correct configuration would be:
Note that in your case all table names are the default table names prefixed with
admin_*
, so you could DRY up the logic to make it work for any future features as well: