rodauth-rails 1.7.1 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/README.md +60 -28
  4. data/lib/generators/rodauth/install_generator.rb +36 -35
  5. data/lib/generators/rodauth/migration/active_record/account_expiration.erb +2 -2
  6. data/lib/generators/rodauth/migration/active_record/active_sessions.erb +4 -4
  7. data/lib/generators/rodauth/migration/active_record/audit_logging.erb +5 -5
  8. data/lib/generators/rodauth/migration/active_record/base.erb +1 -1
  9. data/lib/generators/rodauth/migration/active_record/disallow_password_reuse.erb +2 -2
  10. data/lib/generators/rodauth/migration/active_record/email_auth.erb +3 -2
  11. data/lib/generators/rodauth/migration/active_record/jwt_refresh.erb +3 -3
  12. data/lib/generators/rodauth/migration/active_record/lockout.erb +4 -4
  13. data/lib/generators/rodauth/migration/active_record/otp.erb +3 -3
  14. data/lib/generators/rodauth/migration/active_record/password_expiration.erb +3 -3
  15. data/lib/generators/rodauth/migration/active_record/recovery_codes.erb +2 -2
  16. data/lib/generators/rodauth/migration/active_record/remember.erb +2 -2
  17. data/lib/generators/rodauth/migration/active_record/reset_password.erb +3 -3
  18. data/lib/generators/rodauth/migration/active_record/single_session.erb +2 -2
  19. data/lib/generators/rodauth/migration/active_record/sms_codes.erb +3 -3
  20. data/lib/generators/rodauth/migration/active_record/verify_account.erb +4 -4
  21. data/lib/generators/rodauth/migration/active_record/verify_login_change.erb +2 -2
  22. data/lib/generators/rodauth/migration/active_record/webauthn.erb +5 -5
  23. data/lib/generators/rodauth/migration/sequel/account_expiration.erb +2 -2
  24. data/lib/generators/rodauth/migration/sequel/active_sessions.erb +3 -3
  25. data/lib/generators/rodauth/migration/sequel/audit_logging.erb +3 -3
  26. data/lib/generators/rodauth/migration/sequel/base.erb +1 -1
  27. data/lib/generators/rodauth/migration/sequel/disallow_password_reuse.erb +2 -2
  28. data/lib/generators/rodauth/migration/sequel/email_auth.erb +2 -2
  29. data/lib/generators/rodauth/migration/sequel/jwt_refresh.erb +3 -3
  30. data/lib/generators/rodauth/migration/sequel/lockout.erb +4 -4
  31. data/lib/generators/rodauth/migration/sequel/otp.erb +2 -2
  32. data/lib/generators/rodauth/migration/sequel/password_expiration.erb +2 -2
  33. data/lib/generators/rodauth/migration/sequel/recovery_codes.erb +2 -2
  34. data/lib/generators/rodauth/migration/sequel/remember.erb +2 -2
  35. data/lib/generators/rodauth/migration/sequel/reset_password.erb +2 -2
  36. data/lib/generators/rodauth/migration/sequel/single_session.erb +2 -2
  37. data/lib/generators/rodauth/migration/sequel/sms_codes.erb +2 -2
  38. data/lib/generators/rodauth/migration/sequel/verify_account.erb +2 -2
  39. data/lib/generators/rodauth/migration/sequel/verify_login_change.erb +2 -2
  40. data/lib/generators/rodauth/migration/sequel/webauthn.erb +5 -5
  41. data/lib/generators/rodauth/migration_generator.rb +45 -23
  42. data/lib/generators/rodauth/templates/app/mailers/{rodauth_mailer.rb → rodauth_mailer.rb.tt} +9 -7
  43. data/lib/generators/rodauth/templates/app/misc/{rodauth_main.rb → rodauth_main.rb.tt} +69 -10
  44. data/lib/generators/rodauth/templates/app/models/{account.rb → account.rb.tt} +2 -2
  45. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form.html.erb +1 -1
  46. data/lib/generators/rodauth/templates/app/views/rodauth/login.html.erb +2 -2
  47. data/lib/generators/rodauth/templates/app/views/rodauth/multi_phase_login.html.erb +2 -2
  48. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/_login_form.html.erb +1 -1
  49. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/login.html.erb +2 -2
  50. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/multi_phase_login.html.erb +2 -2
  51. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/webauthn_autofill.html.erb +10 -0
  52. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/webauthn_remove.html.erb +2 -2
  53. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_autofill.html.erb +10 -0
  54. data/lib/generators/rodauth/templates/app/views/rodauth_mailer/unlock_account.text.erb +1 -1
  55. data/lib/generators/rodauth/templates/db/migrate/{create_rodauth.rb → create_rodauth.rb.tt} +1 -1
  56. data/lib/generators/rodauth/templates/test/fixtures/{accounts.yml → accounts.yml.tt} +2 -2
  57. data/lib/generators/rodauth/views_generator.rb +3 -12
  58. data/lib/rodauth/rails/app.rb +18 -1
  59. data/lib/rodauth/rails/feature/base.rb +5 -39
  60. data/lib/rodauth/rails/feature/render.rb +1 -1
  61. data/lib/rodauth/rails/railtie.rb +2 -6
  62. data/lib/rodauth/rails/version.rb +1 -1
  63. data/lib/rodauth/rails.rb +0 -10
  64. data/rodauth-rails.gemspec +2 -2
  65. metadata +17 -18
  66. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form_header.html.erb +0 -3
  67. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/_login_form_header.html.erb +0 -3
  68. data/lib/generators/rodauth/templates/config/initializers/sequel.rb +0 -4
  69. /data/lib/generators/rodauth/templates/app/controllers/{rodauth_controller.rb → rodauth_controller.rb.tt} +0 -0
  70. /data/lib/generators/rodauth/templates/app/misc/{rodauth_app.rb → rodauth_app.rb.tt} +0 -0
  71. /data/lib/generators/rodauth/templates/config/initializers/{rodauth.rb → rodauth.rb.tt} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a0e7a34f68cd9914ad148799dcc5b83c5f8509d6d3278f57a26ebd497a8460c
