code.vegaprotocol.io/vega@v0.79.0/datanode/sqlstore/migrations/0121_add_pap_to_market_data.sql (about) 1 -- +goose Up 2 alter table market_data add column if not exists active_protocol_automated_purchase JSONB; 3 alter table current_market_data add column if not exists active_protocol_automated_purchase JSONB; 4 5 -- +goose StatementBegin 6 CREATE OR REPLACE FUNCTION update_current_market_data() 7 RETURNS TRIGGER 8 LANGUAGE PLPGSQL AS 9 $$ 10 BEGIN 11 INSERT INTO current_market_data(synthetic_time,tx_hash,vega_time,seq_num,market,mark_price,mark_price_type,best_bid_price,best_bid_volume, 12 best_offer_price,best_offer_volume,best_static_bid_price,best_static_bid_volume, 13 best_static_offer_price,best_static_offer_volume,mid_price,static_mid_price,open_interest, 14 auction_end,auction_start,indicative_price,indicative_volume,market_trading_mode, 15 auction_trigger,extension_trigger,target_stake,supplied_stake,price_monitoring_bounds, 16 market_value_proxy,liquidity_provider_fee_shares,market_state,next_mark_to_market, market_growth, last_traded_price, product_data, liquidity_provider_sla, next_network_closeout, mark_price_state, active_protocol_automated_purchase) 17 VALUES(NEW.synthetic_time, NEW.tx_hash, NEW.vega_time, NEW.seq_num, NEW.market, 18 NEW.mark_price, NEW.mark_price_type, NEW.best_bid_price, NEW.best_bid_volume, NEW.best_offer_price, 19 NEW.best_offer_volume, NEW.best_static_bid_price, NEW.best_static_bid_volume, 20 NEW.best_static_offer_price, NEW.best_static_offer_volume, NEW.mid_price, 21 NEW.static_mid_price, NEW.open_interest, NEW.auction_end, NEW.auction_start, 22 NEW.indicative_price, NEW.indicative_volume, NEW.market_trading_mode, 23 NEW.auction_trigger, NEW.extension_trigger, NEW.target_stake, NEW.supplied_stake, 24 NEW.price_monitoring_bounds, NEW.market_value_proxy, 25 NEW.liquidity_provider_fee_shares, NEW.market_state, NEW.next_mark_to_market, NEW.market_growth, NEW.last_traded_price, NEW.product_data, NEW.liquidity_provider_sla, NEW.next_network_closeout, NEW.mark_price_state, NEW.active_protocol_automated_purchase) 26 ON CONFLICT(market) DO UPDATE SET 27 synthetic_time=EXCLUDED.synthetic_time,tx_hash=EXCLUDED.tx_hash,vega_time=EXCLUDED.vega_time,seq_num=EXCLUDED.seq_num,market=EXCLUDED.market,mark_price=EXCLUDED.mark_price, 28 mark_price_type=EXCLUDED.mark_price_type, 29 best_bid_price=EXCLUDED.best_bid_price,best_bid_volume=EXCLUDED.best_bid_volume,best_offer_price=EXCLUDED.best_offer_price,best_offer_volume=EXCLUDED.best_offer_volume, 30 best_static_bid_price=EXCLUDED.best_static_bid_price,best_static_bid_volume=EXCLUDED.best_static_bid_volume,best_static_offer_price=EXCLUDED.best_static_offer_price, 31 best_static_offer_volume=EXCLUDED.best_static_offer_volume,mid_price=EXCLUDED.mid_price,static_mid_price=EXCLUDED.static_mid_price,open_interest=EXCLUDED.open_interest, 32 auction_end=EXCLUDED.auction_end,auction_start=EXCLUDED.auction_start,indicative_price=EXCLUDED.indicative_price,indicative_volume=EXCLUDED.indicative_volume, 33 market_trading_mode=EXCLUDED.market_trading_mode,auction_trigger=EXCLUDED.auction_trigger,extension_trigger=EXCLUDED.extension_trigger,target_stake=EXCLUDED.target_stake, 34 supplied_stake=EXCLUDED.supplied_stake,price_monitoring_bounds=EXCLUDED.price_monitoring_bounds, 35 market_value_proxy=EXCLUDED.market_value_proxy,liquidity_provider_fee_shares=EXCLUDED.liquidity_provider_fee_shares,market_state=EXCLUDED.market_state, 36 next_mark_to_market=EXCLUDED.next_mark_to_market,market_growth=EXCLUDED.market_growth,last_traded_price=EXCLUDED.last_traded_price, 37 product_data=EXCLUDED.product_data,liquidity_provider_sla=EXCLUDED.liquidity_provider_sla,next_network_closeout=EXCLUDED.next_network_closeout, 38 mark_price_state=EXCLUDED.mark_price_state, active_protocol_automated_purchase=EXCLUDED.active_protocol_automated_purchase; 39 40 RETURN NULL; 41 END; 42 $$; 43 -- +goose StatementEnd 44 45 -- +goose Down 46 alter table current_market_data drop column if exists active_protocol_automated_purchase; 47 alter table market_data drop column if exists active_protocol_automated_purchase; 48 49 -- +goose StatementBegin 50 CREATE OR REPLACE FUNCTION update_current_market_data() 51 RETURNS TRIGGER 52 LANGUAGE PLPGSQL AS 53 $$ 54 BEGIN 55 INSERT INTO current_market_data(synthetic_time,tx_hash,vega_time,seq_num,market,mark_price,mark_price_type,best_bid_price,best_bid_volume, 56 best_offer_price,best_offer_volume,best_static_bid_price,best_static_bid_volume, 57 best_static_offer_price,best_static_offer_volume,mid_price,static_mid_price,open_interest, 58 auction_end,auction_start,indicative_price,indicative_volume,market_trading_mode, 59 auction_trigger,extension_trigger,target_stake,supplied_stake,price_monitoring_bounds, 60 market_value_proxy,liquidity_provider_fee_shares,market_state,next_mark_to_market, market_growth, last_traded_price, product_data, liquidity_provider_sla, next_network_closeout, mark_price_state) 61 VALUES(NEW.synthetic_time, NEW.tx_hash, NEW.vega_time, NEW.seq_num, NEW.market, 62 NEW.mark_price, NEW.mark_price_type, NEW.best_bid_price, NEW.best_bid_volume, NEW.best_offer_price, 63 NEW.best_offer_volume, NEW.best_static_bid_price, NEW.best_static_bid_volume, 64 NEW.best_static_offer_price, NEW.best_static_offer_volume, NEW.mid_price, 65 NEW.static_mid_price, NEW.open_interest, NEW.auction_end, NEW.auction_start, 66 NEW.indicative_price, NEW.indicative_volume, NEW.market_trading_mode, 67 NEW.auction_trigger, NEW.extension_trigger, NEW.target_stake, NEW.supplied_stake, 68 NEW.price_monitoring_bounds, NEW.market_value_proxy, 69 NEW.liquidity_provider_fee_shares, NEW.market_state, NEW.next_mark_to_market, NEW.market_growth, NEW.last_traded_price, NEW.product_data, NEW.liquidity_provider_sla, NEW.next_network_closeout, NEW.mark_price_state) 70 ON CONFLICT(market) DO UPDATE SET 71 synthetic_time=EXCLUDED.synthetic_time,tx_hash=EXCLUDED.tx_hash,vega_time=EXCLUDED.vega_time,seq_num=EXCLUDED.seq_num,market=EXCLUDED.market,mark_price=EXCLUDED.mark_price, 72 mark_price_type=EXCLUDED.mark_price_type, 73 best_bid_price=EXCLUDED.best_bid_price,best_bid_volume=EXCLUDED.best_bid_volume,best_offer_price=EXCLUDED.best_offer_price,best_offer_volume=EXCLUDED.best_offer_volume, 74 best_static_bid_price=EXCLUDED.best_static_bid_price,best_static_bid_volume=EXCLUDED.best_static_bid_volume,best_static_offer_price=EXCLUDED.best_static_offer_price, 75 best_static_offer_volume=EXCLUDED.best_static_offer_volume,mid_price=EXCLUDED.mid_price,static_mid_price=EXCLUDED.static_mid_price,open_interest=EXCLUDED.open_interest, 76 auction_end=EXCLUDED.auction_end,auction_start=EXCLUDED.auction_start,indicative_price=EXCLUDED.indicative_price,indicative_volume=EXCLUDED.indicative_volume, 77 market_trading_mode=EXCLUDED.market_trading_mode,auction_trigger=EXCLUDED.auction_trigger,extension_trigger=EXCLUDED.extension_trigger,target_stake=EXCLUDED.target_stake, 78 supplied_stake=EXCLUDED.supplied_stake,price_monitoring_bounds=EXCLUDED.price_monitoring_bounds, 79 market_value_proxy=EXCLUDED.market_value_proxy,liquidity_provider_fee_shares=EXCLUDED.liquidity_provider_fee_shares,market_state=EXCLUDED.market_state, 80 next_mark_to_market=EXCLUDED.next_mark_to_market,market_growth=EXCLUDED.market_growth,last_traded_price=EXCLUDED.last_traded_price, 81 product_data=EXCLUDED.product_data,liquidity_provider_sla=EXCLUDED.liquidity_provider_sla,next_network_closeout=EXCLUDED.next_network_closeout, 82 mark_price_state=EXCLUDED.mark_price_state; 83 RETURN NULL; 84 END; 85 $$; 86 -- +goose StatementEnd