Hi Jeremy,

I'm working on adding support for jruby in rodauth-rails. I'm starting with 
postgres first. I tried naively to reuse the existing extensions, so that 
one would just call #execute on the activerecord connection 
(https://github.com/janko/sequel-activerecord_connection/blob/master/lib/sequel/extensions/activerecord_connection/postgres.rb#L5)
 
. It should just work, but it doesn't. Maybe you can help me find out. So, 
this is how I initiate things:

# activerecord first
ActiveRecord::Base.establish_connection(
        adapter:  "postgresql",
        database: "sequel_activerecord_connection",
        username: "sequel_activerecord_connection",
        password: "sequel_activerecord_connection",
      )
# sequel then
db = Sequel.connect(adapter: "jdbc", test: false)
db.extension :activerecord_connection

# and then, I create a table
db.create_table! :records do
      primary_key :id
      String :col
      Time :time
    end

Once I do that, I get an error:

D, [2020-05-26T14:18:37.927562 #68278] DEBUG -- :    (1.0ms)  BEGIN 
TRANSACTION
D, [2020-05-26T14:18:37.955206 #68278] DEBUG -- :    (18.0ms)  SELECT NULL 
AS "NIL" FROM "RECORDS" LIMIT 1
D, [2020-05-26T14:18:37.964119 #68278] DEBUG -- :    (3.4ms)  ROLLBACK 
TRANSACTION
E

Fabulous run in 18.546650s, 0.0539 runs/s, 0.0000 assertions/s.

  1) Error:
postgres connection#test_0001_supports Dataset#insert:
ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR: relation 
"RECORDS" does not exist
Position: 27
arjdbc/jdbc/RubyJdbcConnection.java:1087:in `execute_query'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activerecord-jdbc-adapter-60.2-java/lib/arjdbc/abstract/database_statements.rb:42:in
 
`block in exec_query'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:722:in
 
`block in log'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in
 
`block in synchronize'
    org/jruby/RubyThread.java:759:in `handle_interrupt'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in
 
`block in synchronize'
    org/jruby/RubyThread.java:759:in `handle_interrupt'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in
 
`synchronize'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:721:in
 
`block in log'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activesupport-6.0.3.1/lib/active_support/notifications/instrumenter.rb:24:in
 
`instrument'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract_adapter.rb:712:in
 
`log'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activerecord-jdbc-adapter-60.2-java/lib/arjdbc/abstract/core.rb:72:in
 
`log'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activerecord-jdbc-adapter-60.2-java/lib/arjdbc/abstract/database_statements.rb:42:in
 
`exec_query'
    
/dev/sequel-activerecord_connection/lib/sequel/extensions/activerecord_connection/jdbc.rb:6:in
 
`execute'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/sequel-5.32.0/lib/sequel/dataset/actions.rb:1089:in
 
`execute'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/sequel-5.32.0/lib/sequel/adapters/jdbc.rb:743:in
 
`fetch_rows'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/sequel-5.32.0/lib/sequel/dataset/actions.rb:152:in
 
`each'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/sequel-5.32.0/lib/sequel/dataset/actions.rb:715:in
 
`single_value'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/sequel-5.32.0/lib/sequel/dataset/actions.rb:310:in
 
`get'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/sequel-5.32.0/lib/sequel/database/query.rb:208:in
 
`_table_exists?'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/sequel-5.32.0/lib/sequel/database/query.rb:197:in
 
`block in table_exists?'
    
/dev/sequel-activerecord_connection/lib/sequel/extensions/activerecord_connection.rb:42:in
 
`block in transaction'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in
 
`block in transaction'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:280:in
 
`block in within_new_transaction'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in
 
`block in synchronize'
    org/jruby/RubyThread.java:759:in `handle_interrupt'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in
 
`block in synchronize'
    org/jruby/RubyThread.java:759:in `handle_interrupt'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in
 
`synchronize'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:278:in
 
`within_new_transaction'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in
 
`transaction'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/activerecord-6.0.3.1/lib/active_record/transactions.rb:212:in
 
`transaction'
    
/dev/sequel-activerecord_connection/lib/sequel/extensions/activerecord_connection.rb:39:in
 
`transaction'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/sequel-5.32.0/lib/sequel/database/query.rb:197:in
 
`table_exists?'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/sequel-5.32.0/lib/sequel/database/schema_methods.rb:350:in
 
`block in drop_table?'
    org/jruby/RubyArray.java:1809:in `each'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/sequel-5.32.0/lib/sequel/database/schema_methods.rb:349:in
 
`drop_table?'
    
/dev/sequel-activerecord_connection/.bundle/jruby/2.5.0/gems/sequel-5.32.0/lib/sequel/database/schema_methods.rb:207:in
 
`create_table!'
    test/postgres_test.rb:7:in `block in test/postgres_test.rb'
    org/jruby/RubyBasicObject.java:2615:in `instance_eval'


This happens for two reasons:

sequel falls back to using 
https://github.com/jeremyevans/sequel/blob/master/lib/sequel/database/schema_methods.rb#L349
 
, when it should be meeting the condition above, like the pg-based adapter 
does. sequel/shared/postgres sets the "supports_drop_table_if_exists?" to 
true, however this file (and condtion) doesn't seem to be picked up when 
using the jdbc adapter. This doesn't seem right,

The second is the error itself. The error appears because the table does 
not exist, however this is exactly what we want to test. It seems that some 
rescue for JDBC errors is missing somewhere.

That or I'm just setting this up real wrong.

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/fe21880a-9b8f-4872-84df-feea08edea15%40googlegroups.com.

Reply via email to