From 7a62b12e41e264d1669c5081deea92ee44322be4 Mon Sep 17 00:00:00 2001 From: Terry Date: Mon, 5 Jun 2023 15:11:08 +0800 Subject: [PATCH] Add rename the fevm related table --- model/fevm/blockheader.go | 6 +++--- model/fevm/receipt.go | 6 +++--- model/fevm/transaction.go | 6 +++--- schemas/v1/26_fevm_rename_table.go | 12 ++++++++++++ 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 schemas/v1/26_fevm_rename_table.go diff --git a/model/fevm/blockheader.go b/model/fevm/blockheader.go index c93131a8..f9d1a188 100644 --- a/model/fevm/blockheader.go +++ b/model/fevm/blockheader.go @@ -10,7 +10,7 @@ import ( ) type FEVMBlockHeader struct { - tableName struct{} `pg:"fevm_block_header"` // nolint: structcheck + tableName struct{} `pg:"fevm_block_headers"` // nolint: structcheck // Height message was executed at. Height int64 `pg:",pk,notnull,use_zero"` @@ -41,7 +41,7 @@ type FEVMBlockHeader struct { } func (f *FEVMBlockHeader) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { - ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_block_header")) + ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_block_headers")) metrics.RecordCount(ctx, metrics.PersistModel, 1) return s.PersistModel(ctx, f) } @@ -52,7 +52,7 @@ func (f FEVMBlockHeaderList) Persist(ctx context.Context, s model.StorageBatch, if len(f) == 0 { return nil } - ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_block_header")) + ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_block_headers")) metrics.RecordCount(ctx, metrics.PersistModel, len(f)) return s.PersistModel(ctx, f) } diff --git a/model/fevm/receipt.go b/model/fevm/receipt.go index 290ef08f..5875b05a 100644 --- a/model/fevm/receipt.go +++ b/model/fevm/receipt.go @@ -10,7 +10,7 @@ import ( ) type FEVMReceipt struct { - tableName struct{} `pg:"fevm_receipt"` // nolint: structcheck + tableName struct{} `pg:"fevm_receipts"` // nolint: structcheck // Height message was executed at. Height int64 `pg:",pk,notnull,use_zero"` @@ -34,7 +34,7 @@ type FEVMReceipt struct { } func (f *FEVMReceipt) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { - ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_receipt")) + ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_receipts")) metrics.RecordCount(ctx, metrics.PersistModel, 1) return s.PersistModel(ctx, f) } @@ -45,7 +45,7 @@ func (f FEVMReceiptList) Persist(ctx context.Context, s model.StorageBatch, vers if len(f) == 0 { return nil } - ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_receipt")) + ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_receipts")) metrics.RecordCount(ctx, metrics.PersistModel, len(f)) return s.PersistModel(ctx, f) } diff --git a/model/fevm/transaction.go b/model/fevm/transaction.go index 85c24c1f..51f5d6ed 100644 --- a/model/fevm/transaction.go +++ b/model/fevm/transaction.go @@ -10,7 +10,7 @@ import ( ) type FEVMTransaction struct { - tableName struct{} `pg:"fevm_transaction"` // nolint: structcheck + tableName struct{} `pg:"fevm_transactions"` // nolint: structcheck // Height message was executed at. Height int64 `pg:",pk,notnull,use_zero"` @@ -36,7 +36,7 @@ type FEVMTransaction struct { } func (f *FEVMTransaction) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { - ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_transaction")) + ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_transactions")) metrics.RecordCount(ctx, metrics.PersistModel, 1) return s.PersistModel(ctx, f) } @@ -47,7 +47,7 @@ func (f FEVMTransactionList) Persist(ctx context.Context, s model.StorageBatch, if len(f) == 0 { return nil } - ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_transaction")) + ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_transactions")) metrics.RecordCount(ctx, metrics.PersistModel, len(f)) return s.PersistModel(ctx, f) } diff --git a/schemas/v1/26_fevm_rename_table.go b/schemas/v1/26_fevm_rename_table.go new file mode 100644 index 00000000..b78fbe12 --- /dev/null +++ b/schemas/v1/26_fevm_rename_table.go @@ -0,0 +1,12 @@ +package v1 + +func init() { + patches.Register( + 26, + ` +ALTER TABLE IF EXISTS {{ .SchemaName | default "public"}}.fevm_block_header RENAME TO fevm_block_headers; +ALTER TABLE IF EXISTS {{ .SchemaName | default "public"}}.fevm_receipt RENAME TO fevm_receipts; +ALTER TABLE IF EXISTS {{ .SchemaName | default "public"}}.fevm_transaction RENAME TO fevm_transactions; +`, + ) +}