Last Update: 2020-06-30 15:06:09 -0700

Store account status in a text column

By default, Rodauth recommends using a separate table for account statuses, and linking them via foreign keys. This is useful as it achieves an enum-like behaviour, where the database ensures a constrained set of status values.

However, if you use a testing environment that starts with a blank database, and don't want to fix your testing environment to support real foreign keys, you can configure Rodauth to store the account status in a text column. Doing so results in problems if a text value you do not expect gets stored in the column. We can mitigate the problems by using a CHECK constraint on the column.

create_table :accounts do
  # ...
  String :status, null: false, default: "verified",
    check: {status: %w'unverified verified closed'}

Then we can configure Rodauth to support this.

plugin :rodauth do
  # ...
  account_status_column :status
  account_unverified_status_value "unverified"
  account_open_status_value "verified"
  account_closed_status_value "closed"