{-# LANGUAGE GADTs                      #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE TypeFamilies               #-}

{- |
Module      :  ./Persistence.DevGraph.hs
Copyright   :  (c) Uni Magdeburg 2017
License     :  GPLv2 or higher, see LICENSE.txt

Maintainer  :  Eugen Kuksa <kuksa@iks.cs.ovgu.de>
Stability   :  provisional
Portability :  portable
-}

module Persistence.DevGraph.Cleaning (clean) where

import Persistence.Database
import Persistence.Schema

import Control.Monad (when)
import Control.Monad.IO.Class (MonadIO (..))
import Database.Persist
import Database.Persist.Sql
import GHC.Int

clean :: MonadIO m => Entity LocIdBase -> DBMonad m ()
clean :: Entity LocIdBase -> DBMonad m ()
clean (Entity documentKey :: Key LocIdBase
documentKey documentValue :: LocIdBase
documentValue) = do
  Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteDocument Key LocIdBase
documentKey
  FileVersionId -> DBMonad m ()
forall (m :: * -> *). MonadIO m => FileVersionId -> DBMonad m ()
deleteDiagnoses (FileVersionId -> DBMonad m ()) -> FileVersionId -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ LocIdBase -> FileVersionId
locIdBaseFileVersionId LocIdBase
documentValue

deleteDiagnoses :: MonadIO m => FileVersionId -> DBMonad m ()
deleteDiagnoses :: FileVersionId -> DBMonad m ()
deleteDiagnoses key :: FileVersionId
key = [Filter Diagnosis] -> DBMonad m ()
forall (m :: * -> *) record backend.
(MonadIO m, DeleteCascade record backend,
 PersistQueryWrite backend) =>
[Filter record] -> ReaderT backend m ()
deleteCascadeWhere [EntityField Diagnosis FileVersionId
forall typ. (typ ~ FileVersionId) => EntityField Diagnosis typ
DiagnosisFileVersionId EntityField Diagnosis FileVersionId
-> FileVersionId -> Filter Diagnosis
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. FileVersionId
key]

deleteDocument :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteDocument :: Key LocIdBase -> DBMonad m ()
deleteDocument key :: Key LocIdBase
key = do
  Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteDocumentLinks Key LocIdBase
key
  Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteOms Key LocIdBase
key
  [Filter Document] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField Document (Key Document)
forall typ. (typ ~ Key Document) => EntityField Document typ
DocumentId EntityField Document (Key Document)
-> Key Document -> Filter Document
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Int64 -> Key Document
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Key LocIdBase -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key LocIdBase
key)]
  [Filter LocIdBase] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField LocIdBase (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField LocIdBase typ
LocIdBaseId EntityField LocIdBase (Key LocIdBase)
-> Key LocIdBase -> Filter LocIdBase
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
key]