4
- data.tar.gz: bfacb6b1ee374c5c0c1178d1a3b22a08bdb78626c1c91f3997a3c8572a8ede85
3
+ metadata.gz: 8f73ab003a11054b2534802c0de9224c867b7a173d8d553888918fa792ee3da4
4
+ data.tar.gz: 07136b1748df5970d5d263d5d9439596c3c2e083ccd88269ab7145a8cd73fefc
5
5
  SHA512:
6
- metadata.gz: eb5ff0efa4e19d89f864eea1e5d2e7541b2a198cff6af02ec281904e660bac5124d59842f602527e988ac958913724c54225fceb02ca834f1ee03cbf6a975f24
7
- data.tar.gz: 13350871f426602595dfa738b1a2016372f589788dfdd5d06ad5e915d351d2d5a4f3cec18c45871337153106c1f524ab27bae7f4c7f30c7e9fb2dbe02025c77d
6
+ metadata.gz: bc8c1a0ef2cd7d9c49f9fed9dd6423e92ec4112ddaa65b5a8fa63134f35d5fa9b5f2f1679c4d4d7f4d9f3cd5a71acf840d4d59ce2731b52d82914c200744eb03
7
+ data.tar.gz: 41f707560dd3ce232f54c80bc83f2210d4667d715c5f25aab812382a54f4115cab03d3e8e23d1c8c8b1e5e572404c91b332b040b741648c2577499779c0bf6a1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,39 @@
1
+ ## 1.9.0 (2023-05-22)
2
+
3
+ * Add support for webauthn_autofill feature to the views generator (@janko)
4
+
5
+ * Generate view templates for two_factor_base feature only if explicitly specified (@janko)
6
+
7
+ * Set `login_param "email"` in generated Rodauth configuration (@janko)
8
+
9
+ * Handle Trilogy adapter in generators (@janko)
10
+
11
+ * Use `email_subject_prefix` in generated mailer (@janko)
12
+
13
+ * Fix typo in `unlock_account` email template (@zavan)
14
+
15
+ * Retrieve current account using `account!` in `#rails_account` method (@janko)
16
+
17
+ * Drop support for Rails 4.2 (@janko)
18
+
19
+ ## 1.8.0 (2023-02-25)
20
+
21
+ * Add table argument to `rodauth:install` generator (@janko)
22
+
23
+ * Add `--prefix` option to `rodauth:migration` generator for choosing table prefix (@janko)
24
+
25
+ * Add `--argon2` option to `rodauth:install` generator for configuring password hashing using Argon2 (@janko)
26
+
27
+ * Move generated Sequel setup from initializer into the Rodauth configuration for faster boot time (@janko)
28
+
29
+ * Use `email_to` and `email_from` Rodauth methods in generated mailer (@janko)
30
+
31
+ * Add missing foreign key constraint in `email_auth` Active Record migration (@janko)
32
+
33
+ * Correctly retrieve JSON request body when using Falcon (@janko)
34
+
35
+ * Render validation error correctly in generated `webauthn_remove` Tailwind template (@janko)
36
+
1
37
  ## 1.7.1 (2023-01-25)
2
38
 
3
39
  * Make internal_request integration work on Rack 3.x (@janko)
