get list of tables from schema

This commit is contained in:
Roy Crihfield 2024-07-11 15:47:14 +08:00
parent c31b1f30ed
commit 2e70a798e2
4 changed files with 11 additions and 17 deletions

View File

@ -67,7 +67,7 @@ func dumpCSVFileData(t *testing.T) {
localOutputDir := filepath.Join(workingDir, file.CSVTestConfig.OutputDir)
for _, tbl := range schema.Tables {
for _, tbl := range schema.EthTables {
err := test_helpers.DedupFile(file.TableFilePath(localOutputDir, tbl.Name))
require.NoError(t, err)

View File

@ -120,7 +120,7 @@ func NewCSVWriter(path string, watchedAddressesFilePath string, diff bool) (*CSV
return nil, fmt.Errorf("unable to create directory '%s': %w", path, err)
}
writers, err := makeFileWriters(path, schema.Tables)
writers, err := makeFileWriters(path, schema.EthTables)
if err != nil {
return nil, err
}

View File

@ -16,7 +16,7 @@
package schema
var Tables = []*Table{
var EthTables = []*Table{
&TableIPLDBlock,
&TableNodeInfo,
&TableHeader,
@ -29,6 +29,11 @@ var Tables = []*Table{
&TableWithdrawal,
}
var AllTables = append(
EthTables,
&TableWatchedAddresses,
)
var TableIPLDBlock = Table{
Name: `ipld.blocks`,
Columns: []Column{

View File

@ -24,6 +24,7 @@ import (
"testing"
"github.com/cerc-io/plugeth-statediff/indexer/database/sql"
"github.com/cerc-io/plugeth-statediff/indexer/shared/schema"
)
// DedupFile removes duplicates from the given file
@ -71,20 +72,8 @@ func ClearDB(db sql.Database) error {
return err
}
statements := []string{
`TRUNCATE nodes`,
`TRUNCATE ipld.blocks`,
`TRUNCATE eth.header_cids`,
`TRUNCATE eth.uncle_cids`,
`TRUNCATE eth.transaction_cids`,
`TRUNCATE eth.receipt_cids`,
`TRUNCATE eth.state_cids`,
`TRUNCATE eth.storage_cids`,
`TRUNCATE eth.log_cids`,
`TRUNCATE eth.withdrawal_cids`,
`TRUNCATE eth_meta.watched_addresses`,
}
for _, stm := range statements {
for _, tbl := range schema.AllTables {
stm := fmt.Sprintf("TRUNCATE %s", tbl.Name)
if _, err = tx.Exec(ctx, stm); err != nil {
return fmt.Errorf("error executing `%s`: %w", stm, err)
}