Skip to content

Commit

Permalink
fixed pgsql bool conversion issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Sep 2, 2023
1 parent d4b1969 commit efbeb79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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++
Expand Down Expand Up @@ -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, `
Expand Down
4 changes: 4 additions & 0 deletions db/schema/pgsql/20230902172124_validator-names.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit efbeb79

Please sign in to comment.