stacker.news/prisma/migrations/20230202164411_streak_trigger/migration.sql

14 lines
414 B
PL/PgSQL

CREATE OR REPLACE FUNCTION user_streak_check() RETURNS TRIGGER AS $$
DECLARE
BEGIN
INSERT INTO pgboss.job (name, data) VALUES ('checkStreak', jsonb_build_object('id', NEW.id));
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS user_streak ON users;
CREATE TRIGGER user_streak
AFTER UPDATE ON users
FOR EACH ROW
WHEN (NEW.msats < OLD.msats)
EXECUTE PROCEDURE user_streak_check();