data/README.md CHANGED
@@ -31,16 +31,13 @@ There are already several popular authentication solutions for Rails (Devise,
31
31
  Sorcery, Clearance, Authlogic), so why would you choose Rodauth? Here are some
32
32
  of the advantages that stand out for me:
33
33
 
34
- * multifactor authentication ([TOTP][otp], [SMS codes][sms_codes], [recovery codes][recovery_codes], [WebAuthn][webauthn])
34
+ * multifactor authentication ([TOTP][otp], [SMS codes][sms_codes], [recovery codes][recovery_codes], [passkeys][webauthn])
35
35
  * standardized [JSON API support][json] for every feature (including [JWT][jwt])
36
36
  * enterprise security features ([password complexity][password_complexity], [disallow password reuse][disallow_password_reuse], [password expiration][password_expiration], [session expiration][session_expiration], [single session][single_session], [account expiration][account_expiration])
37
- * [email authentication][email_auth] (aka "passwordless")
38
- * [audit logging][audit_logging] (for any action)
37
+ * passwordless authentication ([email][email_auth], [passkeys][webauthn_login])
38
+ * [audit logging][audit_logging] for any action
39
39
  * ability to protect password hashes even in case of SQL injection ([more details][password protection])
40
- * additional bruteforce protection for tokens ([more details][bruteforce tokens])
41
- * uniform configuration DSL (any setting can be static or dynamic)
42
- * consistent before/after hooks around everything
43
- * dedicated object encapsulating all authentication logic
40
+ * uniform configuration DSL with before/after hooks around everything
44
41
 
45
42
  ### Sequel
46
43
 
@@ -70,7 +67,13 @@ Next, run the install generator:
70
67
  $ rails generate rodauth:install
71
68
  ```
72
69
 
73
- Or if you want Rodauth endpoints to be exposed via [JSON API]:
70
+ This will use the `accounts` table. If you want a different table name:
71
+
72
+ ```sh
73
+ $ rails generate rodauth:install users
74
+ ```
75
+
76
+ If you want Rodauth endpoints to be exposed via [JSON API]:
74
77
 
75
78
  ```sh
76
79
  $ rails generate rodauth:install --json # regular authentication using the Rails session
@@ -79,6 +82,13 @@ $ rails generate rodauth:install --jwt # token authentication via the "Authoriza
79
82
  $ bundle add jwt
80
83
  ```
81
84
 
85
+ To use Argon2 instead of bcrypt for password hashing:
86
+
87
+ ```sh
88
+ $ rails generate rodauth:install --argon2
89
+ $ bundle add argon2
90
+ ```
91
+
82
92
  This generator will create a Rodauth app and configuration with common
83
93
  authentication features enabled, a database migration with tables required by
84
94
  those features, a mailer with default templates, and a few other files.
@@ -180,12 +190,9 @@ session will be reset.
180
190
 
181
191
  #### Custom account model
182
192
 
183
- The `#rails_account` method will try to infer the account model class from
184
- the configured table name. For example, if the `accounts_table` is set to
185
- `:users`, it will automatically assume the model class of `User`.
186
-
187
- However, if the model class cannot be inferred from the table name, you can
188
- configure it manually:
193
+ The `#rails_account` method will try to infer the account model class from the
194
+ configured accounts table name. However, if the model class cannot be inferred
195
+ from the table name, you can configure it manually:
189
196
 
190
197
  ```rb
191
198
  # app/misc/rodauth_main.rb
@@ -339,7 +346,7 @@ $ rails generate rodauth:views --all
339
346
  Use `--name` to generate views for a different Rodauth configuration:
340
347
 
341
348
  ```sh
342
- $ rails generate rodauth:views webauthn --name admin
349
+ $ rails generate rodauth:views webauthn two_factor_base --name admin
343
350
  ```
344
351
 
345
352
  #### Page titles
@@ -499,7 +506,7 @@ page][custom mailer worker] on how to set it up.
499
506
 
500
507
  The install generator will create a migration for tables used by the Rodauth
501
508
  features enabled by default. For any additional features, you can use the
502
- migration generator to create the corresponding tables:
509
+ migration generator for creating the required tables:
503
510
 
504
511
  ```sh
505
512
  $ rails generate rodauth:migration otp sms_codes recovery_codes
@@ -515,6 +522,30 @@ class CreateRodauthOtpSmsCodesRecoveryCodes < ActiveRecord::Migration
515
522
  end
