familia 2.0.0.pre26 → 2.1.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rst +94 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +12 -2
  5. data/README.md +1 -3
  6. data/docs/guides/feature-encrypted-fields.md +1 -1
  7. data/docs/guides/feature-expiration.md +1 -1
  8. data/docs/guides/feature-quantization.md +1 -1
  9. data/docs/guides/writing-migrations.md +345 -0
  10. data/docs/overview.md +7 -7
  11. data/docs/reference/api-technical.md +103 -7
  12. data/examples/migrations/v1_to_v2_serialization_migration.rb +374 -0
  13. data/examples/schemas/customer.json +33 -0
  14. data/examples/schemas/session.json +27 -0
  15. data/familia.gemspec +3 -2
  16. data/lib/familia/features/schema_validation.rb +139 -0
  17. data/lib/familia/migration/base.rb +447 -0
  18. data/lib/familia/migration/errors.rb +31 -0
  19. data/lib/familia/migration/model.rb +418 -0
  20. data/lib/familia/migration/pipeline.rb +226 -0
  21. data/lib/familia/migration/rake_tasks.rake +3 -0
  22. data/lib/familia/migration/rake_tasks.rb +160 -0
  23. data/lib/familia/migration/registry.rb +364 -0
  24. data/lib/familia/migration/runner.rb +311 -0
  25. data/lib/familia/migration/script.rb +234 -0
  26. data/lib/familia/migration.rb +43 -0
  27. data/lib/familia/schema_registry.rb +173 -0
  28. data/lib/familia/settings.rb +63 -1
  29. data/lib/familia/version.rb +1 -1
  30. data/lib/familia.rb +1 -0
  31. data/try/features/schema_registry_try.rb +193 -0
  32. data/try/features/schema_validation_feature_try.rb +218 -0
  33. data/try/migration/base_try.rb +226 -0
  34. data/try/migration/errors_try.rb +67 -0
  35. data/try/migration/integration_try.rb +451 -0
  36. data/try/migration/model_try.rb +431 -0
  37. data/try/migration/pipeline_try.rb +460 -0
  38. data/try/migration/rake_tasks_try.rb +61 -0
  39. data/try/migration/registry_try.rb +199 -0
  40. data/try/migration/runner_try.rb +311 -0
  41. data/try/migration/schema_validation_try.rb +201 -0
  42. data/try/migration/script_try.rb +192 -0
  43. data/try/migration/v1_to_v2_serialization_try.rb +513 -0
  44. data/try/performance/benchmarks_try.rb +11 -12
  45. metadata +45 -27
  46. data/docs/migrating/v2.0.0-pre.md +0 -84
  47. data/docs/migrating/v2.0.0-pre11.md +0 -253
  48. data/docs/migrating/v2.0.0-pre12.md +0 -306
  49. data/docs/migrating/v2.0.0-pre13.md +0 -95
  50. data/docs/migrating/v2.0.0-pre14.md +0 -37
  51. data/docs/migrating/v2.0.0-pre18.md +0 -58
  52. data/docs/migrating/v2.0.0-pre19.md +0 -197
  53. data/docs/migrating/v2.0.0-pre22.md +0 -241
  54. data/docs/migrating/v2.0.0-pre5.md +0 -131
  55. data/docs/migrating/v2.0.0-pre6.md +0 -154
  56. data/docs/migrating/v2.0.0-pre7.md +0 -222
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: familia
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre26
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -9,20 +9,6 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: benchmark
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - "~>"
17
- - !ruby/object:Gem::Version
18
- version: '0.4'
19
- type: :runtime
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - "~>"
24
- - !ruby/object:Gem::Version
25
- version: '0.4'
26
12
  - !ruby/object:Gem::Dependency
27
13
  name: concurrent-ruby
28
14
  requirement: !ruby/object:Gem::Requirement
@@ -141,6 +127,20 @@ dependencies:
141
127
  - - "~>"
142
128
  - !ruby/object:Gem::Version
143
129
  version: '1.4'
130
+ - !ruby/object:Gem::Dependency
131
+ name: json_schemer
132
+ requirement: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '2.0'
137
+ type: :development
138
+ prerelease: false
139
+ version_requirements: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '2.0'
144
144
  description: 'Familia: An ORM for Valkey-compatible databases in Ruby.. Organize and
