diff --git a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Rollback.hs b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Rollback.hs index 27176412b..9d51e6e6e 100644 --- a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Rollback.hs +++ b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Rollback.hs @@ -1,5 +1,9 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE NumericUnderscores #-} + +#if __GLASGOW_HASKELL__ >= 908 {-# OPTIONS_GHC -Wno-x-partial #-} +#endif module Test.Cardano.Db.Mock.Unit.Conway.Rollback ( simpleRollback, diff --git a/cardano-db/src/Cardano/Db/Statement/Base.hs b/cardano-db/src/Cardano/Db/Statement/Base.hs index ae0d6fa79..c2ff120ec 100644 --- a/cardano-db/src/Cardano/Db/Statement/Base.hs +++ b/cardano-db/src/Cardano/Db/Statement/Base.hs @@ -192,12 +192,13 @@ queryBlockNoAndEpochStmt = -- (where DrepDistr will be inserted). Using the previous block's epoch ensures -- DrepDistr for the current epoch gets deleted, preventing duplicates -- when replaying through the epoch boundary. + -- For genesis (block 0), there's no previous block, so use the current epoch. sql = TextEnc.encodeUtf8 $ Text.concat - [ "SELECT curr.id, prev.epoch_no" + [ "SELECT curr.id, COALESCE(prev.epoch_no, curr.epoch_no)" , " FROM " <> tableName (Proxy @a) <> " curr" - , " JOIN " <> tableName (Proxy @a) <> " prev ON prev.block_no = $1 - 1" + , " LEFT JOIN " <> tableName (Proxy @a) <> " prev ON prev.block_no = $1 - 1" , " WHERE curr.block_no = $1" ]