deleteDocumentLinks :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteDocumentLinks :: Key LocIdBase -> DBMonad m ()
deleteDocumentLinks documentKey :: Key LocIdBase
documentKey =
  [Filter DocumentLink] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere (   [EntityField DocumentLink (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField DocumentLink typ
DocumentLinkSourceId EntityField DocumentLink (Key LocIdBase)
-> Key LocIdBase -> Filter DocumentLink
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
documentKey]
              [Filter DocumentLink]
-> [Filter DocumentLink] -> [Filter DocumentLink]
forall v. [Filter v] -> [Filter v] -> [Filter v]
||. [EntityField DocumentLink (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField DocumentLink typ
DocumentLinkTargetId EntityField DocumentLink (Key LocIdBase)
-> Key LocIdBase -> Filter DocumentLink
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
documentKey]
              )

deleteOms :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteOms :: Key LocIdBase -> DBMonad m ()
deleteOms documentKey :: Key LocIdBase
documentKey = do
  [Entity OMS]
omsL <- [Filter OMS]
-> [SelectOpt OMS] -> ReaderT SqlBackend m [Entity OMS]
forall (m :: * -> *) backend record.
(MonadIO m, PersistQueryRead backend,
 PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList [EntityField OMS (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField OMS typ
OMSDocumentId EntityField OMS (Key LocIdBase) -> Key LocIdBase -> Filter OMS
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
documentKey] []
  (Entity OMS -> DBMonad m ()) -> [Entity OMS] -> DBMonad m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ (Entity omsKey :: Key OMS
omsKey omsValue :: OMS
omsValue) -> do
          DBMonad m ()
-> (Key LocIdBase -> DBMonad m ())
-> Maybe (Key LocIdBase)
-> DBMonad m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> DBMonad m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteOms (Maybe (Key LocIdBase) -> DBMonad m ())
-> Maybe (Key LocIdBase) -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ OMS -> Maybe (Key LocIdBase)
oMSNormalFormId OMS
omsValue
          DBMonad m ()
-> (Key LocIdBase -> DBMonad m ())
-> Maybe (Key LocIdBase)
-> DBMonad m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> DBMonad m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteOms (Maybe (Key LocIdBase) -> DBMonad m ())
-> Maybe (Key LocIdBase) -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ OMS -> Maybe (Key LocIdBase)
oMSFreeNormalFormId OMS
omsValue
          Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteMappings (Key LocIdBase -> DBMonad m ()) -> Key LocIdBase -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> Key LocIdBase) -> Int64 -> Key LocIdBase
forall a b. (a -> b) -> a -> b
$ Key OMS -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key OMS
omsKey
          Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteSentences (Key LocIdBase -> DBMonad m ()) -> Key LocIdBase -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> Key LocIdBase) -> Int64 -> Key LocIdBase
forall a b. (a -> b) -> a -> b
$ Key OMS -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key OMS
omsKey
          Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteSymbols (Key LocIdBase -> DBMonad m ()) -> Key LocIdBase -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> Key LocIdBase) -> Int64 -> Key LocIdBase
forall a b. (a -> b) -> a -> b
$ Key OMS -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key OMS
omsKey
          Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteConsistencyCheckAttempts (Key LocIdBase -> DBMonad m ()) -> Key LocIdBase -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> Key LocIdBase) -> Int64 -> Key LocIdBase
forall a b. (a -> b) -> a -> b
$ Key OMS -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key OMS
omsKey
          [Filter LocIdBase] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField LocIdBase (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField LocIdBase typ
LocIdBaseId EntityField LocIdBase (Key LocIdBase)
-> Key LocIdBase -> Filter LocIdBase
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Key OMS -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key OMS
omsKey)]
          Key OMS -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
delete Key OMS
omsKey
          SignatureId -> DBMonad m ()
forall (m :: * -> *). MonadIO m => SignatureId -> DBMonad m ()
deleteSignature (SignatureId -> DBMonad m ()) -> SignatureId -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ OMS -> SignatureId
oMSSignatureId OMS
omsValue
        ) [Entity OMS]
omsL

deleteMappings :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteMappings :: Key LocIdBase -> DBMonad m ()
deleteMappings omsKey :: Key LocIdBase
omsKey = do
  [Entity Mapping]
