 , tippee                text                        NOT NULL REFERENCES participants ON UPDATE CASCADE ON DELETE RESTRICT
 , amount                numeric(35,2)               NOT NULL
 , context               context_type                NOT NULL
+, payday                integer                     DEFAULT NULL REFERENCES paydays
+                                                        ON UPDATE RESTRICT
+                                                        ON DELETE RESTRICT
  );
 
 -- https://github.com/gratipay/gratipay.com/pull/2723

CREATE INDEX transfers_timestamp_idx ON transfers (timestamp);
CREATE INDEX transfers_tipper_idx ON transfers (tipper);
CREATE INDEX transfers_tippee_idx ON transfers (tippee);


-- paydays -- payday events, stats about them
CREATE TABLE paydays
( id                    serial                      PRIMARY KEY
, ts_start              timestamp with time zone    NOT NULL DEFAULT CURRENT_TIMESTAMP
, ts_end                timestamp with time zone    UNIQUE NOT NULL DEFAULT '1970-01-01T00:00:00+00'::timestamptz
, volume                numeric(35,2)               NOT NULL DEFAULT 0.00
, nusers                bigint                      NOT NULL DEFAULT 0
, stage                 integer                     DEFAULT 0
 );


-- https://github.com/gratipay/gratipay.com/pull/3282

    ('unresolved', 'pending-payout', 'resolved');


-- https://github.com/gratipay/gratipay.com/pull/3733
BEGIN;

