historic-view #92
@ -23,9 +23,6 @@ do $$
|
||||
*/
|
||||
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,
|
||||
txTimestamp timestamp not null,
|
||||
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
|
||||
(
|
||||
-- contextId bigint not null references tx_context (contextId), -- FIXME: this ...
|
||||
txId xid8 not null references tx_context (txId), -- FIXME: ... or that?
|
||||
txId xid8 not null references tx_context (txId),
|
||||
targetTable text not null,
|
||||
targetUuid uuid not null, -- Assumes that all audited tables have a uuid column.
|
||||
targetOp operation not null,
|
||||
@ -65,7 +61,7 @@ create index on tx_journal (targetTable, targetUuid);
|
||||
create view tx_journal_v as
|
||||
select txc.*, txj.targettable, txj.targetop, txj.targetuuid, txj.targetdelta
|
||||
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;
|
||||
--//
|
||||
|
||||
@ -80,18 +76,12 @@ create or replace function tx_journal_trigger()
|
||||
language plpgsql as $$
|
||||
declare
|
||||
curTask text;
|
||||
-- curContextId bigint; FIXME: needed?
|
||||
curTxId xid8;
|
||||
begin
|
||||
curTask := currentTask();
|
||||
-- curContextId := pg_current_xact_id()+bigIntHash(curTask); FIXME: needed?
|
||||
curTxId := pg_current_xact_id();
|
||||
|
||||
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)
|
||||
values ( curTxId, now(),
|
||||
currentUser(), assumedRoles(), curTask, currentRequest())
|
||||
@ -100,17 +90,17 @@ begin
|
||||
case tg_op
|
||||
when 'INSERT' then insert
|
||||
into tx_journal
|
||||
values (curTxId, -- FIXME: curContextId?
|
||||
values (curTxId,
|
||||
tg_table_name, new.uuid, tg_op::operation,
|
||||
to_jsonb(new));
|
||||
when 'UPDATE' then insert
|
||||
into tx_journal
|
||||
values (curTxId, -- FIXME: curContextId?
|
||||
values (curTxId,
|
||||
tg_table_name, old.uuid, tg_op::operation,
|
||||
jsonb_changes_delta(to_jsonb(old), to_jsonb(new)));
|
||||
when 'DELETE' then insert
|
||||
into tx_journal
|
||||
values (curTxId, -- FIXME: curContextId?
|
||||
values (curTxId,
|
||||
tg_table_name, old.uuid, 'DELETE'::operation,
|
||||
null::jsonb);
|
||||
else raise exception 'Trigger op % not supported for %.', tg_op, tg_table_name;
|
||||
|
Loading…
Reference in New Issue
Block a user