145
145
  store ruby objects in Valkey/Redis'
146
146
  email: gems@solutious.com
@@ -193,18 +193,8 @@ files:
193
193
  - docs/guides/optimized-loading.md
194
194
  - docs/guides/thread-safety-monitoring.md
195
195
  - docs/guides/time-literals.md
196
+ - docs/guides/writing-migrations.md
196
197
  - docs/migrating/.gitignore
197
- - docs/migrating/v2.0.0-pre.md
198
- - docs/migrating/v2.0.0-pre11.md
199
- - docs/migrating/v2.0.0-pre12.md
200
- - docs/migrating/v2.0.0-pre13.md
201
- - docs/migrating/v2.0.0-pre14.md
202
- - docs/migrating/v2.0.0-pre18.md
203
- - docs/migrating/v2.0.0-pre19.md
204
- - docs/migrating/v2.0.0-pre22.md
205
- - docs/migrating/v2.0.0-pre5.md
206
- - docs/migrating/v2.0.0-pre6.md
207
- - docs/migrating/v2.0.0-pre7.md
208
198
  - docs/overview.md
209
199
  - docs/qodo-merge-compliance.md
210
200
  - docs/reference/api-technical.md
@@ -214,9 +204,12 @@ files:
214
204
  - examples/datatype_standalone.rb
215
205
  - examples/encrypted_fields.rb
216
206
  - examples/json_usage_patterns.rb
207
+ - examples/migrations/v1_to_v2_serialization_migration.rb
217
208
  - examples/relationships.rb
218
209
  - examples/safe_dump.rb
219
210
  - examples/sampling_demo.rb
211
+ - examples/schemas/customer.json
212
+ - examples/schemas/session.json
220
213
  - examples/single_connection_transaction_confusions.rb
221
214
  - examples/through_relationships.rb
222
215
  - familia.gemspec
@@ -282,6 +275,7 @@ files:
282
275
  - lib/familia/features/relationships/participation_relationship.rb
283
276
  - lib/familia/features/relationships/score_encoding.rb
284
277
  - lib/familia/features/safe_dump.rb
278
+ - lib/familia/features/schema_validation.rb
285
279
  - lib/familia/features/transient_fields.rb
286
280
  - lib/familia/features/transient_fields/redacted_string.rb
287
281
  - lib/familia/features/transient_fields/single_use_redacted_string.rb
@@ -301,10 +295,21 @@ files:
301
295
  - lib/familia/instrumentation.rb
302
296
  - lib/familia/json_serializer.rb
303
297
  - lib/familia/logging.rb
298
+ - lib/familia/migration.rb
299
+ - lib/familia/migration/base.rb
300
+ - lib/familia/migration/errors.rb
301
+ - lib/familia/migration/model.rb
302
+ - lib/familia/migration/pipeline.rb
303
+ - lib/familia/migration/rake_tasks.rake
304
+ - lib/familia/migration/rake_tasks.rb
305
+ - lib/familia/migration/registry.rb
306
+ - lib/familia/migration/runner.rb
307
+ - lib/familia/migration/script.rb
304
308
  - lib/familia/refinements.rb
305
309
  - lib/familia/refinements/dear_json.rb
306
310
  - lib/familia/refinements/stylize_words.rb
307
311
  - lib/familia/refinements/time_literals.rb
312
+ - lib/familia/schema_registry.rb
308
313
  - lib/familia/secure_identifier.rb
309
314
  - lib/familia/settings.rb
310
315
  - lib/familia/thread_safety/instrumented_mutex.rb
@@ -387,6 +392,8 @@ files:
387
392
  - try/features/relationships/relationships_try.rb
388
393
  - try/features/safe_dump/safe_dump_advanced_try.rb
389
394
  - try/features/safe_dump/safe_dump_try.rb
395
+ - try/features/schema_registry_try.rb
396
+ - try/features/schema_validation_feature_try.rb
390
397
  - try/features/transient_fields/redacted_string_try.rb
391
398
  - try/features/transient_fields/refresh_reset_try.rb
392
399
  - try/features/transient_fields/simple_refresh_test.rb
@@ -427,6 +434,17 @@ files:
427
434
  - try/integration/transaction_safety_workflow_try.rb