516
523
  ```
517
524
 
525
+ #### Table prefix
526
+
527
+ If you're storing account records in a table other than `accounts`, you'll want
528
+ to specify the correct table prefix when generating new migrations:
529
+
530
+ ```sh
531
+ $ rails generate rodauth:migration base active_sessions --prefix user
532
+
533
+ # Add the following to your Rodauth configuration:
534
+ #
535
+ # accounts_table :users
536
+ # active_sessions_table :user_active_session_keys
537
+ # active_sessions_account_id_column :user_id
538
+ ```
539
+ ```rb
540
+ # db/migration/*_create_rodauth_user_base_active_sessions.rb
541
+ class CreateRodauthUserBaseActiveSessions < ActiveRecord::Migration
542
+ def change
543
+ create_table :users do |t| ... end
544
+ create_table :user_active_session_keys do |t| ... end
545
+ end
546
+ end
547
+ ```
548
+
518
549
  #### Custom migration name
519
550
 
520
551
  You can change the default migration name:
@@ -821,32 +852,27 @@ documentation].
821
852
  ### Defining custom methods
822
853
 
823
854
  All Rodauth configuration methods are just syntax sugar for defining instance
824
- methods on the auth class. You can also define your own custom methods on the
825
- auth class:
855
+ methods on the auth class. You can also define your own custom methods:
826
856
 
827
857
  ```rb
828
858
  class RodauthMain < Rodauth::Rails::Auth
829
859
  configure do
830
- # ...
831
860
  password_match? { |password| ldap_valid?(password) }
832
- # ...
833
861
  end
834
862
 
835
- # Example external identities table
836
- def identities
837
- db[:account_identities].where(account_id: account_id).all
863
+ def admin?
864
+ rails_account.admin?
838
865
  end
839
866
 
840
867
  private
841
868
 
842
- # Example LDAP authentication
843
869
  def ldap_valid?(password)
844
870
  SimpleLdapAuthenticator.valid?(account[:email], password)
845
871
  end
846
872
  end
847
873
  ```
848
874
  ```rb
849
- rodauth.identities #=> [{ provider: "facebook", uid: "abc123", ... }, ...]
875
+ rodauth.admin? #=> true
850
876
  ```
851
877
 
852
878
  ### Rails URL helpers
@@ -1103,11 +1129,17 @@ require "rodauth/migrations"
1103
1129
 
1104
1130
  class CreateRodauthDatabaseFunctions < ActiveRecord::Migration
1105
1131
  def up
1106
- Rodauth.create_database_authentication_functions(DB)
1132
+ Rodauth.create_database_authentication_functions(db)
1107
1133
  end
1108
1134
 
1109
1135
  def down
1110
- Rodauth.drop_database_authentication_functions(DB)
1136
+ Rodauth.drop_database_authentication_functions(db)
1137
+ end
1138
+
1139
+ private
1140
+
1141
+ def db
1142
+ RodauthMain.allocate.db
1111
1143
  end
1112
1144
  end
1113
1145
  ```
@@ -1187,12 +1219,12 @@ conduct](CODE_OF_CONDUCT.md).
1187
1219
  [sms_codes]: http://rodauth.jeremyevans.net/rdoc/files/doc/sms_codes_rdoc.html
1188
1220
  [recovery_codes]: http://rodauth.jeremyevans.net/rdoc/files/doc/recovery_codes_rdoc.html
1189
1221
  [webauthn]: http://rodauth.jeremyevans.net/rdoc/files/doc/webauthn_rdoc.html
1222
+ [webauthn_login]: http://rodauth.jeremyevans.net/rdoc/files/doc/webauthn_login_rdoc.html
1190
1223
  [json]: http://rodauth.jeremyevans.net/rdoc/files/doc/json_rdoc.html
1191
1224
  [jwt]: http://rodauth.jeremyevans.net/rdoc/files/doc/jwt_rdoc.html
1192
1225
  [email_auth]: http://rodauth.jeremyevans.net/rdoc/files/doc/email_auth_rdoc.html
1193
1226
  [audit_logging]: http://rodauth.jeremyevans.net/rdoc/files/doc/audit_logging_rdoc.html
1194
1227
  [password protection]: https://github.com/jeremyevans/rodauth#label-Password+Hash+Access+Via+Database+Functions
1195
- [bruteforce tokens]: https://github.com/jeremyevans/rodauth#label-Tokens
1196
1228
  [password_complexity]: http://rodauth.jeremyevans.net/rdoc/files/doc/password_complexity_rdoc.html
1197
1229
  [disallow_password_reuse]: http://rodauth.jeremyevans.net/rdoc/files/doc/disallow_password_reuse_rdoc.html
1198
1230
  [password_expiration]: http://rodauth.jeremyevans.net/rdoc/files/doc/password_expiration_rdoc.html
@@ -5,19 +5,13 @@ module Rodauth
5
5
  module Rails
6
6
  module Generators
7
7
  class InstallGenerator < ::Rails::Generators::Base
