rails-uuid-pk 0.1.0 → 0.2.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/CHANGELOG.md +11 -0
- data/lib/rails_uuid_pk/railtie.rb +28 -22
- data/lib/rails_uuid_pk/sqlite3_adapter_extension.rb +9 -0
- data/lib/rails_uuid_pk/type.rb +47 -0
- data/lib/rails_uuid_pk/version.rb +1 -1
- data/lib/rails_uuid_pk.rb +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a1e3ae77afb9d7050fab7a90ea7596b18894cb00006e36e0dd391bc3a1b1194
|
|
4
|
+
data.tar.gz: b28a4b0918db5a7285ad8db6af0e0243a862f781c6476daf1954c282b97475ae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 63f0882a6e7e8f50b35811b81b9efbd75a25ebaa7eadf2b20a75610a14eeb25a4e10635bd39565756d428585609989aabf418dd5486bc361199f49d0fa9eaffb
|
|
7
|
+
data.tar.gz: 7055f26c0c87e83e3af48e3cb08b75cc2582af0de4c3c5706af1ca595468bbf77ba4fa3a9eddc2da05c4f471233c5d1d3debfed2cb0e935ecd1679fb41b97d51
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ 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.2.0] - 2026-01-07
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- SQLite schema dumping support for UUID primary keys using Ruby format
|
|
12
|
+
- Custom UUID type implementation for ActiveRecord type casting and validation
|
|
13
|
+
- SQLite3 adapter extension for native UUID database type definitions
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Switched SQLite schema format from SQL to Ruby for improved compatibility and standard Rails behavior
|
|
17
|
+
- Updated test suite to expect Ruby schema format for SQLite databases
|
|
18
|
+
|
|
8
19
|
## [0.1.0] - 2026-01-07
|
|
9
20
|
|
|
10
21
|
### Added
|
|
@@ -6,34 +6,40 @@ module RailsUuidPk
|
|
|
6
6
|
end
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
initializer "rails-uuid-pk.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
initializer "rails-uuid-pk.configure_type_map", after: "active_record.initialize_database" do
|
|
10
|
+
ActiveSupport.on_load(:active_record) do
|
|
11
|
+
if ActiveRecord::Base.connection.adapter_name == "SQLite"
|
|
12
|
+
# Register the UUID type with ActiveRecord
|
|
13
|
+
ActiveRecord::Type.register(:uuid, RailsUuidPk::Type::Uuid, adapter: :sqlite3)
|
|
14
|
+
|
|
15
|
+
# Map varchar SQL type to our custom UUID type (since that's how UUID columns are stored in SQLite)
|
|
16
|
+
ActiveRecord::Base.connection.send(:type_map).register_type(/varchar/i) do |sql_type|
|
|
17
|
+
RailsUuidPk::Type::Uuid.new
|
|
18
|
+
end
|
|
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
|
+
end
|
|
13
25
|
end
|
|
14
26
|
end
|
|
15
27
|
|
|
16
|
-
initializer "rails-uuid-pk.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
initializer "rails-uuid-pk.native_types" do
|
|
29
|
+
require "active_record/connection_adapters/sqlite3_adapter"
|
|
30
|
+
ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend(RailsUuidPk::Sqlite3AdapterExtension)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
initializer "rails-uuid-pk.schema_format" do |app|
|
|
36
|
+
# Ensure schema_format is set to :ruby for SQLite (default in Rails)
|
|
37
|
+
app.config.active_record.schema_format ||= :ruby
|
|
20
38
|
end
|
|
21
39
|
|
|
22
|
-
initializer "rails-uuid-pk.
|
|
40
|
+
initializer "rails-uuid-pk.include_concern" do
|
|
23
41
|
ActiveSupport.on_load(:active_record) do
|
|
24
|
-
|
|
25
|
-
# Define a custom UUID type for SQLite that reports as :uuid
|
|
26
|
-
uuid_type = Class.new(ActiveRecord::Type::String) do
|
|
27
|
-
def type
|
|
28
|
-
:uuid
|
|
29
|
-
end
|
|
30
|
-
end.new
|
|
31
|
-
|
|
32
|
-
# Map 'uuid' SQL type to our custom UUID type
|
|
33
|
-
ActiveRecord::Base.connection.send(:type_map).register_type "uuid" do |sql_type|
|
|
34
|
-
uuid_type
|
|
35
|
-
end
|
|
36
|
-
end
|
|
42
|
+
ActiveRecord::Base.include RailsUuidPk::HasUuidv7PrimaryKey
|
|
37
43
|
end
|
|
38
44
|
end
|
|
39
45
|
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module RailsUuidPk
|
|
2
|
+
module Type
|
|
3
|
+
class Uuid < ActiveRecord::Type::String
|
|
4
|
+
def type
|
|
5
|
+
# Return :string during schema dumping to avoid "Unknown type 'uuid'" errors
|
|
6
|
+
# Return :uuid for normal operation and tests
|
|
7
|
+
if caller.any? { |c| c.include?("schema_dumper") }
|
|
8
|
+
:string
|
|
9
|
+
else
|
|
10
|
+
:uuid
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def deserialize(value)
|
|
15
|
+
return if value.nil?
|
|
16
|
+
cast(value)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def cast(value)
|
|
20
|
+
return if value.nil?
|
|
21
|
+
return value if value.is_a?(String) && valid?(value)
|
|
22
|
+
|
|
23
|
+
if value.respond_to?(:to_s)
|
|
24
|
+
str = value.to_s
|
|
25
|
+
return str if valid?(str)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Allow invalid UUIDs to be stored (for backward compatibility and manual id assignment)
|
|
29
|
+
value.to_s
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def serialize(value)
|
|
33
|
+
cast(value)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def changed_in_place?(raw_old_value, new_value)
|
|
37
|
+
cast(raw_old_value) != cast(new_value)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def valid?(value)
|
|
43
|
+
value.match?(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
data/lib/rails_uuid_pk.rb
CHANGED
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.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joon Lee
|
|
@@ -69,6 +69,8 @@ files:
|
|
|
69
69
|
- lib/rails_uuid_pk.rb
|
|
70
70
|
- lib/rails_uuid_pk/concern.rb
|
|
71
71
|
- lib/rails_uuid_pk/railtie.rb
|
|
72
|
+
- lib/rails_uuid_pk/sqlite3_adapter_extension.rb
|
|
73
|
+
- lib/rails_uuid_pk/type.rb
|
|
72
74
|
- lib/rails_uuid_pk/version.rb
|
|
73
75
|
- lib/tasks/rails_uuid_pk_tasks.rake
|
|
74
76
|
homepage: https://github.com/seouri/rails-uuid-pk
|