mappings <- [Filter Mapping]
-> [SelectOpt Mapping] -> ReaderT SqlBackend m [Entity Mapping]
forall (m :: * -> *) backend record.
(MonadIO m, PersistQueryRead backend,
 PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList (   [EntityField Mapping (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField Mapping typ
MappingSourceId EntityField Mapping (Key LocIdBase)
-> Key LocIdBase -> Filter Mapping
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
omsKey]
                         [Filter Mapping] -> [Filter Mapping] -> [Filter Mapping]
forall v. [Filter v] -> [Filter v] -> [Filter v]
||. [EntityField Mapping (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField Mapping typ
MappingTargetId EntityField Mapping (Key LocIdBase)
-> Key LocIdBase -> Filter Mapping
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
omsKey]
                         [Filter Mapping] -> [Filter Mapping] -> [Filter Mapping]
forall v. [Filter v] -> [Filter v] -> [Filter v]
||. [EntityField Mapping (Maybe (Key LocIdBase))
forall typ.
(typ ~ Maybe (Key LocIdBase)) =>
EntityField Mapping typ
MappingFreenessParameterOMSId EntityField Mapping (Maybe (Key LocIdBase))
-> Maybe (Key LocIdBase) -> Filter Mapping
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase -> Maybe (Key LocIdBase)
forall a. a -> Maybe a
Just Key LocIdBase
omsKey]
                         ) []
  (Entity Mapping -> DBMonad m ())
-> [Entity Mapping] -> DBMonad m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ (Entity mappingKey :: Key Mapping
mappingKey _) -> do
          [Filter LocIdBase] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField LocIdBase (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField LocIdBase typ
LocIdBaseId EntityField LocIdBase (Key LocIdBase)
-> Key LocIdBase -> Filter LocIdBase
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Key Mapping -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key Mapping
mappingKey)]
          Key Mapping -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
delete Key Mapping
mappingKey
        ) [Entity Mapping]
mappings

deleteSentences :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteSentences :: Key LocIdBase -> DBMonad m ()
deleteSentences omsKey :: Key LocIdBase
omsKey = do
  [Entity Sentence]
sentences <- [Filter Sentence]
-> [SelectOpt Sentence] -> ReaderT SqlBackend m [Entity Sentence]
forall (m :: * -> *) backend record.
(MonadIO m, PersistQueryRead backend,
 PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList [EntityField Sentence (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField Sentence typ
SentenceOmsId EntityField Sentence (Key LocIdBase)
-> Key LocIdBase -> Filter Sentence
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
omsKey] []
  (Entity Sentence -> DBMonad m ())
-> [Entity Sentence] -> DBMonad m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ (Entity sentenceKey :: Key Sentence
sentenceKey _) -> do
          Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteSentencesSymbols (Key LocIdBase -> DBMonad m ()) -> Key LocIdBase -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> Key LocIdBase) -> Int64 -> Key LocIdBase
forall a b. (a -> b) -> a -> b
$ Key Sentence -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key Sentence
sentenceKey
          Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deletePremiseSelectedSentences (Key LocIdBase -> DBMonad m ()) -> Key LocIdBase -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> Key LocIdBase) -> Int64 -> Key LocIdBase
forall a b. (a -> b) -> a -> b
$ Key Sentence -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key Sentence
sentenceKey
          Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteAxiom (Key LocIdBase -> DBMonad m ()) -> Key LocIdBase -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> Key LocIdBase) -> Int64 -> Key LocIdBase
forall a b. (a -> b) -> a -> b
$ Key Sentence -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key Sentence
sentenceKey
          Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteConjecture (Key LocIdBase -> DBMonad m ()) -> Key LocIdBase -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> Key LocIdBase) -> Int64 -> Key LocIdBase
forall a b. (a -> b) -> a -> b
$ Key Sentence -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key Sentence
sentenceKey
          [Filter LocIdBase] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField LocIdBase (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField LocIdBase typ
LocIdBaseId EntityField LocIdBase (Key LocIdBase)
-> Key LocIdBase -> Filter LocIdBase
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Key Sentence -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key Sentence
sentenceKey)]
        ) [Entity Sentence]
sentences
  [Filter Sentence] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField Sentence (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField Sentence typ
SentenceOmsId EntityField Sentence (Key LocIdBase)
-> Key LocIdBase -> Filter Sentence
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
omsKey]

deleteSentencesSymbols :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteSentencesSymbols :: Key LocIdBase -> DBMonad m ()
deleteSentencesSymbols sentenceKey :: Key LocIdBase
sentenceKey =
  [Filter SentenceSymbol] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField SentenceSymbol (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField SentenceSymbol typ
SentenceSymbolSentenceId EntityField SentenceSymbol (Key LocIdBase)
-> Key LocIdBase -> Filter SentenceSymbol
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
sentenceKey]

deletePremiseSelectedSentences :: MonadIO m => LocIdBaseId -> DBMonad m ()
deletePremiseSelectedSentences :: Key LocIdBase -> DBMonad m ()
deletePremiseSelectedSentences sentenceKey :: Key LocIdBase
sentenceKey =
  [Filter PremiseSelectedSentence] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField PremiseSelectedSentence (Key LocIdBase)
forall typ.
(typ ~ Key LocIdBase) =>
EntityField PremiseSelectedSentence typ
PremiseSelectedSentencePremiseId EntityField PremiseSelectedSentence (Key LocIdBase)
-> Key LocIdBase -> Filter PremiseSelectedSentence
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
sentenceKey]

deleteAxiom :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteAxiom :: Key LocIdBase -> DBMonad m ()
deleteAxiom = Key LocIdBase -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
delete

deleteConjecture :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteConjecture :: Key LocIdBase -> DBMonad m ()
deleteConjecture conjectureKey :: Key LocIdBase
conjectureKey = do
  Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteProofAttempts Key LocIdBase
