opaque_id 1.2.0 → 1.4.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/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +48 -0
- data/CODE_OF_CONDUCT.md +11 -11
- data/README.md +82 -0
- data/docs/.gitignore +5 -0
- data/docs/404.html +25 -0
- data/docs/Gemfile +31 -0
- data/docs/Gemfile.lock +335 -0
- data/docs/_config.yml +151 -0
- data/docs/_data/navigation.yml +132 -0
- data/docs/_includes/footer_custom.html +8 -0
- data/docs/_includes/head_custom.html +67 -0
- data/docs/algorithms.md +412 -0
- data/docs/alphabets.md +524 -0
- data/docs/api-reference.md +597 -0
- data/docs/assets/css/custom.scss +751 -0
- data/docs/assets/images/favicon.svg +17 -0
- data/docs/assets/images/og-image.svg +65 -0
- data/docs/configuration.md +551 -0
- data/docs/development.md +570 -0
- data/docs/getting-started.md +259 -0
- data/docs/index.md +135 -0
- data/docs/installation.md +380 -0
- data/docs/performance.md +491 -0
- data/docs/robots.txt +11 -0
- data/docs/security.md +601 -0
- data/docs/usage.md +417 -0
- data/docs/use-cases.md +572 -0
- data/lib/opaque_id/version.rb +1 -1
- data/tasks/0003-prd-documentation-site.md +191 -0
- data/tasks/tasks-0003-prd-documentation-site.md +84 -0
- metadata +27 -2
- data/sig/opaque_id.rbs +0 -4
@@ -0,0 +1,380 @@
|
|
1
|
+
---
|
2
|
+
layout: default
|
3
|
+
title: Installation
|
4
|
+
nav_order: 3
|
5
|
+
description: "Complete installation guide for OpaqueId with all methods and troubleshooting"
|
6
|
+
permalink: /installation/
|
7
|
+
---
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
|
11
|
+
This guide covers all installation methods for OpaqueId, from basic setup to advanced configurations.
|
12
|
+
|
13
|
+
- TOC
|
14
|
+
{:toc}
|
15
|
+
|
16
|
+
## Requirements
|
17
|
+
|
18
|
+
Before installing OpaqueId, ensure your environment meets these requirements:
|
19
|
+
|
20
|
+
### System Requirements
|
21
|
+
|
22
|
+
- **Ruby 3.2+** - OpaqueId uses modern Ruby features and requires Ruby 3.2 or higher
|
23
|
+
- **Rails 8.0+** - Built specifically for Rails 8.0 and later versions
|
24
|
+
- **ActiveRecord 8.0+** - For model integration and generator functionality
|
25
|
+
|
26
|
+
### Database Requirements
|
27
|
+
|
28
|
+
- **Any ActiveRecord-supported database** - SQLite, PostgreSQL, MySQL, etc.
|
29
|
+
- **Database permissions** - Ability to create tables and indexes
|
30
|
+
|
31
|
+
## Installation Methods
|
32
|
+
|
33
|
+
### Method 1: Using Bundler (Recommended)
|
34
|
+
|
35
|
+
This is the recommended approach for Rails applications.
|
36
|
+
|
37
|
+
#### Step 1: Add to Gemfile
|
38
|
+
|
39
|
+
Add OpaqueId to your application's Gemfile:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
# Gemfile
|
43
|
+
gem 'opaque_id'
|
44
|
+
```
|
45
|
+
|
46
|
+
#### Step 2: Install Dependencies
|
47
|
+
|
48
|
+
Run bundle install to install the gem and its dependencies:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
bundle install
|
52
|
+
```
|
53
|
+
|
54
|
+
#### Step 3: Generate Setup
|
55
|
+
|
56
|
+
Use the Rails generator to set up OpaqueId for your models:
|
57
|
+
|
58
|
+
```bash
|
59
|
+
# For a User model
|
60
|
+
rails generate opaque_id:install User
|
61
|
+
|
62
|
+
# For multiple models
|
63
|
+
rails generate opaque_id:install User
|
64
|
+
rails generate opaque_id:install Post
|
65
|
+
rails generate opaque_id:install Comment
|
66
|
+
```
|
67
|
+
|
68
|
+
#### Step 4: Run Migrations
|
69
|
+
|
70
|
+
Execute the generated migrations:
|
71
|
+
|
72
|
+
```bash
|
73
|
+
rails db:migrate
|
74
|
+
```
|
75
|
+
|
76
|
+
### Method 2: Manual Installation
|
77
|
+
|
78
|
+
If you prefer manual installation or need more control over the setup process.
|
79
|
+
|
80
|
+
#### Step 1: Install the Gem
|
81
|
+
|
82
|
+
```bash
|
83
|
+
gem install opaque_id
|
84
|
+
```
|
85
|
+
|
86
|
+
#### Step 2: Create Migration Manually
|
87
|
+
|
88
|
+
Create a migration file:
|
89
|
+
|
90
|
+
```bash
|
91
|
+
rails generate migration AddOpaqueIdToUsers opaque_id:string:uniq
|
92
|
+
```
|
93
|
+
|
94
|
+
#### Step 3: Edit Migration
|
95
|
+
|
96
|
+
Update the migration file:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
# db/migrate/YYYYMMDDHHMMSS_add_opaque_id_to_users.rb
|
100
|
+
class AddOpaqueIdToUsers < ActiveRecord::Migration[8.0]
|
101
|
+
def change
|
102
|
+
add_column :users, :opaque_id, :string
|
103
|
+
add_index :users, :opaque_id, unique: true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
#### Step 4: Update Model
|
109
|
+
|
110
|
+
Manually include the concern in your model:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
# app/models/user.rb
|
114
|
+
class User < ApplicationRecord
|
115
|
+
include OpaqueId::Model
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
#### Step 5: Run Migration
|
120
|
+
|
121
|
+
```bash
|
122
|
+
rails db:migrate
|
123
|
+
```
|
124
|
+
|
125
|
+
### Method 3: From Source
|
126
|
+
|
127
|
+
For development or if you need the latest features.
|
128
|
+
|
129
|
+
#### Step 1: Clone Repository
|
130
|
+
|
131
|
+
```bash
|
132
|
+
git clone https://github.com/nyaggah/opaque_id.git
|
133
|
+
cd opaque_id
|
134
|
+
```
|
135
|
+
|
136
|
+
#### Step 2: Build and Install
|
137
|
+
|
138
|
+
```bash
|
139
|
+
gem build opaque_id.gemspec
|
140
|
+
gem install opaque_id-*.gem
|
141
|
+
```
|
142
|
+
|
143
|
+
#### Step 3: Add to Gemfile
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
# Gemfile
|
147
|
+
gem 'opaque_id', path: '/path/to/opaque_id'
|
148
|
+
```
|
149
|
+
|
150
|
+
#### Step 4: Install Dependencies
|
151
|
+
|
152
|
+
```bash
|
153
|
+
bundle install
|
154
|
+
```
|
155
|
+
|
156
|
+
## Generator Options
|
157
|
+
|
158
|
+
The Rails generator supports several options for customization:
|
159
|
+
|
160
|
+
### Basic Usage
|
161
|
+
|
162
|
+
```bash
|
163
|
+
rails generate opaque_id:install ModelName
|
164
|
+
```
|
165
|
+
|
166
|
+
### Custom Column Name
|
167
|
+
|
168
|
+
```bash
|
169
|
+
rails generate opaque_id:install User --column-name=public_id
|
170
|
+
```
|
171
|
+
|
172
|
+
This will:
|
173
|
+
|
174
|
+
- Create a `public_id` column instead of `opaque_id`
|
175
|
+
- Add `self.opaque_id_column = :public_id` to your model
|
176
|
+
|
177
|
+
### Multiple Models
|
178
|
+
|
179
|
+
```bash
|
180
|
+
rails generate opaque_id:install User
|
181
|
+
rails generate opaque_id:install Post --column-name=slug
|
182
|
+
rails generate opaque_id:install Comment
|
183
|
+
```
|
184
|
+
|
185
|
+
## Post-Installation Setup
|
186
|
+
|
187
|
+
### Verify Installation
|
188
|
+
|
189
|
+
Check that everything is working correctly:
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
# In Rails console
|
193
|
+
rails console
|
194
|
+
|
195
|
+
# Test basic functionality
|
196
|
+
user = User.create!(name: "Test User")
|
197
|
+
puts user.opaque_id
|
198
|
+
# => Should output a 21-character alphanumeric string
|
199
|
+
|
200
|
+
# Test finder methods
|
201
|
+
found_user = User.find_by_opaque_id(user.opaque_id)
|
202
|
+
puts found_user.name
|
203
|
+
# => "Test User"
|
204
|
+
```
|
205
|
+
|
206
|
+
### Configure Global Settings (Optional)
|
207
|
+
|
208
|
+
Create an initializer for global configuration:
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
# config/initializers/opaque_id.rb
|
212
|
+
OpaqueId.configure do |config|
|
213
|
+
config.default_length = 15
|
214
|
+
config.default_alphabet = OpaqueId::STANDARD_ALPHABET
|
215
|
+
end
|
216
|
+
```
|
217
|
+
|
218
|
+
## Troubleshooting
|
219
|
+
|
220
|
+
### Common Installation Issues
|
221
|
+
|
222
|
+
#### Issue: Generator Not Found
|
223
|
+
|
224
|
+
**Error**: `Could not find generator 'opaque_id:install'`
|
225
|
+
|
226
|
+
**Solution**: Ensure the gem is properly installed and bundled:
|
227
|
+
|
228
|
+
```bash
|
229
|
+
bundle install
|
230
|
+
bundle exec rails generate opaque_id:install User
|
231
|
+
```
|
232
|
+
|
233
|
+
#### Issue: Migration Fails
|
234
|
+
|
235
|
+
**Error**: `ActiveRecord::StatementInvalid` or similar database errors
|
236
|
+
|
237
|
+
**Solution**: Check your database permissions and Rails version:
|
238
|
+
|
239
|
+
```bash
|
240
|
+
# Check Rails version
|
241
|
+
rails --version
|
242
|
+
|
243
|
+
# Check database connection
|
244
|
+
rails db:version
|
245
|
+
```
|
246
|
+
|
247
|
+
#### Issue: Model Not Updated
|
248
|
+
|
249
|
+
**Error**: Generator runs but model file isn't updated
|
250
|
+
|
251
|
+
**Solution**: Check file permissions and ensure the model file exists:
|
252
|
+
|
253
|
+
```bash
|
254
|
+
# Check if model file exists
|
255
|
+
ls app/models/user.rb
|
256
|
+
|
257
|
+
# Check file permissions
|
258
|
+
ls -la app/models/user.rb
|
259
|
+
```
|
260
|
+
|
261
|
+
#### Issue: Bundle Install Fails
|
262
|
+
|
263
|
+
**Error**: Dependency conflicts or version issues
|
264
|
+
|
265
|
+
**Solution**: Update your Gemfile and run bundle update:
|
266
|
+
|
267
|
+
```bash
|
268
|
+
bundle update
|
269
|
+
bundle install
|
270
|
+
```
|
271
|
+
|
272
|
+
### Version Compatibility
|
273
|
+
|
274
|
+
#### Ruby Version Issues
|
275
|
+
|
276
|
+
If you're using an older Ruby version:
|
277
|
+
|
278
|
+
```bash
|
279
|
+
# Check Ruby version
|
280
|
+
ruby --version
|
281
|
+
|
282
|
+
# Update Ruby (using rbenv)
|
283
|
+
rbenv install 3.2.0
|
284
|
+
rbenv local 3.2.0
|
285
|
+
```
|
286
|
+
|
287
|
+
#### Rails Version Issues
|
288
|
+
|
289
|
+
If you're using an older Rails version:
|
290
|
+
|
291
|
+
```bash
|
292
|
+
# Check Rails version
|
293
|
+
rails --version
|
294
|
+
|
295
|
+
# Update Rails
|
296
|
+
bundle update rails
|
297
|
+
```
|
298
|
+
|
299
|
+
### Database-Specific Issues
|
300
|
+
|
301
|
+
#### PostgreSQL
|
302
|
+
|
303
|
+
Ensure you have the correct PostgreSQL adapter:
|
304
|
+
|
305
|
+
```ruby
|
306
|
+
# Gemfile
|
307
|
+
gem 'pg', '~> 1.1'
|
308
|
+
```
|
309
|
+
|
310
|
+
#### MySQL
|
311
|
+
|
312
|
+
Ensure you have the correct MySQL adapter:
|
313
|
+
|
314
|
+
```ruby
|
315
|
+
# Gemfile
|
316
|
+
gem 'mysql2', '~> 0.5'
|
317
|
+
```
|
318
|
+
|
319
|
+
#### SQLite
|
320
|
+
|
321
|
+
SQLite should work out of the box with Rails:
|
322
|
+
|
323
|
+
```ruby
|
324
|
+
# Gemfile
|
325
|
+
gem 'sqlite3', '~> 1.4'
|
326
|
+
```
|
327
|
+
|
328
|
+
## Uninstallation
|
329
|
+
|
330
|
+
If you need to remove OpaqueId from your application:
|
331
|
+
|
332
|
+
### Step 1: Remove from Gemfile
|
333
|
+
|
334
|
+
```ruby
|
335
|
+
# Gemfile
|
336
|
+
# gem 'opaque_id' # Comment out or remove this line
|
337
|
+
```
|
338
|
+
|
339
|
+
### Step 2: Remove Dependencies
|
340
|
+
|
341
|
+
```bash
|
342
|
+
bundle install
|
343
|
+
```
|
344
|
+
|
345
|
+
### Step 3: Remove Migrations (Optional)
|
346
|
+
|
347
|
+
If you want to remove the opaque_id columns:
|
348
|
+
|
349
|
+
```bash
|
350
|
+
rails generate migration RemoveOpaqueIdFromUsers opaque_id:string
|
351
|
+
rails db:migrate
|
352
|
+
```
|
353
|
+
|
354
|
+
### Step 4: Remove Model Code
|
355
|
+
|
356
|
+
Remove the include statement from your models:
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
# app/models/user.rb
|
360
|
+
class User < ApplicationRecord
|
361
|
+
# include OpaqueId::Model # Comment out or remove this line
|
362
|
+
end
|
363
|
+
```
|
364
|
+
|
365
|
+
## Next Steps
|
366
|
+
|
367
|
+
After successful installation:
|
368
|
+
|
369
|
+
1. **Read the [Getting Started Guide](getting-started.md)** for basic usage
|
370
|
+
2. **Explore [Configuration](configuration.md)** for advanced setup
|
371
|
+
3. **Check out [Use Cases](use-cases.md)** for real-world usage patterns
|
372
|
+
4. **Review [API Reference](api-reference.md)** for complete documentation
|
373
|
+
|
374
|
+
## Support
|
375
|
+
|
376
|
+
If you encounter issues during installation:
|
377
|
+
|
378
|
+
1. **Check the troubleshooting section** above
|
379
|
+
2. **Review the [GitHub Issues](https://github.com/nyaggah/opaque_id/issues)** for similar problems
|
380
|
+
3. **Open a new issue** with details about your environment and the error
|