rails-uuid-pk 0.11.0 → 0.12.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: 39054803d08ebe8074e8faa144a8277ab62c849ff4fbf79d4956043a747a1349
4
- data.tar.gz: 929b6f1f7ee9c4a7f3b7905c96c9f9706a19caa4410702e9f44fc7005cabcea6
3
+ metadata.gz: 0ef202d7fd8ed44687383011c2306cdafc16fc9a05505270c270a753d4fd4a33
4
+ data.tar.gz: fd9416e86ae299c7d693fcba9bc0e71d179940cd4e1e29dbd4bfc892e30e0248
5
5
  SHA512:
6
- metadata.gz: 0c24c5e17db7d29ed688a3083329ba950b0db2a3f02ca6e35c76aaa7f44b1d47b09270a4662e372fedc7461e5cefff592306f7ab19bf74e376c321705e641383
7
- data.tar.gz: 0c99293ea42f423b350865e8a236ad888a378162e5f5f4cc9b9c77bdfeaa32a313af474a3c4d468ca790d9e7a1321212c19978ef92e35bec4e2d6bb0003db366
6
+ metadata.gz: 4f675cb556f985b0060cc34297182d5dbe1860a05cce42ce1b8de62e4b5f4ea89b07ae84669615dbb109d6f4c4bc0779c6a90bcaf9b0af3cc1b8d42b8588f8cc
7
+ data.tar.gz: 9ac0c2032a0036bc9a5a7441391f30b3991c0557446605ac1bb9b35a100e8fdb9cad565443536ef4b833f3c7c0793ff085b51996e1d75a5e018472ff4edd92af
data/CHANGELOG.md CHANGED
@@ -5,6 +5,22 @@ 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.12.0] - 2026-01-17
9
+
10
+ ### Changed
11
+ - **Refactored Database Adapter Extensions**: Eliminated 152 lines of duplicated code (97% similarity) between MySQL and SQLite adapter extensions by introducing a shared `UuidAdapterExtension` module
12
+ - Created `lib/rails_uuid_pk/uuid_adapter_extension.rb` with common UUID type support functionality
13
+ - Refactored `Mysql2AdapterExtension` and `Sqlite3AdapterExtension` to include the shared module
14
+ - Maintained SQLite-specific transaction-aware connection configuration while standardizing all other UUID handling logic
15
+ - Improved code maintainability and reduced duplication from 156 lines to 99 lines total (37% reduction)
16
+
17
+ ### Technical Details
18
+ - Added shared `UuidAdapterExtension` module containing `native_database_types`, `valid_type?`, `register_uuid_types`, `initialize_type_map`, `configure_connection`, and `type_to_dump` methods
19
+ - Updated `Mysql2AdapterExtension` to include shared module with minimal override for `configure_connection`
20
+ - Updated `Sqlite3AdapterExtension` to include shared module while preserving transaction-aware `configure_connection` implementation
21
+ - Added require statement for new shared module in main library file
22
+ - All existing functionality preserved with identical test suite results (119 tests, 0 failures, 0 errors)
23
+
8
24
  ## [0.11.0] - 2026-01-16
9
25
 
10
26
  ### Added
data/README.md CHANGED
@@ -22,7 +22,7 @@ Automatically use UUID v7 for **all primary keys** in Rails applications. Works
22
22
  Add to your `Gemfile`:
23
23
 
24
24
  ```ruby
25
- gem "rails-uuid-pk", "~> 0.11"
25
+ gem "rails-uuid-pk", "~> 0.12"
26
26
  ```
27
27
 
28
28
  Then run:
@@ -4,8 +4,8 @@ module RailsUuidPk
4
4
  # MySQL adapter extension for UUID type support.
5
5
  #
6
6
  # This module extends ActiveRecord's MySQL2 adapter to provide native UUID
