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