Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions api/migrations/42-add-last-active.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ALTER TABLE ctfnote.profile
ADD COLUMN "lastactive" timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP;


/* UpdateLastActive */
CREATE FUNCTION ctfnote.update_last_active ()
RETURNS void
AS $$
BEGIN
UPDATE ctfnote.profile
SET lastactive = now()
WHERE id = ctfnote_private.user_id ();
END;
$$
LANGUAGE plpgsql VOLATILE
SECURITY DEFINER;
GRANT EXECUTE ON FUNCTION ctfnote.update_last_active () TO user_guest;

CREATE OR REPLACE FUNCTION ctfnote.me ()
RETURNS ctfnote.profile
AS $$
SELECT ctfnote.update_last_active();
SELECT
*
FROM
ctfnote.profile
WHERE
id = ctfnote_private.user_id ()
LIMIT 1;

$$
LANGUAGE SQL
STRICT STABLE;
Loading