7
- # type support. Since MySQL doesn't have a native UUID type, it maps UUIDs
8
- # to VARCHAR(36) columns and registers the custom UUID type handlers.
7
+ # type support. It includes the shared UUID adapter extension functionality
8
+ # and provides MySQL-specific connection configuration.
9
9
  #
10
10
  # @example Automatic type mapping
11
11
  # # MySQL tables with VARCHAR(36) columns are automatically treated as UUIDs
@@ -13,65 +13,17 @@ module RailsUuidPk
13
13
  # t.column :id, :uuid # Maps to VARCHAR(36) in MySQL
14
14
  # end
15
15
  #
16
+ # @see RailsUuidPk::UuidAdapterExtension
16
17
  # @see RailsUuidPk::Type::Uuid
17
18
  # @see https://dev.mysql.com/doc/refman/8.0/en/data-types.html
18
19
  module Mysql2AdapterExtension
19
- # Defines native database types for MySQL UUID support.
20
- #
21
- # @return [Hash] Database type definitions including UUID mapping
22
- def native_database_types
23
- super.merge(
24
- uuid: { name: "varchar", limit: 36 }
25
- )
26
- end
27
-
28
- # Checks if a type is valid for this adapter.
29
- #
30
- # Overrides ActiveRecord's valid_type? to recognize the custom UUID type.
31
- #
32
- # @param type [Symbol] The type to check
33
- # @return [Boolean] true if the type is valid
34
- def valid_type?(type)
35
- return true if type == :uuid
36
- super
37
- end
38
-
39
- # Registers UUID type handlers in the adapter's type map.
40
- #
41
- # @param m [ActiveRecord::ConnectionAdapters::AbstractAdapter::TypeMap] The type map to register with
42
- # @return [void]
43
- def register_uuid_types(m = type_map)
44
- RailsUuidPk.log(:debug, "Registering UUID types on #{m.class}")
45
- m.register_type(/varchar\(36\)/i) { RailsUuidPk::Type::Uuid.new }
46
- m.register_type("uuid") { RailsUuidPk::Type::Uuid.new }
47
- end
48
-
49
- # Initializes the type map with UUID type registrations.
50
- #
51
- # @param m [ActiveRecord::ConnectionAdapters::AbstractAdapter::TypeMap] The type map to initialize
52
- # @return [void]
53
- def initialize_type_map(m = type_map)
54
- super
55
- register_uuid_types(m)
56
- end
20
+ include UuidAdapterExtension
57
21
 
58
22
  # Configures the database connection with UUID type support.
59
23
  #
60
24
  # @return [void]
61
25
  def configure_connection
62
26
  super
63
- register_uuid_types
64
- end
65
-
66
- # Overrides type dumping to properly handle UUID columns.
67
- #
68
- # @param column [ActiveRecord::ConnectionAdapters::Column] The column to dump
69
- # @return [Array] The type and options for the schema dump
70
- def type_to_dump(column)
71
- if column.type == :uuid
72
- return [ :uuid, {} ]
73
- end
74
- super
75
27
  end
76
28
  end
77
29
  end
@@ -4,8 +4,9 @@ module RailsUuidPk
4
4
  # SQLite adapter extension for UUID type support.
5
5
  #
6
6
  # This module extends ActiveRecord's SQLite3 adapter to provide native UUID
7
- # type support. Since SQLite doesn't have a native UUID type, it maps UUIDs
8
- # to VARCHAR(36) columns and registers the custom UUID type handlers.
7
+ # type support. It includes the shared UUID adapter extension functionality
8
+ # and provides SQLite-specific connection configuration, including transaction-aware
9
+ # connection setup.
9
10
  #
10
11
  # @example Automatic type mapping
11
12
  # # SQLite tables with VARCHAR(36) columns are automatically treated as UUIDs
@@ -13,67 +14,22 @@ module RailsUuidPk
13
14
  # t.column :id, :uuid # Maps to VARCHAR(36) in SQLite
14
15
  # end
15
16
  #
