rails-uuid-pk 0.3.0 → 0.5.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: d9552cdab44f5a5a6a4b699e12dc31ee13917ff74f0752f32e823dffed24e2e0
4
- data.tar.gz: 6ddd7862945d8b13939be92990241539d93eaf754d6c47f2733d66eb2e29597e
3
+ metadata.gz: 615c351b860e9cf6b5cc663f8f1a8d4c5781bb6f7f12d658440f42a3173d8fc0
4
+ data.tar.gz: 5973fbaed1fb21337bd3e3377c59f7ba410dd50d8837eb444e0c15ead96ddaaf
5
5
  SHA512:
6
- metadata.gz: 72fb9c050567562c0d01793d801d7633d45b26851734cb069b2e70ee74d8bf3387e515f50cb771fdbb46f8ad9b4cb767058739bad45050134ba710a8f6290201
7
- data.tar.gz: ed3b396026fe6edc6485720d6d80af4d5fd11138652fea133515fcb8d931d9d38cf981553a46689121201922ee41b6fad5829c42c06783109b930b06acf41fda
6
+ metadata.gz: b9a9adf355b72109ed26fa08586983581aa0b4005bbbbc504782a6f5297198b4852f6b664138b24976f2405c464adeba017d177143b15f95761b2901f2aee336
7
+ data.tar.gz: bde5e20373b9d07a9013194f3b90faa01cdad6a63de4598b1d1925c0b80694c8416256290f4410d4c4821c1e7ff51e5bcb9281753bcc12f0ec31fa56c06790be
data/CHANGELOG.md CHANGED
@@ -5,6 +5,51 @@ 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.5.0] - 2026-01-10
9
+
10
+ ### Changed
11
+ - **Made gem truly zero-configuration**: Removed install generator and concern file
12
+ - Simplified installation to just `bundle install` - no generator command needed
13
+ - Removed `app/models/concerns/has_uuidv7_primary_key.rb` template and explicit inclusion option
14
+ - Updated documentation to reflect simplified zero-config approach
15
+ - All functionality now works automatically through Railtie inclusion
16
+
17
+ ### Removed
18
+ - Install generator (`rails g rails_uuid_pk:install`)
19
+ - Optional concern file for explicit inclusion
20
+ - Generator template and associated test cases
21
+ - Manual installation steps and configuration options
22
+
23
+ ### Technical Details
24
+ - Eliminated generator complexity while maintaining all core functionality
25
+ - Streamlined user experience - just add gem to Gemfile and it works
26
+ - Removed optional explicit concern inclusion in favor of automatic Railtie-based inclusion
27
+ - Updated AGENTS.md and README.md to reflect simplified architecture
28
+
29
+ ## [0.4.0] - 2026-01-10
30
+
31
+ ### Added
32
+ - **MySQL 8.0+ support**: Full MySQL compatibility with VARCHAR(36) UUID storage
33
+ - MySQL2 adapter extension for native database type mappings
34
+ - MySQL-specific type handling and schema dumping support
35
+ - Comprehensive MySQL test suite with performance and edge case testing
36
+ - CI pipeline support for MySQL 8.0 testing
37
+ - Updated documentation to include MySQL setup and compatibility notes
38
+
39
+ ### Changed
40
+ - Updated project description to reflect support for PostgreSQL, MySQL, and SQLite
41
+ - Enhanced test runner to support all three database adapters
42
+ - Updated development environment setup to include MySQL configuration
43
+ - Expanded database coverage from 2 to 3 major Rails database adapters
44
+
45
+ ### Technical Details
46
+ - Added `lib/rails_uuid_pk/mysql2_adapter_extension.rb` for MySQL adapter integration
47
+ - Extended Railtie with MySQL-specific type mappings and adapter detection
48
+ - Enhanced migration helpers compatibility with MySQL VARCHAR(36) column detection
49
+ - Added MySQL performance testing (bulk operations, concurrent access, memory efficiency)
50
+ - Implemented MySQL edge case testing (long table names, special characters)
51
+ - Updated CI workflow with MySQL 8.0 service configuration
52
+
8
53
  ## [0.3.0] - 2026-01-09
9
54
 
10
55
  ### Added
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # rails-uuid-pk
2
2
 
3
3
  **Dead-simple UUIDv7 primary keys for modern Rails apps**
4
- Works great with **PostgreSQL 18+** and **SQLite 3.51+** — zero extra extensions required.
4
+ Works great with **PostgreSQL 18+**, **MySQL 8.0+**, and **SQLite 3.51+** — zero extra extensions required.
5
5
 
