sqlite_crypto 2.0.0 → 2.0.1
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 +22 -0
- data/README.md +98 -143
- data/lib/sqlite_crypto/configuration.rb +22 -2
- data/lib/sqlite_crypto/generators/uuid.rb +2 -2
- data/lib/sqlite_crypto/migration_helpers.rb +5 -0
- data/lib/sqlite_crypto/railtie.rb +8 -4
- data/lib/sqlite_crypto/schema_definitions.rb +4 -2
- data/lib/sqlite_crypto/type/ulid.rb +3 -1
- data/lib/sqlite_crypto/type/uuid.rb +3 -1
- data/lib/sqlite_crypto/version.rb +1 -1
- data/lib/sqlite_crypto.rb +0 -6
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f7728bff2a398f6ed1fe0ce0888055586b7619d45954728240ef32ba33cd1650
|
|
4
|
+
data.tar.gz: fb5715411594706283fd93969b4f97709f468870f428105c1cb5ebdefb8d5c56
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7d0efcd9f607384d1e33ee2c55643408cae5d4a0382885dee40ef6bc0dc142f62d4085cc85f529fd2e76694ffc624651aa7802f85bc0de789716a0b3d7c1aa27
|
|
7
|
+
data.tar.gz: 9954abb7f5068e1b85f9e636ce1abe0d921baa94b9b7394711745bba9bf349655611dcbd925b6ba0fe1c4d1405f2ae434bf863c7234ed864de17b5748b3efadd
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,28 @@ 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/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.0.1] - 2026-01-14
|
|
9
|
+
|
|
10
|
+
### Security
|
|
11
|
+
- **CRITICAL:**
|
|
12
|
+
- Fixed regex anchor vulnerability in UUID/ULID validators
|
|
13
|
+
- Fixed action_text-trix XSS vulnerability by updating the version to '>= 2.1.16'
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- **Eager configuration validation**: Setting `uuid_version = :v7` on Ruby < 3.3 now fails at boot time with clear error message instead of runtime failure
|
|
17
|
+
- **Namespace cleanup**: `uuid` and `ulid` schema helpers now scoped to `ActiveRecord::Schema` instead of global `Object`
|
|
18
|
+
- **Performance**: Cached Ruby version check in `V7_AVAILABLE` constant (eliminates repeated `Gem::Version` comparisons)
|
|
19
|
+
- **Boot time**: Added lazy loading with `ActiveSupport.on_load(:active_record)` hook for faster Rails initialization
|
|
20
|
+
- **Migration performance**: Memoized primary key type detection to avoid redundant database queries
|
|
21
|
+
|
|
22
|
+
### Removed
|
|
23
|
+
- Unused `SqliteCrypto::Error` class
|
|
24
|
+
- Unused `SqliteCrypto.load_extensions` placeholder method
|
|
25
|
+
|
|
26
|
+
### Internal
|
|
27
|
+
- Simplified configuration defaults to reuse `Generators::Uuid.v7_available?` logic
|
|
28
|
+
- Improved code organization and removed dead code
|
|
29
|
+
|
|
8
30
|
## [2.0.0] - 2026-01-08
|
|
9
31
|
|
|
10
32
|
### Added
|
data/README.md
CHANGED
|
@@ -4,88 +4,80 @@
|
|
|
4
4
|
[](LICENSE.txt)
|
|
5
5
|
[](https://github.com/bart-oz/sqlite_crypto)
|
|
6
6
|
[](https://github.com/bart-oz/sqlite_crypto/actions)
|
|
7
|
-
[](https://github.com/bart-oz/sqlite_crypto/actions)
|
|
8
8
|
[](https://github.com/bart-oz/sqlite_crypto)
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
Seamless UUID and ULID primary key support for Rails applications using SQLite3. Handles type registration, validation, foreign key detection, and schema generation automatically.
|
|
11
13
|
|
|
12
14
|
```ruby
|
|
13
|
-
# Just use :uuid or :ulid instead of default integer IDs
|
|
14
15
|
create_table :users, id: :uuid do |t|
|
|
15
16
|
t.string :email
|
|
17
|
+
t.timestamps
|
|
16
18
|
end
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
**Key capabilities:**
|
|
22
|
+
- UUID primary keys (v4 random or v7 time-ordered)
|
|
23
|
+
- ULID primary keys (time-sortable, compact)
|
|
24
|
+
- Automatic foreign key type detection
|
|
25
|
+
- Model-level ID generation
|
|
26
|
+
- Clean schema.rb output
|
|
27
|
+
- Zero external dependencies
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
✅ **ULID primary keys** (time-sortable, 26 characters)<br/>
|
|
23
|
-
✅ **Automatic foreign key detection** - `t.references` just works<br/>
|
|
24
|
-
✅ **Model generators** - `generates_uuid :token`<br/>
|
|
25
|
-
✅ **Clean schema.rb** - No verbose type definitions<br/>
|
|
26
|
-
✅ **Zero dependencies** - Uses Ruby's built-in SecureRandom<br/>
|
|
29
|
+
## Compatibility
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
**Ruby & Rails:**
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
| | Rails 7.1 | Rails 7.2 | Rails 8.0 | Rails 8.1 |
|
|
34
|
+
|-------|-----------|-----------|-----------|-----------|
|
|
35
|
+
| Ruby 3.1 | ✓ | ✓ | - | - |
|
|
36
|
+
| Ruby 3.2 | ✓ | ✓ | ✓ | ✓ |
|
|
37
|
+
| Ruby 3.3 | ✓ | ✓ | ✓ | ✓ |
|
|
38
|
+
| Ruby 3.4 | ✓ | ✓ | ✓ | ✓ |
|
|
39
|
+
| Ruby 4.0 | ✓ | ✓ | ✓ | ✓ |
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
**UUID Versions:**
|
|
36
42
|
|
|
37
|
-
|
|
|
38
|
-
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
| **UUIDv4** | `550e8400-e29b-...` (36 chars) | ~2-5% slower inserts | Random IDs, legacy compatibility |
|
|
42
|
-
| **ULID** | `01ARZ3NDEK...` (26 chars) | ~3-7% slower inserts | Time-sortable, compact format |
|
|
43
|
+
| Version | Ruby 3.1/3.2 | Ruby 3.3+ |
|
|
44
|
+
|---------|--------------|-----------|
|
|
45
|
+
| v4 (random) | ✓ | ✓ |
|
|
46
|
+
| v7 (time-ordered) | - | ✓ |
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
**Database:** SQLite3
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
## Installation
|
|
47
51
|
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
```ruby
|
|
53
|
+
# Gemfile
|
|
54
|
+
gem "sqlite_crypto"
|
|
51
55
|
```
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
```bash
|
|
58
|
+
bundle install
|
|
59
|
+
rails generate sqlite_crypto:install
|
|
60
|
+
```
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
The generator creates `config/initializers/sqlite_crypto.rb` for configuration.
|
|
59
63
|
|
|
60
64
|
## Configuration
|
|
61
65
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
After running `rails generate sqlite_crypto:install`:
|
|
66
|
+
**1. Configure UUID Version**
|
|
65
67
|
|
|
66
68
|
```ruby
|
|
67
69
|
# config/initializers/sqlite_crypto.rb
|
|
68
70
|
SqliteCrypto.configure do |config|
|
|
69
|
-
config.uuid_version = :v7 #
|
|
70
|
-
# config.uuid_version = :v4 # Use this for Ruby 3.1/3.2
|
|
71
|
+
config.uuid_version = :v7 # or :v4
|
|
71
72
|
end
|
|
72
73
|
```
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
- Ruby 3.3+ → v4 and v7
|
|
76
|
-
- Ruby 3.1/3.2 → v4 only
|
|
75
|
+
The gem automatically selects a default based on your Ruby version (v7 for Ruby 3.3+, v4 otherwise).
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
```ruby
|
|
80
|
-
SqliteCrypto::Generators::Uuid.v7_available? # => true/false
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Usage Examples
|
|
84
|
-
|
|
85
|
-
### UUID Primary Keys
|
|
77
|
+
**2. Create Tables with UUID/ULID**
|
|
86
78
|
|
|
87
79
|
```ruby
|
|
88
|
-
class CreateUsers < ActiveRecord::Migration[8.
|
|
80
|
+
class CreateUsers < ActiveRecord::Migration[8.0]
|
|
89
81
|
def change
|
|
90
82
|
create_table :users, id: :uuid do |t|
|
|
91
83
|
t.string :email
|
|
@@ -95,106 +87,96 @@ class CreateUsers < ActiveRecord::Migration[8.1]
|
|
|
95
87
|
end
|
|
96
88
|
```
|
|
97
89
|
|
|
98
|
-
|
|
99
|
-
```ruby
|
|
100
|
-
user = User.create!(email: "alice@example.com")
|
|
101
|
-
user.id # => "018d3f91-8f4a-7000-9e7b-4a5c8d2e1f3a" (UUIDv7)
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### ULID Primary Keys
|
|
90
|
+
**3. Use Your Models**
|
|
105
91
|
|
|
106
92
|
```ruby
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
create_table :posts, id: :ulid do |t|
|
|
110
|
-
t.string :title
|
|
111
|
-
t.timestamps
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
93
|
+
user = User.create!(email: "test@example.com")
|
|
94
|
+
user.id # => "018d3f91-8f4a-7000-9e7b-4a5c8d2e1f3a"
|
|
115
95
|
```
|
|
116
96
|
|
|
117
|
-
|
|
118
|
-
```ruby
|
|
119
|
-
post = Post.create!(title: "Hello World")
|
|
120
|
-
post.id # => "01ARZ3NDEKTSV4RRFFQ69G5FAV" (26 chars, time-sortable)
|
|
121
|
-
```
|
|
97
|
+
## Usage
|
|
122
98
|
|
|
123
|
-
|
|
99
|
+
**Primary Keys**
|
|
124
100
|
|
|
125
|
-
|
|
101
|
+
Create tables with UUID or ULID primary keys:
|
|
126
102
|
|
|
127
103
|
```ruby
|
|
128
|
-
#
|
|
104
|
+
# UUID
|
|
129
105
|
create_table :users, id: :uuid do |t|
|
|
130
|
-
t.string :
|
|
106
|
+
t.string :email
|
|
131
107
|
end
|
|
132
108
|
|
|
133
|
-
#
|
|
134
|
-
create_table :posts do |t|
|
|
135
|
-
t.references :user # Auto-detected as varchar(36)!
|
|
109
|
+
# ULID
|
|
110
|
+
create_table :posts, id: :ulid do |t|
|
|
136
111
|
t.string :title
|
|
137
112
|
end
|
|
138
113
|
```
|
|
139
114
|
|
|
140
|
-
|
|
115
|
+
**Foreign Keys**
|
|
116
|
+
|
|
117
|
+
Foreign key types are automatically detected from parent tables:
|
|
118
|
+
|
|
141
119
|
```ruby
|
|
142
|
-
create_table :
|
|
120
|
+
create_table :users, id: :uuid do |t|
|
|
143
121
|
t.string :name
|
|
144
122
|
end
|
|
145
123
|
|
|
146
|
-
create_table :
|
|
147
|
-
t.references :
|
|
124
|
+
create_table :posts do |t|
|
|
125
|
+
t.references :user # Automatically varchar(36)
|
|
126
|
+
t.string :title
|
|
148
127
|
end
|
|
149
128
|
```
|
|
150
129
|
|
|
151
|
-
|
|
130
|
+
**Model-Level Generation**
|
|
131
|
+
|
|
132
|
+
Generate UUIDs or ULIDs for any column:
|
|
152
133
|
|
|
153
134
|
```ruby
|
|
154
135
|
class User < ApplicationRecord
|
|
155
|
-
generates_uuid :
|
|
156
|
-
generates_ulid :
|
|
136
|
+
generates_uuid :api_token
|
|
137
|
+
generates_ulid :tracking_id, unique: true
|
|
157
138
|
end
|
|
158
139
|
|
|
159
|
-
user = User.create!
|
|
160
|
-
user.
|
|
161
|
-
user.
|
|
140
|
+
user = User.create!
|
|
141
|
+
user.api_token # => "550e8400-e29b-41d4-a716-446655440000"
|
|
142
|
+
user.tracking_id # => "01ARZ3NDEKTSV4RRFFQ69G5FAV"
|
|
162
143
|
```
|
|
163
144
|
|
|
164
|
-
##
|
|
145
|
+
## ID Types
|
|
165
146
|
|
|
166
|
-
|
|
167
|
-
- **Rails**: 7.1, 7.2, 8.0, 8.1
|
|
168
|
-
- **Database**: SQLite3
|
|
147
|
+
**Characteristics**
|
|
169
148
|
|
|
170
|
-
|
|
149
|
+
| Type | Length | Format | Ordering | Ruby Version |
|
|
150
|
+
|------|--------|--------|----------|--------------|
|
|
151
|
+
| Integer | 8 bytes | Sequential numbers | Sequential | Any |
|
|
152
|
+
| UUIDv4 | 36 chars | `xxxxxxxx-xxxx-4xxx-...` | Random | 3.1+ |
|
|
153
|
+
| UUIDv7 | 36 chars | `xxxxxxxx-xxxx-7xxx-...` | Time-based | 3.3+ |
|
|
154
|
+
| ULID | 26 chars | `01ARZ3NDEK...` | Time-based | 3.1+ |
|
|
171
155
|
|
|
172
|
-
|
|
156
|
+
**Performance**
|
|
173
157
|
|
|
174
|
-
|
|
158
|
+
Benchmarks with 10,000 records on SQLite3:
|
|
175
159
|
|
|
176
|
-
|
|
|
177
|
-
|
|
178
|
-
|
|
|
179
|
-
|
|
|
180
|
-
|
|
|
160
|
+
| Type | Insert | Query | Index Size |
|
|
161
|
+
|------|--------|-------|------------|
|
|
162
|
+
| Integer | 1.00x | 1.00x | 100% |
|
|
163
|
+
| UUIDv4 | 1.02x | 1.03x | 145% |
|
|
164
|
+
| UUIDv7 | 1.01x | 1.03x | 145% |
|
|
165
|
+
| ULID | 1.05x | 1.04x | 130% |
|
|
181
166
|
|
|
182
|
-
|
|
183
|
-
## Advanced Usage
|
|
167
|
+
Run your own: `bundle exec rspec --tag performance`
|
|
184
168
|
|
|
185
|
-
|
|
169
|
+
## Advanced Usage
|
|
186
170
|
|
|
187
|
-
|
|
171
|
+
**Non-Standard Table Names**
|
|
188
172
|
|
|
189
173
|
```ruby
|
|
190
174
|
create_table :posts do |t|
|
|
191
|
-
t.references :author, to_table: :users
|
|
175
|
+
t.references :author, to_table: :users
|
|
192
176
|
end
|
|
193
177
|
```
|
|
194
178
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
Different tables can use different ID types:
|
|
179
|
+
**Mixed ID Types**
|
|
198
180
|
|
|
199
181
|
```ruby
|
|
200
182
|
create_table :users, id: :uuid do |t|
|
|
@@ -202,65 +184,38 @@ create_table :users, id: :uuid do |t|
|
|
|
202
184
|
end
|
|
203
185
|
|
|
204
186
|
create_table :sessions, id: :ulid do |t|
|
|
205
|
-
t.references :user
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
create_table :logs do |t| # Integer ID (default)
|
|
209
|
-
t.string :message
|
|
187
|
+
t.references :user
|
|
210
188
|
end
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
### ID Prefixes (Stripe-style)
|
|
214
189
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
before_create :add_prefix
|
|
218
|
-
|
|
219
|
-
private
|
|
220
|
-
def add_prefix
|
|
221
|
-
self.id = "inv_#{SecureRandom.uuid}" if id.nil?
|
|
222
|
-
end
|
|
190
|
+
create_table :logs do |t| # Integer ID
|
|
191
|
+
t.text :message
|
|
223
192
|
end
|
|
224
193
|
```
|
|
225
194
|
|
|
226
195
|
## Migrating Existing Apps
|
|
227
196
|
|
|
228
|
-
|
|
197
|
+
Add UUID/ULID to new tables while keeping integer IDs on existing tables:
|
|
229
198
|
|
|
230
199
|
```ruby
|
|
231
|
-
#
|
|
232
|
-
# users: id (integer)
|
|
233
|
-
# posts: id (integer), user_id (integer)
|
|
234
|
-
|
|
235
|
-
# New tables use UUID/ULID
|
|
200
|
+
# Existing tables unchanged
|
|
236
201
|
create_table :invoices, id: :uuid do |t|
|
|
237
|
-
t.references :user #
|
|
202
|
+
t.references :user # Detects integer from users table
|
|
238
203
|
t.decimal :amount
|
|
239
204
|
end
|
|
240
205
|
```
|
|
241
206
|
|
|
242
|
-
## How It Works
|
|
243
|
-
|
|
244
|
-
1. **Type Registration** - Registers `:uuid` and `:ulid` with ActiveRecord's SQLite3 adapter
|
|
245
|
-
2. **Validation** - UUIDs: 36-char format, ULIDs: 26-char format
|
|
246
|
-
3. **Migration Helpers** - `t.uuid()` and `t.ulid()` in migrations
|
|
247
|
-
4. **Smart References** - `t.references` detects parent table ID type
|
|
248
|
-
5. **Model Extensions** - `generates_uuid`/`generates_ulid` for auto-generation
|
|
249
|
-
6. **Schema Dumper** - Clean output: `id: :uuid` instead of verbose definitions
|
|
250
|
-
|
|
251
207
|
## Development
|
|
252
208
|
|
|
253
209
|
```bash
|
|
254
210
|
bundle install
|
|
255
|
-
bundle exec rspec
|
|
256
|
-
bundle exec standardrb
|
|
257
|
-
bundle exec rspec --tag performance # Benchmarks
|
|
211
|
+
bundle exec rspec
|
|
212
|
+
bundle exec standardrb
|
|
258
213
|
```
|
|
259
214
|
|
|
260
215
|
## Contributing
|
|
261
216
|
|
|
262
|
-
|
|
217
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bart-oz/sqlite_crypto.
|
|
263
218
|
|
|
264
219
|
## License
|
|
265
220
|
|
|
266
|
-
|
|
221
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
|
@@ -2,11 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
module SqliteCrypto
|
|
4
4
|
class Configuration
|
|
5
|
-
|
|
5
|
+
attr_reader :uuid_version
|
|
6
6
|
|
|
7
7
|
def initialize
|
|
8
8
|
# Default to v7 on Ruby 3.3+, v4 on older versions
|
|
9
|
-
@uuid_version =
|
|
9
|
+
@uuid_version = Generators::Uuid.v7_available? ? :v7 : :v4
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def uuid_version=(version)
|
|
13
|
+
validate_uuid_version!(version)
|
|
14
|
+
@uuid_version = version
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def validate_uuid_version!(version)
|
|
20
|
+
valid_versions = [:v4, :v7]
|
|
21
|
+
unless valid_versions.include?(version)
|
|
22
|
+
raise ArgumentError, "Invalid UUID version: #{version}. Must be one of #{valid_versions.join(", ")}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
if version == :v7 && !Generators::Uuid.v7_available?
|
|
26
|
+
raise ArgumentError,
|
|
27
|
+
"UUIDv7 requires Ruby 3.3+. Current: #{RUBY_VERSION}. " \
|
|
28
|
+
"Use config.uuid_version = :v4 or upgrade Ruby."
|
|
29
|
+
end
|
|
10
30
|
end
|
|
11
31
|
end
|
|
12
32
|
end
|
|
@@ -6,7 +6,7 @@ module SqliteCrypto
|
|
|
6
6
|
module Generators
|
|
7
7
|
class Uuid
|
|
8
8
|
MINIMUM_RUBY_FOR_V7 = Gem::Version.new("3.3.0")
|
|
9
|
-
|
|
9
|
+
V7_AVAILABLE = (Gem::Version.new(RUBY_VERSION) >= MINIMUM_RUBY_FOR_V7)
|
|
10
10
|
|
|
11
11
|
class << self
|
|
12
12
|
def generate(version: SqliteCrypto.config.uuid_version)
|
|
@@ -21,7 +21,7 @@ module SqliteCrypto
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def v7_available?
|
|
24
|
-
|
|
24
|
+
V7_AVAILABLE
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
private
|
|
@@ -32,6 +32,11 @@ module SqliteCrypto
|
|
|
32
32
|
private
|
|
33
33
|
|
|
34
34
|
def detect_primary_key_type(table_name)
|
|
35
|
+
@pk_type_cache ||= {}
|
|
36
|
+
@pk_type_cache[table_name] ||= fetch_primary_key_type(table_name)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def fetch_primary_key_type(table_name)
|
|
35
40
|
conn = @conn || @base || (respond_to?(:connection) ? connection : nil)
|
|
36
41
|
return nil unless conn&.table_exists?(table_name)
|
|
37
42
|
|
|
@@ -10,13 +10,17 @@ module SqliteCrypto
|
|
|
10
10
|
config.sqlite_crypto = ActiveSupport::OrderedOptions.new
|
|
11
11
|
|
|
12
12
|
initializer "sqlite_crypto.register_types" do
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
ActiveSupport.on_load(:active_record) do
|
|
14
|
+
ActiveRecord::Type.register(:uuid, SqliteCrypto::Type::Uuid, adapter: :sqlite3)
|
|
15
|
+
ActiveRecord::Type.register(:ulid, SqliteCrypto::Type::ULID, adapter: :sqlite3)
|
|
16
|
+
end
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
initializer "sqlite_crypto.native_types" do
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
ActiveSupport.on_load(:active_record) do
|
|
21
|
+
require "active_record/connection_adapters/sqlite3_adapter"
|
|
22
|
+
ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend(SqliteCrypto::Sqlite3AdapterExtension)
|
|
23
|
+
end
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
initializer "sqlite_crypto.schema_dumper", after: "active_record.initialize_database" do
|
|
@@ -13,5 +13,7 @@ module SqliteCrypto
|
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
# Extend
|
|
17
|
-
|
|
16
|
+
# Extend ActiveRecord::Schema context for schema.rb loading (not global Object)
|
|
17
|
+
if defined?(ActiveRecord::Schema)
|
|
18
|
+
ActiveRecord::Schema.include(SqliteCrypto::SchemaDefinitions)
|
|
19
|
+
end
|
|
@@ -5,6 +5,8 @@ require "sqlite_crypto/type/base"
|
|
|
5
5
|
module SqliteCrypto
|
|
6
6
|
module Type
|
|
7
7
|
class ULID < Base
|
|
8
|
+
ULID_PATTERN = /\A[0-7][0-9A-Z]{25}\z/i
|
|
9
|
+
|
|
8
10
|
def type
|
|
9
11
|
:ulid
|
|
10
12
|
end
|
|
@@ -12,7 +14,7 @@ module SqliteCrypto
|
|
|
12
14
|
private
|
|
13
15
|
|
|
14
16
|
def valid?(value)
|
|
15
|
-
|
|
17
|
+
ULID_PATTERN.match?(value)
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
end
|
|
@@ -5,6 +5,8 @@ require "sqlite_crypto/type/base"
|
|
|
5
5
|
module SqliteCrypto
|
|
6
6
|
module Type
|
|
7
7
|
class Uuid < Base
|
|
8
|
+
UUID_PATTERN = /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i
|
|
9
|
+
|
|
8
10
|
def type
|
|
9
11
|
:uuid
|
|
10
12
|
end
|
|
@@ -12,7 +14,7 @@ module SqliteCrypto
|
|
|
12
14
|
private
|
|
13
15
|
|
|
14
16
|
def valid?(value)
|
|
15
|
-
|
|
17
|
+
UUID_PATTERN.match?(value)
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
end
|
data/lib/sqlite_crypto.rb
CHANGED
|
@@ -8,8 +8,6 @@ require "sqlite_crypto/schema_definitions"
|
|
|
8
8
|
require "sqlite_crypto/generators/uuid"
|
|
9
9
|
|
|
10
10
|
module SqliteCrypto
|
|
11
|
-
class Error < StandardError; end
|
|
12
|
-
|
|
13
11
|
class << self
|
|
14
12
|
def configuration
|
|
15
13
|
@configuration ||= Configuration.new
|
|
@@ -24,8 +22,4 @@ module SqliteCrypto
|
|
|
24
22
|
@configuration = Configuration.new
|
|
25
23
|
end
|
|
26
24
|
end
|
|
27
|
-
|
|
28
|
-
def self.load_extensions
|
|
29
|
-
# Placeholder for future extension loading logic
|
|
30
|
-
end
|
|
31
25
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sqlite_crypto
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- BartOz
|
|
@@ -51,8 +51,10 @@ dependencies:
|
|
|
51
51
|
- - "~>"
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '1.0'
|
|
54
|
-
description:
|
|
55
|
-
|
|
54
|
+
description: UUID and ULID primary key support for Rails with SQLite3. Provides automatic
|
|
55
|
+
type registration, validation, foreign key detection, and clean schema generation.
|
|
56
|
+
Supports UUIDv4 (random), UUIDv7 (time-ordered), and ULID (compact, time-sortable)
|
|
57
|
+
with zero external dependencies.
|
|
56
58
|
email:
|
|
57
59
|
- bartek.ozdoba@gmail.com
|
|
58
60
|
executables: []
|
|
@@ -98,5 +100,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
98
100
|
requirements: []
|
|
99
101
|
rubygems_version: 4.0.3
|
|
100
102
|
specification_version: 4
|
|
101
|
-
summary:
|
|
103
|
+
summary: UUID (v4/v7) and ULID primary keys for Rails + SQLite3
|
|
102
104
|
test_files: []
|