428
435
  - try/integration/verifiable_identifier_try.rb
429
436
  - try/investigation/pipeline_routing/README.md
437
+ - try/migration/base_try.rb
438
+ - try/migration/errors_try.rb
439
+ - try/migration/integration_try.rb
440
+ - try/migration/model_try.rb
441
+ - try/migration/pipeline_try.rb
442
+ - try/migration/rake_tasks_try.rb
443
+ - try/migration/registry_try.rb
444
+ - try/migration/runner_try.rb
445
+ - try/migration/schema_validation_try.rb
446
+ - try/migration/script_try.rb
447
+ - try/migration/v1_to_v2_serialization_try.rb
430
448
  - try/performance/benchmarks_try.rb
431
449
  - try/performance/transaction_safety_benchmark_try.rb
432
450
  - try/support/benchmarks/deserialization_benchmark.rb
@@ -557,7 +575,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
557
575
  requirements:
558
576
  - - ">="
559
577
  - !ruby/object:Gem::Version
560
- version: 3.3.6
578
+ version: '3.2'
561
579
  required_rubygems_version: !ruby/object:Gem::Requirement
562
580
  requirements:
563
581
  - - ">="
@@ -1,84 +0,0 @@
1
- # Migrating Guide: v1.x to v2.0.0-pre
2
-
3
- This guide covers migrating from Familia v1.x to the v2.0.0-pre foundation release.
4
-
5
- ## Overview
6
-
7
- The v2.0.0-pre series represents a major modernization of Familia with:
8
- - Complete API redesign for clarity and consistency
9
- - Valkey compatibility alongside Valkey/Redis support
10
- - Ruby 3.4+ modernization with improved thread safety
11
- - New connection pooling architecture
12
-
13
- ## Step-by-Step Migration
14
-
15
- ### 1. Update Connection Configuration
16
-
17
- **Before (v1.x):**
18
- ```ruby
19
- Familia.connect('redis://localhost:6379/0')
20
- ```
21
-
22
- **After (v2.0.0-pre):**
23
- ```ruby
24
- Familia.configure do |config|
25
- config.redis_uri = 'redis://localhost:6379/0'
26
- config.connection_pool = true
27
- end
28
- ```
29
-
30
- ### 2. Migrate Identifier Declarations
31
-
32
- **Before (v1.x):**
33
- ```ruby
34
- class User < Familia::Base
35
- identifier :user_id
36
- end
37
- ```
38
-
39
- **After (v2.0.0-pre):**
40
- ```ruby
41
- class User < Familia::Horreum
42
- identifier_field :user_id
43
- end
44
- ```
45
-
46
- ### 3. Update Feature Activations
47
-
48
- **Before (v1.x):**
49
- ```ruby
50
- class User < Familia::Base
51
- include Familia::Features::Expiration
52
- end
53
- ```
54
-
55
- **After (v2.0.0-pre):**
56
- ```ruby
57
- class User < Familia::Horreum
58
- feature :expiration
59
- end
60
- ```
61
-
62
- ### 4. Review Method Calls
63
-
64
- Several methods were renamed for consistency:
65
-
66
- | v1.x Method | v2.0.0-pre Method | Notes |
67
- |-------------|------------------|-------|
68
- | `delete` | `destroy` | More semantic naming |
69
- | `exists` | `exists?` | Ruby predicate convention |
70
- | `dump` | `serialize` | Clearer intent |
71
-
72
- ## Breaking Changes
73
-
74
- - `Familia::Base` replaced by `Familia::Horreum`
75
- - Connection configuration moved to block-based setup
76
- - Feature inclusion changed from `include` to `feature` declarations
77
- - Several method names updated for consistency
78
-
79
- ## Next Steps
80
-
81
- After completing the foundation migration:
82
- 1. Review [Security Feature Adoption](v2.0.0-pre5.md) for encrypted fields
83
- 2. See [Architecture Migration](v2.0.0-pre6.md) for persistence improvements
84
- 3. Explore [Relationships Migration](v2.0.0-pre7.md) for the new relationship system
@@ -1,253 +0,0 @@
1
- # Migrating Guide: v2.0.0-pre11
2
-
3
- This version introduces significant improvements to Familia's feature system, making it easier to organize and use features across complex projects.
4
-
5
- ## Enhanced Feature System
6
-
7
- ### Model-Specific Feature Registration
8
-
9
- Previously, all features were registered globally. Now you can register features specific to individual model classes, allowing for better organization and namespace management.
10
-
11
- #### Before
12
- ```ruby
13
- # Global feature registration only
14
- module MyProjectFeature
15
- # Feature implementation
16
- end
17
- Familia::Base.add_feature MyProjectFeature, :my_project_feature
18
-
19
- class Customer < Familia::Horreum
20
- feature :my_project_feature
21
- end
22
-
23
- class Session < Familia::Horreum
24
- feature :my_project_feature # Same global feature
25
- end
26
- ```
27
-
28
- #### After
29
- ```ruby
30
- # Model-specific feature registration
31
- module CustomerSpecificFeature
32
- # Feature implementation
33
- end
34
-
35
- # Register feature only for Customer and its subclasses
36
- Customer.add_feature CustomerSpecificFeature, :customer_specific
37
-
38
- class Customer < Familia::Horreum
39
- feature :customer_specific # Available via Customer's registry
40
- end
41
-
42
- class PremiumCustomer < Customer
43
- feature :customer_specific # Inherited via ancestry chain
44
- end
45
-
46
- class Session < Familia::Horreum
47
- # feature :customer_specific # Not available - would raise error
48
- end
49
- ```
50
-
51
- **Benefits:**
52
- - Features can have the same name across different model hierarchies
53
- - Standardized naming: `deprecated_fields.rb` instead of `customer_deprecated_fields.rb`
54
- - Natural inheritance through Ruby's class hierarchy
55
-
56
- ## SafeDump DSL Improvements
57
-
58
- The new DSL replaces the brittle `@safe_dump_fields` class instance variable pattern with clean, explicit methods.
59
-
60
- ### Before
61
- ```ruby
62
- class Customer < Familia::Horreum
63
- feature :safe_dump
64
-
65
- # Brittle - hard to move to feature modules, confusing syntax
66
- @safe_dump_fields = [
67
- :custid,
68
- :email,
69
- { active: ->(obj) { obj.active? } },
70
- { display_name: ->(obj) { "#{obj.name} (#{obj.custid})" } }
71
- ]
72
- end
73
- ```
74
-
75
- ### After
76
- ```ruby
77
- class Customer < Familia::Horreum
78
- feature :safe_dump
79
-
80
- # Clean DSL - easy to understand and organize
81
- safe_dump_field :custid
82
- safe_dump_field :email
83
- safe_dump_field :active, ->(obj) { obj.active? }
84
- safe_dump_field :display_name, ->(obj) { "#{obj.name} (#{obj.custid})" }
85
-
86
- # Or define multiple fields at once
87
- safe_dump_fields :created, :updated, { status: ->(obj) { obj.role } }
88
- end
89
- ```
90
-
91
- **New methods available:**
92
- - `safe_dump_field(name, callable = nil)` - Define a single field
93
- - `safe_dump_fields(*fields)` - Define multiple fields or get field names
94
- - `safe_dump_field_names` - Get array of field names
95
- - `safe_dump_field_map` - Get the internal callable map
96
-
97
- **Backward Compatibility:**
98
- - `set_safe_dump_fields(*fields)` - Legacy setter method (still works)
99
- - The old `@safe_dump_fields` pattern is no longer supported
100
-
101
- ## Auto-loading Features
102
-
103
- ### Before: Manual Loading
104
- ```ruby
105
- # customer/features.rb
106
-
107
- # Manual feature loading (copied from Familia)
108
- features_dir = File.join(__dir__, 'features')
109
- if Dir.exist?(features_dir)
110
- Dir.glob(File.join(features_dir, '*.rb')).each do |feature_file|
111
- require_relative feature_file
112
- end
113
- end
114
-
115
- class Customer < Familia::Horreum
116
- # Features now available for use
117
- feature :deprecated_fields
118
- end
119
- ```
120
-
121
- ### After: Automatic Loading
122
- ```ruby
123
- # customer/features.rb
124
-
125
- class Customer < Familia::Horreum
126
- module Features
127
- include Familia::Features::Autoloader
128
- # Automatically discovers and loads all *.rb files from customer/features/
129
- end
130
- end
131
-
132
- class Customer < Familia::Horreum
133
- # Features automatically loaded and available
134
- feature :deprecated_fields
135
- end
136
- ```
137
-
138
- **Directory structure this enables:**
139
- ```
140
- models/
141
- ├── customer/
142
- │ ├── features/
143
- │ │ ├── deprecated_fields.rb # Standardized names!
144
- │ │ ├── legacy_support.rb
145
- │ │ └── stripe_integration.rb
146
- │ └── features.rb # Include Autoloader here
147
- ├── session/
148
- │ ├── features/
149
- │ │ ├── deprecated_fields.rb # Same name, different implementation
150
- │ │ └── expiration_hooks.rb
151
- │ └── features.rb
152
- └── customer.rb
153
- ```
154
-
155
- ## Field Definitions in Feature Modules
156
-
157
- Feature modules can now define fields directly in their `ClassMethods` modules. When a class extends the module, the field definitions execute in the extending class's context.
158
-
159
- ### Example
160
- ```ruby
161
- # features/common_fields.rb
162
-
163
- module CommonFields
164
- def self.included(base)
165
- base.extend ClassMethods
166
- end
167
-
168
- module ClassMethods
169
- # These field calls execute in the extending class's context
170
- field :created
171
- field :updated
172
- field :version
173
-
174
- def touch_updated
175
- self.updated = Familia.now.to_i
176
- end
177
- end
178
-
179
- Familia::Base.add_feature self, :common_fields
180
- end
181
-
182
- # Usage
183
- class Customer < Familia::Horreum
184
- feature :common_fields
185
- # Now has :created, :updated, :version fields and touch_updated class method
186
- end
187
- ```
188
-
189
- ## Migration Steps
190
-
191
- ### 1. Update SafeDump Usage
192
- Replace all `@safe_dump_fields` definitions with the new DSL:
193
-
194
- ```ruby
195
- # Find and replace pattern:
196
- # Old: @safe_dump_fields = [:field1, :field2, { field3: ->(obj) { ... } }]
197
- # New: safe_dump_fields :field1, :field2, { field3: ->(obj) { ... } }
198
-
199
- # Or use individual field definitions for better readability:
200
- safe_dump_field :field1
201
- safe_dump_field :field2
202
- safe_dump_field :field3, ->(obj) { ... }
203
- ```
204
-
205
- ### 2. UnsortedSet Up Auto-loading (Optional)
206
- If you have project-specific features, set up auto-loading:
207
-
208
- ```ruby
209
- # Create: models/[model_name]/features.rb
210
- module YourProject
211
- class ModelName < Familia::Horreum
212
- module Features
213
- include Familia::Features::Autoloader
214
- end
215
- end
216
- end
217
-
218
- # Require this file before your model definitions
219
- require_relative 'model_name/features'
220
- ```
221
-
222
- ### 3. Organize Features by Model (Optional)
223
- Consider reorganizing shared feature names by model:
224
-
225
- ```ruby
226
- # Before: features/customer_deprecated_fields.rb
227
- # After: models/customer/features/deprecated_fields.rb
228
-
229
- # This allows multiple models to have their own deprecated_fields.rb
230
- ```
231
-
232
- ### 4. Test Your Changes
233
- Run your test suite to ensure all SafeDump functionality works correctly:
234
-
235
- ```ruby
236
- # Verify SafeDump DSL works
237
- model = YourModel.new(field1: 'value')
238
- result = model.safe_dump
239
- puts result.keys # Should include your defined fields
240
- ```
241
-
242
- ## Breaking Changes
243
-
244
- 1. **`@safe_dump_fields` no longer supported** - Must migrate to DSL methods
245
- 2. **SafeDump field order** - Fields are now returned in definition order via Hash keys (Ruby 1.9+ behavior)
246
-
247
- ## New Capabilities Unlocked
248
-
249
- 1. **Standardized feature names** across different models
250
- 2. **Cleaner SafeDump definitions** that can be easily moved to feature modules
251
- 3. **Automatic feature discovery** for better project organization
252
- 4. **Model-specific feature registries** for better namespace management
253
- 5. **Field definitions in feature modules** for shared functionality