diff --git a/CHANGELOG.md b/CHANGELOG.md index 221af40..c33ba7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## HEAD + +* Avoid generating Active Record specific `convert_token_id_to_integer?` when Sequel is used + ## 1.14.1 (2024-05-15) * Fix matching on account status when passing Active Record object to `Rodauth::Rails.account` (@dush) diff --git a/lib/generators/rodauth/install_generator.rb b/lib/generators/rodauth/install_generator.rb index 8e97528..60fca2f 100644 --- a/lib/generators/rodauth/install_generator.rb +++ b/lib/generators/rodauth/install_generator.rb @@ -101,9 +101,12 @@ def argon2? options[:argon2] end - def sequel_activerecord_integration? - defined?(ActiveRecord::Railtie) && - (!defined?(Sequel) || Sequel::DATABASES.empty?) + def activerecord? + defined?(ActiveRecord::Railtie) + end + + def sequel? + defined?(Sequel) && Sequel::DATABASES.any? end def session_store? diff --git a/lib/generators/rodauth/templates/app/misc/rodauth_main.rb.tt b/lib/generators/rodauth/templates/app/misc/rodauth_main.rb.tt index 37cc201..ab61498 100644 --- a/lib/generators/rodauth/templates/app/misc/rodauth_main.rb.tt +++ b/lib/generators/rodauth/templates/app/misc/rodauth_main.rb.tt @@ -12,16 +12,17 @@ class RodauthMain < Rodauth::Rails::Auth # http://rodauth.jeremyevans.net/documentation.html # ==> General -<% if sequel_activerecord_integration? -%> +<% if activerecord? && !sequel? -%> # Initialize Sequel and have it reuse Active Record's database connection. <% if RUBY_ENGINE == "jruby" -%> db Sequel.connect("jdbc:<%= sequel_adapter %>://", extensions: :activerecord_connection, keep_reference: false) <% else -%> db Sequel.<%= sequel_adapter %>(extensions: :activerecord_connection, keep_reference: false) <% end -%> - +<% if activerecord? -%> # Avoid DB query that checks accounts table schema at boot time. convert_token_id_to_integer? { <%= table_prefix.camelize %>.columns_hash["id"].type == :integer } +<% end -%> <% end -%> # Change prefix of table and foreign key column names from default "account" diff --git a/lib/generators/rodauth/templates/app/models/account.rb.tt b/lib/generators/rodauth/templates/app/models/account.rb.tt index 3b68513..13257f2 100644 --- a/lib/generators/rodauth/templates/app/models/account.rb.tt +++ b/lib/generators/rodauth/templates/app/models/account.rb.tt @@ -1,4 +1,4 @@ -<% if defined?(ActiveRecord::Railtie) -%> +<% if activerecord? -%> class <%= table_prefix.camelize %> < ApplicationRecord include Rodauth::Rails.model <% if ActiveRecord.version >= Gem::Version.new("7.0") -%>