17
+ # @see RailsUuidPk::UuidAdapterExtension
16
18
  # @see RailsUuidPk::Type::Uuid
17
19
  # @see https://www.sqlite.org/datatype3.html
18
20
  module Sqlite3AdapterExtension
19
- # Defines native database types for SQLite UUID support.
20
- #
21
- # @return [Hash] Database type definitions including UUID mapping
22
- def native_database_types
23
- super.merge(
24
- uuid: { name: "varchar", limit: 36 }
25
- )
26
- end
27
-
28
- # Checks if a type is valid for this adapter.
29
- #
30
- # Overrides ActiveRecord's valid_type? to recognize the custom UUID type.
31
- #
32
- # @param type [Symbol] The type to check
33
- # @return [Boolean] true if the type is valid
34
- def valid_type?(type)
35
- return true if type == :uuid
36
- super
37
- end
38
-
39
- # Registers UUID type handlers in the adapter's type map.
40
- #
41
- # @param m [ActiveRecord::ConnectionAdapters::AbstractAdapter::TypeMap] The type map to register with
42
- # @return [void]
43
- def register_uuid_types(m = type_map)
44
- RailsUuidPk.log(:debug, "Registering UUID types on #{m.class}")
45
- m.register_type(/varchar\(36\)/i) { RailsUuidPk::Type::Uuid.new }
46
- m.register_type("uuid") { RailsUuidPk::Type::Uuid.new }
47
- end
48
-
49
- # Initializes the type map with UUID type registrations.
50
- #
51
- # @param m [ActiveRecord::ConnectionAdapters::AbstractAdapter::TypeMap] The type map to initialize
52
- # @return [void]
53
- def initialize_type_map(m = type_map)
54
- super
55
- register_uuid_types(m)
56
- end
21
+ include UuidAdapterExtension
57
22
 
58
23
  # Configures the database connection with UUID type support.
59
24
  #
25
+ # SQLite-specific implementation that avoids calling super inside transactions,
26
+ # as PRAGMA statements cannot be executed inside transactions in SQLite.
27
+ #
60
28
  # @return [void]
61
29
  def configure_connection
62
30
  # Only call super if not inside a transaction, as PRAGMA statements
63
31
  # cannot be executed inside transactions in SQLite
64
32
  super unless open_transactions > 0
65
- register_uuid_types
66
- end
67
-
68
- # Overrides type dumping to properly handle UUID columns.
69
- #
70
- # @param column [ActiveRecord::ConnectionAdapters::Column] The column to dump
71
- # @return [Array] The type and options for the schema dump
72
- def type_to_dump(column)
73
- if column.type == :uuid
74
- return [ :uuid, {} ]
75
- end
76
- super
77
33
  end
78
34
  end
79
35
  end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsUuidPk
