pg_sql_triggers 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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +144 -0
  3. data/COVERAGE.md +26 -19
  4. data/Goal.md +276 -155
  5. data/README.md +27 -1
  6. data/app/assets/javascripts/pg_sql_triggers/trigger_actions.js +50 -0
  7. data/app/controllers/concerns/pg_sql_triggers/error_handling.rb +56 -0
  8. data/app/controllers/concerns/pg_sql_triggers/kill_switch_protection.rb +66 -0
  9. data/app/controllers/concerns/pg_sql_triggers/permission_checking.rb +117 -0
  10. data/app/controllers/pg_sql_triggers/application_controller.rb +10 -62
  11. data/app/controllers/pg_sql_triggers/audit_logs_controller.rb +102 -0
  12. data/app/controllers/pg_sql_triggers/dashboard_controller.rb +4 -9
  13. data/app/controllers/pg_sql_triggers/tables_controller.rb +30 -4
  14. data/app/controllers/pg_sql_triggers/triggers_controller.rb +3 -21
  15. data/app/helpers/pg_sql_triggers/permissions_helper.rb +43 -0
  16. data/app/models/pg_sql_triggers/audit_log.rb +106 -0
  17. data/app/models/pg_sql_triggers/trigger_registry.rb +178 -9
  18. data/app/views/layouts/pg_sql_triggers/application.html.erb +26 -6
  19. data/app/views/pg_sql_triggers/audit_logs/index.html.erb +177 -0
  20. data/app/views/pg_sql_triggers/dashboard/index.html.erb +33 -8
  21. data/app/views/pg_sql_triggers/tables/index.html.erb +76 -3
  22. data/app/views/pg_sql_triggers/tables/show.html.erb +17 -4
  23. data/app/views/pg_sql_triggers/triggers/_drop_modal.html.erb +16 -7
  24. data/app/views/pg_sql_triggers/triggers/_re_execute_modal.html.erb +16 -7
  25. data/app/views/pg_sql_triggers/triggers/show.html.erb +26 -6
  26. data/config/routes.rb +2 -0
  27. data/db/migrate/20260103000001_create_pg_sql_triggers_audit_log.rb +28 -0
  28. data/docs/README.md +15 -5
  29. data/docs/api-reference.md +191 -0
  30. data/docs/audit-trail.md +413 -0
  31. data/docs/configuration.md +6 -6
  32. data/docs/permissions.md +369 -0
  33. data/docs/troubleshooting.md +486 -0
  34. data/docs/ui-guide.md +211 -0
  35. data/docs/web-ui.md +257 -34
  36. data/lib/pg_sql_triggers/errors.rb +245 -0
  37. data/lib/pg_sql_triggers/generator/service.rb +32 -0
  38. data/lib/pg_sql_triggers/permissions/checker.rb +9 -2
  39. data/lib/pg_sql_triggers/registry.rb +141 -8
  40. data/lib/pg_sql_triggers/sql/kill_switch.rb +33 -5
  41. data/lib/pg_sql_triggers/testing/function_tester.rb +2 -0
  42. data/lib/pg_sql_triggers/version.rb +1 -1
  43. data/lib/pg_sql_triggers.rb +3 -6
  44. metadata +29 -6
  45. data/docs/screenshots/.gitkeep +0 -1
  46. data/docs/screenshots/Generate Trigger.png +0 -0
  47. data/docs/screenshots/Triggers Page.png +0 -0
  48. data/docs/screenshots/kill error.png +0 -0
  49. data/docs/screenshots/kill modal for migration down.png +0 -0
