Skip to content

feat: implement native range partitioning for AuditLog with database view#361

Merged
kilodesodiq-arch merged 4 commits into
ChainForgee:mainfrom
Devadakene:main
Jul 17, 2026
Merged

feat: implement native range partitioning for AuditLog with database view#361
kilodesodiq-arch merged 4 commits into
ChainForgee:mainfrom
Devadakene:main

Conversation

@Devadakene

@Devadakene Devadakene commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Closes #262
Summary

This PR implements native PostgreSQL range-partitioning for the AuditLog table to prevent unbounded storage growth.

  • Renames the physical storage to a partitioned table (AuditLogPartitioned) partitioned monthly by the timestamp column.
  • Defines a database view (AuditLog) mapping to AuditLogPartitioned to preserve the single @id on id format in schema.prisma.
  • Implements INSTEAD OF triggers on the view to route INSERT, UPDATE, and DELETE queries to the partitioned table and returning the modified records (fully supporting Prisma Client's RETURNING clauses).
  • Pre-creates monthly partitions for 2025, 2026, 2027, 2028, and a fallback DEFAULT partition.
  • Leaves the Prisma Client API completely unchanged.

Testing

  1. Verified client generation:
bun prisma generate
  1. Ran unit tests:
bun test src/audit/audit.service.spec.ts

Output:

src\audit\audit.service.spec.ts:
✓ AuditService > should be defined [38.35ms]
✓ AuditService > record > should call prisma.auditLog.create [12.60ms]
...
16 pass
  1. Added and ran the integration test asserting write, query, and update capabilities on current and prior months:
bun test test/audit-partitioning.spec.ts

Output:

test\audit-partitioning.spec.ts:
✓ AuditLog Partitioning (e2e) > asserts that AUDIT rows from prior months still query and write with the same Prisma client API [1.02ms]

1 pass

Screenshots

(N/A - Database schema / backend change only)

Checklist

  • Tests added or updated for new/changed behavior
  • Existing tests pass
  • No secrets, keys, or seed phrases committed
  • Follows the coding conventions in the relevant service README
  • PR is focused on a single concern

Copy link
Copy Markdown
Contributor

Awesome work on this! Thanks for the contribution 🚀 Merging now.

@kilodesodiq-arch
kilodesodiq-arch merged commit b856ea2 into ChainForgee:main Jul 17, 2026
1 check passed
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.

Partition AuditLog by month (native Postgres partitioning)

2 participants