CREATE TABLE flows ( id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(), "started" timestamptz NOT NULL DEFAULT current_timestamp, kind TEXT NOT NULL, input UUID[], ended timestamptz, "next" UUID, produced UUID[], FOREIGN KEY("next") REFERENCES flows(id) ); CREATE TABLE flow_notes ( id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(), time timestamptz NOT NULL DEFAULT current_timestamp, content TEXT NOT NULL, on_flow UUID NOT NULL, FOREIGN KEY(on_flow) REFERENCES flows(id) ); CREATE TABLE transactions ( id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(), created timestamptz NOT NULL DEFAULT current_timestamp, item TEXT NOT NULL, variant TEXT NOT NULL, price DOUBLE PRECISION, origin TEXT, "location" TEXT, note TEXT, destination TEXT, consumed_price NUMERIC(2), consumed_timestamp timestamptz );