diff --git a/db/db.go b/db/db.go index 7ced59f0..700515cf 100644 --- a/db/db.go +++ b/db/db.go @@ -458,7 +458,7 @@ func GetBlocks(firstBlock uint64, limit uint32, withOrphaned bool) []*dbtypes.Bl blocks := []*dbtypes.Block{} orphanedLimit := "" if !withOrphaned { - orphanedLimit = "AND NOT orphaned" + orphanedLimit = "AND orphaned = 0" } err := ReaderDb.Select(&blocks, ` SELECT @@ -481,7 +481,7 @@ func GetBlocksForSlots(firstSlot uint64, lastSlot uint64, withOrphaned bool) []* blocks := []*dbtypes.Block{} orphanedLimit := "" if !withOrphaned { - orphanedLimit = "AND NOT orphaned" + orphanedLimit = "AND orphaned = 0" } err := ReaderDb.Select(&blocks, ` SELECT @@ -552,9 +552,9 @@ func GetFilteredBlocks(filter *dbtypes.BlockFilter, firstSlot uint64, offset uin if filter.WithMissing != 0 { fmt.Fprintf(&sql, `blocks.orphaned IS NULL OR`) } - fmt.Fprintf(&sql, ` NOT blocks.orphaned) `) + fmt.Fprintf(&sql, ` blocks.orphaned = 0) `) } else if filter.WithOrphaned == 2 { - fmt.Fprintf(&sql, ` AND blocks.orphaned `) + fmt.Fprintf(&sql, ` AND blocks.orphaned = 1`) } if filter.ProposerIndex != nil { argIdx++ @@ -678,7 +678,7 @@ func GetHighestRootBeforeSlot(slot uint64, withOrphaned bool) []byte { var result []byte orphanedLimit := "" if !withOrphaned { - orphanedLimit = "AND NOT orphaned" + orphanedLimit = "AND orphaned = 0" } err := ReaderDb.Get(&result, ` diff --git a/db/schema/pgsql/20230902172124_validator-names.sql b/db/schema/pgsql/20230902172124_validator-names.sql index 45a10d21..49319c41 100644 --- a/db/schema/pgsql/20230902172124_validator-names.sql +++ b/db/schema/pgsql/20230902172124_validator-names.sql @@ -12,6 +12,10 @@ CREATE INDEX IF NOT EXISTS "validator_names_name_idx" ON public."validator_names" USING gin ("name" gin_trgm_ops); +ALTER TABLE public."blocks" ALTER COLUMN "orphaned" TYPE smallint USING CASE + WHEN "orphaned" THEN 1 ELSE 0 + END; + -- +goose StatementEnd -- +goose Down -- +goose StatementBegin