CREATE TABLE "orchestration_session_state" (
"orchestration_session_state_id" VARCHAR PRIMARY KEY NOT NULL,
"session_id" VARCHAR NOT NULL,
"session_entry_id" VARCHAR,
"from_state" TEXT NOT NULL,
"to_state" TEXT NOT NULL,
"transition_result" TEXT CHECK(json_valid(transition_result) OR transition_result IS NULL),
"transition_reason" TEXT,
"transitioned_at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
"elaboration" TEXT CHECK(json_valid(elaboration) OR elaboration IS NULL),
FOREIGN KEY("session_id") REFERENCES "orchestration_session"("orchestration_session_id"),
FOREIGN KEY("session_entry_id") REFERENCES "orchestration_session_entry"("orchestration_session_entry_id"),
UNIQUE("orchestration_session_state_id", "from_state", "to_state")
)