Skip to content

Commit fe7f430

Browse files
committed
Improved generator for Active Record encryption and MySQL
1 parent aa0e6c0 commit fe7f430

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.0 (unreleased)
2+
3+
- Improved generator for Active Record encryption and MySQL
4+
15
## 0.5.0 (2023-07-02)
26

37
- Made Active Record and Active Job optional

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rails generate authtrail:install --encryption=lockbox
2121
rails db:migrate
2222
```
2323

24-
To use Active Record encryption (Rails 7+, experimental), run:
24+
To use Active Record encryption (Rails 7+), run:
2525

2626
```sh
2727
rails generate authtrail:install --encryption=activerecord

lib/generators/authtrail/install_generator.rb

+13-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ def identity_column
3939
when "lockbox"
4040
"t.text :identity_ciphertext\n t.string :identity_bidx, index: true"
4141
else
42-
# TODO add limit: 510 for Active Record encryption + MySQL?
43-
"t.string :identity, index: true"
42+
if encryption == "activerecord" && mysql?
43+
"t.string :identity, limit: 510, index: true"
44+
else
45+
"t.string :identity, index: true"
46+
end
4447
end
4548
end
4649

@@ -49,7 +52,6 @@ def ip_column
4952
when "lockbox"
5053
"t.text :ip_ciphertext\n t.string :ip_bidx, index: true"
5154
else
52-
# TODO add limit: 510 for Active Record encryption + MySQL?
5355
"t.string :ip, index: true"
5456
end
5557
end
@@ -78,6 +80,14 @@ def lockbox_method
7880
"has_encrypted"
7981
end
8082
end
83+
84+
def mysql?
85+
adapter =~ /mysql|trilogy/i
86+
end
87+
88+
def adapter
89+
ActiveRecord::Base.connection_db_config.adapter.to_s
90+
end
8191
end
8292
end
8393
end

0 commit comments

Comments
 (0)