Persist owner-scoped client_key on freeform_documents so upload create can retry safely without inventing local doc-upload orphans. Co-authored-by: Cursor <cursoragent@cursor.com>
19 lines
810 B
SQL
19 lines
810 B
SQL
-- +goose Up
|
|
-- 2026-09-13 freeform upload registration: formal client_key for idempotent server fact-source create
|
|
-- Schema 28 → 29
|
|
|
|
ALTER TABLE freeform_documents
|
|
ADD COLUMN IF NOT EXISTS client_key VARCHAR(128) NULL;
|
|
|
|
COMMENT ON COLUMN freeform_documents.client_key IS
|
|
'Client-supplied idempotency key for direct create (e.g. upload batch id); NULL for message-derived docs';
|
|
|
|
-- Same owner cannot register the same client_key twice while the doc is alive.
|
|
CREATE UNIQUE INDEX IF NOT EXISTS uq_freeform_owner_client_key
|
|
ON freeform_documents (owner_user_id, client_key)
|
|
WHERE is_deleted = FALSE AND client_key IS NOT NULL AND length(trim(client_key)) > 0;
|
|
|
|
-- +goose Down
|
|
DROP INDEX IF EXISTS uq_freeform_owner_client_key;
|
|
ALTER TABLE freeform_documents DROP COLUMN IF EXISTS client_key;
|