conjectureKey
  Key LocIdBase -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
delete Key LocIdBase
conjectureKey

deleteProofAttempts :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteProofAttempts :: Key LocIdBase -> DBMonad m ()
deleteProofAttempts conjectureKey :: Key LocIdBase
conjectureKey = do
  [Entity ProofAttempt]
proofAttempts <- [Filter ProofAttempt]
-> [SelectOpt ProofAttempt]
-> ReaderT SqlBackend m [Entity ProofAttempt]
forall (m :: * -> *) backend record.
(MonadIO m, PersistQueryRead backend,
 PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList [EntityField ProofAttempt (Maybe (Key LocIdBase))
forall typ.
(typ ~ Maybe (Key LocIdBase)) =>
EntityField ProofAttempt typ
ProofAttemptConjectureId EntityField ProofAttempt (Maybe (Key LocIdBase))
-> Maybe (Key LocIdBase) -> Filter ProofAttempt
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase -> Maybe (Key LocIdBase)
forall a. a -> Maybe a
Just Key LocIdBase
conjectureKey] []
  (Entity ProofAttempt -> DBMonad m ())
-> [Entity ProofAttempt] -> DBMonad m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ (Entity proofAttemptKey :: Key ProofAttempt
proofAttemptKey _) ->
          Int64 -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Int64 -> DBMonad m ()
deleteReasoningAttempt (Int64 -> DBMonad m ()) -> Int64 -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Key ProofAttempt -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key ProofAttempt
proofAttemptKey
        ) [Entity ProofAttempt]
proofAttempts
  [Filter ProofAttempt] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField ProofAttempt (Maybe (Key LocIdBase))
forall typ.
(typ ~ Maybe (Key LocIdBase)) =>
EntityField ProofAttempt typ
ProofAttemptConjectureId EntityField ProofAttempt (Maybe (Key LocIdBase))
-> Maybe (Key LocIdBase) -> Filter ProofAttempt
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase -> Maybe (Key LocIdBase)
forall a. a -> Maybe a
Just Key LocIdBase
conjectureKey]

deleteReasoningAttempt :: MonadIO m => GHC.Int.Int64 -> DBMonad m ()
deleteReasoningAttempt :: Int64 -> DBMonad m ()
deleteReasoningAttempt keyInt :: Int64
keyInt = do
  let reasoningAttemptKey :: Key ReasoningAttempt
reasoningAttemptKey = Int64 -> Key ReasoningAttempt
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey Int64
keyInt
  Maybe ReasoningAttempt
reasoningAttemptValueM <- Key ReasoningAttempt
-> ReaderT SqlBackend m (Maybe ReasoningAttempt)
forall backend (m :: * -> *) record.
(PersistStoreRead backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m (Maybe record)
get Key ReasoningAttempt
reasoningAttemptKey
  Key ReasoningAttempt -> DBMonad m ()
forall (m :: * -> *).
MonadIO m =>
Key ReasoningAttempt -> DBMonad m ()
deleteGeneratedAxioms Key ReasoningAttempt
reasoningAttemptKey
  Key ReasoningAttempt -> DBMonad m ()
forall (m :: * -> *).
MonadIO m =>
Key ReasoningAttempt -> DBMonad m ()
deleteReasonerOutputs Key ReasoningAttempt
reasoningAttemptKey
  Key ReasoningAttempt -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
delete Key ReasoningAttempt
reasoningAttemptKey
  case Maybe ReasoningAttempt
reasoningAttemptValueM of
    Just reasoningAttemptValue :: ReasoningAttempt
reasoningAttemptValue -> ReasonerConfigurationId -> DBMonad m ()
forall (m :: * -> *).
MonadIO m =>
ReasonerConfigurationId -> DBMonad m ()
deleteReasoningConfiguration (ReasonerConfigurationId -> DBMonad m ())
-> ReasonerConfigurationId -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ ReasoningAttempt -> ReasonerConfigurationId
reasoningAttemptReasonerConfigurationId ReasoningAttempt
reasoningAttemptValue
    Nothing -> () -> DBMonad m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

deleteGeneratedAxioms :: MonadIO m => ReasoningAttemptId -> DBMonad m ()
deleteGeneratedAxioms :: Key ReasoningAttempt -> DBMonad m ()
deleteGeneratedAxioms reasoningAttemptKey :: Key ReasoningAttempt
reasoningAttemptKey =
  [Filter GeneratedAxiom] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField GeneratedAxiom (Key ReasoningAttempt)
forall typ.
(typ ~ Key ReasoningAttempt) =>
EntityField GeneratedAxiom typ
GeneratedAxiomReasoningAttemptId EntityField GeneratedAxiom (Key ReasoningAttempt)
-> Key ReasoningAttempt -> Filter GeneratedAxiom
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key ReasoningAttempt
reasoningAttemptKey]

