-- ==============================================================
-- GNUmed database schema change script
--
-- License: GPL v2 or later
-- Author: karsten.hilbert@gmx.net
-- 
-- ==============================================================
-- force terminate + exit(3) on errors if non-interactive
\set ON_ERROR_STOP 1
--set default_transaction_read_only to off;

-- --------------------------------------------------------------
alter table audit.audit_trail
	drop constraint if exists audit__audit_trail__uniq_row_version_per_table;

alter table audit.audit_trail
	add constraint audit__audit_trail__uniq_row_ver_per_table
		unique (src__tableoid, src_row__version);




alter table audit.audit_trail
	rename column orig_tableoid to src__tabloid;

alter table audit.audit_trail
	rename column orig_version to src_row__version;

alter table audit.audit_trail
	rename column orig_by to src_row__version_created_by;

alter table audit.audit_trail
	rename column orig_when to src_row__version_created_when;

alter table audit.audit_trail
	rename column audit_action to log_row__reason;

alter table audit.audit_trail
	rename column audit_by to log_row__created_by;

alter table audit.audit_trail
	rename column audit_when to log_row__created_when;

-- --------------------------------------------------------------
select gm.log_script_insertion('v23-audit-audit_trail-dynamic.sql', 'v23');
