Skip to content

Commit

Permalink
fix(schema): fix primary key for miner_sector_deals table (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
iand authored Dec 2, 2020
1 parent ae6d3a8 commit b0958b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion model/actors/miner/sectordeals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions storage/migrations/23_miner_sector_deals_pk.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit b0958b7

Please sign in to comment.