deleteReasonerOutputs :: MonadIO m => ReasoningAttemptId -> DBMonad m ()
deleteReasonerOutputs :: Key ReasoningAttempt -> DBMonad m ()
deleteReasonerOutputs reasoningAttemptKey :: Key ReasoningAttempt
reasoningAttemptKey =
  [Filter ReasonerOutput] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField ReasonerOutput (Key ReasoningAttempt)
forall typ.
(typ ~ Key ReasoningAttempt) =>
EntityField ReasonerOutput typ
ReasonerOutputReasoningAttemptId EntityField ReasonerOutput (Key ReasoningAttempt)
-> Key ReasoningAttempt -> Filter ReasonerOutput
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key ReasoningAttempt
reasoningAttemptKey]

deleteReasoningConfiguration :: MonadIO m
                             => ReasonerConfigurationId -> DBMonad m ()
deleteReasoningConfiguration :: ReasonerConfigurationId -> DBMonad m ()
deleteReasoningConfiguration reasoningConfigurationKey :: ReasonerConfigurationId
reasoningConfigurationKey = do
  [Entity ReasoningAttempt]
reasoningAttempts <- [Filter ReasoningAttempt]
-> [SelectOpt ReasoningAttempt]
-> ReaderT SqlBackend m [Entity ReasoningAttempt]
forall (m :: * -> *) backend record.
(MonadIO m, PersistQueryRead backend,
 PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList [EntityField ReasoningAttempt ReasonerConfigurationId
forall typ.
(typ ~ ReasonerConfigurationId) =>
EntityField ReasoningAttempt typ
ReasoningAttemptReasonerConfigurationId EntityField ReasoningAttempt ReasonerConfigurationId
-> ReasonerConfigurationId -> Filter ReasoningAttempt
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. ReasonerConfigurationId
reasoningConfigurationKey] []
  Bool -> DBMonad m () -> DBMonad m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Entity ReasoningAttempt] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Entity ReasoningAttempt]
reasoningAttempts) (DBMonad m () -> DBMonad m ()) -> DBMonad m () -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ do
    ReasonerConfigurationId -> DBMonad m ()
forall (m :: * -> *).
MonadIO m =>
ReasonerConfigurationId -> DBMonad m ()
deletePremiseSelections ReasonerConfigurationId
reasoningConfigurationKey
    ReasonerConfigurationId -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
delete ReasonerConfigurationId
reasoningConfigurationKey

deletePremiseSelections :: MonadIO m => ReasonerConfigurationId -> DBMonad m ()
deletePremiseSelections :: ReasonerConfigurationId -> DBMonad m ()
deletePremiseSelections reasoningConfigurationKey :: ReasonerConfigurationId
reasoningConfigurationKey = do
  [Entity PremiseSelection]
premiseSelections <- [Filter PremiseSelection]
-> [SelectOpt PremiseSelection]
-> ReaderT SqlBackend m [Entity PremiseSelection]
forall (m :: * -> *) backend record.
(MonadIO m, PersistQueryRead backend,
 PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList [EntityField PremiseSelection ReasonerConfigurationId
forall typ.
(typ ~ ReasonerConfigurationId) =>
EntityField PremiseSelection typ
PremiseSelectionReasonerConfigurationId EntityField PremiseSelection ReasonerConfigurationId
-> ReasonerConfigurationId -> Filter PremiseSelection
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. ReasonerConfigurationId
reasoningConfigurationKey] []
  (Entity PremiseSelection -> DBMonad m ())
-> [Entity PremiseSelection] -> DBMonad m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ (Entity premiseSelectionKey :: Key PremiseSelection
premiseSelectionKey _) -> do
          ManualPremiseSelectionId -> DBMonad m ()
forall (m :: * -> *).
MonadIO m =>
ManualPremiseSelectionId -> DBMonad m ()
deleteManualPremiseSelection (ManualPremiseSelectionId -> DBMonad m ())
-> ManualPremiseSelectionId -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> ManualPremiseSelectionId
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> ManualPremiseSelectionId)
-> Int64 -> ManualPremiseSelectionId
forall a b. (a -> b) -> a -> b
$ Key PremiseSelection -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key PremiseSelection
premiseSelectionKey
          SinePremiseSelectionId -> DBMonad m ()
