remove column tx_contextid and use txId as primary key
This commit is contained in:
parent
36c21505a3
commit
f973868bf9
@ -23,8 +23,10 @@ do $$
|
||||
*/
|
||||
create table tx_context
|
||||
(
|
||||
contextId bigint primary key not null,
|
||||
txId bigint not null,
|
||||
-- FIXME: what whas the purpose of such a hash(task+txid)?
|
||||
-- contextId bigint primary key not null,
|
||||
-- txId bigint not null,
|
||||
txId bigint primary key not null,
|
||||
txTimestamp timestamp not null,
|
||||
currentUser varchar(63) not null, -- not the uuid, because users can be deleted
|
||||
assumedRoles varchar(1023) not null, -- not the uuids, because roles can be deleted
|
||||
@ -43,7 +45,8 @@ create index on tx_context using brin (txTimestamp);
|
||||
*/
|
||||
create table tx_journal
|
||||
(
|
||||
contextId bigint not null references tx_context (contextId),
|
||||
-- contextId bigint not null references tx_context (contextId), -- FIXME: this ...
|
||||
txId bigint not null references tx_context (txId), -- FIXME: ... or that?
|
||||
targetTable text not null,
|
||||
targetUuid uuid not null, -- Assumes that all audited tables have a uuid column.
|
||||
targetOp operation not null,
|
||||
@ -62,7 +65,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 (contextid)
|
||||
left join tx_context txc using (txId) -- FIXME: or contextId?
|
||||
order by txc.txtimestamp;
|
||||
--//
|
||||
|
||||
@ -77,31 +80,37 @@ create or replace function tx_journal_trigger()
|
||||
language plpgsql as $$
|
||||
declare
|
||||
curTask text;
|
||||
curContextId bigint;
|
||||
-- curContextId bigint; FIXME: needed?
|
||||
curTxId bigint;
|
||||
begin
|
||||
curTask := currentTask();
|
||||
curContextId := txid_current()+bigIntHash(curTask);
|
||||
-- curContextId := txid_current()+bigIntHash(curTask); FIXME: needed?
|
||||
curTxId := txid_current();
|
||||
|
||||
insert
|
||||
into tx_context (contextId, txId, txTimestamp, currentUser, assumedRoles, currentTask, currentRequest)
|
||||
values (curContextId, txid_current(), now(),
|
||||
currentUser(), assumedRoles(), curTask, currentRequest())
|
||||
-- FIXME
|
||||
-- into tx_context (contextId, txId, txTimestamp, currentUser, assumedRoles, currentTask, currentRequest)
|
||||
-- values (curContextId, txid_current(), now(),
|
||||
-- currentUser(), assumedRoles(), curTask, currentRequest())
|
||||
into tx_context (txId, txTimestamp, currentUser, assumedRoles, currentTask, currentRequest)
|
||||
values ( curTxId, now(),
|
||||
currentUser(), assumedRoles(), curTask, currentRequest())
|
||||
on conflict do nothing;
|
||||
|
||||
case tg_op
|
||||
when 'INSERT' then insert
|
||||
into tx_journal
|
||||
values (curContextId,
|
||||
values (curTxId, -- FIXME: curContextId?
|
||||
tg_table_name, new.uuid, tg_op::operation,
|
||||
to_jsonb(new));
|
||||
when 'UPDATE' then insert
|
||||
into tx_journal
|
||||
values (curContextId,
|
||||
values (curTxId, -- FIXME: curContextId?
|
||||
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 (curContextId,
|
||||
values (curTxId, -- FIXME: curContextId?
|
||||
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