diff --git a/internal/db/schema/migrations/oss/postgres/80/03_iam.up.sql b/internal/db/schema/migrations/oss/postgres/80/03_iam.up.sql index 6ba5d6012..4923c8e27 100644 --- a/internal/db/schema/migrations/oss/postgres/80/03_iam.up.sql +++ b/internal/db/schema/migrations/oss/postgres/80/03_iam.up.sql @@ -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;