8
- if RUBY_ENGINE == "jruby"
9
- SEQUEL_ADAPTERS = {
10
- "sqlite3" => "sqlite",
11
- "oracle_enhanced" => "oracle", # https://github.com/rsim/oracle-enhanced
12
- "sqlserver" => "mssql",
13
- }
14
- else
15
- SEQUEL_ADAPTERS = {
16
- "sqlite3" => "sqlite",
17
- "oracle_enhanced" => "oracle", # https://github.com/rsim/oracle-enhanced
18
- "sqlserver" => "tinytds", # https://github.com/rails-sqlserver/activerecord-sqlserver-adapter
19
- }
20
- end
8
+ SEQUEL_ADAPTERS = {
9
+ "postgresql" => RUBY_ENGINE == "jruby" ? "postgresql" : "postgres",
10
+ "mysql2" => RUBY_ENGINE == "jruby" ? "mysql" : "mysql2",
11
+ "sqlite3" => "sqlite",
12
+ "oracle_enhanced" => "oracle",
13
+ "sqlserver" => RUBY_ENGINE == "jruby" ? "mssql" : "tinytds",
14
+ }
21
15
 
22
16
  MAILER_VIEWS = %w[
23
17
  email_auth
@@ -31,24 +25,23 @@ module Rodauth
31
25
  source_root "#{__dir__}/templates"
32
26
  namespace "rodauth:install"
33
27
 
28
+ argument :table, optional: true, type: :string, desc: "Name of the accounts table"
29
+
30
+ class_option :prefix, type: :string, desc: "Change name for account tables"
31
+ class_option :argon2, type: :boolean, desc: "Use Argon2 for password hashing"
34
32
  class_option :json, type: :boolean, desc: "Configure JSON support"
35
33
  class_option :jwt, type: :boolean, desc: "Configure JWT support"
36
34
 
37
- def create_rodauth_migration
38
- invoke "rodauth:migration", migration_features, name: "create_rodauth"
35
+ def generate_rodauth_migration
36
+ invoke "rodauth:migration", migration_features,
37
+ name: "create_rodauth",
38
+ prefix: table_prefix
39
39
  end
40
40
 
41
41
  def create_rodauth_initializer
42
42
  template "config/initializers/rodauth.rb"
43
43
  end
44
44
 
45
- def create_sequel_initializer
46
- return unless defined?(ActiveRecord::Railtie)
47
- return if defined?(Sequel) && !Sequel::DATABASES.empty?
48
-
49
- template "config/initializers/sequel.rb"
50
- end
51
-
52
45
  def create_rodauth_app
53
46
  template "app/misc/rodauth_app.rb"
54
47
  template "app/misc/rodauth_main.rb"
@@ -59,7 +52,7 @@ module Rodauth
59
52
  end
60
53
 
61
54
  def create_account_model
62
- template "app/models/account.rb"
55
+ template "app/models/account.rb", "app/models/#{table_prefix}.rb"
63
56
  end
64
57
 
65
58
  def create_mailer
@@ -73,13 +66,10 @@ module Rodauth
73
66
  end
74
67
 
75
68
  def create_fixtures
76
- test_unit_options = ::Rails.application.config.generators.options[:test_unit]
77
- if test_unit_options[:fixture] && test_unit_options[:fixture_replacement].nil?
78
- if ::Rails.application.config.generators.options[:rails][:test_framework] == :rspec
79
- template "test/fixtures/accounts.yml", "spec/fixtures/accounts.yml"
80
- else
81
- template "test/fixtures/accounts.yml", "test/fixtures/accounts.yml"
82
- end
69
+ generator_options = ::Rails.application.config.generators.options
70
+ if generator_options[:test_unit][:fixture] && generator_options[:test_unit][:fixture_replacement].nil?
71
+ test_dir = generator_options[:rails][:test_framework] == :rspec ? "spec" : "test"
72
+ template "test/fixtures/accounts.yml", "#{test_dir}/fixtures/#{table_prefix.pluralize}.yml"
83
73
  end
84
74
  end
85
75
 
@@ -95,6 +85,10 @@ module Rodauth
95
85
  features
96
86
  end
97
87
 
88
+ def table_prefix
89
+ table&.underscore&.singularize || "account"
90
+ end
91
+
98
92
  def json?
99
93
  options[:json] || api_only? && session_store? && !options[:jwt]
100
94
  end
@@ -103,18 +97,25 @@ module Rodauth
103
97
  options[:jwt] || api_only? && !session_store? && !options[:json]
104
98
  end
105
99
 
100
+ def argon2?
101
+ options[:argon2]
102
+ end
103
+
104
+ def sequel_activerecord_integration?
105
+ defined?(ActiveRecord::Railtie) &&
106
+ (!defined?(Sequel) || Sequel::DATABASES.empty?)
107
+ end
108
+
106
109
  def session_store?
107
110
  !!::Rails.application.config.session_store
108
111
  end
109
112
 
110
113
  def api_only?
111
- Rodauth::Rails.api_only?
114
+ ::Rails.application.config.api_only
112
115
  end
113
116
 
114
- def sequel_uri_scheme
115
- scheme = SEQUEL_ADAPTERS[activerecord_adapter] || activerecord_adapter
116
- scheme = "jdbc:#{scheme}" if RUBY_ENGINE == "jruby"
117
- scheme
117
+ def sequel_adapter
118
+ SEQUEL_ADAPTERS[activerecord_adapter] || activerecord_adapter
118
119
  end
119
120
 
120
121
  def activerecord_adapter
@@ -1,7 +1,7 @@
1
1
  # Used by the account expiration feature
2
- create_table :account_activity_times, id: false do |t|
2
+ create_table :<%= table_prefix %>_activity_times, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
- t.foreign_key :accounts, column: :id
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
5
  t.datetime :last_activity_at, null: false
6
6
  t.datetime :last_login_at, null: false
7
7
  t.datetime :expired_at
@@ -1,7 +1,7 @@
1
1
  # Used by the active sessions feature
2
- create_table :account_active_session_keys, primary_key: [:account_id, :session_id] do |t|
3
- t.references :account, foreign_key: true<%= primary_key_type(:type) %>
2
+ create_table :<%= table_prefix %>_active_session_keys, primary_key: [:<%= table_prefix %>_id, :session_id] do |t|
3
+ t.references :<%= table_prefix %>, foreign_key: true<%= primary_key_type(:type) %>
4
4
  t.string :session_id
5
- t.datetime :created_at, null: false, default: <%= current_timestamp %>
6
- t.datetime :last_use, null: false, default: <%= current_timestamp %>
5
+ t.datetime :created_at, null: false, default: -> { "<%= current_timestamp %>" }
6
+ t.datetime :last_use, null: false, default: -> { "<%= current_timestamp %>" }
7
7
  end
@@ -1,16 +1,16 @@
1
1
  # Used by the audit logging feature
2
- create_table :account_authentication_audit_logs<%= primary_key_type %> do |t|
3
- t.references :account, foreign_key: true, null: false<%= primary_key_type(:type) %>
4
- t.datetime :at, null: false, default: <%= current_timestamp %>
2
+ create_table :<%= table_prefix %>_authentication_audit_logs<%= primary_key_type %> do |t|
3
+ t.references :<%= table_prefix %>, foreign_key: true, null: false<%= primary_key_type(:type) %>
4
+ t.datetime :at, null: false, default: -> { "<%= current_timestamp %>" }
5
5
  t.text :message, null: false
6
6
  <% case activerecord_adapter -%>
7
7
  <% when "postgresql" -%>
8
8
  t.jsonb :metadata
9
- <% when "sqlite3", "mysql2" -%>
9
+ <% when "sqlite3", "mysql2", "trilogy" -%>
10
10
  t.json :metadata
11
11
  <% else -%>
12
12
  t.string :metadata
13
13
  <% end -%>
14
- t.index [:account_id, :at], name: "audit_account_at_idx"
14
+ t.index [:<%= table_prefix %>_id, :at], name: "audit_<%= table_prefix %>_at_idx"
15
15
  t.index :at, name: "audit_at_idx"
16
16
  end
@@ -2,7 +2,7 @@
2
2
  enable_extension "citext"
3
3
 
4
4
  <% end -%>
5
- create_table :accounts<%= primary_key_type %> do |t|
5
+ create_table :<%= table_prefix.pluralize %><%= primary_key_type %> do |t|
6
6
  t.integer :status, null: false, default: 1
7
7
  <% case activerecord_adapter -%>
8
8
  <% when "postgresql" -%>
@@ -1,5 +1,5 @@
1
1
  # Used by the disallow password reuse feature
2
- create_table :account_previous_password_hashes do |t|
3
- t.references :account, foreign_key: true<%= primary_key_type(:type) %>
2
+ create_table :<%= table_prefix %>_previous_password_hashes do |t|
3
+ t.references :<%= table_prefix %>, foreign_key: true<%= primary_key_type(:type) %>
4
4
  t.string :password_hash, null: false
5
5
  end
@@ -1,7 +1,8 @@
1
1
  # Used by the email auth feature
2
- create_table :account_email_auth_keys, id: false do |t|
2
+ create_table :<%= table_prefix %>_email_auth_keys, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
4
5
  t.string :key, null: false
5
6
  t.datetime :deadline, null: false
6
- t.datetime :email_last_sent, null: false, default: <%= current_timestamp %>
7
+ t.datetime :email_last_sent, null: false, default: -> { "<%= current_timestamp %>" }
7
8
  end
@@ -1,7 +1,7 @@
1
1
  # Used by the jwt refresh feature
2
- create_table :account_jwt_refresh_keys<%= primary_key_type %> do |t|
3
- t.references :account, foreign_key: true, null: false<%= primary_key_type(:type) %>
2
+ create_table :<%= table_prefix %>_jwt_refresh_keys<%= primary_key_type %> do |t|
3
+ t.references :<%= table_prefix %>, foreign_key: true, null: false<%= primary_key_type(:type) %>
4
4
  t.string :key, null: false
5
5
  t.datetime :deadline, null: false
6
- t.index :account_id, name: "account_jwt_rk_account_id_idx"
6
+ t.index :<%= table_prefix %>_id, name: "<%= table_prefix %>_jwt_rk_<%= table_prefix %>_id_idx"
7
7
  end
@@ -1,12 +1,12 @@
1
1
  # Used by the lockout feature
2
- create_table :account_login_failures, id: false do |t|
2
+ create_table :<%= table_prefix %>_login_failures, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
- t.foreign_key :accounts, column: :id
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
5
  t.integer :number, null: false, default: 1
6
6
  end
7
- create_table :account_lockouts, id: false do |t|
7
+ create_table :<%= table_prefix %>_lockouts, id: false do |t|
8
8
  t.<%= primary_key_type(nil) %> :id, primary_key: true
9
- t.foreign_key :accounts, column: :id
9
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
10
10
  t.string :key, null: false
11
11
  t.datetime :deadline, null: false
12
12
  t.datetime :email_last_sent
@@ -1,8 +1,8 @@
1
1
  # Used by the otp feature
2
- create_table :account_otp_keys, id: false do |t|
2
+ create_table :<%= table_prefix %>_otp_keys, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
- t.foreign_key :accounts, column: :id
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
5
  t.string :key, null: false
6
6
  t.integer :num_failures, null: false, default: 0
7
- t.datetime :last_use, null: false, default: <%= current_timestamp %>
7
+ t.datetime :last_use, null: false, default: -> { "<%= current_timestamp %>" }
8
8
  end
@@ -1,6 +1,6 @@
1
1
  # Used by the password expiration feature
2
- create_table :account_password_change_times, id: false do |t|
2
+ create_table :<%= table_prefix %>_password_change_times, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
- t.foreign_key :accounts, column: :id
5
- t.datetime :changed_at, null: false, default: <%= current_timestamp %>
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
+ t.datetime :changed_at, null: false, default: -> { "<%= current_timestamp %>" }
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # Used by the recovery codes feature
2
- create_table :account_recovery_codes, primary_key: [:id, :code] do |t|
2
+ create_table :<%= table_prefix %>_recovery_codes, primary_key: [:id, :code] do |t|
3
3
  t.<%= primary_key_type(nil) %> :id
4
- t.foreign_key :accounts, column: :id
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
5
  t.string :code
6
6
  end
@@ -1,7 +1,7 @@
1
1
  # Used by the remember me feature
2
- create_table :account_remember_keys, id: false do |t|
2
+ create_table :<%= table_prefix %>_remember_keys, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
- t.foreign_key :accounts, column: :id
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
5
  t.string :key, null: false
6
6
  t.datetime :deadline, null: false
7
7
  end
@@ -1,8 +1,8 @@
1
1
  # Used by the password reset feature
2
- create_table :account_password_reset_keys, id: false do |t|
2
+ create_table :<%= table_prefix %>_password_reset_keys, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
- t.foreign_key :accounts, column: :id
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
5
  t.string :key, null: false
6
6
  t.datetime :deadline, null: false
7
- t.datetime :email_last_sent, null: false, default: <%= current_timestamp %>
7
+ t.datetime :email_last_sent, null: false, default: -> { "<%= current_timestamp %>" }
8
8
  end
@@ -1,6 +1,6 @@
1
1
  # Used by the single session feature
2
- create_table :account_session_keys, id: false do |t|
2
+ create_table :<%= table_prefix %>_session_keys, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
- t.foreign_key :accounts, column: :id
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
5
  t.string :key, null: false
6
6
  end
@@ -1,9 +1,9 @@
1
1
  # Used by the sms codes feature
2
- create_table :account_sms_codes, id: false do |t|
2
+ create_table :<%= table_prefix %>_sms_codes, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
- t.foreign_key :accounts, column: :id
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
5
  t.string :phone_number, null: false
6
6
  t.integer :num_failures
7
7
  t.string :code
8
- t.datetime :code_issued_at, null: false, default: <%= current_timestamp %>
8
+ t.datetime :code_issued_at, null: false, default: -> { "<%= current_timestamp %>" }
9
9
  end
@@ -1,8 +1,8 @@
1
1
  # Used by the account verification feature
2
- create_table :account_verification_keys, id: false do |t|
2
+ create_table :<%= table_prefix %>_verification_keys, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
- t.foreign_key :accounts, column: :id
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
5
  t.string :key, null: false
6
- t.datetime :requested_at, null: false, default: <%= current_timestamp %>
7
- t.datetime :email_last_sent, null: false, default: <%= current_timestamp %>
6
+ t.datetime :requested_at, null: false, default: -> { "<%= current_timestamp %>" }
7
+ t.datetime :email_last_sent, null: false, default: -> { "<%= current_timestamp %>" }
8
8
  end
@@ -1,7 +1,7 @@
1
1
  # Used by the verify login change feature
2
- create_table :account_login_change_keys, id: false do |t|
2
+ create_table :<%= table_prefix %>_login_change_keys, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
- t.foreign_key :accounts, column: :id
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
5
  t.string :key, null: false
6
6
  t.string :login, null: false
7
7
  t.datetime :deadline, null: false
@@ -1,13 +1,13 @@
1
1
  # Used by the webauthn feature
2
- create_table :account_webauthn_user_ids, id: false do |t|
2
+ create_table :<%= table_prefix %>_webauthn_user_ids, id: false do |t|
3
3
  t.<%= primary_key_type(nil) %> :id, primary_key: true
4
- t.foreign_key :accounts, column: :id
4
+ t.foreign_key :<%= table_prefix.pluralize %>, column: :id
5
5
  t.string :webauthn_id, null: false
6
6
  end
7
- create_table :account_webauthn_keys, primary_key: [:account_id, :webauthn_id] do |t|
8
- t.references :account, foreign_key: true<%= primary_key_type(:type) %>
7
+ create_table :<%= table_prefix %>_webauthn_keys, primary_key: [:<%= table_prefix %>_id, :webauthn_id] do |t|
8
+ t.references :<%= table_prefix %>, foreign_key: true<%= primary_key_type(:type) %>
9
9
  t.string :webauthn_id
10
10
  t.string :public_key, null: false
11
11
  t.integer :sign_count, null: false
12
- t.datetime :last_use, null: false, default: <%= current_timestamp %>
12
+ t.datetime :last_use, null: false, default: -> { "<%= current_timestamp %>" }
13
13
  end
@@ -1,6 +1,6 @@
1
1
  # Used by the account expiration feature
2
- create_table :account_activity_times do
3
- foreign_key :id, :accounts, primary_key: true, type: :Bignum
2
+ create_table :<%= table_prefix %>_activity_times do
3
+ foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
4
4
  DateTime :last_activity_at, null: false
5
5
  DateTime :last_login_at, null: false
6
6
  DateTime :expired_at
@@ -1,8 +1,8 @@
1
1
  # Used by the active sessions feature
2
- create_table :account_active_session_keys do
3
- foreign_key :account_id, :accounts, type: :Bignum
2
+ create_table :<%= table_prefix %>_active_session_keys do
3
+ foreign_key :<%= table_prefix %>_id, :<%= table_prefix.pluralize %>, type: :Bignum
4
4
  String :session_id
5
5
  Time :created_at, null: false, default: Sequel::CURRENT_TIMESTAMP
6
6
  Time :last_use, null: false, default: Sequel::CURRENT_TIMESTAMP
7
- primary_key [:account_id, :session_id]
7
+ primary_key [:<%= table_prefix %>_id, :session_id]
8
8
  end
@@ -1,7 +1,7 @@
1
1
  # Used by the audit logging feature
2
- create_table :account_authentication_audit_logs do
2
+ create_table :<%= table_prefix %>_authentication_audit_logs do
3
3
  primary_key :id, type: :Bignum
4
- foreign_key :account_id, :accounts, null: false, type: :Bignum
4
+ foreign_key :<%= table_prefix %>_id, :<%= table_prefix.pluralize %>, null: false, type: :Bignum
5
5
  DateTime :at, null: false, default: Sequel::CURRENT_TIMESTAMP
6
6
  String :message, null: false
7
7
  <% case db.database_type -%>
@@ -12,6 +12,6 @@ create_table :account_authentication_audit_logs do
12
12
  <% else -%>
13
13
  String :metadata
14
14
  <% end -%>
15
- index [:account_id, :at], name: :audit_account_at_idx
15
+ index [:<%= table_prefix %>_id, :at], name: :audit_<%= table_prefix %>_at_idx
16
16
  index :at, name: :audit_at_idx
17
17
  end