The human ledger and the document body are different stores. Record the projection intent in the same transaction as the ledger, and clear it only when the body write succeeds so a retry cannot append a second revision. Co-authored-by: Cursor <cursoragent@cursor.com>
23 lines
920 B
SQL
23 lines
920 B
SQL
-- +goose Up
|
|
-- 人工修订账本与正文投影不是同一个存储。投影意图与账本同一事务写入,
|
|
-- 投影成功后才标 projected。进程在两次写之间退出时,未投影行仍可重放。
|
|
|
|
CREATE TABLE IF NOT EXISTS document_content_projections (
|
|
doc_id TEXT NOT NULL,
|
|
snapshot_id BIGINT NOT NULL,
|
|
revision_no INT NOT NULL,
|
|
idempotency_key TEXT NOT NULL DEFAULT '',
|
|
status TEXT NOT NULL DEFAULT 'pending',
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
projected_at TIMESTAMPTZ,
|
|
PRIMARY KEY (doc_id, snapshot_id),
|
|
CONSTRAINT chk_doc_content_projection_status CHECK (status IN ('pending', 'projected'))
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_doc_content_projection_pending
|
|
ON document_content_projections (created_at)
|
|
WHERE status = 'pending';
|
|
|
|
-- +goose Down
|
|
DROP TABLE IF EXISTS document_content_projections;
|