beteran-api-kgon-server-ser.../migrations/202208041000_initialize/up.sql

17 lines
388 B
MySQL
Raw Normal View History

2022-08-17 17:45:00 +00:00
CREATE OR REPLACE FUNCTION update_synchronizations()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO api_kgon_synchronizations
(item, last_code, synchronized_at)
VALUES
(NEW.item, NEW.code, (extract(epoch from now()) * 1000))
ON CONFLICT (item)
DO UPDATE
SET
last_code = NEW.code,
synchronized_at = (extract(epoch from now()) * 1000);
RETURN NEW;
END;
$$ language 'plpgsql';