forall (m :: * -> *).
MonadIO m =>
SinePremiseSelectionId -> DBMonad m ()
deleteSinePremiseSelection (SinePremiseSelectionId -> DBMonad m ())
-> SinePremiseSelectionId -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> SinePremiseSelectionId
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> SinePremiseSelectionId)
-> Int64 -> SinePremiseSelectionId
forall a b. (a -> b) -> a -> b
$ Key PremiseSelection -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key PremiseSelection
premiseSelectionKey
        ) [Entity PremiseSelection]
premiseSelections
  [Filter PremiseSelection] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField PremiseSelection ReasonerConfigurationId
forall typ.
(typ ~ ReasonerConfigurationId) =>
EntityField PremiseSelection typ
PremiseSelectionReasonerConfigurationId EntityField PremiseSelection ReasonerConfigurationId
-> ReasonerConfigurationId -> Filter PremiseSelection
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. ReasonerConfigurationId
reasoningConfigurationKey]

deleteManualPremiseSelection :: MonadIO m => ManualPremiseSelectionId -> DBMonad m ()
deleteManualPremiseSelection :: ManualPremiseSelectionId -> DBMonad m ()
deleteManualPremiseSelection = ManualPremiseSelectionId -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
delete

deleteSinePremiseSelection :: MonadIO m => SinePremiseSelectionId -> DBMonad m ()
deleteSinePremiseSelection :: SinePremiseSelectionId -> DBMonad m ()
deleteSinePremiseSelection sinePremiseSelectionKey :: SinePremiseSelectionId
sinePremiseSelectionKey = do
  SinePremiseSelectionId -> DBMonad m ()
forall (m :: * -> *).
MonadIO m =>
SinePremiseSelectionId -> DBMonad m ()
deleteSineSymbolPremiseTriggers SinePremiseSelectionId
sinePremiseSelectionKey
  SinePremiseSelectionId -> DBMonad m ()
forall (m :: * -> *).
MonadIO m =>
SinePremiseSelectionId -> DBMonad m ()
deleteSineSymbolCommonnesses SinePremiseSelectionId
sinePremiseSelectionKey
  SinePremiseSelectionId -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
delete SinePremiseSelectionId
sinePremiseSelectionKey

deleteSineSymbolPremiseTriggers :: MonadIO m => SinePremiseSelectionId -> DBMonad m ()
deleteSineSymbolPremiseTriggers :: SinePremiseSelectionId -> DBMonad m ()
deleteSineSymbolPremiseTriggers sinePremiseSelectionKey :: SinePremiseSelectionId
sinePremiseSelectionKey =
  [Filter SineSymbolPremiseTrigger] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField SineSymbolPremiseTrigger SinePremiseSelectionId
forall typ.
(typ ~ SinePremiseSelectionId) =>
EntityField SineSymbolPremiseTrigger typ
SineSymbolPremiseTriggerSinePremiseSelectionId EntityField SineSymbolPremiseTrigger SinePremiseSelectionId
-> SinePremiseSelectionId -> Filter SineSymbolPremiseTrigger
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. SinePremiseSelectionId
sinePremiseSelectionKey]

deleteSineSymbolCommonnesses :: MonadIO m => SinePremiseSelectionId -> DBMonad m ()
deleteSineSymbolCommonnesses :: SinePremiseSelectionId -> DBMonad m ()
deleteSineSymbolCommonnesses sinePremiseSelectionKey :: SinePremiseSelectionId
sinePremiseSelectionKey =
  [Filter SineSymbolCommonness] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField SineSymbolCommonness SinePremiseSelectionId
