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
data/DEVELOPMENT.md
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# Development Guide
|
|
2
|
+
|
|
3
|
+
This guide covers development setup, testing, and contribution guidelines for rails-uuid-pk.
|
|
4
|
+
|
|
5
|
+
## Devcontainer Setup
|
|
6
|
+
|
|
7
|
+
This project includes a devcontainer configuration for VS Code (highly recommended, as it automatically sets up Ruby 3.3, Rails, PostgreSQL, MySQL, and SQLite in an isolated environment).
|
|
8
|
+
|
|
9
|
+
### Quick Start
|
|
10
|
+
|
|
11
|
+
1. Open the project in VS Code
|
|
12
|
+
2. When prompted, click "Reopen in Container" (or run `Dev Containers: Reopen in Container` from the command palette)
|
|
13
|
+
3. The devcontainer will set up Ruby 3.3, Rails, and all dependencies automatically
|
|
14
|
+
|
|
15
|
+
### Devcontainer CLI
|
|
16
|
+
|
|
17
|
+
For terminal-based development or automation, you can use the Devcontainer CLI. The devcontainer will be built and started automatically when you run the exec commands.
|
|
18
|
+
|
|
19
|
+
#### Installation
|
|
20
|
+
|
|
21
|
+
- **MacOS**: `brew install devcontainer`
|
|
22
|
+
- **Other systems**: `npm install -g @devcontainers/cli`
|
|
23
|
+
|
|
24
|
+
#### Usage
|
|
25
|
+
|
|
26
|
+
Run commands inside the devcontainer:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Install dependencies
|
|
30
|
+
devcontainer exec --workspace-folder . bundle install
|
|
31
|
+
|
|
32
|
+
# Run tests
|
|
33
|
+
devcontainer exec --workspace-folder . ./bin/test
|
|
34
|
+
|
|
35
|
+
# Run code quality checks
|
|
36
|
+
devcontainer exec --workspace-folder . ./bin/rubocop
|
|
37
|
+
|
|
38
|
+
# Interactive shell
|
|
39
|
+
devcontainer exec --workspace-folder . bash
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Code Quality
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Run RuboCop for style checking
|
|
48
|
+
./bin/rubocop
|
|
49
|
+
|
|
50
|
+
# Auto-fix RuboCop offenses
|
|
51
|
+
./bin/rubocop -a
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Building the Gem
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Build the gem
|
|
58
|
+
gem build rails_uuid_pk.gemspec
|
|
59
|
+
|
|
60
|
+
# Install locally for testing
|
|
61
|
+
gem install rails-uuid-pk-0.11.0.gem
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Database Setup
|
|
65
|
+
|
|
66
|
+
For database testing, ensure the respective databases are running and accessible. The test suite uses these environment variables:
|
|
67
|
+
- `DB_HOST` (defaults to localhost)
|
|
68
|
+
- `RAILS_ENV=test_postgresql` for PostgreSQL tests
|
|
69
|
+
- `RAILS_ENV=test_mysql` for MySQL tests
|
|
70
|
+
|
|
71
|
+
## Contributing
|
|
72
|
+
|
|
73
|
+
### For Contributors
|
|
74
|
+
|
|
75
|
+
1. **Understand the problem**: Read issue/PR description and existing code
|
|
76
|
+
2. **Check existing patterns**: Review similar functionality in the codebase
|
|
77
|
+
3. **Write tests first**: Add tests for new features/fixes
|
|
78
|
+
4. **Implement changes**: Follow existing code patterns
|
|
79
|
+
5. **Update YARD documentation**: Add/update YARD comments for any new/modified code
|
|
80
|
+
6. **Run tests**: Ensure all tests pass (`./bin/test`)
|
|
81
|
+
7. **Code quality**: Run RuboCop (`./bin/rubocop`)
|
|
82
|
+
8. **Verify documentation**: Run `yard doc lib/` to ensure 100% documentation coverage
|
|
83
|
+
9. **Update documentation**: README, CHANGELOG if needed
|
|
84
|
+
|
|
85
|
+
### YARD Documentation Guidelines
|
|
86
|
+
|
|
87
|
+
**Always update YARD documentation when making code changes:**
|
|
88
|
+
|
|
89
|
+
#### When Adding New Code
|
|
90
|
+
```ruby
|
|
91
|
+
# For new modules/classes
|
|
92
|
+
# @example Usage example
|
|
93
|
+
# MyClass.new.do_something
|
|
94
|
+
class MyClass
|
|
95
|
+
# @param param [Type] Description of parameter
|
|
96
|
+
# @return [ReturnType] Description of return value
|
|
97
|
+
def my_method(param)
|
|
98
|
+
# implementation
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### When Modifying Existing Code
|
|
104
|
+
- **Update method descriptions** if behavior changes
|
|
105
|
+
- **Add/modify parameter documentation** (`@param`) for new/changed parameters
|
|
106
|
+
- **Update return types** (`@return`) if they change
|
|
107
|
+
- **Add examples** (`@example`) for complex functionality
|
|
108
|
+
- **Update `@see` references** for related components
|
|
109
|
+
|
|
110
|
+
#### Required YARD Tags
|
|
111
|
+
- `@param [Type] description` - For all method parameters
|
|
112
|
+
- `@return [Type] description` - For all return values (use `[void]` for no return)
|
|
113
|
+
- `@example` - Code examples showing usage
|
|
114
|
+
- `@see ClassName` - Cross-references to related classes/modules
|
|
115
|
+
- `@note` - Important implementation notes
|
|
116
|
+
|
|
117
|
+
#### Verification Steps
|
|
118
|
+
```bash
|
|
119
|
+
# Generate documentation and check coverage
|
|
120
|
+
yard doc lib/
|
|
121
|
+
|
|
122
|
+
# Expected output should show:
|
|
123
|
+
# Files: 8
|
|
124
|
+
# Modules: 7 ( 0 undocumented)
|
|
125
|
+
# Classes: 2 ( 0 undocumented)
|
|
126
|
+
# Constants: 2 ( 0 undocumented)
|
|
127
|
+
# Methods: 19 ( 0 undocumented)
|
|
128
|
+
# 100.00% documented
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Common Tasks
|
|
132
|
+
|
|
133
|
+
#### Adding New Features
|
|
134
|
+
1. Determine if it affects core concern, railtie, or generator
|
|
135
|
+
2. Add tests in the appropriate subdirectory under `test/` (e.g., `test/uuid/`, `test/migration_helpers/`, etc.)
|
|
136
|
+
3. Implement in appropriate module
|
|
137
|
+
4. Update README if user-facing
|
|
138
|
+
|
|
139
|
+
#### Database Compatibility
|
|
140
|
+
1. Test changes with both SQLite and PostgreSQL
|
|
141
|
+
2. Update type mappings in railtie if needed
|
|
142
|
+
3. Consider schema format implications
|
|
143
|
+
|
|
144
|
+
#### Generator Changes
|
|
145
|
+
1. Modify templates in `lib/generators/rails_uuid_pk/add_opt_outs/templates/`
|
|
146
|
+
2. Update generator logic in `add_opt_outs_generator.rb`
|
|
147
|
+
3. Test generator output in `test/generators/add_opt_outs_generator_test.rb`
|
|
148
|
+
|
|
149
|
+
#### Migration Generator
|
|
150
|
+
1. The `rails_uuid_pk:add_opt_outs` generator scans all ActiveRecord models
|
|
151
|
+
2. Checks database schema for primary key types
|
|
152
|
+
3. Adds `use_integer_primary_key` to models with integer primary keys
|
|
153
|
+
4. Tests in `test/generators/add_opt_outs_generator_test.rb`
|
|
154
|
+
5. Update documentation in README.md when adding new generators
|
|
155
|
+
|
|
156
|
+
#### Migration Helpers
|
|
157
|
+
1. Modify `lib/rails_uuid_pk/migration_helpers.rb` for foreign key type detection logic
|
|
158
|
+
2. Add comprehensive tests in `test/migration_helpers/` for all scenarios:
|
|
159
|
+
- References to existing UUID tables
|
|
160
|
+
- References to non-UUID tables
|
|
161
|
+
- Polymorphic associations
|
|
162
|
+
- Explicit type overrides
|
|
163
|
+
- Non-existent table handling
|
|
164
|
+
3. Update railtie in `lib/rails_uuid_pk/railtie.rb` if inclusion logic changes
|
|
165
|
+
4. Test with both SQLite and PostgreSQL databases
|
|
166
|
+
|
|
167
|
+
#### Bulk Operations
|
|
168
|
+
1. Remember that bulk operations (`Model.import`, `Model.insert_all`) bypass callbacks
|
|
169
|
+
2. Explicitly assign UUIDs when using bulk operations to avoid data integrity issues
|
|
170
|
+
3. Consider performance implications: bulk operations are faster but require manual UUID management
|
|
171
|
+
4. Test bulk operation scenarios to ensure data consistency
|
|
172
|
+
|
|
173
|
+
#### Opt-out Functionality
|
|
174
|
+
1. **Default behavior**: rails-uuid-pk assumes UUIDv7 primary keys for all models by default
|
|
175
|
+
2. **Exceptions only**: Use `use_integer_primary_key` class method ONLY for specific models that need integer primary keys (legacy tables, third-party integrations, etc.)
|
|
176
|
+
3. When opting out: Modify generated migration to change `id: :uuid` to `id: :integer` for the table schema
|
|
177
|
+
4. Migration helpers automatically detect mixed primary key types and set appropriate foreign key types
|
|
178
|
+
5. Test mixed scenarios thoroughly when combining UUID and integer primary key models
|
|
179
|
+
6. **Inheritance behavior**: Subclasses do NOT automatically inherit the opt-out setting. Each class must explicitly call `use_integer_primary_key`. This is intentional to prevent accidental inheritance in polymorphic hierarchies where different tables may have different primary key types.
|
|
180
|
+
|
|
181
|
+
## Coding Conventions
|
|
182
|
+
|
|
183
|
+
### Ruby Style
|
|
184
|
+
- Follows RuboCop configuration (`.rubocop.yml`)
|
|
185
|
+
- Standard Ruby naming conventions
|
|
186
|
+
- 2-space indentation
|
|
187
|
+
- Line length: 120 characters
|
|
188
|
+
|
|
189
|
+
### Rails Patterns
|
|
190
|
+
- Uses ActiveSupport::Concern for mixins
|
|
191
|
+
- Railtie for Rails integration
|
|
192
|
+
- Standard Rails generator structure
|
|
193
|
+
- Follows Rails testing conventions
|
|
194
|
+
|
|
195
|
+
### Code Quality
|
|
196
|
+
- **RuboCop**: Enforced via CI
|
|
197
|
+
- **No monkey-patching**: Clean integration approach
|
|
198
|
+
- **Comprehensive tests**: High test coverage
|
|
199
|
+
- **Documentation**: README and inline comments
|
|
200
|
+
|
|
201
|
+
## Testing Strategy
|
|
202
|
+
|
|
203
|
+
### Test Organization
|
|
204
|
+
- **Unit tests**: Core functionality organized by feature in subdirectories:
|
|
205
|
+
- `test/configuration/`: Configuration and setup tests
|
|
206
|
+
- `test/database_adapters/`: Database-specific adapter tests
|
|
207
|
+
- `test/migration_helpers/`: Migration helper functionality tests
|
|
208
|
+
- `test/uuid/`: UUID generation and type tests
|
|
209
|
+
- **Integration tests**: Full Rails app testing via dummy app
|
|
210
|
+
- **Database coverage**: Tests run against SQLite, PostgreSQL, and MySQL
|
|
211
|
+
- **CI coverage**: GitHub Actions runs all tests on multiple Ruby versions
|
|
212
|
+
|
|
213
|
+
### Running Tests
|
|
214
|
+
```bash
|
|
215
|
+
# All tests (SQLite + PostgreSQL + MySQL)
|
|
216
|
+
./bin/test
|
|
217
|
+
|
|
218
|
+
# Specific database
|
|
219
|
+
DB=sqlite ./bin/test
|
|
220
|
+
DB=postgres ./bin/test
|
|
221
|
+
DB=mysql ./bin/test
|
|
222
|
+
|
|
223
|
+
# Specific test file
|
|
224
|
+
./bin/test test/uuid/generation_test.rb
|
|
225
|
+
|
|
226
|
+
# Specific test file with specific database
|
|
227
|
+
DB=sqlite ./bin/test test/uuid/type_test.rb
|
|
228
|
+
|
|
229
|
+
# Multiple specific test files
|
|
230
|
+
./bin/test test/uuid/generation_test.rb test/uuid/type_test.rb
|
|
231
|
+
|
|
232
|
+
# Rails test suite (from test/dummy/)
|
|
233
|
+
cd test/dummy && rails test
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Test Database Setup
|
|
237
|
+
- SQLite: Automatic, no setup required
|
|
238
|
+
- PostgreSQL: Requires running PostgreSQL instance with test database
|
|
239
|
+
- MySQL: Requires running MySQL 8.0+ instance with test database
|
|
240
|
+
|
|
241
|
+
## Troubleshooting
|
|
242
|
+
|
|
243
|
+
### Common Issues
|
|
244
|
+
|
|
245
|
+
**Tests failing on PostgreSQL**:
|
|
246
|
+
- Ensure PostgreSQL is running
|
|
247
|
+
- Check `DB_HOST` environment variable
|
|
248
|
+
- Verify database credentials in `test/dummy/config/database.yml`
|
|
249
|
+
|
|
250
|
+
**RuboCop offenses**:
|
|
251
|
+
- Run `./bin/rubocop -a` for auto-fixes
|
|
252
|
+
- Check `.rubocop.yml` for project-specific rules
|
|
253
|
+
|
|
254
|
+
**Gem build issues**:
|
|
255
|
+
- Ensure all files are included in `rails_uuid_pk.gemspec`
|
|
256
|
+
- Check for syntax errors in Ruby files
|
|
257
|
+
|
|
258
|
+
### Getting Help
|
|
259
|
+
- Check existing tests for usage examples
|
|
260
|
+
- Review Rails documentation for integration patterns
|
|
261
|
+
- Look at similar Rails gems for inspiration
|
|
262
|
+
|
|
263
|
+
## Project Structure
|
|
264
|
+
|
|
265
|
+
```
|
|
266
|
+
rails-uuid-pk/
|
|
267
|
+
├── lib/ # Main gem code
|
|
268
|
+
│ ├── rails_uuid_pk.rb # Main module
|
|
269
|
+
│ ├── rails_uuid_pk/ # Core functionality
|
|
270
|
+
│ │ ├── concern.rb # UUIDv7 generation concern
|
|
271
|
+
│ │ ├── migration_helpers.rb # Smart foreign key type detection
|
|
272
|
+
│ │ ├── mysql2_adapter_extension.rb # MySQL adapter UUID support
|
|
273
|
+
│ │ ├── railtie.rb # Rails integration
|
|
274
|
+
│ │ ├── sqlite3_adapter_extension.rb # SQLite adapter UUID support
|
|
275
|
+
│ │ ├── type.rb # Custom UUID ActiveRecord type
|
|
276
|
+
│ │ ├── uuid_adapter_extension.rb # Shared UUID adapter functionality
|
|
277
|
+
│ │ └── version.rb # Version info
|
|
278
|
+
│ ├── generators/ # Rails generators
|
|
279
|
+
│ │ └── rails_uuid_pk/
|
|
280
|
+
│ │ ├── add_opt_outs_generator.rb # Generator for adding opt-out calls
|
|
281
|
+
│ │ └── templates/ # Generator templates
|
|
282
|
+
│ └── tasks/ # Rake tasks
|
|
283
|
+
│ └── rails_uuid_pk_tasks.rake # Custom rake tasks
|
|
284
|
+
├── test/ # Test suite
|
|
285
|
+
│ ├── railtie_test.rb # Dedicated railtie functionality tests
|
|
286
|
+
│ ├── configuration/ # Configuration and setup tests
|
|
287
|
+
│ ├── database_adapters/ # Database-specific adapter tests
|
|
288
|
+
│ ├── dummy/ # Rails dummy app for testing
|
|
289
|
+
│ ├── generators/ # Generator tests
|
|
290
|
+
│ ├── migration_helpers/ # Migration helper functionality tests
|
|
291
|
+
│ ├── test_helper.rb # Test configuration
|
|
292
|
+
│ └── uuid/ # UUID generation and type tests
|
|
293
|
+
├── bin/ # Executable scripts
|
|
294
|
+
│ ├── benchmark # Performance benchmarking
|
|
295
|
+
│ ├── coverage # Test coverage reporting
|
|
296
|
+
│ ├── rubocop # Code quality checker
|
|
297
|
+
│ └── test # Test runner
|
|
298
|
+
├── .github/ # GitHub configuration
|
|
299
|
+
│ ├── dependabot.yml # Dependency update automation
|
|
300
|
+
│ └── workflows/
|
|
301
|
+
│ └── ci.yml # CI configuration
|
|
302
|
+
├── .gitignore # Git ignore patterns
|
|
303
|
+
├── .rubocop.yml # Code style configuration
|
|
304
|
+
├── Gemfile # Development dependencies
|
|
305
|
+
├── Gemfile.lock # Dependency lock file
|
|
306
|
+
├── MIT-LICENSE # License file
|
|
307
|
+
├── Rakefile # Rake tasks configuration
|
|
308
|
+
├── rails_uuid_pk.gemspec # Gem specification
|
|
309
|
+
├── ARCHITECTURE.md # Architectural decisions and design rationale
|
|
310
|
+
├── CHANGELOG.md # Version history and changes
|
|
311
|
+
├── DEVELOPMENT.md # Development setup and guidelines
|
|
312
|
+
├── PERFORMANCE.md # Detailed performance analysis and optimization
|
|
313
|
+
├── README.md # User documentation
|
|
314
|
+
└── SECURITY.md # Security policy and considerations
|