diff --git a/CHANGELOG.md b/CHANGELOG.md index 25eff13..320324a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.2 (unreleased) + +- Improved generator for Active Record encryption and MySQL + ## 2.3.1 (2024-09-09) - Fixed deprecation warning with Rails 7.1 diff --git a/README.md b/README.md index 2df4121..6543ead 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ rails generate ahoy:messages --encryption=lockbox rails db:migrate ``` -To use Active Record encryption (Rails 7+, experimental), run: +To use Active Record encryption (Rails 7+), run: ```sh rails generate ahoy:messages --encryption=activerecord diff --git a/lib/generators/ahoy/messages/activerecord_generator.rb b/lib/generators/ahoy/messages/activerecord_generator.rb index dd104d5..5068724 100644 --- a/lib/generators/ahoy/messages/activerecord_generator.rb +++ b/lib/generators/ahoy/messages/activerecord_generator.rb @@ -34,8 +34,11 @@ def to_column when "lockbox" "t.text :to_ciphertext\n t.string :to_bidx, index: true" else - # TODO add limit: 510 for Active Record encryption + MySQL? - "t.string :to, index: true" + if encryption == "activerecord" && mysql? + "t.string :to, limit: 510, index: true" + else + "t.string :to, index: true" + end end end @@ -63,6 +66,14 @@ def lockbox_method "has_encrypted" end end + + def mysql? + adapter =~ /mysql|trilogy/i + end + + def adapter + ActiveRecord::Base.connection_db_config.adapter.to_s + end end end end