From 21d7692c9432fa65cfcbd6a9e11bdfba2c9a222a Mon Sep 17 00:00:00 2001 From: weichen Date: Tue, 15 Sep 2026 09:59:54 +0000 Subject: [PATCH] feat(db): record unique projection outcomes per envelope version Co-authored-by: Cursor --- .../00043_2026-09-15-projection-outcome.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 deploy/postgres/goose/00043_2026-09-15-projection-outcome.sql diff --git a/deploy/postgres/goose/00043_2026-09-15-projection-outcome.sql b/deploy/postgres/goose/00043_2026-09-15-projection-outcome.sql new file mode 100644 index 00000000..fc6bdb42 --- /dev/null +++ b/deploy/postgres/goose/00043_2026-09-15-projection-outcome.sql @@ -0,0 +1,17 @@ +-- +goose Up +-- E1C: unique projection apply per envelope; no-replace is enforced in SQL + consumer. +CREATE TABLE IF NOT EXISTS event_projection_outcomes ( + source_event_id TEXT PRIMARY KEY, + doc_id TEXT NOT NULL, + version_no INT NOT NULL, + snapshot_id BIGINT NOT NULL DEFAULT 0, + applied BOOLEAN NOT NULL DEFAULT FALSE, + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE UNIQUE INDEX IF NOT EXISTS uq_projection_doc_version + ON event_projection_outcomes (doc_id, version_no); + +-- +goose Down +DROP INDEX IF EXISTS uq_projection_doc_version; +DROP TABLE IF EXISTS event_projection_outcomes;