forall typ.
(typ ~ SinePremiseSelectionId) =>
EntityField SineSymbolCommonness typ
SineSymbolCommonnessSinePremiseSelectionId EntityField SineSymbolCommonness SinePremiseSelectionId
-> SinePremiseSelectionId -> Filter SineSymbolCommonness
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. SinePremiseSelectionId
sinePremiseSelectionKey]

deleteSymbols :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteSymbols :: Key LocIdBase -> DBMonad m ()
deleteSymbols omsKey :: Key LocIdBase
omsKey = do
  [Entity Symbol]
symbols <- [Filter Symbol]
-> [SelectOpt Symbol] -> ReaderT SqlBackend m [Entity Symbol]
forall (m :: * -> *) backend record.
(MonadIO m, PersistQueryRead backend,
 PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList [EntityField Symbol (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField Symbol typ
SymbolOmsId EntityField Symbol (Key LocIdBase)
-> Key LocIdBase -> Filter Symbol
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
omsKey] []
  (Entity Symbol -> DBMonad m ()) -> [Entity Symbol] -> DBMonad m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ (Entity symbolKey :: Key Symbol
symbolKey _) -> do
          Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteSymbolMappings (Key LocIdBase -> DBMonad m ()) -> Key LocIdBase -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> Key LocIdBase) -> Int64 -> Key LocIdBase
forall a b. (a -> b) -> a -> b
$ Key Symbol -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key Symbol
symbolKey
          Key LocIdBase -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m ()
deleteSignatureSymbols (Key LocIdBase -> DBMonad m ()) -> Key LocIdBase -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Int64 -> Key LocIdBase) -> Int64 -> Key LocIdBase
forall a b. (a -> b) -> a -> b
$ Key Symbol -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key Symbol
symbolKey
          [Filter LocIdBase] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField LocIdBase (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField LocIdBase typ
LocIdBaseId EntityField LocIdBase (Key LocIdBase)
-> Key LocIdBase -> Filter LocIdBase
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Int64 -> Key LocIdBase
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey (Key Symbol -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key Symbol
symbolKey)]
        ) [Entity Symbol]
symbols
  [Filter Symbol] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField Symbol (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField Symbol typ
SymbolOmsId EntityField Symbol (Key LocIdBase)
-> Key LocIdBase -> Filter Symbol
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
omsKey]

deleteSymbolMappings :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteSymbolMappings :: Key LocIdBase -> DBMonad m ()
deleteSymbolMappings symbolKey :: Key LocIdBase
symbolKey =
  [Filter SymbolMapping] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere (   [EntityField SymbolMapping (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField SymbolMapping typ
SymbolMappingSourceId EntityField SymbolMapping (Key LocIdBase)
-> Key LocIdBase -> Filter SymbolMapping
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
symbolKey]
              [Filter SymbolMapping]
-> [Filter SymbolMapping] -> [Filter SymbolMapping]
forall v. [Filter v] -> [Filter v] -> [Filter v]
||. [EntityField SymbolMapping (Key LocIdBase)
forall typ. (typ ~ Key LocIdBase) => EntityField SymbolMapping typ
SymbolMappingTargetId EntityField SymbolMapping (Key LocIdBase)
-> Key LocIdBase -> Filter SymbolMapping
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
symbolKey]
              )

deleteSignatureSymbols :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteSignatureSymbols :: Key LocIdBase -> DBMonad m ()
deleteSignatureSymbols symbolKey :: Key LocIdBase
symbolKey =
  [Filter SignatureSymbol] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField SignatureSymbol (Key LocIdBase)
forall typ.
(typ ~ Key LocIdBase) =>
EntityField SignatureSymbol typ
SignatureSymbolSymbolId EntityField SignatureSymbol (Key LocIdBase)
-> Key LocIdBase -> Filter SignatureSymbol
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase
symbolKey]

deleteConsistencyCheckAttempts :: MonadIO m => LocIdBaseId -> DBMonad m ()
deleteConsistencyCheckAttempts :: Key LocIdBase -> DBMonad m ()
deleteConsistencyCheckAttempts omsKey :: Key LocIdBase
omsKey = do
  [Entity ConsistencyCheckAttempt]
consistencyCheckAttempts <-
    [Filter ConsistencyCheckAttempt]
