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';
