activerecord-enhancedsqlite3-adapter icon indicating copy to clipboard operation
activerecord-enhancedsqlite3-adapter copied to clipboard

Compatibility with Rails 7.2 or Rails 8.0

Open westonganger opened this issue 1 year ago • 13 comments

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 avatar Aug 21 '24 17:08 westonganger

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

westonganger avatar Sep 30 '24 16:09 westonganger

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.

johnpitchko avatar Oct 20 '24 04:10 johnpitchko

@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.

airblade avatar Oct 20 '24 08:10 airblade

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 avatar Oct 20 '24 17:10 johnpitchko

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 avatar Oct 20 '24 17:10 johnpitchko

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!

johnpitchko avatar Oct 21 '24 03:10 johnpitchko

@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.

airblade avatar Oct 21 '24 13:10 airblade

For those waiting for an update. This should help:

image

thedumbtechguy avatar Nov 15 '24 11:11 thedumbtechguy

@thedumbtechguy thanks for the info. Do you have a link to that screenshots conversation?

westonganger avatar Nov 25 '24 23:11 westonganger

I'm having the same issues @johnpitchko. Using Rails 8.0, exact same gem versions.

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

I also added a debugger in the same file, and get a eval error: cannot load such file -- sqlite_ulid when I try to require extension_name.

I deleted the Gemfile.lock file a couple times, with no success on a reinstall. Is there another step I'm missing?

hslzr avatar Nov 29 '24 15:11 hslzr

I'm on vacation this week, but I'll sort this out next week

fractaledmind avatar Nov 29 '24 18:11 fractaledmind

I deleted the Gemfile.lock file a couple times, with no success on a reinstall. Is there another step I'm missing?

Its been awhile and I abandoned the project that I was considering this for. As best as I can remember, deleting and recreating the lock file was the only action I performed to resolve the error.

johnpitchko avatar Dec 02 '24 12:12 johnpitchko

I got sqlite-ulid and extension loading in Rails 8.0.2 by using the sqlpkg-ruby gem, described in SQLite on Rails: Loading Extensions.

bundle add sqlpkg
rails generate sqlpkg:install
bundle exec sqlpkg install asg017/ulid

Remove gem "sqlite-ulid" from the Gemfile and bundle.

# config/database.yml
default:
  adapter: sqlite3
  extensions:
    - <%= Sqlpkg.path_for("asg017/ulid") %>

With that, I felt I no longer needed this gem (i.e. activerecord-enhancedsqlite3-adapter).

airblade avatar Jul 02 '25 15:07 airblade