Skip to content

Commit

Permalink
db-sync: Fix (again) foreign key exception on pool offline data
Browse files Browse the repository at this point in the history
This was supposed to be fixed in d658f38 but probably due to a git
merge error, the new functions that were supposed to fix this issue were
added but not used.

The fix is to use the checked versions of the functions and completely
remove the unchecked functions so they cannot be called by accident.

Closes: #858
  • Loading branch information
erikd committed Sep 29, 2021
1 parent c677b2b commit 20ce462
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Offline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ insertOfflineResults trce resultQueue = do
insert :: (MonadBaseControl IO m, MonadIO m) => FetchResult -> ReaderT SqlBackend m ()
insert fr =
case fr of
ResultMetadata md -> void $ DB.insertPoolOfflineData md
ResultError fe -> void $ DB.insertPoolOfflineFetchError fe
ResultMetadata md -> void $ DB.insertCheckPoolOfflineData md
ResultError fe -> void $ DB.insertCheckPoolOfflineFetchError fe

isFetchError :: FetchResult -> Bool
isFetchError fe =
Expand Down
12 changes: 2 additions & 10 deletions cardano-db/src/Cardano/Db/Insert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ module Cardano.Db.Insert
, insertPotTransfer
, insertPoolHash
, insertPoolMetadataRef
, insertPoolOfflineData
, insertPoolOfflineFetchError
, insertPoolOwner
, insertPoolRelay
, insertPoolRetire
Expand Down Expand Up @@ -157,12 +155,6 @@ insertPoolHash = insertCheckUnique "PoolHash"
insertPoolMetadataRef :: (MonadBaseControl IO m, MonadIO m) => PoolMetadataRef -> ReaderT SqlBackend m PoolMetadataRefId
insertPoolMetadataRef = insertCheckUnique "PoolMetadataRef"

insertPoolOfflineData :: (MonadBaseControl IO m, MonadIO m) => PoolOfflineData -> ReaderT SqlBackend m PoolOfflineDataId
insertPoolOfflineData = insertCheckUnique "PoolOfflineData"

insertPoolOfflineFetchError :: (MonadBaseControl IO m, MonadIO m) => PoolOfflineFetchError -> ReaderT SqlBackend m PoolOfflineFetchErrorId
insertPoolOfflineFetchError = insertCheckUnique "PoolOfflineFetchError"

insertPoolOwner :: (MonadBaseControl IO m, MonadIO m) => PoolOwner -> ReaderT SqlBackend m PoolOwnerId
insertPoolOwner = insertCheckUnique "PoolOwner"

Expand Down Expand Up @@ -227,13 +219,13 @@ insertCheckPoolOfflineData :: (MonadBaseControl IO m, MonadIO m) => PoolOfflineD
insertCheckPoolOfflineData pod = do
foundPool <- existsPoolHashId (poolOfflineDataPoolId pod)
foundMeta <- existsPoolMetadataRefId (poolOfflineDataPmrId pod)
when (foundPool && foundMeta) $ void $ insertPoolOfflineData pod
when (foundPool && foundMeta) . void $ insertCheckUnique "PoolOfflineData" pod

insertCheckPoolOfflineFetchError :: (MonadBaseControl IO m, MonadIO m) => PoolOfflineFetchError -> ReaderT SqlBackend m ()
insertCheckPoolOfflineFetchError pofe = do
foundPool <- existsPoolHashId (poolOfflineFetchErrorPoolId pofe)
foundMeta <- existsPoolMetadataRefId (poolOfflineFetchErrorPmrId pofe)
when (foundPool && foundMeta) $ void $ insertPoolOfflineFetchError pofe
when (foundPool && foundMeta) . void $ insertCheckUnique "PoolOfflineFetchError" pofe

-- -----------------------------------------------------------------------------

Expand Down

0 comments on commit 20ce462

Please sign in to comment.