forked from determined-ai/determined
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update
modified_at
by insert in user table (determined-ai#7949)
* fix: update `modified_at` by insert in user table * fix: minor changes * fix: return value properly
- Loading branch information
1 parent
2d65e82
commit e031a2f
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...atic/migrations/20230920130838_add-update-modified-at-in-user-table-by-insert.tx.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
19 changes: 19 additions & 0 deletions
19
...static/migrations/20230920130838_add-update-modified-at-in-user-table-by-insert.tx.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |