pg_sql_triggers 1.1.1 → 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.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -0
- data/CHANGELOG.md +200 -0
- data/COVERAGE.md +45 -34
- data/Goal.md +276 -155
- data/README.md +56 -1
- data/app/assets/javascripts/pg_sql_triggers/trigger_actions.js +50 -0
- data/app/controllers/concerns/pg_sql_triggers/error_handling.rb +56 -0
- data/app/controllers/concerns/pg_sql_triggers/kill_switch_protection.rb +66 -0
- data/app/controllers/concerns/pg_sql_triggers/permission_checking.rb +117 -0
- data/app/controllers/pg_sql_triggers/application_controller.rb +10 -62
- data/app/controllers/pg_sql_triggers/audit_logs_controller.rb +102 -0
- data/app/controllers/pg_sql_triggers/dashboard_controller.rb +6 -1
- data/app/controllers/pg_sql_triggers/migrations_controller.rb +62 -10
- data/app/controllers/pg_sql_triggers/sql_capsules_controller.rb +161 -0
- data/app/controllers/pg_sql_triggers/tables_controller.rb +30 -4
- data/app/controllers/pg_sql_triggers/triggers_controller.rb +147 -0
- data/app/helpers/pg_sql_triggers/permissions_helper.rb +43 -0
- data/app/models/pg_sql_triggers/audit_log.rb +106 -0
- data/app/models/pg_sql_triggers/trigger_registry.rb +297 -5
- data/app/views/layouts/pg_sql_triggers/application.html.erb +26 -6
- data/app/views/pg_sql_triggers/audit_logs/index.html.erb +177 -0
- data/app/views/pg_sql_triggers/dashboard/index.html.erb +65 -2
- data/app/views/pg_sql_triggers/sql_capsules/new.html.erb +81 -0
- data/app/views/pg_sql_triggers/sql_capsules/show.html.erb +85 -0
- data/app/views/pg_sql_triggers/tables/index.html.erb +76 -3
- data/app/views/pg_sql_triggers/tables/show.html.erb +49 -2
- data/app/views/pg_sql_triggers/triggers/_drop_modal.html.erb +138 -0
- data/app/views/pg_sql_triggers/triggers/_re_execute_modal.html.erb +145 -0
- data/app/views/pg_sql_triggers/triggers/show.html.erb +206 -0
- data/config/routes.rb +11 -0
- data/db/migrate/20260103000001_create_pg_sql_triggers_audit_log.rb +28 -0
- data/docs/README.md +15 -5
- data/docs/api-reference.md +443 -4
- data/docs/audit-trail.md +413 -0
- data/docs/configuration.md +6 -6
- data/docs/permissions.md +369 -0
- data/docs/troubleshooting.md +486 -0
- data/docs/ui-guide.md +211 -0
- data/docs/web-ui.md +328 -40
- data/lib/pg_sql_triggers/errors.rb +245 -0
- data/lib/pg_sql_triggers/generator/service.rb +32 -0
- data/lib/pg_sql_triggers/permissions/checker.rb +9 -2
- data/lib/pg_sql_triggers/registry/manager.rb +28 -13
- data/lib/pg_sql_triggers/registry.rb +176 -2
- data/lib/pg_sql_triggers/sql/capsule.rb +79 -0
- data/lib/pg_sql_triggers/sql/executor.rb +200 -0
- data/lib/pg_sql_triggers/sql/kill_switch.rb +33 -5
- data/lib/pg_sql_triggers/testing/function_tester.rb +2 -0
- data/lib/pg_sql_triggers/version.rb +1 -1
- data/lib/pg_sql_triggers.rb +3 -6
- metadata +38 -6
- data/docs/screenshots/.gitkeep +0 -1
- data/docs/screenshots/Generate Trigger.png +0 -0
- data/docs/screenshots/Triggers Page.png +0 -0
- data/docs/screenshots/kill error.png +0 -0
- data/docs/screenshots/kill modal for migration down.png +0 -0
data/docs/web-ui.md
CHANGED
|
@@ -9,6 +9,7 @@ The PgSqlTriggers web interface provides a visual dashboard for managing trigger
|
|
|
9
9
|
- [Managing Triggers](#managing-triggers)
|
|
10
10
|
- [Migration Management](#migration-management)
|
|
11
11
|
- [SQL Capsules](#sql-capsules)
|
|
12
|
+
- [Audit Log](#audit-log)
|
|
12
13
|
- [Permissions and Safety](#permissions-and-safety)
|
|
13
14
|
|
|
14
15
|
## Accessing the Web UI
|
|
@@ -34,11 +35,12 @@ The dashboard provides a comprehensive view of your trigger ecosystem.
|
|
|
34
35
|
|
|
35
36
|
### Main Features
|
|
36
37
|
|
|
37
|
-
1. **Trigger List**: View all triggers with their current status
|
|
38
|
+
1. **Trigger List**: View all triggers with their current status and "Last Applied" timestamps
|
|
38
39
|
2. **Drift Detection**: Visual indicators for drift states
|
|
39
40
|
3. **Migration Status**: See pending and applied migrations
|
|
40
|
-
4. **Quick Actions**: Enable/disable triggers, run migrations
|
|
41
|
+
4. **Quick Actions**: Enable/disable triggers, drop/re-execute triggers (based on permissions), run migrations
|
|
41
42
|
5. **Kill Switch Status**: Production environment indicator
|
|
43
|
+
6. **Audit Trail**: All operations are logged with actor information and viewable via Audit Log UI
|
|
42
44
|
|
|
43
45
|

|
|
44
46
|
|
|
@@ -50,32 +52,116 @@ The dashboard provides a comprehensive view of your trigger ecosystem.
|
|
|
50
52
|
- **○ Gray**: Disabled
|
|
51
53
|
- **? Purple**: Unknown
|
|
52
54
|
|
|
55
|
+
## Database Tables & Triggers
|
|
56
|
+
|
|
57
|
+
The Database Tables & Triggers page provides a comprehensive view of all tables in your database and their associated triggers. This page helps you understand which tables have triggers and which don't, making it easier to manage your trigger ecosystem.
|
|
58
|
+
|
|
59
|
+
### Accessing the Tables Page
|
|
60
|
+
|
|
61
|
+
1. Click "View Tables" from the dashboard
|
|
62
|
+
2. Or navigate directly to `/pg_sql_triggers/tables`
|
|
63
|
+
|
|
64
|
+
### Statistics Overview
|
|
65
|
+
|
|
66
|
+
The page displays three key statistics:
|
|
67
|
+
- **Tables with Triggers**: Count of tables that have at least one trigger
|
|
68
|
+
- **Tables without Triggers**: Count of tables that have no triggers
|
|
69
|
+
- **Total Tables**: Total count of all tables in the database
|
|
70
|
+
|
|
71
|
+
### Filtering Tables
|
|
72
|
+
|
|
73
|
+
Use the filter controls to view different subsets of tables:
|
|
74
|
+
- **All Tables**: Shows all tables regardless of trigger status
|
|
75
|
+
- **With Triggers**: Shows only tables that have at least one trigger (default)
|
|
76
|
+
- **Without Triggers**: Shows only tables that have no triggers
|
|
77
|
+
|
|
78
|
+
The active filter is highlighted with a colored background. Click any filter button to switch views.
|
|
79
|
+
|
|
80
|
+
### Pagination
|
|
81
|
+
|
|
82
|
+
When you have many tables, the list is paginated for better performance:
|
|
83
|
+
- **Default**: 20 tables per page
|
|
84
|
+
- **Configurable**: Choose 10, 20, 50, or 100 tables per page
|
|
85
|
+
- **Navigation**: Use Previous/Next buttons to move between pages
|
|
86
|
+
- **Filter Preservation**: Your selected filter is preserved when navigating pages
|
|
87
|
+
|
|
88
|
+
### Table Information
|
|
89
|
+
|
|
90
|
+
Each table row displays:
|
|
91
|
+
- **Table Name**: The name of the database table
|
|
92
|
+
- **Trigger Count**: Number of triggers on the table (badge indicator)
|
|
93
|
+
- **Trigger Names & Functions**: List of all triggers with their function names
|
|
94
|
+
- Registry triggers (blue border) - Triggers managed by pg_sql_triggers
|
|
95
|
+
- Database-only triggers (yellow border) - Triggers not in the registry
|
|
96
|
+
- **Status**: Summary of enabled/disabled triggers
|
|
97
|
+
- **Actions**:
|
|
98
|
+
- "View Details" - Navigate to the table detail page
|
|
99
|
+
- "Create Trigger" - Generate a new trigger for this table
|
|
100
|
+
|
|
101
|
+
### Table Detail Page
|
|
102
|
+
|
|
103
|
+
Click "View Details" on any table to see:
|
|
104
|
+
- **Table Columns**: Complete list of columns with data types and nullability
|
|
105
|
+
- **Registered Triggers**: All triggers managed by pg_sql_triggers with full details
|
|
106
|
+
- **Database Triggers**: Triggers that exist in the database but aren't in the registry
|
|
107
|
+
|
|
108
|
+
From the table detail page, you can:
|
|
109
|
+
- Enable/disable individual triggers (Operator+ permission)
|
|
110
|
+
- Drop triggers (Admin permission)
|
|
111
|
+
- Re-execute drifted triggers (Admin permission)
|
|
112
|
+
- Create new triggers for the table
|
|
113
|
+
|
|
53
114
|
## Managing Triggers
|
|
54
115
|
|
|
55
116
|
### Viewing Trigger Details
|
|
56
117
|
|
|
57
|
-
Click on any trigger to
|
|
58
|
-
|
|
118
|
+
Click on any trigger name (from dashboard or table view) to access the trigger detail page. The detail page includes:
|
|
119
|
+
|
|
120
|
+
#### Navigation
|
|
121
|
+
- **Breadcrumb Navigation**: Dashboard → Tables → Table Name → Trigger Name
|
|
122
|
+
- **Quick Links**: Back to Dashboard, View Table
|
|
123
|
+
|
|
124
|
+
#### Summary Panel
|
|
125
|
+
- Current status and drift state with visual indicators
|
|
59
126
|
- Table and function information
|
|
60
|
-
- Version
|
|
61
|
-
-
|
|
62
|
-
-
|
|
127
|
+
- Version, source (DSL/generated/manual_sql), and environment
|
|
128
|
+
- **Last Applied**: Human-readable timestamp showing when trigger was last applied (e.g., "2 hours ago")
|
|
129
|
+
- **Last Verified**: Timestamp of last drift verification
|
|
130
|
+
- **Created At**: Original creation timestamp
|
|
131
|
+
|
|
132
|
+
#### SQL Information
|
|
133
|
+
- **Function Body**: Complete PL/pgSQL function code
|
|
134
|
+
- **Trigger Configuration**: Events, timing, conditions
|
|
135
|
+
- **SQL Diff View**: If drift detected, shows expected vs actual SQL side-by-side
|
|
136
|
+
|
|
137
|
+
#### Actions
|
|
138
|
+
All action buttons available based on permissions:
|
|
139
|
+
- Enable/Disable (Operator+)
|
|
140
|
+
- Re-Execute (Admin, shown only when drift detected)
|
|
141
|
+
- Drop (Admin)
|
|
63
142
|
|
|
64
143
|
### Enabling/Disabling Triggers
|
|
65
144
|
|
|
145
|
+
Triggers can be enabled or disabled from multiple locations:
|
|
146
|
+
- **Dashboard**: Quick action buttons in the trigger table (Operator+ permission)
|
|
147
|
+
- **Table Detail Page**: Action buttons for each trigger (Operator+ permission)
|
|
148
|
+
- **Trigger Detail Page**: Full action panel (Operator+ permission)
|
|
149
|
+
|
|
66
150
|
#### Enable a Trigger
|
|
67
151
|
|
|
68
|
-
1. Navigate to the trigger
|
|
69
|
-
2. Click the "Enable" button
|
|
152
|
+
1. Navigate to the trigger (dashboard, table view, or trigger detail page)
|
|
153
|
+
2. Click the "Enable" button (green button)
|
|
70
154
|
3. In production environments, enter the confirmation text when prompted
|
|
71
|
-
4. Confirm the action
|
|
155
|
+
4. Confirm the action in the modal
|
|
156
|
+
5. The trigger will be enabled and the operation logged to the audit trail
|
|
72
157
|
|
|
73
158
|
#### Disable a Trigger
|
|
74
159
|
|
|
75
|
-
1. Navigate to the trigger
|
|
76
|
-
2. Click the "Disable" button
|
|
160
|
+
1. Navigate to the trigger (dashboard, table view, or trigger detail page)
|
|
161
|
+
2. Click the "Disable" button (red button)
|
|
77
162
|
3. In production environments, enter the confirmation text when prompted
|
|
78
|
-
4. Confirm the action
|
|
163
|
+
4. Confirm the action in the modal
|
|
164
|
+
5. The trigger will be disabled and the operation logged to the audit trail
|
|
79
165
|
|
|
80
166
|
### Viewing Drift Status
|
|
81
167
|
|
|
@@ -93,9 +179,69 @@ Available actions depend on trigger state and your permissions:
|
|
|
93
179
|
- **Enable/Disable**: Toggle trigger activation
|
|
94
180
|
- **Apply**: Apply generated trigger definition
|
|
95
181
|
- **Drop**: Remove trigger from database (Admin only)
|
|
182
|
+
- **Re-Execute**: Drop and recreate trigger from registry definition (Admin only)
|
|
96
183
|
- **View SQL**: See the trigger's SQL definition
|
|
97
184
|
- **View Diff**: Compare DSL vs database state
|
|
98
185
|
|
|
186
|
+
### Drop Trigger
|
|
187
|
+
|
|
188
|
+
The drop action permanently removes a trigger from the database and registry. Available from:
|
|
189
|
+
- **Dashboard**: "Drop" button in trigger table (Admin only)
|
|
190
|
+
- **Table Detail Page**: "Drop Trigger" button (Admin only)
|
|
191
|
+
- **Trigger Detail Page**: "Drop Trigger" button (Admin only)
|
|
192
|
+
|
|
193
|
+
**Steps**:
|
|
194
|
+
1. Navigate to the trigger (any view with drop button)
|
|
195
|
+
2. Click the "Drop Trigger" button (gray button with warning icon)
|
|
196
|
+
3. A modal will appear requiring:
|
|
197
|
+
- **Reason**: Explanation for dropping the trigger (required for audit trail)
|
|
198
|
+
- **Confirmation**: In protected environments, type the exact confirmation text shown
|
|
199
|
+
4. Review the warning message carefully
|
|
200
|
+
5. Click "Drop Trigger" to confirm
|
|
201
|
+
|
|
202
|
+
**Important Notes**:
|
|
203
|
+
- This action is **irreversible** - the trigger will be permanently removed
|
|
204
|
+
- Requires **Admin** permission level
|
|
205
|
+
- Protected by kill switch in production environments
|
|
206
|
+
- Reason is logged for compliance and audit purposes
|
|
207
|
+
- The trigger is removed from both the database and the registry
|
|
208
|
+
- Operation is logged to audit trail with actor information and state changes
|
|
209
|
+
|
|
210
|
+
### Re-Execute Trigger
|
|
211
|
+
|
|
212
|
+
The re-execute action fixes drifted triggers by dropping and recreating them from the registry definition. Available from:
|
|
213
|
+
- **Dashboard**: "Re-Execute" button in trigger table (Admin only, shown only when drift detected)
|
|
214
|
+
- **Table Detail Page**: "Re-Execute Trigger" button (Admin only, shown only when drift detected)
|
|
215
|
+
- **Trigger Detail Page**: "Re-Execute Trigger" button (Admin only, shown only when drift detected)
|
|
216
|
+
|
|
217
|
+
**Steps**:
|
|
218
|
+
1. Navigate to the trigger (any view with re-execute button)
|
|
219
|
+
2. If the trigger is drifted, you'll see a drift warning and the "Re-Execute" button will be visible
|
|
220
|
+
3. Click the "Re-Execute" button (yellow/warning button)
|
|
221
|
+
4. A modal will appear showing:
|
|
222
|
+
- **Drift Comparison**: Side-by-side differences between expected (registry) and actual (database) SQL
|
|
223
|
+
- **Reason Field**: Explanation for re-executing (required for audit trail)
|
|
224
|
+
- **Confirmation**: In protected environments, type the exact confirmation text shown
|
|
225
|
+
5. Review the drift differences carefully to understand what will change
|
|
226
|
+
6. Click "Re-Execute Trigger" to confirm
|
|
227
|
+
|
|
228
|
+
**What Happens**:
|
|
229
|
+
1. Current trigger is dropped from the database
|
|
230
|
+
2. New trigger is created using the registry definition (function_body, events, timing, condition)
|
|
231
|
+
3. Registry is updated with execution timestamp
|
|
232
|
+
4. Operation is logged to audit trail with:
|
|
233
|
+
- Reason and actor information
|
|
234
|
+
- Before and after state
|
|
235
|
+
- SQL diff information
|
|
236
|
+
|
|
237
|
+
**Important Notes**:
|
|
238
|
+
- Requires **Admin** permission level
|
|
239
|
+
- Protected by kill switch in production environments
|
|
240
|
+
- Reason is logged for compliance and audit purposes
|
|
241
|
+
- Executes in a database transaction (rolls back on error)
|
|
242
|
+
- Best used to fix triggers that have drifted from their DSL definition
|
|
243
|
+
- Button only appears when drift is detected
|
|
244
|
+
|
|
99
245
|
## Migration Management
|
|
100
246
|
|
|
101
247
|
The Web UI provides full migration management capabilities.
|
|
@@ -159,33 +305,51 @@ After each migration action:
|
|
|
159
305
|
|
|
160
306
|
## SQL Capsules
|
|
161
307
|
|
|
162
|
-
SQL Capsules provide emergency escape hatches for executing SQL directly.
|
|
308
|
+
SQL Capsules provide emergency escape hatches for executing SQL directly with comprehensive safety checks and audit logging.
|
|
163
309
|
|
|
164
310
|
### When to Use SQL Capsules
|
|
165
311
|
|
|
166
312
|
Use SQL Capsules for:
|
|
167
313
|
- Emergency fixes in production
|
|
168
|
-
-
|
|
314
|
+
- Critical data corrections
|
|
169
315
|
- Testing SQL functions
|
|
170
316
|
- Debugging trigger behavior
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
317
|
+
- One-off database operations
|
|
318
|
+
|
|
319
|
+
### Creating and Executing SQL Capsules
|
|
320
|
+
|
|
321
|
+
1. Navigate to "SQL Capsules" → "New SQL Capsule"
|
|
322
|
+
2. Fill in the capsule form:
|
|
323
|
+
- **Name**: Unique identifier (alphanumeric, underscores, hyphens only)
|
|
324
|
+
- **Environment**: Target environment (e.g., production, staging)
|
|
325
|
+
- **Purpose**: Detailed explanation of what the SQL does and why (required for audit trail)
|
|
326
|
+
- **SQL**: The SQL statement(s) to execute
|
|
327
|
+
3. Click "Create and Execute" or "Save for Later"
|
|
328
|
+
4. Review the capsule details on the confirmation page
|
|
329
|
+
5. In protected environments, enter confirmation text when prompted
|
|
330
|
+
6. Click "Execute" to run the SQL
|
|
331
|
+
7. Review the execution results
|
|
332
|
+
|
|
333
|
+
### Viewing Capsule History
|
|
334
|
+
|
|
335
|
+
1. Navigate to "SQL Capsules" → "History"
|
|
336
|
+
2. View list of previously executed capsules with:
|
|
337
|
+
- Name and purpose
|
|
338
|
+
- Environment and timestamp
|
|
339
|
+
- SQL checksum
|
|
340
|
+
- Execution status
|
|
341
|
+
3. Click on a capsule to view details
|
|
342
|
+
4. Re-execute historical capsules if needed
|
|
182
343
|
|
|
183
344
|
### Safety Features
|
|
184
345
|
|
|
185
|
-
- **
|
|
186
|
-
- **
|
|
187
|
-
- **
|
|
188
|
-
- **
|
|
346
|
+
- **Admin Permission Required**: Only Admin users can create and execute SQL capsules
|
|
347
|
+
- **Production Protection**: Requires typed confirmation in protected environments
|
|
348
|
+
- **Kill Switch Integration**: All executions are protected by kill switch
|
|
349
|
+
- **Comprehensive Logging**: All operations logged with actor, timestamp, and checksum
|
|
350
|
+
- **Transactional Execution**: SQL runs in a transaction and rolls back on error
|
|
351
|
+
- **Registry Storage**: All capsules are stored in the registry with checksums
|
|
352
|
+
- **Purpose Tracking**: Required purpose field ensures all executions are documented
|
|
189
353
|
|
|
190
354
|
### Example SQL Capsules
|
|
191
355
|
|
|
@@ -216,6 +380,92 @@ SELECT * FROM pg_sql_triggers_registry
|
|
|
216
380
|
WHERE trigger_name = 'users_email_validation';
|
|
217
381
|
```
|
|
218
382
|
|
|
383
|
+
## Audit Log
|
|
384
|
+
|
|
385
|
+
The Audit Log provides a comprehensive view of all trigger operations performed through the web UI, console APIs, and CLI. This feature is essential for compliance, debugging, and tracking changes to your trigger ecosystem.
|
|
386
|
+
|
|
387
|
+
### Accessing the Audit Log
|
|
388
|
+
|
|
389
|
+
1. Navigate to the "Audit Log" link in the main navigation menu
|
|
390
|
+
2. Or visit `/pg_sql_triggers/audit_logs` directly
|
|
391
|
+
|
|
392
|
+
### Viewing Audit Log Entries
|
|
393
|
+
|
|
394
|
+
The audit log displays all operations with the following information:
|
|
395
|
+
|
|
396
|
+
- **Time**: When the operation occurred (relative time with exact timestamp on hover)
|
|
397
|
+
- **Trigger**: The trigger name (clickable link to trigger detail page if available)
|
|
398
|
+
- **Operation**: The type of operation performed (e.g., `trigger_enable`, `trigger_drop`, `trigger_re_execute`)
|
|
399
|
+
- **Status**: Success or failure indicator
|
|
400
|
+
- **Environment**: The environment where the operation was performed
|
|
401
|
+
- **Actor**: Who performed the operation (e.g., `UI:user_id`, `Console:email`)
|
|
402
|
+
- **Reason**: Explanation for the operation (for drop/re-execute operations)
|
|
403
|
+
- **Error**: Error message if the operation failed
|
|
404
|
+
|
|
405
|
+
### Filtering Audit Logs
|
|
406
|
+
|
|
407
|
+
The audit log supports multiple filters to help you find specific entries:
|
|
408
|
+
|
|
409
|
+
1. **Trigger Name**: Filter by specific trigger name
|
|
410
|
+
2. **Operation**: Filter by operation type (enable, disable, drop, re_execute, etc.)
|
|
411
|
+
3. **Status**: Filter by success or failure
|
|
412
|
+
4. **Environment**: Filter by environment (production, staging, development, etc.)
|
|
413
|
+
5. **Sort Order**: Sort by date (newest first or oldest first)
|
|
414
|
+
|
|
415
|
+
Click "Apply Filters" to update the view, or "Clear" to remove all filters.
|
|
416
|
+
|
|
417
|
+
### Exporting Audit Logs
|
|
418
|
+
|
|
419
|
+
To export audit log entries:
|
|
420
|
+
|
|
421
|
+
1. Apply any desired filters
|
|
422
|
+
2. Click the "Export CSV" button
|
|
423
|
+
3. The CSV file will include all entries matching your filters (not just the current page)
|
|
424
|
+
4. File is named with timestamp: `audit_logs_YYYYMMDD_HHMMSS.csv`
|
|
425
|
+
|
|
426
|
+
The CSV export includes:
|
|
427
|
+
- ID, Trigger Name, Operation, Status, Environment
|
|
428
|
+
- Actor Type and ID
|
|
429
|
+
- Reason and Error Message
|
|
430
|
+
- Created At timestamp
|
|
431
|
+
|
|
432
|
+
### Pagination
|
|
433
|
+
|
|
434
|
+
The audit log uses pagination to handle large datasets:
|
|
435
|
+
|
|
436
|
+
- Default: 50 entries per page (adjustable via URL parameter)
|
|
437
|
+
- Maximum: 200 entries per page
|
|
438
|
+
- Navigate using "Previous" and "Next" buttons
|
|
439
|
+
- Page numbers and total count displayed
|
|
440
|
+
|
|
441
|
+
### What Gets Logged
|
|
442
|
+
|
|
443
|
+
All of the following operations are logged to the audit log:
|
|
444
|
+
|
|
445
|
+
- **Enable Trigger**: Success/failure, before/after state
|
|
446
|
+
- **Disable Trigger**: Success/failure, before/after state
|
|
447
|
+
- **Drop Trigger**: Success/failure, reason, state changes
|
|
448
|
+
- **Re-execute Trigger**: Success/failure, reason, drift diff information
|
|
449
|
+
- **SQL Capsule Execution**: Success/failure, capsule details
|
|
450
|
+
- **Migration Operations**: Up, down, and redo operations (infrastructure ready)
|
|
451
|
+
|
|
452
|
+
Each log entry includes:
|
|
453
|
+
- Complete actor information (who performed the operation)
|
|
454
|
+
- Before and after state (for state-changing operations)
|
|
455
|
+
- Operation metadata (reason, confirmation text, environment)
|
|
456
|
+
- Error details (if the operation failed)
|
|
457
|
+
- Timestamp of the operation
|
|
458
|
+
|
|
459
|
+
### Use Cases
|
|
460
|
+
|
|
461
|
+
Common use cases for the audit log:
|
|
462
|
+
|
|
463
|
+
- **Compliance**: Track all changes for audit requirements
|
|
464
|
+
- **Debugging**: Understand what operations were performed before an issue
|
|
465
|
+
- **Accountability**: See who performed specific operations
|
|
466
|
+
- **Troubleshooting**: Review failed operations and their error messages
|
|
467
|
+
- **Change History**: Track the evolution of your trigger ecosystem over time
|
|
468
|
+
|
|
219
469
|
## Permissions and Safety
|
|
220
470
|
|
|
221
471
|
### Permission Levels
|
|
@@ -257,7 +507,13 @@ In protected environments (production, staging), the Web UI enforces additional
|
|
|
257
507
|
1. **Status Indicator**: Kill switch badge shows protection status
|
|
258
508
|
2. **Confirmation Required**: Dangerous operations require typed confirmation
|
|
259
509
|
3. **Warning Banners**: Visual alerts for production environment
|
|
260
|
-
4. **Audit Logging**: All protected operations are logged
|
|
510
|
+
4. **Audit Logging**: All protected operations are logged with complete audit trail:
|
|
511
|
+
- Actor information (who performed the operation)
|
|
512
|
+
- Before and after state
|
|
513
|
+
- Operation details (reason, confirmation text)
|
|
514
|
+
- Success/failure status
|
|
515
|
+
- Error messages (if failed)
|
|
516
|
+
- Timestamp of operation
|
|
261
517
|
|
|
262
518
|
### Configuring Permissions
|
|
263
519
|
|
|
@@ -267,20 +523,26 @@ Set up custom permission checking in the initializer:
|
|
|
267
523
|
# config/initializers/pg_sql_triggers.rb
|
|
268
524
|
PgSqlTriggers.configure do |config|
|
|
269
525
|
config.permission_checker = ->(actor, action, environment) {
|
|
270
|
-
user = User.
|
|
526
|
+
user = User.find_by(id: actor[:id])
|
|
527
|
+
return false unless user
|
|
271
528
|
|
|
272
529
|
case action
|
|
273
|
-
when :
|
|
274
|
-
user.present?
|
|
275
|
-
when :
|
|
276
|
-
user.
|
|
277
|
-
when :
|
|
278
|
-
user.admin?
|
|
530
|
+
when :view_triggers, :view_diffs
|
|
531
|
+
user.present? # Viewer level
|
|
532
|
+
when :enable_trigger, :disable_trigger, :apply_trigger, :generate_trigger, :test_trigger, :dry_run_sql
|
|
533
|
+
user.operator? || user.admin? # Operator level
|
|
534
|
+
when :drop_trigger, :execute_sql, :override_drift
|
|
535
|
+
user.admin? # Admin level
|
|
279
536
|
else
|
|
280
537
|
false
|
|
281
538
|
end
|
|
282
539
|
}
|
|
283
540
|
end
|
|
541
|
+
```else
|
|
542
|
+
false
|
|
543
|
+
end
|
|
544
|
+
}
|
|
545
|
+
end
|
|
284
546
|
```
|
|
285
547
|
|
|
286
548
|
## Screenshots
|
|
@@ -314,13 +576,39 @@ The preview page displays:
|
|
|
314
576
|
### SQL Capsules
|
|
315
577
|

|
|
316
578
|
|
|
579
|
+
## Dashboard Enhancements (v1.3.0+)
|
|
580
|
+
|
|
581
|
+
### Last Applied Column
|
|
582
|
+
|
|
583
|
+
The dashboard now includes a "Last Applied" column showing when each trigger was last applied to the database:
|
|
584
|
+
- **Human-readable format**: Displays relative time (e.g., "2 hours ago", "3 days ago")
|
|
585
|
+
- **Tooltip**: Hover over the timestamp to see exact date and time
|
|
586
|
+
- **Default sorting**: Dashboard sorted by most recently applied triggers first
|
|
587
|
+
- **Never applied**: Shows "Never" if trigger has never been applied
|
|
588
|
+
|
|
589
|
+
This helps you quickly identify:
|
|
590
|
+
- Which triggers are actively maintained
|
|
591
|
+
- How recently triggers were updated
|
|
592
|
+
- Triggers that may need attention
|
|
593
|
+
|
|
594
|
+
### Quick Actions in Dashboard
|
|
595
|
+
|
|
596
|
+
The dashboard trigger table now includes quick action buttons:
|
|
597
|
+
- **Enable/Disable**: Toggle trigger state (Operator+ permission)
|
|
598
|
+
- **Drop**: Remove trigger permanently (Admin only)
|
|
599
|
+
- **Re-Execute**: Fix drifted triggers (Admin only, shown only when drift detected)
|
|
600
|
+
|
|
601
|
+
All actions respect permission levels and show/hide buttons based on your role.
|
|
602
|
+
|
|
317
603
|
## Tips and Best Practices
|
|
318
604
|
|
|
319
605
|
1. **Check Status Regularly**: Monitor drift detection to catch unexpected changes
|
|
320
606
|
2. **Use Confirmations**: Don't bypass production confirmations without understanding the impact
|
|
321
607
|
3. **Test in Development**: Always test UI actions in development before production
|
|
322
|
-
4. **Review Logs**: Check application logs after important operations
|
|
323
|
-
5. **Document Changes**: Add
|
|
608
|
+
4. **Review Logs**: Check application logs and audit trail after important operations
|
|
609
|
+
5. **Document Changes**: Add detailed reasons when dropping or re-executing triggers
|
|
610
|
+
6. **Monitor Last Applied**: Use the "Last Applied" column to track trigger maintenance activity
|
|
611
|
+
7. **Breadcrumb Navigation**: Use breadcrumbs on trigger detail page for easy navigation
|
|
324
612
|
|
|
325
613
|
## Troubleshooting
|
|
326
614
|
|