feat(sql): Add history table for iam_user

This adds a history table for `iam_user`.
This commit is contained in:
Michael Gaffney authored and Timothy Messier committed 2023-05-31 12:18:14 +00:00
1 parent 8ae658a570
commit 463f1e36af
1 file changed
+26
@@ -37,4 +37,30 @@ begin;
select public_id, name, description, type, parent_id, primary_auth_method_id
from iam_scope;
create table iam_user_hst (
public_id wt_user_id not null,
name text null,
description text null,
scope_id wt_scope_id not null,
history_id wt_url_safe_id default wt_url_safe_id() primary key,
valid_range tstzrange not null default tstzrange(current_timestamp, null),
constraint iam_user_hst_valid_range_excl
exclude using gist (public_id with =, valid_range with &&)
);
comment on table iam_user_hst is
'iam_user_hst is a history table where each row contains the values from a row '
'in the iam_user table during the time range in the valid_range column.';
create trigger hst_on_insert after insert on iam_user
for each row execute function hst_on_insert();
create trigger hst_on_update after update on iam_user
for each row execute function hst_on_update();
create trigger hst_on_delete after delete on iam_user
for each row execute function hst_on_delete();
insert into iam_user_hst
(public_id, name, description, scope_id)
select public_id, name, description, scope_id
from iam_user;
commit;