code.vegaprotocol.io/vega@v0.79.0/datanode/sqlstore/migrations/0021_remove_oracle_data_current_table.sql (about) 1 -- +goose Up 2 3 drop trigger if exists update_current_oracle_data on oracle_data; 4 drop function if exists update_current_oracle_data; 5 DROP TABLE IF EXISTS oracle_data_current; 6 7 -- +goose Down 8 9 10 create table if not exists oracle_data_current ( 11 signers bytea[], 12 data jsonb not null, 13 matched_spec_ids bytea[], 14 broadcast_at timestamp with time zone not null, 15 tx_hash bytea not null, 16 vega_time timestamp with time zone not null, 17 seq_num BIGINT NOT NULL, 18 PRIMARY KEY(matched_spec_ids, data) 19 ); 20 21 -- +goose StatementBegin 22 23 CREATE OR REPLACE FUNCTION update_current_oracle_data() 24 RETURNS TRIGGER 25 LANGUAGE PLPGSQL AS 26 $$ 27 BEGIN 28 INSERT INTO oracle_data_current(signers,data,matched_spec_ids,broadcast_at,tx_hash,vega_time,seq_num) 29 VALUES(NEW.signers,NEW.data,NEW.matched_spec_ids,NEW.broadcast_at,NEW.tx_hash,NEW.vega_time,NEW.seq_num) 30 ON CONFLICT(matched_spec_ids, data) DO UPDATE SET 31 signers=EXCLUDED.signers, 32 broadcast_at=EXCLUDED.broadcast_at, 33 tx_hash=EXCLUDED.tx_hash, 34 vega_time=EXCLUDED.vega_time, 35 seq_num=EXCLUDED.seq_num; 36 RETURN NULL; 37 END; 38 $$; 39 -- +goose StatementEnd 40 41 CREATE TRIGGER update_current_oracle_data AFTER INSERT ON oracle_data FOR EACH ROW EXECUTE function update_current_oracle_data();