rails-uuid-pk 0.11.0 → 0.13.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 +4 -4
- data/ARCHITECTURE.md +508 -0
- data/CHANGELOG.md +78 -0
- data/DEVELOPMENT.md +314 -0
- data/PERFORMANCE.md +417 -0
- data/README.md +43 -12
- data/SECURITY.md +321 -0
- data/lib/generators/rails_uuid_pk/add_opt_outs_generator.rb +183 -0
- data/lib/rails_uuid_pk/migration_helpers.rb +6 -2
- data/lib/rails_uuid_pk/mysql2_adapter_extension.rb +14 -56
- data/lib/rails_uuid_pk/railtie.rb +7 -2
- data/lib/rails_uuid_pk/sqlite3_adapter_extension.rb +8 -52
- data/lib/rails_uuid_pk/trilogy_adapter_extension.rb +39 -0
- data/lib/rails_uuid_pk/uuid_adapter_extension.rb +80 -0
- data/lib/rails_uuid_pk/version.rb +2 -2
- data/lib/rails_uuid_pk.rb +5 -0
- metadata +26 -3
|
@@ -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.
|
|
8
|
-
#
|
|
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
|
-
|
|
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,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsUuidPk
|
|
4
|
+
# Trilogy adapter extension for UUID type support.
|
|
5
|
+
#
|
|
6
|
+
# This module extends ActiveRecord's Trilogy adapter to provide native UUID
|
|
7
|
+
# type support. It includes the shared UUID adapter extension functionality
|
|
8
|
+
# and provides Trilogy-specific connection configuration.
|
|
9
|
+
#
|
|
10
|
+
# Trilogy is GitHub's high-performance MySQL adapter that offers significant
|
|
11
|
+
# performance improvements over the standard mysql2 adapter, particularly for
|
|
12
|
+
# high-traffic Rails applications.
|
|
13
|
+
#
|
|
14
|
+
# @example UUID primary key and foreign key references
|
|
15
|
+
# # Primary key uses UUID type
|
|
16
|
+
# create_table :users, id: :uuid do |t|
|
|
17
|
+
# t.string :name
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# # Foreign key automatically detects and uses UUID type
|
|
21
|
+
# create_table :posts do |t|
|
|
22
|
+
# t.references :user # Automatically uses :uuid type
|
|
23
|
+
# t.string :title
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# @see RailsUuidPk::UuidAdapterExtension
|
|
27
|
+
# @see RailsUuidPk::Type::Uuid
|
|
28
|
+
# @see https://github.com/trilogy-libraries/trilogy
|
|
29
|
+
module TrilogyAdapterExtension
|
|
30
|
+
include RailsUuidPk::UuidAdapterExtension
|
|
31
|
+
|
|
32
|
+
# Configures the database connection with UUID type support.
|
|
33
|
+
#
|
|
34
|
+
# @return [void]
|
|
35
|
+
def configure_connection
|
|
36
|
+
super
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
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
|
data/lib/rails_uuid_pk.rb
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
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"
|
|
9
|
+
require "rails_uuid_pk/trilogy_adapter_extension"
|
|
8
10
|
require "rails_uuid_pk/railtie"
|
|
9
11
|
|
|
12
|
+
# Load generators
|
|
13
|
+
require "generators/rails_uuid_pk/add_opt_outs_generator" if defined?(Rails::Generators)
|
|
14
|
+
|
|
10
15
|
# Rails UUID Primary Key
|
|
11
16
|
#
|
|
12
17
|
# A Rails gem that automatically uses UUIDv7 for all primary keys in Rails applications.
|
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.
|
|
4
|
+
version: 0.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joon Lee
|
|
@@ -37,6 +37,20 @@ dependencies:
|
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
39
|
version: 0.5.7
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: trilogy
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '2.10'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '2.10'
|
|
40
54
|
- !ruby/object:Gem::Dependency
|
|
41
55
|
name: pg
|
|
42
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -136,24 +150,32 @@ dependencies:
|
|
|
136
150
|
- !ruby/object:Gem::Version
|
|
137
151
|
version: '0.5'
|
|
138
152
|
description: Automatically use UUID v7 for all primary keys in Rails applications.
|
|
139
|
-
Works with PostgreSQL, MySQL, and SQLite, zero configuration
|
|
153
|
+
Works with PostgreSQL, MySQL (mysql2 & trilogy), and SQLite, zero configuration
|
|
154
|
+
required.
|
|
140
155
|
email:
|
|
141
156
|
- seouri@gmail.com
|
|
142
157
|
executables: []
|
|
143
158
|
extensions: []
|
|
144
159
|
extra_rdoc_files: []
|
|
145
160
|
files:
|
|
161
|
+
- ARCHITECTURE.md
|
|
146
162
|
- CHANGELOG.md
|
|
163
|
+
- DEVELOPMENT.md
|
|
147
164
|
- MIT-LICENSE
|
|
165
|
+
- PERFORMANCE.md
|
|
148
166
|
- README.md
|
|
149
167
|
- Rakefile
|
|
168
|
+
- SECURITY.md
|
|
169
|
+
- lib/generators/rails_uuid_pk/add_opt_outs_generator.rb
|
|
150
170
|
- lib/rails_uuid_pk.rb
|
|
151
171
|
- lib/rails_uuid_pk/concern.rb
|
|
152
172
|
- lib/rails_uuid_pk/migration_helpers.rb
|
|
153
173
|
- lib/rails_uuid_pk/mysql2_adapter_extension.rb
|
|
154
174
|
- lib/rails_uuid_pk/railtie.rb
|
|
155
175
|
- lib/rails_uuid_pk/sqlite3_adapter_extension.rb
|
|
176
|
+
- lib/rails_uuid_pk/trilogy_adapter_extension.rb
|
|
156
177
|
- lib/rails_uuid_pk/type.rb
|
|
178
|
+
- lib/rails_uuid_pk/uuid_adapter_extension.rb
|
|
157
179
|
- lib/rails_uuid_pk/version.rb
|
|
158
180
|
- lib/tasks/rails_uuid_pk_tasks.rake
|
|
159
181
|
homepage: https://github.com/seouri/rails-uuid-pk
|
|
@@ -163,7 +185,8 @@ metadata:
|
|
|
163
185
|
homepage_uri: https://github.com/seouri/rails-uuid-pk
|
|
164
186
|
source_code_uri: https://github.com/seouri/rails-uuid-pk
|
|
165
187
|
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.
|
|
188
|
+
documentation_uri: https://www.rubydoc.info/gems/rails-uuid-pk/0.13.0
|
|
189
|
+
rubygems_mfa_required: 'true'
|
|
167
190
|
rdoc_options: []
|
|
168
191
|
require_paths:
|
|
169
192
|
- lib
|