I still think the problem is in sequel. What sequel-activerecord_connection
does is:
* Initiates a sequel database object via Sequel.connect with test: false,
to not initiate a db connection itself.
* loads the activerecord_connection extension, which injects the
plugin-specific methods.
I'm trying to get the first step working, which is all sequel. Here's how
it went for me:
1. Sequel.connect(adapter: "postgresql", test: false)
Sequel::AdapterNotFound (LoadError: no such file to load -- pg)
sequel doesn't try to automatically use jdbc in jruby, so it tries to load
an adapter which can't be used in jruby.
2. Sequel.connect(adapter: "jdbc:postgresql", test: false)
Sequel::AdapterNotFound (LoadError: no such file to load --
sequel/adapters/jdbc:postgresql)
Although I'm using a similar way of declaring the adapter as the one for
the full URI, jdbc isn't properly inferred here, and the file lookup
obviously fails.
3. Sequel.connect(adapter: "jdbc/postgresql", test: false)
NameError (uninitialized constant Sequel::JDBC)
I tried to work on the previous one by declaring the subpath, so the file
was required (good) but the constant doesn't exist (bad), which probably
means that the jdbc adapter has to be loaded first.
4. Sequel.connect(adapter: "jdbc", test: false)
=> #<Sequel::JDBC::Database: "jdbc:" {:adapter=>"jdbc", :test=>false}>
this one actually works... however, it doesn't load the jdbc
postgresql-specific code that I need, and then all of those errors I
reported in the beginning start happening.
In order for sequel-activerecord_connection to work for jruby, sequel must
allow to create a database object with the db-specific extensions and which
doesn't initiate a db connection; just like it's doing for the other
non-jruby adapters. IMO one of 1, 2, 3 must work in order for me to
accomplish this. Or is there another way of doing this for which I didn't
find documentation?
quarta-feira, 27 de Maio de 2020 às 00:23:32 UTC+1, Tiago Cardoso escreveu:
>
> 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/c11aa3aa-704c-438c-8b1f-b70251300f77%40googlegroups.com.