Entity History
Overview
Section titled “Overview”Entity history records a snapshot of entity values on every create, update, and delete. This gives you a full audit trail with diffs.
Enabling History
Section titled “Enabling History”Backend
Section titled “Backend”Enable history in initializeRebaseBackend:
await initializeRebaseBackend({ // ... history: true});Or with custom retention settings:
history: { maxEntries: 200, // Per entity, oldest pruned first (default: 200) ttlDays: 90 // Entries older than this are pruned (default: 90)}Per Collection
Section titled “Per Collection”Mark which collections should track history:
const ordersCollection: EntityCollection = { slug: "orders", history: true, // Enable for this collection properties: { /* ... */ }};How It Works
Section titled “How It Works”- The backend creates a
rebase.entity_historytable automatically - On every create, update, or delete, a snapshot is recorded with:
- Entity ID, collection slug, and table name
- The full entity values (before and after)
- Timestamp and user ID
- Operation type (
insert,update,delete)
- Old entries are pruned periodically (every 6 hours)
REST Endpoint
Section titled “REST Endpoint”GET /api/data/:slug/:entityId/historyReturns a list of history entries for a specific entity, ordered by most recent first:
{ "data": [ { "id": 42, "entity_id": "123", "collection_slug": "orders", "operation": "update", "values": { "status": "shipped", "total": 99.99 }, "previous_values": { "status": "pending", "total": 99.99 }, "user_id": "admin-user-id", "created_at": "2025-01-15T10:30:00Z" } ]}Retention Configuration
Section titled “Retention Configuration”| Setting | Default | Description |
|---|---|---|
maxEntries | 200 | Maximum entries per entity. Oldest are pruned. |
ttlDays | 90 | Entries older than this are deleted. |
The backend runs a global prune sweep every 6 hours.
Next Steps
Section titled “Next Steps”- Entity Callbacks — Lifecycle hooks
- Backend Overview — Full backend configuration