feat: trigger for ctime on usertitle update

This commit is contained in:
Iron_Felix 2025-11-24 09:04:40 +03:00
parent e999534b3f
commit 15a681c622

View file

@ -87,7 +87,7 @@ CREATE TABLE usertitles (
status usertitle_status_t NOT NULL,
rate int CHECK (rate > 0 AND rate <= 10),
review_id bigint REFERENCES reviews (id),
ctime timestamptz
ctime timestamptz NOT NULL DEFAULT now()
-- // TODO: series status
);
@ -169,4 +169,17 @@ EXECUTE FUNCTION update_title_rating();
CREATE TRIGGER trg_notify_new_signal
AFTER INSERT ON signals
FOR EACH ROW
EXECUTE FUNCTION notify_new_signal();
EXECUTE FUNCTION notify_new_signal();
CREATE OR REPLACE FUNCTION set_ctime()
RETURNS TRIGGER AS $$
BEGIN
NEW.ctime = now();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER set_ctime_on_update
BEFORE UPDATE ON usertitles
FOR EACH ROW
EXECUTE FUNCTION set_ctime();