code.vegaprotocol.io/vega@v0.79.0/datanode/sqlstore/migrations/0117_funding_payment_loss.sql (about)

     1  -- +goose Up
     2  
     3  DROP TRIGGER IF EXISTS update_funding_payment ON funding_payment;
     4  
     5  ALTER TABLE funding_payment ADD COLUMN IF NOT EXISTS loss_socialisation_amount NUMERIC NOT NULL DEFAULT (0);
     6  
     7  -- +goose StatementBegin
     8  CREATE OR REPLACE FUNCTION update_funding_payments()
     9         RETURNS TRIGGER
    10         language plpgsql
    11  AS $$
    12     BEGIN
    13          INSERT INTO funding_payment(market_id, party_id, funding_period_seq, amount, vega_time, tx_hash, loss_socialisation_amount)
    14          VALUES (new.market_id, new.party_id, new.funding_period_seq, new.amount, new.vega_time, new.tx_hash, new.loss_socialisation_amount)
    15          ON CONFLICT(party_id, market_id, vega_time)
    16          DO UPDATE SET
    17              amount = excluded.amount,
    18              loss_socialisation_amount = excluded.loss_socialisation_amount;
    19          RETURN NULL;
    20      END;
    21  $$;
    22  -- +goose StatementEnd
    23  
    24  CREATE TRIGGER update_funding_payment
    25      AFTER INSERT 
    26      ON funding_payment
    27      FOR EACH ROW EXECUTE FUNCTION update_funding_payments();
    28  
    29  -- +goose Down
    30  
    31  DROP TRIGGER IF EXISTS update_funding_payment ON funding_payment;
    32  
    33  ALTER TABLE funding_payment DROP COLUMN IF EXISTS loss_socialisation_amount;
    34  
    35  DROP FUNCTION IF EXISTS update_funding_payments();
    36