-> [SelectOpt ConsistencyCheckAttempt]
-> ReaderT SqlBackend m [Entity ConsistencyCheckAttempt]
forall (m :: * -> *) backend record.
(MonadIO m, PersistQueryRead backend,
 PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList [EntityField ConsistencyCheckAttempt (Maybe (Key LocIdBase))
forall typ.
(typ ~ Maybe (Key LocIdBase)) =>
EntityField ConsistencyCheckAttempt typ
ConsistencyCheckAttemptOmsId EntityField ConsistencyCheckAttempt (Maybe (Key LocIdBase))
-> Maybe (Key LocIdBase) -> Filter ConsistencyCheckAttempt
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase -> Maybe (Key LocIdBase)
forall a. a -> Maybe a
Just Key LocIdBase
omsKey] []
  (Entity ConsistencyCheckAttempt -> DBMonad m ())
-> [Entity ConsistencyCheckAttempt] -> DBMonad m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ (Entity consistencyCheckAttemptKey :: Key ConsistencyCheckAttempt
consistencyCheckAttemptKey _) ->
          Int64 -> DBMonad m ()
forall (m :: * -> *). MonadIO m => Int64 -> DBMonad m ()
deleteReasoningAttempt (Int64 -> DBMonad m ()) -> Int64 -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ Key ConsistencyCheckAttempt -> Int64
forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey Key ConsistencyCheckAttempt
consistencyCheckAttemptKey
        ) [Entity ConsistencyCheckAttempt]
consistencyCheckAttempts
  [Filter ConsistencyCheckAttempt] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere [EntityField ConsistencyCheckAttempt (Maybe (Key LocIdBase))
forall typ.
(typ ~ Maybe (Key LocIdBase)) =>
EntityField ConsistencyCheckAttempt typ
ConsistencyCheckAttemptOmsId EntityField ConsistencyCheckAttempt (Maybe (Key LocIdBase))
-> Maybe (Key LocIdBase) -> Filter ConsistencyCheckAttempt
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. Key LocIdBase -> Maybe (Key LocIdBase)
forall a. a -> Maybe a
Just Key LocIdBase
omsKey]

deleteSignature :: MonadIO m => SignatureId -> DBMonad m ()
deleteSignature :: SignatureId -> DBMonad m ()
deleteSignature signatureKey :: SignatureId
signatureKey = do
  [Entity OMS]
oms <- [Filter OMS]
-> [SelectOpt OMS] -> ReaderT SqlBackend m [Entity OMS]
forall (m :: * -> *) backend record.
(MonadIO m, PersistQueryRead backend,
 PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList [EntityField OMS SignatureId
forall typ. (typ ~ SignatureId) => EntityField OMS typ
OMSSignatureId EntityField OMS SignatureId -> SignatureId -> Filter OMS
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. SignatureId
signatureKey] []
  Bool -> DBMonad m () -> DBMonad m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Entity OMS] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Entity OMS]
oms) (DBMonad m () -> DBMonad m ()) -> DBMonad m () -> DBMonad m ()
forall a b. (a -> b) -> a -> b
$ do
    SignatureId -> DBMonad m ()
forall (m :: * -> *). MonadIO m => SignatureId -> DBMonad m ()
deleteSignatureMorphisms SignatureId
signatureKey
    SignatureId -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
delete SignatureId
signatureKey

deleteSignatureMorphisms :: MonadIO m => SignatureId -> DBMonad m ()
deleteSignatureMorphisms :: SignatureId -> DBMonad m ()
deleteSignatureMorphisms signatureKey :: SignatureId
signatureKey =
  [Filter SignatureMorphism] -> DBMonad m ()
forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere (   [EntityField SignatureMorphism SignatureId
forall typ.
(typ ~ SignatureId) =>
EntityField SignatureMorphism typ
SignatureMorphismSourceId EntityField SignatureMorphism SignatureId
-> SignatureId -> Filter SignatureMorphism
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. SignatureId
signatureKey]
              [Filter SignatureMorphism]
-> [Filter SignatureMorphism] -> [Filter SignatureMorphism]
forall v. [Filter v] -> [Filter v] -> [Filter v]
||. [EntityField SignatureMorphism SignatureId
forall typ.
(typ ~ SignatureId) =>
EntityField SignatureMorphism typ
SignatureMorphismTargetId EntityField SignatureMorphism SignatureId
-> SignatureId -> Filter SignatureMorphism
forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. SignatureId
signatureKey]
              )