Skip to content

feat(db): add audit columns (created/updated by) - #1817

Merged
github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
faith3310:fix/issue-1801-audit-columns
Oct 17, 2026
Merged

github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
faith3310:fix/issue-1801-audit-columns

Conversation

@faith3310

Copy link
Copy Markdown
Contributor

Summary

Resolves #1801

Add created_by and updated_by TEXT columns to 7 core entity tables with indexes for creator lookups, an auto-updating trigger for updated_at, and an AuditContext utility for populating the columns from request context.

Changes

  • Create db/migrations/012_audit_columns_created_updated_by.sql: adds created_by/updated_by to 7 core tables, creates set_updated_at() trigger function and BEFORE UPDATE triggers, includes -- @down rollback
  • Create backend/shared/db/auditColumns.ts: AuditContext class (fromRequest, system, anonymous) and withAuditColumns builder for INSERT/UPDATE statements
  • Create backend/shared/db/__tests__/auditColumns.test.ts: 12 test cases

Acceptance Criteria

  • Columns added — created_by/updated_by on 7 core tables
  • Populated — AuditContext + withAuditColumns builders, triggers
  • Tested — 12 test cases

Add created_by and updated_by TEXT columns to 7 core entity tables with
indexes for creator lookups, an auto-updating trigger for updated_at, and
an AuditContext utility for populating the columns from request context.

Changes:
- Create db/migrations/012_audit_columns_created_updated_by.sql: adds
  created_by/updated_by to subscriptions, transactions, users, merchants,
  loyalty, payment_methods, plans. Creates set_updated_at() trigger function
  and BEFORE UPDATE triggers on all tables. Includes -- @down rollback.
- Create backend/shared/db/auditColumns.ts: AuditContext class (fromRequest,
  system, anonymous) and withAuditColumns builder for INSERT/UPDATE
  statements that include audit attribution.
- Create backend/shared/db/__tests__/auditColumns.test.ts: 12 test cases

Acceptance criteria:
- [x] Columns added — created_by/updated_by on 7 core tables
- [x] Populated — AuditContext + withAuditColumns builders, triggers
- [x] Tested — 12 test cases covering context creation and SQL building
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@faith3310 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@github-actions
github-actions Bot merged commit 7dcba8d into Smartdevs17:main Oct 17, 2026
13 of 30 checks passed
@faith3310
faith3310 deployed to security-review October 17, 2026 11:04 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
security-review — fa5ff718 Deployed Oct 17, 2026 by faith3310 via Security Dashboard #1367
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add audit columns (created/updated by)

2 participants