From 72d4d6d205a2e2add7a7bc631d6d9da1416ab227 Mon Sep 17 00:00:00 2001 From: Michael Gaffney Date: Wed, 1 Dec 2021 11:05:19 -0500 Subject: [PATCH] fix(sql): Remove warning from create_time trigger (#1751) Raising a warning in the default trigger used for setting the value in create_time columns creates unnecessary noise in the PostgreSQL log files. Closes #1744 --- .../oss/postgres/0/01_domain_types.up.sql | 1 + .../oss/postgres/21/01_default_time.up.sql | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 internal/db/schema/migrations/oss/postgres/21/01_default_time.up.sql diff --git a/internal/db/schema/migrations/oss/postgres/0/01_domain_types.up.sql b/internal/db/schema/migrations/oss/postgres/0/01_domain_types.up.sql index c7a4a66d1a..098e2d5ba5 100644 --- a/internal/db/schema/migrations/oss/postgres/0/01_domain_types.up.sql +++ b/internal/db/schema/migrations/oss/postgres/0/01_domain_types.up.sql @@ -63,6 +63,7 @@ comment on function is 'function used in before update triggers to properly set update_time columns'; +-- Replaced in 21/01_default_time.up.sql create or replace function default_create_time() returns trigger diff --git a/internal/db/schema/migrations/oss/postgres/21/01_default_time.up.sql b/internal/db/schema/migrations/oss/postgres/21/01_default_time.up.sql new file mode 100644 index 0000000000..c10817f27f --- /dev/null +++ b/internal/db/schema/migrations/oss/postgres/21/01_default_time.up.sql @@ -0,0 +1,15 @@ +begin; + +-- Replaces function from 0/01_domain_types.up.sql +create or replace function default_create_time() + returns trigger +as $$ +begin + if new.create_time is distinct from now() then + new.create_time = now(); + end if; + return new; +end; +$$ language plpgsql; + +commit;