rails-uuid-pk 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44071099c05c09c2bd83cf2c82eac2cd7794990d288d68d8ef775e2ecaa410e2
4
- data.tar.gz: ba6ad1a7f1a00c2d5201122215c9fcfbd39142088775b24234f2a01c9e25dc05
3
+ metadata.gz: cda21a747f154d1863e741ecce9b44855009bc202b11524be1a48911c6945ee2
4
+ data.tar.gz: f513b130b54f7d2230a13aa53bd60b707174005eff1bb792c0380a9d2b80a885
5
5
  SHA512:
6
- metadata.gz: caf06da62bc4a35bd6eb8fc578e298d3a1652e89a1ea0bf74118aeb325b780e3f0dc8b7a1b37828967a6ca9287d164631ac4355a2817c9c483a4e4934396adef
7
- data.tar.gz: 0b6a0d2920550d3d0eb385f4f42dcafd55877a6a603d6347d1d13b6a9171ddd4a74c8f14439125666455e91f2481d57b688bf8e6a18e9dde439c7daaa3918db3
6
+ metadata.gz: 44070a3cf56eca32a1e83abdb83fa084abcb8c6042d2a2e06f3314bcfbf9df4e12a2794a5fab1e7d50d589455f2242dbf7e141618cd2b2b721b76be92ddfdc0f
7
+ data.tar.gz: 04ca3df41f44ca36bba89849a5c2a515481417b28b995670ecb93fb7a87a90abe5d9bf74bdb1b3a31c109a28127df2b9478bd63adbfa83fb5d0011e0b334a872
data/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v1.0.0.html).
7
7
 
8
+ ## [0.8.0] - 2026-01-12
9
+
10
+ ### Changed
11
+ - **Refactored UUID Type Registration**: Moved from global type map registration to connection-specific registration for improved precision and database compatibility
12
+ - **Enhanced Type Mapping Precision**: UUID types now only map to specific `varchar(36)` and `uuid` SQL types, preventing hijacking of standard string columns
13
+ - **Improved Adapter Extensions**: Enhanced MySQL and SQLite adapter extensions with dedicated `register_uuid_types` methods and proper initialization hooks
14
+
15
+ ### Added
16
+ - **String Column Protection Test**: Added test to ensure standard string columns are not incorrectly mapped to UUID type
17
+
18
+ ### Technical Details
19
+ - Updated Railtie to use `ActiveSupport.on_load` hooks for cleaner adapter extension prepending
20
+ - Implemented connection-aware UUID type registration during adapter initialization and connection setup
21
+ - Enhanced migration helpers compatibility and type detection robustness
22
+
8
23
  ## [0.7.0] - 2026-01-12
9
24
 
10
25
  ### Added
data/README.md CHANGED
@@ -25,7 +25,7 @@ Automatically use UUID v7 for **all primary keys** in Rails applications. Works
25
25
  Add to your `Gemfile`:
26
26
 
27
27
  ```ruby
28
- gem "rails-uuid-pk", "~> 0.6"
28
+ gem "rails-uuid-pk", "~> 0.8"
29
29
  ```
30
30
 
31
31
  Then run:
@@ -5,5 +5,20 @@ module RailsUuidPk
5
5
  uuid: { name: "varchar", limit: 36 }
6
6
  )
7
7
  end
8
+
9
+ def register_uuid_types(m = type_map)
10
+ m.register_type(/varchar\(36\)/i) { RailsUuidPk::Type::Uuid.new }
11
+ m.register_type("uuid") { RailsUuidPk::Type::Uuid.new }
12
+ end
13
+
14
+ def initialize_type_map(m = type_map)
15
+ super
16
+ register_uuid_types(m)
17
+ end
18
+
19
+ def configure_connection
20
+ super
21
+ register_uuid_types
22
+ end
8
23
  end
9
24
  end
@@ -16,17 +16,31 @@ module RailsUuidPk
16
16
  end
17
17
 
18
18
  initializer "rails-uuid-pk.native_types" do
19
+ ActiveSupport.on_load(:active_record_sqlite3adapter) do
20
+ prepend RailsUuidPk::Sqlite3AdapterExtension
21
+ end
22
+
23
+ ActiveSupport.on_load(:active_record_mysql2adapter) do
24
+ prepend RailsUuidPk::Mysql2AdapterExtension
25
+ end
26
+ end
27
+
28
+ config.after_initialize do
19
29
  ActiveSupport.on_load(:active_record) do
20
- case ActiveRecord::Base.connection.adapter_name
21
- when "SQLite"
22
- require "active_record/connection_adapters/sqlite3_adapter"
23
- ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend(RailsUuidPk::Sqlite3AdapterExtension)
24
- when "MySQL"
25
- begin
26
- require "active_record/connection_adapters/mysql2_adapter"
27
- ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(RailsUuidPk::Mysql2AdapterExtension)
28
- rescue LoadError
29
- # MySQL adapter not available
30
+ if ActiveRecord::Base.connected?
31
+ ActiveRecord::Base.connection_handler.connection_pool_list.each do |pool|
32
+ connections = if pool.respond_to?(:connections)
33
+ pool.connections
34
+ else
35
+ # Fallback or older rails
36
+ [ pool.connection ] rescue []
37
+ end
38
+
39
+ connections.each do |conn|
40
+ if conn.respond_to?(:register_uuid_types)
41
+ conn.register_uuid_types
42
+ end
43
+ end
30
44
  end
31
45
  end
32
46
  end
@@ -54,13 +68,6 @@ module RailsUuidPk
54
68
 
55
69
  def self.register_uuid_type(adapter)
56
70
  ActiveRecord::Type.register(:uuid, RailsUuidPk::Type::Uuid, adapter: adapter)
57
-
58
- # Get the connection-specific type map
59
- type_map = ActiveRecord::Base.connection.send(:type_map)
60
- # Map varchar(36) or varchar SQL type to our custom UUID type
61
- type_map.register_type(/varchar/i) { RailsUuidPk::Type::Uuid.new }
62
- # Also map "uuid" SQL type for direct lookups
63
- type_map.register_type("uuid") { RailsUuidPk::Type::Uuid.new }
64
71
  end
65
72
  end
66
73
  end
@@ -5,5 +5,21 @@ module RailsUuidPk
5
5
  uuid: { name: "varchar", limit: 36 }
6
6
  )
7
7
  end
8
+
9
+ def register_uuid_types(m = type_map)
10
+ puts "[RailsUuidPk] Registering UUID types on #{m.class}"
11
+ m.register_type(/varchar\(36\)/i) { RailsUuidPk::Type::Uuid.new }
12
+ m.register_type("uuid") { RailsUuidPk::Type::Uuid.new }
13
+ end
14
+
15
+ def initialize_type_map(m = type_map)
16
+ super
17
+ register_uuid_types(m)
18
+ end
19
+
20
+ def configure_connection
21
+ super
22
+ register_uuid_types
23
+ end
8
24
  end
9
25
  end
@@ -1,3 +1,3 @@
1
1
  module RailsUuidPk
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-uuid-pk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joon Lee