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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +144 -0
- data/COVERAGE.md +26 -19
- data/Goal.md +276 -155
- data/README.md +27 -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 +4 -9
- data/app/controllers/pg_sql_triggers/tables_controller.rb +30 -4
- data/app/controllers/pg_sql_triggers/triggers_controller.rb +3 -21
- 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 +178 -9
- 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 +33 -8
- data/app/views/pg_sql_triggers/tables/index.html.erb +76 -3
- data/app/views/pg_sql_triggers/tables/show.html.erb +17 -4
- data/app/views/pg_sql_triggers/triggers/_drop_modal.html.erb +16 -7
- data/app/views/pg_sql_triggers/triggers/_re_execute_modal.html.erb +16 -7
- data/app/views/pg_sql_triggers/triggers/show.html.erb +26 -6
- data/config/routes.rb +2 -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 +191 -0
- 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 +257 -34
- 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.rb +141 -8
- 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 +29 -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/Goal.md
CHANGED
|
@@ -132,18 +132,27 @@ Drift states:
|
|
|
132
132
|
|
|
133
133
|
Provide console APIs:
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
✅ `PgSqlTriggers::Registry.list` - Returns all registered triggers
|
|
136
|
+
✅ `PgSqlTriggers::Registry.enabled` - Returns enabled triggers
|
|
137
|
+
✅ `PgSqlTriggers::Registry.disabled` - Returns disabled triggers
|
|
138
|
+
✅ `PgSqlTriggers::Registry.for_table(:users)` - Returns triggers for a specific table
|
|
139
|
+
✅ `PgSqlTriggers::Registry.diff` - Checks for drift (fully working with drift detection)
|
|
140
|
+
✅ `PgSqlTriggers::Registry.validate!` - Validates all triggers
|
|
141
|
+
✅ `PgSqlTriggers::Registry.drifted` - Returns all drifted triggers
|
|
142
|
+
✅ `PgSqlTriggers::Registry.in_sync` - Returns all in-sync triggers
|
|
143
|
+
✅ `PgSqlTriggers::Registry.unknown_triggers` - Returns all unknown (external) triggers
|
|
144
|
+
✅ `PgSqlTriggers::Registry.dropped` - Returns all dropped triggers
|
|
145
|
+
✅ `PgSqlTriggers::Registry.enable(trigger_name, actor:, confirmation:)` - Enable a trigger
|
|
146
|
+
✅ `PgSqlTriggers::Registry.disable(trigger_name, actor:, confirmation:)` - Disable a trigger
|
|
147
|
+
✅ `PgSqlTriggers::Registry.drop(trigger_name, actor:, reason:, confirmation:)` - Drop a trigger
|
|
148
|
+
✅ `PgSqlTriggers::Registry.re_execute(trigger_name, actor:, reason:, confirmation:)` - Re-execute a trigger
|
|
149
|
+
|
|
150
|
+
✅ No raw SQL required by users for basic operations.
|
|
151
|
+
✅ All console APIs are fully documented with YARD documentation.
|
|
143
152
|
|
|
144
153
|
---
|
|
145
154
|
|
|
146
|
-
## 4. Free-Form SQL Execution (MANDATORY)
|
|
155
|
+
## 4. Free-Form SQL Execution (MANDATORY) ✅ (fully implemented in v1.2.0)
|
|
147
156
|
|
|
148
157
|
The gem MUST support free-form SQL execution.
|
|
149
158
|
|
|
@@ -156,46 +165,53 @@ This is required for:
|
|
|
156
165
|
|
|
157
166
|
Free-form SQL is wrapped in **named SQL capsules**:
|
|
158
167
|
|
|
159
|
-
-
|
|
160
|
-
-
|
|
161
|
-
-
|
|
162
|
-
-
|
|
168
|
+
- ✅ Must be named (fully implemented - `PgSqlTriggers::SQL::Capsule` class)
|
|
169
|
+
- ✅ Must declare environment (fully implemented)
|
|
170
|
+
- ✅ Must declare purpose (fully implemented)
|
|
171
|
+
- ✅ Must be applied explicitly (fully implemented - web UI and console API)
|
|
163
172
|
|
|
164
173
|
Rules:
|
|
165
|
-
-
|
|
166
|
-
-
|
|
167
|
-
-
|
|
168
|
-
-
|
|
169
|
-
|
|
170
|
-
**Status:**
|
|
174
|
+
- ✅ Runs in a transaction (fully implemented - `PgSqlTriggers::SQL::Executor` executes in transaction)
|
|
175
|
+
- ✅ Checksum verified (fully implemented - checksum calculated and stored)
|
|
176
|
+
- ✅ Registry updated (fully implemented - registry updated with `source = manual_sql`)
|
|
177
|
+
- ✅ Marked as `source = manual_sql` (fully implemented)
|
|
178
|
+
|
|
179
|
+
**Status:** ✅ Fully implemented in v1.2.0. Includes:
|
|
180
|
+
- `PgSqlTriggers::SQL::Capsule` class for defining SQL capsules
|
|
181
|
+
- `PgSqlTriggers::SQL::Executor.execute` method for safe execution
|
|
182
|
+
- Web UI controller (`SqlCapsulesController`) with create, show, and execute actions
|
|
183
|
+
- Permission checks (Admin role required for execution)
|
|
184
|
+
- Kill switch protection
|
|
185
|
+
- Comprehensive audit logging
|
|
186
|
+
- Console API: `PgSqlTriggers::SQL::Executor.execute(capsule, actor:, confirmation:)`
|
|
171
187
|
|
|
172
188
|
---
|
|
173
189
|
|
|
174
|
-
## 5. Permissions Model v1
|
|
190
|
+
## 5. Permissions Model v1 ✅ (fully implemented and enforced in v1.3.0)
|
|
175
191
|
|
|
176
192
|
Three permission levels:
|
|
177
193
|
|
|
178
194
|
### Viewer
|
|
179
|
-
-
|
|
180
|
-
-
|
|
181
|
-
-
|
|
195
|
+
- ✅ Read-only (fully enforced)
|
|
196
|
+
- ✅ View triggers (fully enforced)
|
|
197
|
+
- ✅ View diffs (fully enforced)
|
|
182
198
|
|
|
183
199
|
### Operator
|
|
184
|
-
-
|
|
185
|
-
-
|
|
186
|
-
-
|
|
187
|
-
-
|
|
200
|
+
- ✅ Enable / Disable triggers (fully enforced)
|
|
201
|
+
- ✅ Apply generated triggers (fully enforced)
|
|
202
|
+
- ✅ Re-execute triggers in non-prod (fully enforced)
|
|
203
|
+
- ✅ Dry-run SQL (fully enforced)
|
|
188
204
|
|
|
189
205
|
### Admin
|
|
190
|
-
-
|
|
191
|
-
-
|
|
192
|
-
-
|
|
193
|
-
-
|
|
206
|
+
- ✅ Drop triggers (fully enforced - Admin only)
|
|
207
|
+
- ✅ Execute free-form SQL (fully enforced - Admin only)
|
|
208
|
+
- ✅ Re-execute triggers in any env (fully enforced - Admin only)
|
|
209
|
+
- ✅ Override drift (fully enforced)
|
|
194
210
|
|
|
195
211
|
Permissions enforced in:
|
|
196
|
-
-
|
|
197
|
-
-
|
|
198
|
-
-
|
|
212
|
+
- ✅ UI (fully enforced - buttons show/hide based on permissions, controllers check permissions)
|
|
213
|
+
- ✅ CLI (kill switch provides protection - permissions can be added if needed)
|
|
214
|
+
- ✅ Console (fully enforced - all console APIs check permissions via `permission_checker` configuration)
|
|
199
215
|
|
|
200
216
|
---
|
|
201
217
|
|
|
@@ -268,45 +284,54 @@ trigger.enable!(confirmation: "EXECUTE TRIGGER_ENABLE")
|
|
|
268
284
|
|
|
269
285
|
UI is operational, not decorative.
|
|
270
286
|
|
|
271
|
-
### Dashboard ✅ (implemented
|
|
287
|
+
### Dashboard ✅ (fully implemented in v1.3.0)
|
|
272
288
|
- ✅ Trigger name
|
|
273
289
|
- ✅ Table
|
|
274
290
|
- ✅ Version
|
|
275
291
|
- ✅ Status (enabled/disabled)
|
|
276
292
|
- ✅ Source
|
|
277
|
-
-
|
|
293
|
+
- ✅ Drift state (drift detection fully implemented - shows drift count and states)
|
|
278
294
|
- ✅ Environment
|
|
279
|
-
-
|
|
280
|
-
|
|
281
|
-
### Trigger Detail Page
|
|
282
|
-
-
|
|
283
|
-
-
|
|
284
|
-
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
-
|
|
290
|
-
-
|
|
291
|
-
-
|
|
295
|
+
- ✅ Last applied (installed_at displayed with human-readable formatting and tooltips in v1.3.0)
|
|
296
|
+
|
|
297
|
+
### Trigger Detail Page ✅ (fully implemented in v1.3.0)
|
|
298
|
+
- ✅ Summary panel (dedicated trigger detail route and page with comprehensive metadata)
|
|
299
|
+
- ✅ SQL diff (expected vs actual comparison with syntax highlighting)
|
|
300
|
+
- ✅ Registry state (comprehensive state display including checksum, drift detection, manual override status)
|
|
301
|
+
- ✅ Breadcrumb navigation (Dashboard → Tables → Table → Trigger)
|
|
302
|
+
- ✅ Enhanced timestamp display (installed_at and last_verified_at with relative time formatting)
|
|
303
|
+
|
|
304
|
+
### Actions (State-Based) ✅ (fully implemented in v1.2.0 and v1.3.0)
|
|
305
|
+
- ✅ Enable (UI buttons in dashboard, table view, and trigger detail page with kill switch protection)
|
|
306
|
+
- ✅ Disable (UI buttons in dashboard, table view, and trigger detail page with kill switch protection)
|
|
307
|
+
- ✅ Drop (fully implemented in v1.2.0 - UI buttons with confirmation modal in v1.3.0)
|
|
308
|
+
- ✅ Re-execute (fully implemented in v1.2.0 - UI buttons with drift diff display in v1.3.0)
|
|
309
|
+
- ✅ Execute SQL capsule (fully implemented in v1.2.0 - UI buttons in v1.3.0)
|
|
292
310
|
|
|
293
311
|
Buttons must:
|
|
294
|
-
-
|
|
295
|
-
-
|
|
312
|
+
- ✅ Be permission-aware (fully enforced - buttons show/hide based on user permissions in v1.3.0)
|
|
313
|
+
- ✅ Be env-aware (fully implemented - warning colors for production, environment-aware styling)
|
|
296
314
|
- ✅ Respect kill switch (kill switch fully implemented - see Section 6)
|
|
297
315
|
|
|
298
316
|
---
|
|
299
317
|
|
|
300
|
-
## 9. Drop & Re-Execute Flow (CRITICAL)
|
|
318
|
+
## 9. Drop & Re-Execute Flow (CRITICAL) ✅ (fully implemented in v1.2.0, UI added in v1.3.0)
|
|
301
319
|
|
|
302
320
|
Re-execute must:
|
|
303
|
-
1.
|
|
304
|
-
2.
|
|
305
|
-
3.
|
|
306
|
-
4.
|
|
307
|
-
5.
|
|
321
|
+
1. ✅ Show diff (fully implemented - drift diff displayed before re-execution)
|
|
322
|
+
2. ✅ Require reason (fully implemented - reason field required and logged)
|
|
323
|
+
3. ✅ Require typed confirmation (fully implemented - confirmation text required in protected environments)
|
|
324
|
+
4. ✅ Execute transactionally (fully implemented - all operations run in transactions)
|
|
325
|
+
5. ✅ Update registry (fully implemented - registry updated atomically with operations)
|
|
326
|
+
|
|
327
|
+
Drop must:
|
|
328
|
+
1. ✅ Require reason (fully implemented - reason field required and logged)
|
|
329
|
+
2. ✅ Require typed confirmation (fully implemented - confirmation text required in protected environments)
|
|
330
|
+
3. ✅ Execute transactionally (fully implemented - drop runs in transaction)
|
|
331
|
+
4. ✅ Update registry (fully implemented - trigger removed from registry after drop)
|
|
332
|
+
5. ✅ Require Admin permission (fully enforced)
|
|
308
333
|
|
|
309
|
-
No silent operations allowed.
|
|
334
|
+
No silent operations allowed. ✅ All operations are logged to audit trail with actor, reason, and state changes.
|
|
310
335
|
|
|
311
336
|
---
|
|
312
337
|
|
|
@@ -349,15 +374,17 @@ This gem must be described as:
|
|
|
349
374
|
- ✅ Drift Detection (Section 3.E) - fully implemented with all 6 drift states
|
|
350
375
|
- ✅ Rails Console Introspection (Section 3.F) - including working diff method
|
|
351
376
|
- ✅ Kill Switch for Production Safety (Section 6) - fully implemented
|
|
352
|
-
- ✅
|
|
377
|
+
- ✅ SQL Capsules (Section 4) - fully implemented in v1.2.0
|
|
378
|
+
- ✅ Permissions Model (Section 5) - fully enforced in v1.3.0
|
|
379
|
+
- ✅ Drop & Re-Execute Flow (Section 9) - fully implemented in v1.2.0, UI in v1.3.0
|
|
380
|
+
- ✅ Complete UI (Section 8) - dashboard, trigger detail page, all action buttons implemented in v1.3.0
|
|
381
|
+
- ✅ Audit Logging System (Section 13) - fully implemented in v1.3.0 with UI
|
|
353
382
|
|
|
354
383
|
**Partially Implemented:**
|
|
355
|
-
-
|
|
356
|
-
- ⚠️ Permissions Model (Section 5) - structure exists but not enforced
|
|
384
|
+
- None - all critical features are fully implemented
|
|
357
385
|
|
|
358
|
-
**Not Implemented (
|
|
359
|
-
- ❌
|
|
360
|
-
- ❌ Drop & Re-Execute Flow (Section 9) - CRITICAL operational requirement
|
|
386
|
+
**Not Implemented (Optional/Low Priority):**
|
|
387
|
+
- ❌ Time-window auto-lock for kill switch (Section 6 - optional feature)
|
|
361
388
|
|
|
362
389
|
### ✅ Achieved Features
|
|
363
390
|
|
|
@@ -372,7 +399,7 @@ This gem must be described as:
|
|
|
372
399
|
- ✅ Enable/Disable trigger methods on TriggerRegistry model - Basic functionality
|
|
373
400
|
- ✅ Kill Switch for Production Safety (fully implemented) - Section 6
|
|
374
401
|
- ✅ Mountable Rails Engine with routes - Supporting infrastructure
|
|
375
|
-
- ✅
|
|
402
|
+
- ✅ Complete UI (Dashboard, Tables view, Generator, Trigger Detail Page, all action buttons) - Section 8 (fully implemented in v1.3.0)
|
|
376
403
|
|
|
377
404
|
**From Section 3.A (Trigger Declaration DSL):**
|
|
378
405
|
- ✅ DSL generates metadata
|
|
@@ -431,56 +458,96 @@ This gem must be described as:
|
|
|
431
458
|
- ✅ UI, CLI, and Console enforcement
|
|
432
459
|
- ✅ Thread-safe override mechanism
|
|
433
460
|
|
|
461
|
+
**From Section 4 (SQL Capsules):**
|
|
462
|
+
- ✅ `PgSqlTriggers::SQL::Capsule` class for defining SQL capsules
|
|
463
|
+
- ✅ `PgSqlTriggers::SQL::Executor.execute` method for safe execution
|
|
464
|
+
- ✅ Web UI controller (`SqlCapsulesController`) with create, show, and execute actions
|
|
465
|
+
- ✅ Permission checks (Admin role required)
|
|
466
|
+
- ✅ Kill switch protection
|
|
467
|
+
- ✅ Transactional execution
|
|
468
|
+
- ✅ Checksum calculation and storage
|
|
469
|
+
- ✅ Registry update with `source = manual_sql`
|
|
470
|
+
- ✅ Comprehensive audit logging
|
|
471
|
+
- ✅ Console API: `PgSqlTriggers::SQL::Executor.execute(capsule, actor:, confirmation:)`
|
|
472
|
+
|
|
473
|
+
**From Section 5 (Permissions Model):**
|
|
474
|
+
- ✅ Permission structure (Viewer, Operator, Admin roles)
|
|
475
|
+
- ✅ Permission enforcement in UI (controllers and views)
|
|
476
|
+
- ✅ Permission enforcement in Console APIs (all Registry methods)
|
|
477
|
+
- ✅ Permission enforcement in SQL Executor
|
|
478
|
+
- ✅ `PermissionsHelper` module for view-level permission checks
|
|
479
|
+
- ✅ Permission helper methods in `ApplicationController`
|
|
480
|
+
- ✅ Configurable `permission_checker` via configuration
|
|
481
|
+
- ✅ `PermissionError` exception class
|
|
482
|
+
- ✅ Comprehensive test coverage
|
|
483
|
+
|
|
434
484
|
**From Section 8 (UI):**
|
|
435
|
-
- ✅ Dashboard with: Trigger name, Table, Version, Status (enabled/disabled), Source, Environment
|
|
436
|
-
-
|
|
485
|
+
- ✅ Dashboard with: Trigger name, Table, Version, Status (enabled/disabled), Source, Environment, Drift state, Last Applied
|
|
486
|
+
- ✅ Dashboard displays drift count (fully working with drift detection)
|
|
437
487
|
- ✅ Tables view with table listing and trigger details
|
|
438
|
-
- ✅
|
|
488
|
+
- ✅ Trigger detail page (dedicated route/page with comprehensive metadata, SQL diff, registry state)
|
|
439
489
|
- ✅ Generator UI (form-based wizard for creating triggers)
|
|
440
490
|
- ✅ Migration management UI (up/down/redo with kill switch protection)
|
|
441
|
-
-
|
|
491
|
+
- ✅ All action buttons (enable/disable/drop/re-execute/execute SQL capsule)
|
|
492
|
+
- ✅ Permission-aware button visibility
|
|
493
|
+
- ✅ Environment-aware button styling
|
|
494
|
+
- ✅ Breadcrumb navigation
|
|
495
|
+
- ✅ Enhanced timestamp display
|
|
496
|
+
|
|
497
|
+
**From Section 9 (Drop & Re-Execute Flow):**
|
|
498
|
+
- ✅ `TriggerRegistry#drop!` method with permission checks, kill switch, reason, confirmation
|
|
499
|
+
- ✅ `TriggerRegistry#re_execute!` method with drift diff, reason, confirmation
|
|
500
|
+
- ✅ UI buttons for drop and re-execute in dashboard, table view, and trigger detail page
|
|
501
|
+
- ✅ Confirmation modals with reason input and typed confirmation
|
|
502
|
+
- ✅ Drift comparison shown before re-execution
|
|
503
|
+
- ✅ Transactional execution
|
|
504
|
+
- ✅ Registry updates
|
|
505
|
+
- ✅ Comprehensive audit logging
|
|
442
506
|
|
|
443
507
|
---
|
|
444
508
|
|
|
445
|
-
###
|
|
509
|
+
### ✅ HIGH PRIORITY - All Critical Features Completed
|
|
446
510
|
|
|
447
|
-
**
|
|
511
|
+
**Status:** All HIGH priority features have been fully implemented in v1.2.0 and v1.3.0.
|
|
448
512
|
|
|
449
|
-
#### 1. SQL Capsules (MANDATORY - Section 4) -
|
|
513
|
+
#### 1. SQL Capsules (MANDATORY - Section 4) - ✅ COMPLETED in v1.2.0
|
|
450
514
|
**Priority:** HIGH - Mandatory feature for emergency operations
|
|
451
515
|
|
|
452
|
-
**Status:**
|
|
516
|
+
**Status:** ✅ Fully implemented in v1.2.0
|
|
453
517
|
|
|
454
|
-
**
|
|
455
|
-
-
|
|
456
|
-
-
|
|
457
|
-
-
|
|
458
|
-
-
|
|
459
|
-
-
|
|
518
|
+
**Implementation:**
|
|
519
|
+
- ✅ `lib/pg_sql_triggers/sql/capsule.rb` - SQL capsule definition class
|
|
520
|
+
- ✅ `lib/pg_sql_triggers/sql/executor.rb` - SQL execution with transaction, checksum, registry update
|
|
521
|
+
- ✅ `app/controllers/pg_sql_triggers/sql_capsules_controller.rb` - UI controller
|
|
522
|
+
- ✅ SQL capsule views (new, show, create, execute)
|
|
523
|
+
- ✅ SQL capsule storage mechanism (registry table with `source = manual_sql`)
|
|
460
524
|
|
|
461
|
-
**
|
|
462
|
-
-
|
|
463
|
-
-
|
|
464
|
-
-
|
|
465
|
-
-
|
|
466
|
-
-
|
|
467
|
-
-
|
|
525
|
+
**Functionality:**
|
|
526
|
+
- ✅ Named SQL capsules with environment and purpose declaration
|
|
527
|
+
- ✅ Explicit application workflow with confirmation
|
|
528
|
+
- ✅ Transactional execution
|
|
529
|
+
- ✅ Checksum verification
|
|
530
|
+
- ✅ Registry update with `source = manual_sql`
|
|
531
|
+
- ✅ Kill switch protection (blocks in production)
|
|
532
|
+
- ✅ Permission checks (Admin only)
|
|
533
|
+
- ✅ Comprehensive audit logging
|
|
468
534
|
|
|
469
|
-
**Impact:**
|
|
535
|
+
**Impact:** ✅ Emergency SQL execution fully operational with safety controls.
|
|
470
536
|
|
|
471
|
-
#### 2. Drop & Re-Execute Flow (Section 9) -
|
|
537
|
+
#### 2. Drop & Re-Execute Flow (Section 9) - ✅ COMPLETED in v1.2.0, UI in v1.3.0
|
|
472
538
|
**Priority:** HIGH - Operational requirements
|
|
473
539
|
|
|
474
|
-
**Status:**
|
|
540
|
+
**Status:** ✅ Fully implemented in v1.2.0, UI added in v1.3.0
|
|
475
541
|
|
|
476
|
-
**
|
|
477
|
-
-
|
|
478
|
-
-
|
|
479
|
-
-
|
|
480
|
-
-
|
|
481
|
-
-
|
|
542
|
+
**Implementation:**
|
|
543
|
+
- ✅ Drop trigger functionality with permission checks, kill switch, reason, typed confirmation
|
|
544
|
+
- ✅ Re-execute functionality with diff display, reason, typed confirmation
|
|
545
|
+
- ✅ UI for drop/re-execute actions (buttons in dashboard, table view, trigger detail page)
|
|
546
|
+
- ✅ Confirmation modals with reason input and typed confirmation text
|
|
547
|
+
- ✅ Transactional execution and registry update
|
|
548
|
+
- ✅ Comprehensive audit logging with state changes
|
|
482
549
|
|
|
483
|
-
**Impact:**
|
|
550
|
+
**Impact:** ✅ Safe drop and re-execute workflows fully operational with UI access.
|
|
484
551
|
|
|
485
552
|
#### 3. Safe Apply & Deploy (Section 3.D) - ✅ FULLY IMPLEMENTED
|
|
486
553
|
**Priority:** MEDIUM-HIGH - Deployment safety enhancement
|
|
@@ -506,116 +573,170 @@ This gem must be described as:
|
|
|
506
573
|
|
|
507
574
|
---
|
|
508
575
|
|
|
509
|
-
###
|
|
576
|
+
### ✅ MEDIUM PRIORITY - All User-Facing Features Completed
|
|
577
|
+
|
|
578
|
+
**Status:** All MEDIUM priority features have been fully implemented in v1.3.0.
|
|
510
579
|
|
|
511
|
-
#### 4. Trigger Detail Page (Section 8 - UI)
|
|
580
|
+
#### 4. Trigger Detail Page (Section 8 - UI) - ✅ COMPLETED in v1.3.0
|
|
512
581
|
**Priority:** MEDIUM - Usability
|
|
513
582
|
|
|
514
|
-
**Status:**
|
|
583
|
+
**Status:** ✅ Fully implemented in v1.3.0
|
|
515
584
|
|
|
516
|
-
**
|
|
517
|
-
-
|
|
518
|
-
-
|
|
519
|
-
-
|
|
520
|
-
-
|
|
521
|
-
-
|
|
522
|
-
-
|
|
585
|
+
**Implementation:**
|
|
586
|
+
- ✅ Dedicated trigger detail route and controller action (`triggers#show`)
|
|
587
|
+
- ✅ Summary panel with all trigger metadata (name, table, version, status, source, environment, timestamps)
|
|
588
|
+
- ✅ SQL diff view (expected vs actual with syntax highlighting)
|
|
589
|
+
- ✅ Registry state display (comprehensive state including checksum, drift detection, manual override)
|
|
590
|
+
- ✅ Action buttons (Enable/Disable/Drop/Re-execute/Execute SQL capsule)
|
|
591
|
+
- ✅ Permission-aware, environment-aware, kill switch-aware button visibility
|
|
592
|
+
- ✅ Breadcrumb navigation
|
|
523
593
|
|
|
524
|
-
#### 5. UI Actions (Section 8)
|
|
594
|
+
#### 5. UI Actions (Section 8) - ✅ COMPLETED in v1.3.0
|
|
525
595
|
**Priority:** MEDIUM - Usability
|
|
526
596
|
|
|
527
|
-
**Status:**
|
|
597
|
+
**Status:** ✅ Fully implemented in v1.3.0
|
|
528
598
|
|
|
529
|
-
**
|
|
530
|
-
-
|
|
531
|
-
-
|
|
532
|
-
-
|
|
533
|
-
-
|
|
599
|
+
**Implementation:**
|
|
600
|
+
- ✅ Enable/Disable buttons in dashboard, tables/show, and trigger detail pages
|
|
601
|
+
- ✅ Drop button with confirmation modal (Admin permission required)
|
|
602
|
+
- ✅ Re-execute button with drift diff display (Admin permission required)
|
|
603
|
+
- ✅ Execute SQL capsule button (Admin permission required)
|
|
534
604
|
|
|
535
605
|
**What Works:**
|
|
536
606
|
- ✅ Kill switch enforcement in UI (fully implemented - see Section 6)
|
|
537
607
|
- ✅ Migration actions (up/down/redo) with kill switch protection
|
|
608
|
+
- ✅ All action buttons with permission checks
|
|
609
|
+
- ✅ AJAX-based actions to avoid full page reloads
|
|
538
610
|
|
|
539
|
-
#### 6. Permissions Enforcement (Section 5)
|
|
611
|
+
#### 6. Permissions Enforcement (Section 5) - ✅ COMPLETED in v1.3.0
|
|
540
612
|
**Priority:** MEDIUM - Security
|
|
541
613
|
|
|
542
|
-
**Status:**
|
|
614
|
+
**Status:** ✅ Fully enforced in v1.3.0
|
|
543
615
|
|
|
544
|
-
**
|
|
545
|
-
-
|
|
546
|
-
-
|
|
547
|
-
-
|
|
548
|
-
-
|
|
549
|
-
-
|
|
550
|
-
-
|
|
616
|
+
**Implementation:**
|
|
617
|
+
- ✅ Permission checking in controllers (all UI actions check permissions)
|
|
618
|
+
- ✅ Permission checking in UI (buttons show/hide based on role via `PermissionsHelper`)
|
|
619
|
+
- ✅ Permission checks in `TriggerRegistry#enable!` and `disable!` (Operator or Admin required)
|
|
620
|
+
- ✅ Permission checks in console APIs (all Registry methods check permissions)
|
|
621
|
+
- ✅ Permission checks in SQL Executor (Admin required)
|
|
622
|
+
- ✅ Actor context passing through all operations (actor tracked in audit logs)
|
|
551
623
|
|
|
552
624
|
**What Exists:**
|
|
553
625
|
- ✅ Permission structure (Viewer, Operator, Admin roles defined)
|
|
554
626
|
- ✅ Permission model classes (`PgSqlTriggers::Permissions::Checker`)
|
|
627
|
+
- ✅ Configurable `permission_checker` via configuration
|
|
628
|
+
- ✅ `PermissionError` exception class
|
|
555
629
|
|
|
556
630
|
---
|
|
557
631
|
|
|
558
632
|
### 🟢 LOW PRIORITY - Polish & Improvements
|
|
559
633
|
|
|
560
|
-
#### 7. Enhanced Logging & Audit Trail
|
|
634
|
+
#### 7. Enhanced Logging & Audit Trail - ✅ COMPLETED in v1.3.0
|
|
561
635
|
**Priority:** LOW - Operational polish
|
|
562
636
|
|
|
563
|
-
**Status:**
|
|
637
|
+
**Status:** ✅ Fully implemented in v1.3.0
|
|
564
638
|
|
|
565
|
-
**
|
|
639
|
+
**Implementation:**
|
|
566
640
|
- ✅ Kill switch activation attempts logging (fully implemented)
|
|
567
641
|
- ✅ Kill switch overrides logging (fully implemented)
|
|
568
|
-
-
|
|
569
|
-
|
|
570
|
-
|
|
642
|
+
- ✅ Comprehensive audit trail table (`pg_sql_triggers_audit_log`) for all operations
|
|
643
|
+
- ✅ Audit logging for enable/disable/drop/re-execute/SQL capsule execution
|
|
644
|
+
- ✅ Complete state capture (before/after) for all operations
|
|
645
|
+
- ✅ Actor tracking for all operations
|
|
646
|
+
- ✅ Error message logging for failed operations
|
|
647
|
+
- ✅ Audit log UI with filtering, sorting, pagination, and CSV export
|
|
648
|
+
- ✅ Console API: `PgSqlTriggers::AuditLog.for_trigger(name)`
|
|
649
|
+
|
|
650
|
+
#### 8. Error Handling Consistency - ✅ COMPLETED in v1.3.0
|
|
571
651
|
**Priority:** LOW - Code quality
|
|
572
652
|
|
|
573
|
-
**Status:**
|
|
653
|
+
**Status:** ✅ Fully implemented in v1.3.0
|
|
574
654
|
|
|
575
|
-
**
|
|
655
|
+
**Implementation:**
|
|
656
|
+
- ✅ Comprehensive error hierarchy with base `Error` class and specialized error types
|
|
657
|
+
- ✅ Error classes: `PermissionError`, `KillSwitchError`, `DriftError`, `ValidationError`, `ExecutionError`, `UnsafeMigrationError`, `NotFoundError`
|
|
658
|
+
- ✅ Error codes for programmatic handling (e.g., `PERMISSION_DENIED`, `KILL_SWITCH_ACTIVE`, `DRIFT_DETECTED`)
|
|
659
|
+
- ✅ Standardized error messages with recovery suggestions
|
|
660
|
+
- ✅ Enhanced error display in UI with user-friendly formatting
|
|
661
|
+
- ✅ Context information included in all errors for better debugging
|
|
662
|
+
- ✅ Error handling helpers in `ApplicationController` for consistent error formatting
|
|
576
663
|
- ✅ Kill switch violations raise `KillSwitchError` (fully implemented)
|
|
577
|
-
-
|
|
664
|
+
- ✅ Permission violations raise `PermissionError` (fully implemented)
|
|
578
665
|
- ✅ Drift detection implemented (can be used for error handling)
|
|
579
|
-
-
|
|
666
|
+
- ✅ Consistent error handling across all operations
|
|
580
667
|
|
|
581
|
-
#### 9. Testing Coverage
|
|
668
|
+
#### 9. Testing Coverage - ✅ COMPREHENSIVE
|
|
582
669
|
**Priority:** LOW - Quality assurance
|
|
583
670
|
|
|
584
|
-
**Status:**
|
|
671
|
+
**Status:** ✅ Comprehensive test coverage achieved (93.45% in v1.3.0)
|
|
585
672
|
|
|
586
|
-
**
|
|
587
|
-
-
|
|
673
|
+
**Implementation:**
|
|
674
|
+
- ✅ SQL capsules have comprehensive tests
|
|
588
675
|
- ✅ Kill switch has comprehensive tests (fully tested)
|
|
589
676
|
- ✅ Drift detection has comprehensive tests (fully tested)
|
|
590
|
-
-
|
|
591
|
-
-
|
|
677
|
+
- ✅ Permission enforcement has comprehensive tests
|
|
678
|
+
- ✅ Drop/re-execute flow has comprehensive tests
|
|
679
|
+
- ✅ UI controller tests (triggers, dashboard, SQL capsules, audit logs)
|
|
680
|
+
- ✅ Integration tests (full workflows)
|
|
681
|
+
- ✅ Error handling tests
|
|
592
682
|
|
|
593
|
-
#### 10. Documentation Updates
|
|
683
|
+
#### 10. Documentation Updates - ✅ COMPLETED in v1.3.0
|
|
594
684
|
**Priority:** LOW - User experience
|
|
595
685
|
|
|
596
|
-
**Status:**
|
|
686
|
+
**Status:** ✅ Comprehensive documentation completed in v1.3.0
|
|
597
687
|
|
|
598
|
-
**
|
|
599
|
-
-
|
|
688
|
+
**Implementation:**
|
|
689
|
+
- ✅ README updated with all v1.3.0 features
|
|
690
|
+
- ✅ README includes SQL capsules documentation with examples
|
|
600
691
|
- ✅ README includes kill switch documentation with enforcement details (fully documented)
|
|
601
|
-
-
|
|
602
|
-
-
|
|
603
|
-
- ✅ Drift detection fully documented
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
-
|
|
692
|
+
- ✅ Examples provided for SQL capsules
|
|
693
|
+
- ✅ Examples provided for permission configuration
|
|
694
|
+
- ✅ Drift detection fully documented
|
|
695
|
+
- ✅ New comprehensive guides:
|
|
696
|
+
- `docs/ui-guide.md` - Using the web UI
|
|
697
|
+
- `docs/permissions.md` - Configuring permissions
|
|
698
|
+
- `docs/audit-trail.md` - Viewing audit logs
|
|
699
|
+
- `docs/troubleshooting.md` - Common issues and solutions
|
|
700
|
+
- ✅ API reference updated with all new methods
|
|
701
|
+
|
|
702
|
+
#### 11. Implementation Status Summary
|
|
703
|
+
**Priority:** LOW - Status tracking
|
|
704
|
+
|
|
705
|
+
**All Features Completed:**
|
|
706
|
+
- ✅ **Permissions Model** - Fully enforced in UI/CLI/console (v1.3.0)
|
|
610
707
|
- ✅ **Kill Switch** - Fully implemented (see Section 6 for details)
|
|
611
708
|
- ✅ **Checksum** - Fully implemented with consistent field-concatenation algorithm across all creation paths
|
|
612
709
|
- ✅ **Drift Detection** - Fully implemented with all 6 drift states, comprehensive tests, and console APIs
|
|
613
|
-
-
|
|
614
|
-
-
|
|
615
|
-
-
|
|
710
|
+
- ✅ **Dashboard** - `installed_at` displayed with formatting in UI (v1.3.0)
|
|
711
|
+
- ✅ **Trigger Detail Page** - Dedicated route/page fully implemented (v1.3.0)
|
|
712
|
+
- ✅ **Enable/Disable UI** - UI buttons implemented with permission checks (v1.3.0)
|
|
713
|
+
- ✅ **SQL Capsules** - Fully implemented (v1.2.0)
|
|
714
|
+
- ✅ **Drop & Re-Execute Flow** - Fully implemented (v1.2.0, UI in v1.3.0)
|
|
715
|
+
- ✅ **Audit Logging** - Comprehensive audit trail with UI (v1.3.0)
|
|
716
|
+
- ✅ **Error Handling** - Consistent error hierarchy and handling (v1.3.0)
|
|
616
717
|
|
|
617
718
|
---
|
|
618
719
|
|
|
619
720
|
### 📝 Technical Notes
|
|
620
721
|
|
|
621
|
-
1. **Console API Naming:**
|
|
722
|
+
1. **Console API Naming:** ✅ Standardized - All console APIs follow consistent naming:
|
|
723
|
+
- Query methods: `list`, `enabled`, `disabled`, `for_table`, `diff`, `drifted`, `in_sync`, `unknown_triggers`, `dropped`
|
|
724
|
+
- Action methods: `enable`, `disable`, `drop`, `re_execute`
|
|
725
|
+
- All methods are fully documented with YARD documentation
|
|
726
|
+
|
|
727
|
+
2. **Code Organization:** ✅ Improved - Common controller concerns extracted:
|
|
728
|
+
- `KillSwitchProtection` - Handles kill switch checking and confirmation
|
|
729
|
+
- `PermissionChecking` - Handles permission checks and actor management
|
|
730
|
+
- `ErrorHandling` - Handles error formatting and flash messages
|
|
731
|
+
- All controllers inherit from `ApplicationController` which includes these concerns
|
|
732
|
+
|
|
733
|
+
3. **Service Object Patterns:** ✅ Standardized - All service objects follow consistent patterns:
|
|
734
|
+
- `Generator::Service` - Class methods for stateless operations, fully documented
|
|
735
|
+
- `SQL::Executor` - Class methods for stateless operations, fully documented
|
|
736
|
+
- All public methods have YARD documentation
|
|
737
|
+
|
|
738
|
+
4. **YARD Documentation:** ✅ Added - Comprehensive YARD documentation for:
|
|
739
|
+
- `PgSqlTriggers::Registry` module and all public methods
|
|
740
|
+
- `PgSqlTriggers::TriggerRegistry` model and all public methods
|
|
741
|
+
- `PgSqlTriggers::Generator::Service` and all public methods
|
|
742
|
+
- `PgSqlTriggers::SQL::Executor` and all public methods
|
data/README.md
CHANGED
|
@@ -95,7 +95,18 @@ Automatically detect when database triggers drift from your DSL definitions.
|
|
|
95
95
|
Multi-layered safety mechanism preventing accidental destructive operations in production environments.
|
|
96
96
|
|
|
97
97
|
### Web Dashboard
|
|
98
|
-
Visual interface for managing triggers, running migrations, and executing SQL capsules.
|
|
98
|
+
Visual interface for managing triggers, running migrations, and executing SQL capsules. Includes:
|
|
99
|
+
- **Quick Actions**: Enable/disable, drop, and re-execute triggers from dashboard
|
|
100
|
+
- **Last Applied Tracking**: See when triggers were last applied with human-readable timestamps
|
|
101
|
+
- **Breadcrumb Navigation**: Easy navigation between dashboard, tables, and triggers
|
|
102
|
+
- **Permission-Aware UI**: Buttons show/hide based on user role
|
|
103
|
+
|
|
104
|
+
### Audit Logging
|
|
105
|
+
Comprehensive audit trail for all trigger operations:
|
|
106
|
+
- Track who performed each operation (actor tracking)
|
|
107
|
+
- Before and after state capture
|
|
108
|
+
- Success/failure logging with error messages
|
|
109
|
+
- Reason tracking for drop and re-execute operations
|
|
99
110
|
|
|
100
111
|
### SQL Capsules
|
|
101
112
|
Emergency SQL execution feature for critical operations with Admin permission requirements, kill switch protection, and comprehensive logging.
|
|
@@ -111,6 +122,19 @@ Three-tier permission system (Viewer, Operator, Admin) with customizable authori
|
|
|
111
122
|
PgSqlTriggers provides a comprehensive console API for managing triggers programmatically:
|
|
112
123
|
|
|
113
124
|
```ruby
|
|
125
|
+
# Query triggers
|
|
126
|
+
triggers = PgSqlTriggers::Registry.list
|
|
127
|
+
enabled = PgSqlTriggers::Registry.enabled
|
|
128
|
+
disabled = PgSqlTriggers::Registry.disabled
|
|
129
|
+
user_triggers = PgSqlTriggers::Registry.for_table(:users)
|
|
130
|
+
|
|
131
|
+
# Check drift status
|
|
132
|
+
drift_info = PgSqlTriggers::Registry.diff
|
|
133
|
+
drifted = PgSqlTriggers::Registry.drifted
|
|
134
|
+
in_sync = PgSqlTriggers::Registry.in_sync
|
|
135
|
+
unknown = PgSqlTriggers::Registry.unknown_triggers
|
|
136
|
+
dropped = PgSqlTriggers::Registry.dropped
|
|
137
|
+
|
|
114
138
|
# Enable/disable triggers
|
|
115
139
|
PgSqlTriggers::Registry.enable("users_email_validation", actor: current_user, confirmation: "EXECUTE TRIGGER_ENABLE")
|
|
116
140
|
PgSqlTriggers::Registry.disable("users_email_validation", actor: current_user, confirmation: "EXECUTE TRIGGER_DISABLE")
|
|
@@ -129,6 +153,8 @@ capsule = PgSqlTriggers::SQL::Capsule.new(
|
|
|
129
153
|
PgSqlTriggers::SQL::Executor.execute(capsule, actor: current_user, confirmation: "EXECUTE SQL")
|
|
130
154
|
```
|
|
131
155
|
|
|
156
|
+
See the [API Reference](docs/api-reference.md) for complete documentation of all console APIs.
|
|
157
|
+
|
|
132
158
|
## Examples
|
|
133
159
|
|
|
134
160
|
For working examples and complete demonstrations, check out the [example repository](https://github.com/samaswin/pg_triggers_example).
|