mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
42 lines
1.3 KiB
Haskell
42 lines
1.3 KiB
Haskell
module Hasura.RQL.DDL.Relationship.Rename
|
|
(runRenameRel)
|
|
where
|
|
|
|
import Data.Text.Extended
|
|
import Hasura.EncJSON
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.DDL.Relationship.Types
|
|
import Hasura.RQL.DDL.Schema (renameRelInCatalog)
|
|
import Hasura.RQL.Types
|
|
import Hasura.SQL.Types
|
|
|
|
import qualified Data.HashMap.Strict as Map
|
|
|
|
renameRelP2
|
|
:: (QErrM m, MonadTx m, CacheRM m)
|
|
=> QualifiedTable -> RelName -> RelInfo -> m ()
|
|
renameRelP2 qt newRN relInfo = withNewInconsistentObjsCheck $ do
|
|
tabInfo <- askTableCoreInfo qt
|
|
-- check for conflicts in fieldInfoMap
|
|
case Map.lookup (fromRel newRN) $ _tciFieldInfoMap tabInfo of
|
|
Nothing -> return ()
|
|
Just _ ->
|
|
throw400 AlreadyExists $ "cannot rename relationship " <> oldRN
|
|
<<> " to " <> newRN <<> " in table " <> qt <<>
|
|
" as a column/relationship with the name already exists"
|
|
-- update catalog
|
|
renameRelInCatalog qt oldRN newRN
|
|
where
|
|
oldRN = riName relInfo
|
|
|
|
runRenameRel
|
|
:: (MonadTx m, CacheRWM m)
|
|
=> RenameRel -> m EncJSON
|
|
runRenameRel (RenameRel qt rn newRN) = do
|
|
tabInfo <- askTableCoreInfo qt
|
|
ri <- askRelType (_tciFieldInfoMap tabInfo) rn ""
|
|
withNewInconsistentObjsCheck do
|
|
renameRelP2 qt newRN ri
|
|
buildSchemaCache
|
|
pure successMsg
|