Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: align the pkey in model to real database schema #1271

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions model/actordumps/fevm_actor_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type FEVMActorDump struct {
// Height message was executed at.
Height int64 `pg:",pk,notnull,use_zero"`
// Actor address.
ActorID string `pg:",notnull"`
ActorID string `pg:",pk,notnull"`
// Actor Address in ETH.
EthAddress string `pg:",notnull"`
// Contract Bytecode.
Expand All @@ -25,7 +25,7 @@ type FEVMActorDump struct {
// Balance of EVM actor in attoFIL.
Balance string `pg:"type:numeric,notnull"`
// The next actor nonce that is expected to appear on chain.
Nonce uint64 `pg:",use_zero"`
Nonce uint64 `pg:",pk,use_zero"`
// Actor Name
ActorName string `pg:",notnull"`
}
Expand Down
8 changes: 4 additions & 4 deletions model/actors/market/dealstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
type MarketDealState struct {
Height int64 `pg:",pk,notnull,use_zero"`
DealID uint64 `pg:",pk,use_zero"`
SectorStartEpoch int64 `pg:",pk,use_zero"`
LastUpdateEpoch int64 `pg:",pk,use_zero"`
SlashEpoch int64 `pg:",pk,use_zero"`
SectorStartEpoch int64 `pg:",use_zero"`
LastUpdateEpoch int64 `pg:",use_zero"`
SlashEpoch int64 `pg:",use_zero"`

StateRoot string `pg:",notnull"`
StateRoot string `pg:",pk,notnull"`
}

func (ds *MarketDealState) Persist(ctx context.Context, s model.StorageBatch, _ model.Version) error {
Expand Down
2 changes: 1 addition & 1 deletion model/blocks/drand.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type DrandBlockEntrie struct {
// Round is the round number of randomness used.
Round uint64 `pg:",pk,use_zero"`
// Block is the CID of the block.
Block string `pg:",notnull"`
Block string `pg:",pk,notnull"`
}

func (dbe *DrandBlockEntrie) Persist(ctx context.Context, s model.StorageBatch, _ model.Version) error {
Expand Down
2 changes: 1 addition & 1 deletion model/blocks/parent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type BlockParent struct {
Height int64 `pg:",pk,notnull,use_zero"`
Block string `pg:",pk,notnull"`
Parent string `pg:",notnull"`
Parent string `pg:",pk,notnull"`
}

func (bp *BlockParent) Persist(ctx context.Context, s model.StorageBatch, _ model.Version) error {
Expand Down
2 changes: 1 addition & 1 deletion model/chain/economics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type ChainEconomics struct {
tableName struct{} `pg:"chain_economics"` // nolint: structcheck
Height int64 `pg:",pk,notnull,use_zero"`
ParentStateRoot string `pg:",notnull"`
ParentStateRoot string `pg:",pk,notnull"`
CirculatingFil string `pg:"type:numeric,notnull"`
VestedFil string `pg:"type:numeric,notnull"`
MinedFil string `pg:"type:numeric,notnull"`
Expand Down
4 changes: 2 additions & 2 deletions model/fevm/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type FEVMContract struct {
// Height message was executed at.
Height int64 `pg:",pk,notnull,use_zero"`
// Actor address.
ActorID string `pg:",notnull"`
ActorID string `pg:",pk,notnull"`
// Actor Address in ETH.
EthAddress string `pg:",notnull"`
// Contract Bytecode.
Expand All @@ -25,7 +25,7 @@ type FEVMContract struct {
// Balance of EVM actor in attoFIL.
Balance string `pg:"type:numeric,notnull"`
// The next actor nonce that is expected to appear on chain.
Nonce uint64 `pg:",use_zero"`
Nonce uint64 `pg:",pk,use_zero"`
}

func (f *FEVMContract) Persist(ctx context.Context, s model.StorageBatch, _ model.Version) error {
Expand Down
2 changes: 1 addition & 1 deletion model/fevm/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type FEVMReceipt struct {
// Message CID
Message string `pg:",use_zero"`
// Hash of transaction.
TransactionHash string `pg:",notnull"`
TransactionHash string `pg:",pk,notnull"`
// Integer of the transactions index position in the block.
TransactionIndex uint64 `pg:",use_zero"`
// Hash of the block where this transaction was in.
Expand Down
2 changes: 1 addition & 1 deletion model/messages/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type VMMessage struct {
// Returns value of message receipt.
Returns string `pg:",type:jsonb"`
// Index indicating the order of the messages execution.
Index uint64 `pg:",notnull,use_zero"`
Index uint64 `pg:",pk,notnull,use_zero"`
}

func (v *VMMessage) Persist(ctx context.Context, s model.StorageBatch, _ model.Version) error {
Expand Down
12 changes: 12 additions & 0 deletions schemas/v1/35_add_pkey_for_tables.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package v1

func init() {
patches.Register(
35,
`
ALTER TABLE ONLY {{ .SchemaName | default "public"}}.drand_block_entries ADD CONSTRAINT drand_block_entries_pkey PRIMARY KEY (round, block);

ALTER TABLE {{ .SchemaName | default "public"}}.vm_messages DROP CONSTRAINT IF EXISTS vm_messages_pkey CASCADE, ADD PRIMARY KEY(height, state_root, cid, source, index)
`,
)
}