4
+ # Shared UUID adapter extension for database adapters.
5
+ #
6
+ # This module provides common UUID type support functionality that can be
7
+ # included by specific database adapter extensions (MySQL, SQLite, etc.).
8
+ # Since most databases don't have native UUID types, it maps UUIDs to
9
+ # VARCHAR(36) columns and registers the custom UUID type handlers.
10
+ #
11
+ # @example Automatic type mapping
12
+ # # Database tables with VARCHAR(36) columns are automatically treated as UUIDs
13
+ # create_table :users do |t|
14
+ # t.column :id, :uuid # Maps to VARCHAR(36) in supported databases
15
+ # end
16
+ #
17
+ # @see RailsUuidPk::Type::Uuid
18
+ module UuidAdapterExtension
19
+ # Defines native database types for UUID support.
20
+ #
21
+ # @return [Hash] Database type definitions including UUID mapping
22
+ def native_database_types
23
+ super.merge(
24
+ uuid: { name: "varchar", limit: 36 }
25
+ )
26
+ end
27
+
28
+ # Checks if a type is valid for this adapter.
29
+ #
30
+ # Overrides ActiveRecord's valid_type? to recognize the custom UUID type.
31
+ #
32
+ # @param type [Symbol] The type to check
33
+ # @return [Boolean] true if the type is valid
34
+ def valid_type?(type)
35
+ return true if type == :uuid
36
+ super
37
+ end
38
+
39
+ # Registers UUID type handlers in the adapter's type map.
40
+ #
41
+ # @param m [ActiveRecord::ConnectionAdapters::AbstractAdapter::TypeMap] The type map to register with
42
+ # @return [void]
43
+ def register_uuid_types(m = type_map)
44
+ RailsUuidPk.log(:debug, "Registering UUID types on #{m.class}")
45
+ m.register_type(/varchar\(36\)/i) { RailsUuidPk::Type::Uuid.new }
46
+ m.register_type("uuid") { RailsUuidPk::Type::Uuid.new }
47
+ end
48
+
49
+ # Initializes the type map with UUID type registrations.
50
+ #
51
+ # @param m [ActiveRecord::ConnectionAdapters::AbstractAdapter::TypeMap] The type map to initialize
52
+ # @return [void]
53
+ def initialize_type_map(m = type_map)
54
+ super
55
+ register_uuid_types(m)
56
+ end
57
+
58
+ # Configures the database connection with UUID type support.
59
+ #
60
+ # This method should be overridden by including adapters to handle
61
+ # database-specific connection configuration requirements.
62
+ #
63
+ # @return [void]
64
+ def configure_connection
65
+ super
66
+ register_uuid_types
67
+ end
68
+
69
+ # Overrides type dumping to properly handle UUID columns.
70
+ #
71
+ # @param column [ActiveRecord::ConnectionAdapters::Column] The column to dump
72
+ # @return [Array] The type and options for the schema dump
73
+ def type_to_dump(column)
74
+ if column.type == :uuid
75
+ return [ :uuid, {} ]
76
+ end
77
+ super
78
+ end
79
+ end
80
+ end
@@ -7,6 +7,6 @@ module RailsUuidPk
7
7
  #
8
8
  # @return [String] The current version
9
9
  # @example
10
- # RailsUuidPk::VERSION # => "0.11.0"
11
- VERSION = "0.11.0"
10
+ # RailsUuidPk::VERSION # => "0.12.0"
11
+ VERSION = "0.12.0"
12
12
  end
data/lib/rails_uuid_pk.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "rails_uuid_pk/version"
4
4
  require "rails_uuid_pk/concern"
5
5
  require "rails_uuid_pk/type"
6
+ require "rails_uuid_pk/uuid_adapter_extension"
6
7
  require "rails_uuid_pk/sqlite3_adapter_extension"
7
8
  require "rails_uuid_pk/mysql2_adapter_extension"
8
9
  require "rails_uuid_pk/railtie"
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.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joon Lee
@@ -154,6 +154,7 @@ files:
154
154
  - lib/rails_uuid_pk/railtie.rb
155
155
  - lib/rails_uuid_pk/sqlite3_adapter_extension.rb
156
156
  - lib/rails_uuid_pk/type.rb
157
+ - lib/rails_uuid_pk/uuid_adapter_extension.rb
157
158
  - lib/rails_uuid_pk/version.rb
158
159
  - lib/tasks/rails_uuid_pk_tasks.rake
159
160
  homepage: https://github.com/seouri/rails-uuid-pk
@@ -163,7 +164,7 @@ metadata:
163
164
  homepage_uri: https://github.com/seouri/rails-uuid-pk
164
165
  source_code_uri: https://github.com/seouri/rails-uuid-pk
165
166
  changelog_uri: https://github.com/seouri/rails-uuid-pk/blob/main/CHANGELOG.md
166
- documentation_uri: https://www.rubydoc.info/gems/rails-uuid-pk/0.11.0
167
+ documentation_uri: https://www.rubydoc.info/gems/rails-uuid-pk/0.12.0
167
168
  rdoc_options: []
168
169
  require_paths:
169
170
  - lib