code.vegaprotocol.io/vega@v0.79.0/datanode/sqlstore/migrations/0026_periodic_settlement_data.sql (about) 1 -- +goose Up 2 3 ALTER TYPE proposal_error ADD VALUE IF NOT EXISTS 'PROPOSAL_ERROR_INVALID_PERPETUAL_PRODUCT'; 4 5 CREATE TABLE IF NOT EXISTS funding_period ( 6 market_id BYTEA NOT NULL, 7 funding_period_seq BIGINT NOT NULL, 8 start_time TIMESTAMP WITH TIME ZONE NOT NULL, 9 end_time TIMESTAMP WITH TIME ZONE, 10 funding_payment NUMERIC, 11 funding_rate NUMERIC, 12 external_twap NUMERIC, 13 internal_twap NUMERIC, 14 vega_time TIMESTAMP WITH TIME ZONE NOT NULL, 15 tx_hash BYTEA NOT NULL, 16 PRIMARY KEY (market_id, funding_period_seq) 17 ); 18 19 CREATE TYPE funding_period_data_point_source AS ENUM ('SOURCE_UNSPECIFIED', 'SOURCE_EXTERNAL', 'SOURCE_INTERNAL'); 20 21 CREATE TABLE IF NOT EXISTS funding_period_data_points ( 22 market_id BYTEA NOT NULL, 23 funding_period_seq BIGINT NOT NULL, 24 data_point_type funding_period_data_point_source NOT NULL, 25 price NUMERIC NOT NULL, 26 twap NUMERIC NOT NULL, 27 timestamp TIMESTAMP WITH TIME ZONE NOT NULL, 28 vega_time TIMESTAMP WITH TIME ZONE NOT NULL, 29 tx_hash BYTEA NOT NULL, 30 PRIMARY KEY (market_id, funding_period_seq, data_point_type, vega_time), 31 -- Because we really shouldn't have a funding period data point for a non-existent funding period. 32 FOREIGN KEY (market_id, funding_period_seq) REFERENCES funding_period(market_id, funding_period_seq) 33 ); 34 35 -- +goose Down 36 37 DROP TABLE IF EXISTS funding_period_data_points cascade; 38 DROP TYPE IF EXISTS funding_period_data_point_source; 39 DROP TABLE IF EXISTS funding_period cascade;