diff --git a/model/actors/miner/sectordeals.go b/model/actors/miner/sectordeals.go index 2cd3c085c..8e901e01f 100644 --- a/model/actors/miner/sectordeals.go +++ b/model/actors/miner/sectordeals.go @@ -15,7 +15,7 @@ type MinerSectorDeal struct { Height int64 `pg:",pk,notnull,use_zero"` MinerID string `pg:",pk,notnull"` SectorID uint64 `pg:",pk,use_zero"` - DealID uint64 `pg:",use_zero"` + DealID uint64 `pg:",pk,use_zero"` } func (ds *MinerSectorDeal) PersistWithTx(ctx context.Context, tx *pg.Tx) error { diff --git a/storage/migrations/23_miner_sector_deals_pk.go b/storage/migrations/23_miner_sector_deals_pk.go new file mode 100644 index 000000000..0851df676 --- /dev/null +++ b/storage/migrations/23_miner_sector_deals_pk.go @@ -0,0 +1,24 @@ +package migrations + +import ( + "github.com/go-pg/migrations/v8" +) + +// Schema version 23 fixes the miner sector deals primary key + +func init() { + up := batch(` + -- old index from when table was named miner_deal_sectors + ALTER TABLE public.miner_sector_deals DROP CONSTRAINT IF EXISTS miner_deal_sectors_pkey; + + ALTER TABLE public.miner_sector_deals DROP CONSTRAINT IF EXISTS miner_sector_deals_pkey; + ALTER TABLE public.miner_sector_deals ADD PRIMARY KEY (height, miner_id, sector_id, deal_id); +`) + + down := batch(` + ALTER TABLE public.miner_sector_deals DROP CONSTRAINT IF EXISTS miner_sector_deals_pkey; + ALTER TABLE public.miner_sector_deals ADD PRIMARY KEY (height, miner_id, sector_id); +`) + + migrations.MustRegisterTx(up, down) +}