Skip to content

Commit

Permalink
Skip generating convert_token_id_to_integer? with Sequel
Browse files Browse the repository at this point in the history
That is Active Record specific code, so it would fail for Sequel models.
  • Loading branch information
janko committed May 23, 2024
1 parent 6152523 commit 9d2daf9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
9 changes: 6 additions & 3 deletions lib/generators/rodauth/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
5 changes: 3 additions & 2 deletions lib/generators/rodauth/templates/app/misc/rodauth_main.rb.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rodauth/templates/app/models/account.rb.tt
Original file line number Diff line number Diff line change
@@ -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") -%>
Expand Down

0 comments on commit 9d2daf9

Please sign in to comment.