Some checks failed
CI / Frontend Lint (push) Failing after 6s
CI / Frontend Type Check (push) Failing after 6s
CI / Frontend Build (push) Failing after 6s
CI / Frontend E2E Tests (push) Failing after 8s
CI / Contracts Compile (push) Has been cancelled
CI / Contracts Test (push) Has been cancelled
CI / Orchestrator Build (push) Has been cancelled
Security Scan / OWASP ZAP Scan (push) Has been cancelled
Security Scan / Dependency Vulnerability Scan (push) Has been cancelled
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { query } from "../postgres";
|
|
import { TRANSACTION_STATES } from "../../types/transactionState";
|
|
|
|
/**
|
|
* Migration 002 — workflow-level transaction state.
|
|
*
|
|
* Architecture note §8 (12-state machine) + §9 (transition table).
|
|
*
|
|
* Adds:
|
|
* - plans.transaction_state column (CHECK-constrained)
|
|
* - transaction_state_transitions append-only table
|
|
*/
|
|
export async function up() {
|
|
const states = TRANSACTION_STATES.map((s) => `'${s}'`).join(",");
|
|
|
|
await query(
|
|
`ALTER TABLE plans
|
|
ADD COLUMN IF NOT EXISTS transaction_state VARCHAR(32) NOT NULL
|
|
DEFAULT 'DRAFT'
|
|
CHECK (transaction_state IN (${states}))`,
|
|
);
|
|
|
|
await query(
|
|
`CREATE TABLE IF NOT EXISTS transaction_state_transitions (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
plan_id UUID NOT NULL REFERENCES plans(plan_id) ON DELETE CASCADE,
|
|
from_state VARCHAR(32),
|
|
to_state VARCHAR(32) NOT NULL CHECK (to_state IN (${states})),
|
|
reason TEXT,
|
|
source_event_id UUID,
|
|
actor VARCHAR(255) NOT NULL,
|
|
actor_role VARCHAR(32) NOT NULL,
|
|
signature TEXT,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
)`,
|
|
);
|
|
|
|
await query(
|
|
`CREATE INDEX IF NOT EXISTS idx_tx_transitions_plan_id
|
|
ON transaction_state_transitions(plan_id)`,
|
|
);
|
|
await query(
|
|
`CREATE INDEX IF NOT EXISTS idx_tx_transitions_created_at
|
|
ON transaction_state_transitions(created_at)`,
|
|
);
|
|
|
|
console.log("Migration 002 applied: transaction_state + transitions table");
|
|
}
|