diff --git a/internal/db/schema/migrations/oss/postgres/82/03_auth_token_issued.up.sql b/internal/db/schema/migrations/oss/postgres/82/03_auth_token_issued.up.sql new file mode 100644 index 0000000000..6707d34ea0 --- /dev/null +++ b/internal/db/schema/migrations/oss/postgres/82/03_auth_token_issued.up.sql @@ -0,0 +1,19 @@ +-- Copyright (c) HashiCorp, Inc. +-- SPDX-License-Identifier: BUSL-1.1 + +begin; + create function auth_token_before_issued() returns trigger + as $$ + begin + if new.status = 'token issued' then + new.approximate_last_access_time = now(); + end if; + return new; + end; + $$ language plpgsql; + + create trigger auth_token_before_inserted before insert on auth_token + for each row execute procedure auth_token_before_issued(); + create trigger auth_token_before_updated before update on auth_token + for each row execute procedure auth_token_before_issued(); +commit;