code.vegaprotocol.io/vega@v0.79.0/datanode/sqlstore/migrations/0112_fix_pnl.sql (about) 1 -- +goose Up 2 3 WITH updated_pnl AS ( 4 SELECT DISTINCT ON (pc.party_id) pc.party_id AS pid, pc.market_id AS mid, pc.loss - ph.loss AS correct_loss, pc.loss_socialisation_amount - ph.loss_socialisation_amount AS correct_loss_soc, 5 pc.realised_pnl - ph.realised_pnl AS correct_pnl, 6 pc.pending_realised_pnl - ph.pending_realised_pnl AS correct_ppnl, 7 pc.adjustment - ph.adjustment AS correct_adj 8 FROM positions_current AS pc 9 JOIN positions AS ph 10 ON pc.party_id = ph.party_id 11 AND pc.market_id = ph.market_id 12 WHERE pc.party_id IN ('\x947a700141e3d175304ee176d0beecf9ee9f462e09330e33c386952caf21f679', '\x15a8f372e255c6fa596a0b3acd62bc3be63b65188c23d33fc350f38ef52902e3', '\xaa1ce33b0b31a2e0f0a947ba83f64fa4a7e5d977fffb82c278c3b33fb0498113', '\x6527ffdd223ef2b4695ad90d832adc5493e9b8e25ad3185e67d873767f1f275e') 13 AND ph.vega_time >= '2024-06-08 19:38:49.89053+00' 14 AND pc.market_id = '\xe63a37edae8b74599d976f5dedbf3316af82579447f7a08ae0495a021fd44d13' 15 ORDER BY pc.party_id, ph.vega_time ASC 16 ) 17 UPDATE positions_current 18 SET loss = updated_pnl.correct_loss, 19 loss_socialisation_amount = updated_pnl.correct_loss_soc, 20 realised_pnl = updated_pnl.correct_pnl, 21 pending_realised_pnl = updated_pnl.correct_ppnl, 22 adjustment = updated_pnl.correct_adj 23 FROM updated_pnl 24 WHERE party_id = updated_pnl.pid AND market_id = updated_pnl.mid; 25 26 -- +goose Down 27 -- nothing