@@ -0,0 +1,486 @@
1
+ # Troubleshooting Guide
2
+
3
+ Common issues and solutions for PgSqlTriggers.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation Issues](#installation-issues)
8
+ - [Permission Errors](#permission-errors)
9
+ - [Kill Switch Errors](#kill-switch-errors)
10
+ - [Drift Detection Issues](#drift-detection-issues)
11
+ - [Migration Problems](#migration-problems)
12
+ - [UI Issues](#ui-issues)
13
+ - [Performance Issues](#performance-issues)
14
+ - [Error Codes Reference](#error-codes-reference)
15
+
16
+ ## Installation Issues
17
+
18
+ ### Migration Errors
19
+
20
+ **Problem**: Migrations fail during installation.
21
+
22
+ **Solutions**:
23
+ 1. Ensure PostgreSQL is running and accessible
24
+ 2. Check database connection in `config/database.yml`
25
+ 3. Verify you have sufficient database permissions
26
+ 4. Check migration logs for specific errors
27
+
28
+ ```bash
29
+ # Check database connection
30
+ rails db:version
31
+
32
+ # Run migrations with verbose output
33
+ rails db:migrate VERBOSE=true
34
+ ```
35
+
36
+ ### Initializer Not Loading
37
+
38
+ **Problem**: Configuration not being applied.
39
+
40
+ **Solutions**:
41
+ 1. Restart Rails server after changing initializer
42
+ 2. Check for syntax errors in `config/initializers/pg_sql_triggers.rb`
43
+ 3. Verify the file is being loaded (check Rails logs)
44
+
45
+ ```ruby
46
+ # Test configuration
47
+ rails console
48
+ > PgSqlTriggers.kill_switch_enabled
49
+ ```
50
+
51
+ ### Web UI Not Accessible
52
+
53
+ **Problem**: Cannot access web UI at `/pg_sql_triggers`.
54
+
55
+ **Solutions**:
56
+ 1. Verify engine is mounted in `config/routes.rb`:
57
+ ```ruby
58
+ mount PgSqlTriggers::Engine, at: "/pg_sql_triggers"
59
+ ```
60
+ 2. Restart Rails server
61
+ 3. Check for route conflicts
62
+ 4. Verify database tables exist
63
+
64
+ ## Permission Errors
65
+
66
+ ### Permission Denied Errors
67
+
68
+ **Problem**: `PermissionError` with code `PERMISSION_DENIED`.
69
+
70
+ **Error Message**: "Permission denied: [action] requires [role] level access"
71
+
72
+ **Solutions**:
73
+ 1. **Check permission configuration**:
74
+ ```ruby
75
+ # Verify permission checker is configured
76
+ PgSqlTriggers.permission_checker # Should not be nil
77
+ ```
78
+
79
+ 2. **Verify actor format**:
80
+ ```ruby
81
+ # In your controller
82
+ def current_actor
83
+ {
84
+ type: current_user.class.name,
85
+ id: current_user.id.to_s,
86
+ role: current_user.role # Ensure role is included
87
+ }
88
+ end
89
+ ```
90
+
91
+ 3. **Check required role for action**:
92
+ - Viewer: `view_triggers`, `view_diffs`
93
+ - Operator: `enable_trigger`, `disable_trigger`, `apply_trigger`
94
+ - Admin: `drop_trigger`, `execute_sql`, `override_drift`
95
+
96
+ 4. **Review permission checker logic**:
97
+ ```ruby
98
+ config.permission_checker = ->(actor, action, environment) {
99
+ # Debug: add logging
100
+ Rails.logger.debug "Checking permission: #{action} for #{actor}"
101
+ # Your permission logic
102
+ }
103
+ ```
104
+
105
+ ### All Users Have Full Access
106
+
107
+ **Problem**: Permissions are not being enforced.
108
+
109
+ **Solutions**:
110
+ 1. **Configure permission checker** (default is permissive):
111
+ ```ruby
112
+ PgSqlTriggers.configure do |config|
113
+ config.permission_checker = ->(actor, action, environment) {
114
+ # Your permission logic
115
+ }
116
+ end
117
+ ```
118
+
119
+ 2. **Verify in production**: Default allows all permissions for development convenience
120
+
121
+ ### UI Buttons Hidden
122
+
123
+ **Problem**: Action buttons are not visible in UI.
124
+
125
+ **Solutions**:
126
+ 1. Check your permission level (Viewer/Operator/Admin)
127
+ 2. Verify `current_actor` method returns correct role
128
+ 3. Check browser console for JavaScript errors
129
+ 4. Review permission helper methods in views
130
+
131
+ ## Kill Switch Errors
132
+
133
+ ### Operation Blocked by Kill Switch
134
+
135
+ **Problem**: `KillSwitchError` with code `KILL_SWITCH_ACTIVE`.
136
+
137
+ **Error Message**: "Kill switch is active for [environment] environment"
138
+
139
+ **Solutions**:
140
+ 1. **Provide confirmation text**:
141
+ ```bash
142
+ # CLI/rake tasks
143
+ KILL_SWITCH_OVERRIDE=true CONFIRMATION_TEXT="EXECUTE OPERATION_NAME" rake your:task
144
+
145
+ # Console
146
+ PgSqlTriggers::SQL::KillSwitch.override(confirmation: "EXECUTE OPERATION_NAME") do
147
+ # your operation
148
+ end
149
+ ```
150
+
151
+ 2. **UI operations**: Enter confirmation text in the modal
152
+
153
+ 3. **Check expected confirmation format**:
154
+ ```ruby
155
+ # Default pattern
156
+ "EXECUTE #{operation.to_s.upcase}"
157
+
158
+ # Check your configuration
159
+ PgSqlTriggers.kill_switch_confirmation_pattern.call(:trigger_enable)
160
+ ```
161
+
162
+ ### Invalid Confirmation Text
163
+
164
+ **Problem**: `KillSwitchError` with code `KILL_SWITCH_CONFIRMATION_INVALID`.
165
+
166
+ **Error Message**: "Invalid confirmation text. Expected: '[expected]', got: '[provided]'"
167
+
168
+ **Solutions**:
169
+ 1. Use exact confirmation text (case-sensitive)
170
+ 2. Check confirmation pattern configuration
171
+ 3. Verify no extra whitespace
172
+ 4. Use the exact format shown in error message
173
+
174
+ ### Kill Switch Not Working
175
+
176
+ **Problem**: Operations execute even with kill switch enabled.
177
+
178
+ **Solutions**:
179
+ 1. **Verify kill switch is enabled**:
180
+ ```ruby
181
+ PgSqlTriggers.kill_switch_enabled # Should be true
182
+ ```
183
+
184
+ 2. **Check protected environments**:
185
+ ```ruby
186
+ PgSqlTriggers.kill_switch_environments # Should include current environment
187
+ ```
188
+
189
+ 3. **Verify environment detection**:
190
+ ```ruby
191
+ PgSqlTriggers.default_environment.call # Should match your environment
192
+ ```
193
+
194
+ ## Drift Detection Issues
195
+
196
+ ### False Drift Detections
197
+
198
+ **Problem**: Triggers show as drifted when they are not.
199
+
200
+ **Solutions**:
201
+ 1. **Re-run drift detection**:
202
+ ```ruby
203
+ PgSqlTriggers::Drift.detect("trigger_name")
204
+ ```
205
+
206
+ 2. **Check function body formatting**: Whitespace differences can cause drift
207
+
208
+ 3. **Verify trigger definition**: Ensure DSL matches database state
209
+
210
+ 4. **Use re-execute**: If drift is expected, use re-execute to sync
211
+
212
+ ### Drift Not Detected
213
+
214
+ **Problem**: Manual changes not detected as drift.
215
+
216
+ **Solutions**:
217
+ 1. Run drift detection manually:
218
+ ```ruby
219
+ PgSqlTriggers::Drift.detect("trigger_name")
220
+ ```
221
+
222
+ 2. Check drift state:
223
+ ```ruby
224
+ trigger = PgSqlTriggers::TriggerRegistry.find_by(trigger_name: "trigger_name")
225
+ trigger.drift_state
226
+ ```
227
+
228
+ 3. Verify database trigger exists and matches definition
229
+
230
+ ### Unknown Drift State
231
+
232
+ **Problem**: Drift state shows as "unknown".
233
+
234
+ **Solutions**:
235
+ 1. **Check database connection**: Verify PostgreSQL is accessible
236
+ 2. **Verify trigger exists in database**: Check `pg_trigger` system catalog
237
+ 3. **Check function exists**: Verify function is in `pg_proc`
238
+ 4. **Review error logs**: Check Rails logs for drift detection errors
239
+
240
+ ## Migration Problems
241
+
242
+ ### Migration Fails to Apply
243
+
244
+ **Problem**: Migration fails with SQL errors.
245
+
246
+ **Solutions**:
247
+ 1. **Check SQL syntax**: Validate function and trigger SQL
248
+ 2. **Verify table exists**: Ensure target table exists
249
+ 3. **Check dependencies**: Ensure required functions exist
250
+ 4. **Review error message**: Check Rails logs for specific SQL error
251
+
252
+ ```bash
253
+ # Run migration with verbose output
254
+ rake trigger:migrate VERBOSE=true
255
+ ```
256
+
257
+ ### Unsafe Migration Error
258
+
259
+ **Problem**: `UnsafeMigrationError` with code `UNSAFE_MIGRATION`.
260
+
261
+ **Error Message**: "Migration contains unsafe DROP + CREATE operations"
262
+
263
+ **Solutions**:
264
+ 1. **Use CREATE OR REPLACE** (for functions):
265
+ ```sql
266
+ -- Instead of:
267
+ DROP FUNCTION my_function();
268
+ CREATE FUNCTION my_function() ...
269
+
270
+ -- Use:
271
+ CREATE OR REPLACE FUNCTION my_function() ...
272
+ ```
273
+
274
+ 2. **Allow unsafe migrations** (if intentional):
275
+ ```ruby
276
+ PgSqlTriggers.configure do |config|
277
+ config.allow_unsafe_migrations = true
278
+ end
279
+ ```
280
+
281
+ 3. **Use kill switch override** for specific migrations
282
+
283
+ ### Migration Version Conflicts
284
+
285
+ **Problem**: Migration version already exists or not found.
286
+
287
+ **Solutions**:
288
+ 1. **Check migration status**:
289
+ ```ruby
290
+ PgSqlTriggers::Migrator.status
291
+ ```
292
+
293
+ 2. **Verify migration files**: Check `db/triggers/` directory
294
+
295
+ 3. **Check registry table**: Verify migration versions in database
296
+
297
+ ## UI Issues
298
+
299
+ ### Buttons Not Working
300
+
301
+ **Problem**: Action buttons don't respond to clicks.
302
+
303
+ **Solutions**:
304
+ 1. Check browser console for JavaScript errors
305
+ 2. Verify CSRF token is present
306
+ 3. Check network tab for failed requests
307
+ 4. Ensure JavaScript is enabled
308
+ 5. Clear browser cache
309
+
310
+ ### Error Messages Not Displaying
311
+
312
+ **Problem**: Errors occur but not shown in UI.
313
+
314
+ **Solutions**:
315
+ 1. Check flash messages are being set
316
+ 2. Verify error handling in controllers
317
+ 3. Check browser console for JavaScript errors
318
+ 4. Review Rails logs for actual errors
319
+
320
+ ### Slow UI Performance
321
+
322
+ **Problem**: Dashboard or pages load slowly.
323
+
324
+ **Solutions**:
325
+ 1. **Check database performance**: Add indexes if needed
326
+ 2. **Limit result sets**: Use pagination
327
+ 3. **Review drift detection**: Drift detection can be slow for many triggers
328
+ 4. **Check audit log size**: Large audit logs can slow queries
329
+
330
+ ### Audit Log Not Loading
331
+
332
+ **Problem**: Audit log page fails to load or is empty.
333
+
334
+ **Solutions**:
335
+ 1. Verify audit log table exists:
336
+ ```bash
337
+ rails db:migrate
338
+ ```
339
+
340
+ 2. Check for audit log entries:
341
+ ```ruby
342
+ PgSqlTriggers::AuditLog.count
343
+ ```
344
+
345
+ 3. Review controller logs for errors
346
+ 4. Check database connection
347
+
348
+ ## Performance Issues
349
+
350
+ ### Slow Drift Detection
351
+
352
+ **Problem**: Drift detection takes too long.
353
+
354
+ **Solutions**:
355
+ 1. **Batch detection**: Don't detect drift for all triggers at once
356
+ 2. **Cache results**: Store drift state in registry
357
+ 3. **Optimize queries**: Review database query performance
358
+ 4. **Limit triggers checked**: Only check triggers that changed
359
+
360
+ ### Large Audit Log Table
361
+
362
+ **Problem**: Audit log queries are slow.
363
+
364
+ **Solutions**:
365
+ 1. **Add indexes**:
366
+ ```ruby
367
+ # Migration
368
+ add_index :pg_sql_triggers_audit_log, :trigger_name
369
+ add_index :pg_sql_triggers_audit_log, :operation
370
+ add_index :pg_sql_triggers_audit_log, :created_at
371
+ add_index :pg_sql_triggers_audit_log, :status
372
+ ```
373
+
374
+ 2. **Archive old logs**: Implement retention policy
375
+ 3. **Use pagination**: Limit results per page
376
+ 4. **Filter aggressively**: Use filters to reduce result set
377
+
378
+ ### Registry Table Performance
379
+
380
+ **Problem**: Registry queries are slow.
381
+
382
+ **Solutions**:
383
+ 1. **Add indexes**: Ensure indexes on frequently queried columns
384
+ 2. **Limit triggers**: Consider partitioning if you have many triggers
385
+ 3. **Optimize queries**: Review query plans
386
+ 4. **Cache frequently accessed data**: Store in memory cache
387
+
388
+ ## Error Codes Reference
389
+
390
+ ### Kill Switch Errors
391
+
392
+ - **`KILL_SWITCH_ACTIVE`**: Kill switch is blocking operation
393
+ - Solution: Provide confirmation text to override
394
+
395
+ - **`KILL_SWITCH_CONFIRMATION_REQUIRED`**: Confirmation text is required
396
+ - Solution: Provide confirmation text
397
+
398
+ - **`KILL_SWITCH_CONFIRMATION_INVALID`**: Confirmation text doesn't match
399
+ - Solution: Use exact confirmation text format
400
+
401
+ ### Permission Errors
402
+
403
+ - **`PERMISSION_DENIED`**: User doesn't have required permission
404
+ - Solution: Request appropriate role or configure permissions
405
+
406
+ ### Validation Errors
407
+
408
+ - **`VALIDATION_FAILED`**: Input validation failed
409
+ - Solution: Review error message for specific field issues
410
+
411
+ ### Execution Errors
412
+
413
+ - **`EXECUTION_FAILED`**: SQL execution failed
414
+ - Solution: Check SQL syntax and database state
415
+
416
+ ### Migration Errors
417
+
418
+ - **`UNSAFE_MIGRATION`**: Migration contains unsafe operations
419
+ - Solution: Use CREATE OR REPLACE or allow unsafe migrations
420
+
421
+ - **`TRIGGER_NOT_FOUND`**: Trigger not found in registry
422
+ - Solution: Verify trigger name or create trigger first
423
+
424
+ ### Drift Errors
425
+
426
+ - **`DRIFT_DETECTED`**: Trigger has drifted from definition
427
+ - Solution: Run migration or re-execute trigger
428
+
429
+ ## Getting Help
430
+
431
+ ### Debug Mode
432
+
433
+ Enable verbose logging:
434
+
435
+ ```ruby
436
+ # In initializer or console
437
+ Rails.logger.level = Logger::DEBUG
438
+ ```
439
+
440
+ ### Check Logs
441
+
442
+ Review Rails logs for detailed error information:
443
+
444
+ ```bash
445
+ # Development
446
+ tail -f log/development.log
447
+
448
+ # Production
449
+ tail -f log/production.log
450
+ ```
451
+
452
+ ### Common Debugging Steps
453
+
454
+ 1. **Verify configuration**:
455
+ ```ruby
456
+ rails console
457
+ > PgSqlTriggers.kill_switch_enabled
458
+ > PgSqlTriggers.permission_checker
459
+ ```
460
+
461
+ 2. **Check database state**:
462
+ ```ruby
463
+ > PgSqlTriggers::TriggerRegistry.count
464
+ > PgSqlTriggers::AuditLog.count
465
+ ```
466
+
467
+ 3. **Test permissions**:
468
+ ```ruby
469
+ > actor = { type: "User", id: "1", role: "admin" }
470
+ > PgSqlTriggers::Permissions.can?(actor, :drop_trigger)
471
+ ```
472
+
473
+ 4. **Verify trigger state**:
474
+ ```ruby
475
+ > trigger = PgSqlTriggers::TriggerRegistry.first
476
+ > trigger.drift_state
477
+ > trigger.enabled?
478
+ ```
479
+
480
+ ## Related Documentation
481
+
482
+ - [Configuration Reference](configuration.md) - Configuration options
483
+ - [Permissions Guide](permissions.md) - Permission system details
484
+ - [Kill Switch Guide](kill-switch.md) - Kill switch configuration
485
+ - [API Reference](api-reference.md) - Console API methods
486
+
data/docs/ui-guide.md ADDED
@@ -0,0 +1,211 @@
1
+ # UI Guide
2
+
3
+ A quick-start guide to using the PgSqlTriggers web interface.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Getting Started](#getting-started)
8
+ - [Dashboard](#dashboard)
9
+ - [Trigger Management](#trigger-management)
10
+ - [Quick Actions](#quick-actions)
11
+ - [Permissions](#permissions)
12
+ - [Common Tasks](#common-tasks)
13
+
14
+ ## Getting Started
15
+
16
+ ### Accessing the UI
17
+
18
+ The PgSqlTriggers web UI is available at:
19
+
20
+ ```
21
+ http://localhost:3000/pg_sql_triggers
22
+ ```
23
+
24
+ You can customize the mount path in your routes if needed.
25
+
26
+ ### Navigation
27
+
28
+ The main navigation includes:
29
+
30
+ - **Dashboard**: Overview of all triggers
31
+ - **Tables**: Browse triggers by table (with pagination and filters)
32
+ - **Generator**: Create new triggers via UI
33
+ - **Audit Log**: View operation history
34
+
35
+ ## Dashboard
36
+
37
+ The dashboard provides an overview of your trigger ecosystem.
38
+
39
+ ### Key Features
40
+
41
+ - **Trigger List**: All triggers with status indicators
42
+ - **Status Colors**: Visual indicators for trigger states
43
+ - **Last Applied**: When triggers were last applied
44
+ - **Quick Actions**: Enable/disable buttons (based on permissions)
45
+ - **Drift Indicators**: Visual warnings for drifted triggers
46
+
47
+ ## Tables Page
48
+
49
+ The Tables page shows all database tables and their triggers.
50
+
51
+ ### Key Features
52
+
53
+ - **Statistics**: Count of tables with/without triggers
54
+ - **Filtering**: View all tables, only with triggers, or only without triggers
55
+ - **Pagination**: Navigate through large table lists (20 per page by default)
56
+ - **Table Details**: Click "View Details" to see all triggers for a table
57
+ - **Quick Actions**: Create triggers directly from the table list
58
+
59
+ ### Using Filters
60
+
61
+ 1. Click "View Tables" from dashboard
62
+ 2. Use filter buttons:
63
+ - **All Tables**: Shows everything
64
+ - **With Triggers**: Only tables that have triggers (default)
65
+ - **Without Triggers**: Only tables without triggers
66
+ 3. Filter selection is preserved when navigating pages
67
+
68
+ ### Status Indicators
69
+
70
+ - **✓ Green**: Managed and in sync
71
+ - **⚠ Yellow**: Drifted or manual override
72
+ - **✗ Red**: Dropped or error
73
+ - **○ Gray**: Disabled
74
+ - **? Purple**: Unknown state
75
+
76
+ ### Sorting and Filtering
77
+
78
+ - Click column headers to sort
79
+ - Use filters to narrow results
80
+ - Search by trigger name
81
+
82
+ ## Trigger Management
83
+
84
+ ### Viewing Trigger Details
85
+
86
+ Click any trigger name to view details:
87
+
88
+ - **Summary Panel**: Status, version, environment
89
+ - **SQL Information**: Function body and trigger configuration
90
+ - **Drift Information**: Expected vs actual SQL (if drifted)
91
+ - **Action Buttons**: Enable, disable, drop, re-execute
92
+
93
+ ### Enabling/Disabling Triggers
94
+
95
+ 1. Navigate to trigger (dashboard or detail page)
96
+ 2. Click **Enable** or **Disable** button
97
+ 3. In production, enter confirmation text when prompted
98
+ 4. Confirm in modal
99
+ 5. Operation is logged to audit trail
100
+
101
+ ### Dropping Triggers (Admin Only)
102
+
103
+ 1. Navigate to trigger detail page
104
+ 2. Click **Drop** button (Admin permission required)
105
+ 3. Enter reason for dropping
106
+ 4. Enter confirmation text (in production)
107
+ 5. Confirm in modal
108
+ 6. Trigger is removed from database and registry
109
+
110
+ ### Re-executing Triggers (Admin Only)
111
+
112
+ Re-execute is used to fix drifted triggers:
113
+
114
+ 1. Navigate to drifted trigger detail page
115
+ 2. Review drift diff (expected vs actual)
116
+ 3. Click **Re-execute** button
117
+ 4. Enter reason
118
+ 5. Enter confirmation text (in production)
119
+ 6. Confirm in modal
120
+ 7. Trigger is dropped and recreated with current definition
121
+
122
+ ## Quick Actions
123
+
124
+ ### From Dashboard
125
+
126
+ - **Enable/Disable**: Quick toggle buttons (Operator+)
127
+ - **View Details**: Click trigger name
128
+ - **View Table**: Click table name
129
+
130
+ ### From Trigger Detail Page
131
+
132
+ - **Enable/Disable**: Full action panel
133
+ - **Drop**: Remove trigger (Admin)
134
+ - **Re-execute**: Fix drift (Admin)
135
+ - **View Table**: Navigate to table view
136
+ - **Back to Dashboard**: Return to overview
137
+
138
+ ## Permissions
139
+
140
+ The UI automatically adjusts based on your role:
141
+
142
+ - **Viewer**: Can view all triggers and details
143
+ - **Operator**: Can enable/disable, generate triggers
144
+ - **Admin**: Full access including drop and re-execute
145
+
146
+ Buttons are hidden if you don't have permission. See [Permissions Guide](permissions.md) for configuration details.
147
+
148
+ ## Common Tasks
149
+
150
+ ### Enable a Disabled Trigger
151
+
152
+ 1. Go to Dashboard
153
+ 2. Find trigger (gray indicator = disabled)
154
+ 3. Click **Enable** button
155
+ 4. Enter confirmation (if in production)
156
+ 5. Confirm
157
+
158
+ ### Fix a Drifted Trigger
159
+
160
+ 1. Go to Dashboard
161
+ 2. Find drifted trigger (yellow indicator)
162
+ 3. Click trigger name to view details
163
+ 4. Review drift diff
164
+ 5. Click **Re-execute** button (Admin required)
165
+ 6. Enter reason: "Fix drift"
166
+ 7. Enter confirmation (if in production)
167
+ 8. Confirm
168
+
169
+ ### View Trigger History
170
+
171
+ 1. Go to Audit Log
172
+ 2. Filter by trigger name
173
+ 3. Review operation history
174
+ 4. Click entry for details
175
+
176
+ ### Generate a New Trigger
177
+
178
+ 1. Go to Generator
179
+ 2. Fill in trigger details:
180
+ - Trigger name
181
+ - Table name
182
+ - Events (INSERT, UPDATE, etc.)
183
+ - Function body (SQL)
184
+ - Version
185
+ 3. Preview DSL and SQL
186
+ 4. Validate SQL
187
+ 5. Create trigger
188
+ 6. Run migration: `rake trigger:migrate`
189
+
190
+ ### Export Audit Logs
191
+
192
+ 1. Go to Audit Log
193
+ 2. Apply filters (optional)
194
+ 3. Click **Export CSV**
195
+ 4. File downloads with filtered results
196
+
197
+ ## Tips
198
+
199
+ - **Use filters**: Narrow results quickly
200
+ - **Check drift regularly**: Yellow indicators need attention
201
+ - **Review audit logs**: Understand what operations occurred
202
+ - **Use breadcrumbs**: Easy navigation between views
203
+ - **Read error messages**: They include recovery suggestions
204
+
205
+ ## Next Steps
206
+
207
+ - [Web UI Documentation](web-ui.md) - Comprehensive UI reference
208
+ - [Permissions Guide](permissions.md) - Configure access controls
209
+ - [Audit Trail Guide](audit-trail.md) - Viewing and exporting logs
210
+ - [Troubleshooting Guide](troubleshooting.md) - Common issues and solutions
211
+