6
6
  [![Gem Version](https://img.shields.io/gem/v/rails-uuid-pk.svg?style=flat-square)](https://rubygems.org/gems/rails-uuid-pk)
7
7
  [![Ruby](https://img.shields.io/badge/ruby-≥3.3-red.svg?style=flat-square)](https://www.ruby-lang.org)
@@ -12,8 +12,9 @@ Works great with **PostgreSQL 18+** and **SQLite 3.51+** — zero extra extensio
12
12
  - Uses **native** `SecureRandom.uuid_v7` (Ruby 3.3+)
13
13
  - Automatically sets `:uuid` as default primary key type
14
14
  - Adds reliable `before_create` callback for UUIDv7 generation
15
- - Works perfectly on **both PostgreSQL 18+** and **SQLite** (and older PostgreSQL versions too)
15
+ - Works perfectly on **PostgreSQL 18+**, **MySQL 8.0+**, and **SQLite** (and older versions too)
16
16
  - **PostgreSQL**: Uses native `UUID` column types with full database support
17
+ - **MySQL**: Uses `VARCHAR(36)` with custom ActiveRecord type handling
17
18
  - **SQLite**: Uses `VARCHAR(36)` with custom ActiveRecord type handling
18
19
  - Zero database extensions needed
19
20
  - Minimal and maintainable — no monkey-patching hell
@@ -23,21 +24,16 @@ Works great with **PostgreSQL 18+** and **SQLite 3.51+** — zero extra extensio
23
24
  Add to your `Gemfile`:
24
25
 
25
26
  ```ruby
26
- gem "rails-uuid-pk", "~> 0.3"
27
+ gem "rails-uuid-pk", "~> 0.5"
27
28
  ```
28
29
 
29
30
  Then run:
30
31
 
31
32
  ```bash
32
33
  bundle install
33
- rails generate rails_uuid_pk:install
34
34
  ```
35
35
 
36
- The generator will:
37
-
38
- - Set `primary_key_type: :uuid` in your generators config
39
- - Create `app/models/concerns/has_uuidv7_primary_key.rb` (optional explicit include)
40
- - Show important compatibility notes
36
+ That's it! The gem automatically enables UUIDv7 primary keys for all your models.
41
37
 
42
38
  ## Usage
43
39
 
@@ -59,39 +55,36 @@ User.create!(name: "Alice") # ← id is automatically a proper UUIDv7
59
55
 
60
56
  ### Action Text & Active Storage
61
57
 
62
- When you run:
58
+ When you install Action Text or Active Storage:
63
59
 
64
60
  ```bash
65
61
  rails action_text:install
66
62
  rails active_storage:install
67
63
  ```
68
64
 
69
- The generated migrations will **automatically use the correct foreign key types** when referencing tables with UUID primary keys. No manual editing required!
70
-
71
- This works because rails-uuid-pk includes smart migration helpers that detect the primary key type of referenced tables and automatically set `type: :uuid` for foreign keys.
65
+ The generated migrations seamlessly integrate with UUID primary keys. Rails-uuid-pk's smart migration helpers automatically detect UUID primary keys in referenced tables and set the appropriate `type: :uuid` for foreign keys.
72
66
 
73
67
  ### Polymorphic associations
74
68
 
75
- **Polymorphic associations** (like Action Text's `record` references) will automatically use the correct foreign key type based on the referenced table's primary key. If the parent model uses UUID primary keys, the foreign key will be UUID type.
69
+ Polymorphic associations work seamlessly with UUID primary keys. Whether you're using Action Text's `record` references or custom polymorphic associations, the migration helpers automatically detect the parent table's primary key type and set the correct foreign key type.
76
70
 
77
- For **custom polymorphic associations**, the migration helpers will also automatically detect and set the correct type:
71
+ For example, this migration will automatically use `type: :uuid` when the parent models have UUID primary keys:
78
72
 
79
73
  ```ruby
80
- # This will automatically use type: :uuid if the parent models have UUID primary keys
81
74
  create_table :comments do |t|
82
75
  t.references :commentable, polymorphic: true
83
76
  end
84
77
  ```
85
78
 
86
- No manual `type: :uuid` specification needed!
87
-
88
79
  ## Features / Trade-offs
89
80
 
90
81
  | Feature | Status | Notes |
91
82
  |--------------------------------------|-----------------|-----------------------------------------------------------------------|
92
83
  | UUIDv7 generation | Automatic | Uses `SecureRandom.uuid_v7` (very good randomness + monotonicity) |
93
84
  | PostgreSQL 18+ native `uuidv7()` | Not used | Fallback approach — more universal, no extensions needed |
94
- | SQLite support | Full | No native function app-side generation works great |
85
+ | PostgreSQL support | Full | Native `UUID` column types with full database support |
86
+ | MySQL 8.0+ support | Full | Uses `VARCHAR(36)` with custom ActiveRecord type handling |
87
+ | SQLite support | Full | Uses `VARCHAR(36)` with custom ActiveRecord type handling |
95
88
  | Index locality / performance | Very good | UUIDv7 is monotonic → almost as good as sequential IDs |
96
89
  | Zero config after install | Yes | Migration helpers automatically handle foreign key types |
97
90
  | Works with Rails 7.1 – 8+ | Yes | Tested conceptually up to Rails 8.1+ |
@@ -119,15 +112,16 @@ This project includes a devcontainer configuration for VS Code. To get started:
119
112
 
120
113
  ### Running Tests
121
114
 
122
- The project includes a comprehensive test suite that runs against both SQLite and PostgreSQL.
115
+ The project includes a comprehensive test suite that runs against SQLite, PostgreSQL, and MySQL.
123
116
 
124
117
  ```bash
125
- # Run all tests (SQLite + PostgreSQL)
118
+ # Run all tests (SQLite + PostgreSQL + MySQL)
126
119
  ./bin/test
127
120
 
128
121
  # Run tests for specific database
129
122
  DB=sqlite ./bin/test # SQLite only
130
123
  DB=postgres ./bin/test # PostgreSQL only
124
+ DB=mysql ./bin/test # MySQL only
131
125
  ```
132
126
 
133
127
  ### Code Quality
@@ -152,9 +146,10 @@ gem install rails-uuid-pk-0.1.0.gem
152
146
 
153
147
  ### Database Setup
154
148
 
155
- For PostgreSQL testing, ensure PostgreSQL is running and accessible. The test suite uses these environment variables:
149
+ For database testing, ensure the respective databases are running and accessible. The test suite uses these environment variables:
156
150
  - `DB_HOST` (defaults to localhost)
157
151
  - `RAILS_ENV=test_postgresql` for PostgreSQL tests
152
+ - `RAILS_ENV=test_mysql` for MySQL tests
158
153
 
159
154
  ## Contributing
160
155
 
@@ -0,0 +1,9 @@
1
+ module RailsUuidPk
2
+ module Mysql2AdapterExtension
3
+ def native_database_types
4
+ super.merge(
5
+ uuid: { name: "varchar", limit: 36 }
6
+ )
7
+ end
8
+ end
9
+ end
@@ -17,6 +17,19 @@ module RailsUuidPk
17
17
  RailsUuidPk::Type::Uuid.new
18
18
  end
19
19
 
20
+ # Also map "uuid" SQL type to our custom UUID type for direct lookups
21
+ ActiveRecord::Base.connection.send(:type_map).register_type "uuid" do |sql_type|
22
+ RailsUuidPk::Type::Uuid.new
23
+ end
24
+ elsif ActiveRecord::Base.connection.adapter_name == "MySQL"
25
+ # Register the UUID type with ActiveRecord for MySQL
26
+ ActiveRecord::Type.register(:uuid, RailsUuidPk::Type::Uuid, adapter: :mysql2)
27
+
28
+ # Map varchar SQL type to our custom UUID type (since that's how UUID columns are stored in MySQL)
29
+ ActiveRecord::Base.connection.send(:type_map).register_type(/varchar/i) do |sql_type|
30
+ RailsUuidPk::Type::Uuid.new
31
+ end
32
+
20
33
  # Also map "uuid" SQL type to our custom UUID type for direct lookups
21
34
  ActiveRecord::Base.connection.send(:type_map).register_type "uuid" do |sql_type|
22
35
  RailsUuidPk::Type::Uuid.new
@@ -30,6 +43,15 @@ module RailsUuidPk
30
43
  ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend(RailsUuidPk::Sqlite3AdapterExtension)
31
44
  end
32
45
 
46
+ initializer "rails-uuid-pk.mysql_native_types" do
47
+ begin
48
+ require "active_record/connection_adapters/mysql2_adapter"
49
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(RailsUuidPk::Mysql2AdapterExtension)
50
+ rescue LoadError
51
+ # MySQL adapter not available, skip MySQL-specific initialization
52
+ end
53
+ end
54
+
33
55
 
34
56
 
35
57
  initializer "rails-uuid-pk.schema_format" do |app|
@@ -1,3 +1,3 @@
1
1
  module RailsUuidPk
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/rails_uuid_pk.rb CHANGED
@@ -2,6 +2,7 @@ require "rails_uuid_pk/version"
2
2
  require "rails_uuid_pk/concern"
3
3
  require "rails_uuid_pk/type"
4
4
  require "rails_uuid_pk/sqlite3_adapter_extension"
5
+ require "rails_uuid_pk/mysql2_adapter_extension"
5
6
  require "rails_uuid_pk/railtie"
6
7
 
7
8
  module RailsUuidPk
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.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joon Lee
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '8.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: mysql2
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.5.7
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.5.7
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: pg
28
42
  requirement: !ruby/object:Gem::Requirement
@@ -51,8 +65,8 @@ dependencies:
51
65
  - - "~>"
52
66
  - !ruby/object:Gem::Version
53
67
  version: 2.9.0
54
- description: Automatically use UUIDv7 for all primary keys in Rails applications.
55
- Works with PostgreSQL and SQLite, zero configuration required.
68
+ description: Automatically use UUID v7 for all primary keys in Rails applications.
69
+ Works with PostgreSQL, MySQL, and SQLite, zero configuration required.
56
70
  email:
57
71
  - seouri@gmail.com
58
72
  executables: []
@@ -63,12 +77,10 @@ files:
63
77
  - MIT-LICENSE
64
78
  - README.md
65
79
  - Rakefile
66
- - app/models/concerns/has_uuidv7_primary_key.rb
67
- - lib/generators/rails_uuid_pk/install/install_generator.rb
68
- - lib/generators/rails_uuid_pk/install/templates/has_uuidv7_primary_key.rb
69
80
  - lib/rails_uuid_pk.rb
70
81
  - lib/rails_uuid_pk/concern.rb
71
82
  - lib/rails_uuid_pk/migration_helpers.rb
83
+ - lib/rails_uuid_pk/mysql2_adapter_extension.rb
72
84
  - lib/rails_uuid_pk/railtie.rb
73
85
  - lib/rails_uuid_pk/sqlite3_adapter_extension.rb
74
86
  - lib/rails_uuid_pk/type.rb
@@ -97,5 +109,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
109
  requirements: []
98
110
  rubygems_version: 4.0.3
99
111
  specification_version: 4
100
- summary: Dead-simple UUIDv7 primary keys for Rails apps
112
+ summary: Dead-simple UUID v7 primary keys for Rails apps
101
113
  test_files: []
@@ -1,17 +0,0 @@
1
- # app/models/concerns/has_uuidv7_primary_key.rb
2
- # (this file is copied by the generator - you can modify it later if needed)
3
-
4
- module HasUuidv7PrimaryKey
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- before_create :assign_uuidv7_if_needed, if: -> { id.nil? }
9
- end
10
-
11
- private
12
-
13
- def assign_uuidv7_if_needed
14
- return if id.present?
15
- self.id = SecureRandom.uuid_v7
16
- end
17
- end
@@ -1,42 +0,0 @@
1
- module RailsUuidPk
2
- module Generators
3
- class InstallGenerator < Rails::Generators::Base
4
- source_root File.expand_path("templates", __dir__)
5
-
6
- desc "Installs rails-uuid-pk: sets uuid primary key + includes UUIDv7 concern"
7
-
8
- def add_concern_file
9
- copy_file "has_uuidv7_primary_key.rb",
10
- "app/models/concerns/has_uuidv7_primary_key.rb"
11
- end
12
-
13
- def show_next_steps
14
- say "\nrails-uuid-pk was successfully installed!", :green
15
-
16
- say "\n✅ Action Text & Active Storage compatibility", :green
17
- say "─────────────────────────────────────────────────────────────"
18
- say "Migration helpers now automatically handle foreign key types!"
19
- say "When you run:"
20
- say " rails action_text:install"
21
- say " rails active_storage:install"
22
- say ""
23
- say "The generated migrations will automatically use the correct UUID types"
24
- say "for foreign keys. No manual editing required!"
25
- say "─────────────────────────────────────────────────────────────\n"
26
-
27
- say "\nRecommended next steps:", :yellow
28
- say " 1. Add to ApplicationRecord (if you prefer explicit include):"
29
- say " class ApplicationRecord < ActiveRecord::Base"
30
- say " primary_abstract_class"
31
- say " include HasUuidv7PrimaryKey"
32
- say " end\n"
33
-
34
- say " 2. Or keep relying on Railtie automatic include (recommended for most cases)\n"
35
-
36
- say " 3. Now you can run:", :cyan
37
- say " rails g model User name:string email:string\n"
38
- say " → will create table with uuid primary key + automatic uuidv7\n"
39
- end
40
- end
41
- end
42
- end
@@ -1,17 +0,0 @@
1
- # app/models/concerns/has_uuidv7_primary_key.rb
2
- # (this file is copied by the generator - you can modify it later if needed)
3
-
4
- module HasUuidv7PrimaryKey
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- before_create :assign_uuidv7_if_needed, if: -> { id.nil? }
9
- end
10
-
11
- private
12
-
13
- def assign_uuidv7_if_needed
14
- return if id.present?
15
- self.id = SecureRandom.uuid_v7
16
- end
17
- end