fractaledmind / activerecord-enhancedsqlite3-adapter

ActiveRecord adapter for SQLite that enhances the default. Back-ports generated column support, deferred foreign key support, custom foreign key support, improved default configuration, and adds support for pragma tuning and extension loading
MIT License
140 stars 4 forks source link

Compatibility with Rails 7.2 #23

Open westonganger opened 2 months ago

westonganger commented 2 months ago

I see that in the README it says

Enhance ActiveRecord's 7.1 SQLite3 adapter

Is this still accurate? I know that you merged some improvements to Rails core. Just wondering if this gem is expected to gracefully fallback with Rails 7.2 and the current state of Rails core.

westonganger commented 3 weeks ago

As a follow up question to this, is this gem recommended for Rails 8.0? (now that the beta has been released)

johnpitchko commented 5 days ago

I'm curious about this as well. I'm working on a rails 7.2 app and, after following the instructions listed here, I cannot get the ULID extensions to load.

airblade commented 5 days ago

@johnpitchko I'm running a Rails 7.2 app with the ULID extension as described in the readme. What error message are you getting?

For what it's worth, my Gemfile includes:

gem "activerecord-enhancedsqlite3-adapter", "~> 0.8.0"
gem "sqlite3", ">= 1.4"
gem "sqlite-ulid", "~> 0.2.1"

Which resolves to versions 0.8.0, 1.7.3-x86_64-{darwin,linux}, and 0.2.1-x86_64-{darwin,linux} respectively.

johnpitchko commented 4 days ago

Hi @airblade

ActiveRecord::Base.connection.execute("SELECT ULID_ENCODE(ULID_NEW())")
=> SQLite3::SQLException: no such function: ULID_NEW (ActiveRecord::StatementInvalid)

Now I noticed my Gemfile is:

gem "sqlite3", ">= 2.1"
gem "activerecord-enhancedsqlite3-adapter"
gem "sqlite-ulid", "0.2.1", platforms: %i[ruby_31]

meaning I'm using sqlite 2.1 - perhaps this version is not compatible with enhancedsqlite3?

johnpitchko commented 4 days ago

Doing some more testing - when I execute ActiveRecord::Base.connection.execute("SELECT ULID_ENCODE(ULID_NEW())") Rails does seem to call the #configure_extensions method in the enhanced adapter.

I dropped a debugger statement at the require statement on this line. Interestingly, when I run the require statement, I receive an error:

(ruby) require extension_name
eval error: cannot load such file -- sqlite_ulid
johnpitchko commented 4 days ago

Based on advice from ChatGPT, I deleted my Gemfile.lock and re-ran bundle. The sqlite-ulid gem installed successfully (or at least bundler didn't report any errors).

The require extension_name aka require "sqlite_ulid" line above executed successfully along with the rest of the #configure_extensions method.

Now I receive this error when testing generation of ULIDs:

ActiveRecord::Base.connection.execute("SELECT ULID_ENCODE(ULID_NEW())")
=> ():5:in `<main>': SQLite3::SQLException: no such function: ULID_NEW (ActiveRecord::StatementInvalid)

So maybe that SQL statement ☝️ was not correct

I then tried:

ActiveRecord::Base.connection.execute('select ulid();')
   (1.0ms)  select ulid();
=> [{"ulid()"=>"01japj3vc32th55re76cjp4s49"}]

Success!

airblade commented 3 days ago

@johnpitchko Glad you got it going!

meaning I'm using sqlite 2.1 - perhaps this version is not compatible with enhancedsqlite3?

This gem is compatible with sqlite 2.1 – see #15. It's not entirely clear to me whether Rails is yet.