Skip to content

Commit

Permalink
fix: update modified_at by insert in user table (determined-ai#7949)
Browse files Browse the repository at this point in the history
* fix: update `modified_at` by insert in user table

* fix: minor changes

* fix: return value properly
  • Loading branch information
keita-determined authored Sep 22, 2023
1 parent 2d65e82 commit e031a2f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE OR REPLACE FUNCTION public.set_modified_time ()
RETURNS TRIGGER
AS $$
BEGIN
IF (TG_OP = 'UPDATE') THEN
NEW.modified_at := now();
RETURN NEW;
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS autoupdate_users_modified_at on users;

CREATE TRIGGER autoupdate_users_modified_at
BEFORE INSERT ON public.users
FOR EACH ROW
EXECUTE PROCEDURE public.set_modified_time();
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE OR REPLACE FUNCTION public.set_modified_time ()
RETURNS TRIGGER
AS $$
BEGIN
IF (TG_OP = 'INSERT' OR TG_OP = 'UPDATE') THEN
NEW.modified_at := now();
RETURN NEW;
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS autoupdate_users_modified_at on users;

CREATE TRIGGER autoupdate_users_modified_at
BEFORE INSERT OR UPDATE ON public.users
FOR EACH ROW
EXECUTE PROCEDURE public.set_modified_time();

0 comments on commit e031a2f

Please sign in to comment.