historic-view #92

Merged
hsh-michaelhoennig merged 19 commits from historic-view into master 2024-08-29 17:00:20 +02:00
Showing only changes of commit 6f740c7209 - Show all commits

View File

@ -23,9 +23,6 @@ do $$
*/ */
create table tx_context create table tx_context
( (
-- FIXME: what whas the purpose of such a hash(task+txid)?
-- contextId bigint primary key not null,
-- txId bigint not null,
txId xid8 primary key not null, txId xid8 primary key not null,
txTimestamp timestamp not null, txTimestamp timestamp not null,
currentUser varchar(63) not null, -- not the uuid, because users can be deleted currentUser varchar(63) not null, -- not the uuid, because users can be deleted
@ -45,8 +42,7 @@ create index on tx_context using brin (txTimestamp);
*/ */
create table tx_journal create table tx_journal
( (
-- contextId bigint not null references tx_context (contextId), -- FIXME: this ... txId xid8 not null references tx_context (txId),
txId xid8 not null references tx_context (txId), -- FIXME: ... or that?
targetTable text not null, targetTable text not null,
targetUuid uuid not null, -- Assumes that all audited tables have a uuid column. targetUuid uuid not null, -- Assumes that all audited tables have a uuid column.
targetOp operation not null, targetOp operation not null,
@ -65,7 +61,7 @@ create index on tx_journal (targetTable, targetUuid);
create view tx_journal_v as create view tx_journal_v as
select txc.*, txj.targettable, txj.targetop, txj.targetuuid, txj.targetdelta select txc.*, txj.targettable, txj.targetop, txj.targetuuid, txj.targetdelta
from tx_journal txj from tx_journal txj
left join tx_context txc using (txId) -- FIXME: or contextId? left join tx_context txc using (txId)
order by txc.txtimestamp; order by txc.txtimestamp;
--// --//
@ -80,18 +76,12 @@ create or replace function tx_journal_trigger()
language plpgsql as $$ language plpgsql as $$
declare declare
curTask text; curTask text;
-- curContextId bigint; FIXME: needed?
curTxId xid8; curTxId xid8;
begin begin
curTask := currentTask(); curTask := currentTask();
-- curContextId := pg_current_xact_id()+bigIntHash(curTask); FIXME: needed?
curTxId := pg_current_xact_id(); curTxId := pg_current_xact_id();
insert insert
-- FIXME
-- into tx_context (contextId, txId, txTimestamp, currentUser, assumedRoles, currentTask, currentRequest)
-- values (curContextId, pg_current_xact_id(), now(),
-- currentUser(), assumedRoles(), curTask, currentRequest())
into tx_context (txId, txTimestamp, currentUser, assumedRoles, currentTask, currentRequest) into tx_context (txId, txTimestamp, currentUser, assumedRoles, currentTask, currentRequest)
values ( curTxId, now(), values ( curTxId, now(),
currentUser(), assumedRoles(), curTask, currentRequest()) currentUser(), assumedRoles(), curTask, currentRequest())
@ -100,17 +90,17 @@ begin
case tg_op case tg_op
when 'INSERT' then insert when 'INSERT' then insert
into tx_journal into tx_journal
values (curTxId, -- FIXME: curContextId? values (curTxId,
tg_table_name, new.uuid, tg_op::operation, tg_table_name, new.uuid, tg_op::operation,
to_jsonb(new)); to_jsonb(new));
when 'UPDATE' then insert when 'UPDATE' then insert
into tx_journal into tx_journal
values (curTxId, -- FIXME: curContextId? values (curTxId,
tg_table_name, old.uuid, tg_op::operation, tg_table_name, old.uuid, tg_op::operation,
jsonb_changes_delta(to_jsonb(old), to_jsonb(new))); jsonb_changes_delta(to_jsonb(old), to_jsonb(new)));
when 'DELETE' then insert when 'DELETE' then insert
into tx_journal into tx_journal
values (curTxId, -- FIXME: curContextId? values (curTxId,
tg_table_name, old.uuid, 'DELETE'::operation, tg_table_name, old.uuid, 'DELETE'::operation,
null::jsonb); null::jsonb);
else raise exception 'Trigger op % not supported for %.', tg_op, tg_table_name; else raise exception 'Trigger op % not supported for %.', tg_op, tg_table_name;