Skip to content

Fixes for Rails 8 (and others)#17

Closed
yostinso wants to merge 3 commits intobart-oz:mainfrom
yostinso:fix_generators_rails_8
Closed

Fixes for Rails 8 (and others)#17
yostinso wants to merge 3 commits intobart-oz:mainfrom
yostinso:fix_generators_rails_8

Conversation

@yostinso
Copy link

@yostinso yostinso commented Feb 4, 2026

In trying to adopt this gem into a fresh Rails 8.1 project, I ran across a couple of bugs:

  • First, I couldn't run the generator; it wasn't being autodiscovered by Rails. Some Claude-assisted research led me to discover that it was because the generator file itself wasn't in the folder structure expected by Rails. Moving the file fixed that.
  • Second, the schema tests were failing after a migration with create_table "table_name", id: uuid ... because uuid wasn't defined. Some digging showed that at least in my version of Rails, the schema code isn't executed in the context of ActiveRecord::Schema but instead in the context of ActiveRecord::Schema::Definition. Patching that second class (if present) let my schema tests pass.

Thanks for putting together this gem; I was pretty pleased to run across a solution for UUIDs in simple Rails/Sqlite3 apps.

Without tzinfo-data, a simple:
bundle install
bundle exec rspec

was failing with a report of it being missing.

All tests pass now.
Rails doesn't seem to autodiscover the generators unless they're in
`lib/<generators>/<gem_name>/<generator>/<generator>_generator.rb`

After this change `./bin/rails generate --help` shows the generator as expected
and running `rails generate sqlite_crypto:install` creates the initializer file
as expected.
In Rails 8, the schema.rb is wrapped in:
ActiveRecord::Schema[8.1].define(version: ...) do

Within that context,  isn't ActiveRecord::Schema as it
presumably is under Rails < 7. Instead it's ActiveRecord::Schema::Definition
so the  helper isn't defined and so
errors because  is undefined.

This change opportunistically patches the correct class if it's available.
@bart-oz
Copy link
Owner

bart-oz commented Feb 11, 2026

Hey @yostinso - I’m closing this PR since I opened and released new FIX based on your discoveries, and added also integrations tests, and few things. Thanks again for reporting these - both are confirmed bugs.

Here's more detailed info:

  • Generator: You were spot on. The file was at lib/sqlite_crypto/generators/ but Rails only autodiscovers generators under lib/generators/. This was broken since v2.0.0 when the generator was first added - in specs I was manually required the file, so it never caught the missing autodiscovery 😱 😅

  • Schema uuid undefined: I was checking the root cause and it was a load-order issue introduced in v2.0.1. The uuid/ulid helpers were being included into ActiveRecord::Schema at require-time with a if defined? guard - but in real apps, Bundler loads gems before Rails initializes ActiveRecord, so the guard always returned false and the include silently skipped. I also added the Schema::Definition include you identified for Rails 8+ compatibility.

  • tzinfo-data: this is a platform-specific dependency (Windows/JRuby) and doesn't belong in the gem’s Gemfile. You can add gem "tzinfo-data", platforms: [:windows, :jruby] to your app's Gemfile if needed. That’s why I decided to skip this from your investigation.

Fix PR with updated tests: #18

@bart-oz bart-oz closed this Feb 11, 2026
@yostinso
Copy link
Author

Thanks! I actually ran into tzinfo-data missing inside a hardened Ubuntu container, but fair point that it's environment dependent.

@yostinso yostinso deleted the fix_generators_rails_8 branch February 12, 2026 20:31
@bart-oz
Copy link
Owner

bart-oz commented Feb 13, 2026

Sure, whenever you find something else that needs fix or improvement feel free to reach out or create PR.

Have a nice day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants