-- Every create/update/delete of a visa/master or sber order, for the -- order page's "Ammallar" table: who did it, whether it went through, and -- for an update only the columns that changed - original holds their -- values before, changes after. A create has no original and a delete no -- changes. Failed actions are kept too, with exception set and changes -- holding what was attempted. created_by is null when no user started it -- (the GBÜS callback finalizing a payment). CREATE TABLE IF NOT EXISTS visa_master_order_actions ( id bigserial PRIMARY KEY, order_id bigint NOT NULL, name character varying(20) NOT NULL, status character varying(20) NOT NULL, original jsonb, changes jsonb, exception text, created_by bigint, created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL, CONSTRAINT visa_master_order_actions_order_id_fkey FOREIGN KEY (order_id) REFERENCES visa_master_payment_orders(id), CONSTRAINT visa_master_order_actions_created_by_fkey FOREIGN KEY (created_by) REFERENCES users(id) ); CREATE INDEX IF NOT EXISTS visa_master_order_actions_order_id_idx ON visa_master_order_actions (order_id, id DESC);