-
Notifications
You must be signed in to change notification settings - Fork 0
Database Schema Requirements
Ahmed edited this page Mar 16, 2026
·
2 revisions
EventLens expects a read‑only view (or table) within your PostgreSQL database.
Your view must project the following conceptual schema:
-
event_id– Globally unique ID, monotonically increasing per stream (often the PK). -
aggregate_id– String ID of the aggregate / entity. -
aggregate_type– Domain type (e.g.,ORDER,USER). -
sequence_number– Version within the aggregate’s stream (1, 2, 3, …). -
event_type– Logical event type (e.g.,ORDER_PLACED). -
payload– JSON body of the domain event. -
metadata– JSON with headers, correlation IDs, etc. ({}is fine). -
timestamp– Event creation time (timestamptzor epoch seconds). -
global_position– Total ordering across all events (often the same asevent_id).
If your existing event table has a different shape, create a view like this:
CREATE OR REPLACE VIEW eventlens_events AS
SELECT
e.id AS event_id,
e.aggregate_id::text AS aggregate_id,
e.aggregate_type AS aggregate_type,
e.version AS sequence_number,
e.event_type AS event_type,
e.json_data AS payload,
'{}'::jsonb AS metadata,
COALESCE(
(e.json_data::jsonb->>'createdDate')::timestamptz,
e.created_at,
CURRENT_TIMESTAMP
) AS timestamp,
e.id AS global_position
FROM your_event_table e;Key Rules:
- Keep it read‑only (view only, no triggers).
- Do not change your existing write model – project into this view.