2019-03-01 12:17:22 +03:00
|
|
|
module Hasura.RQL.DDL.Relationship.Rename
|
|
|
|
(runRenameRel)
|
|
|
|
where
|
|
|
|
|
2019-03-18 19:22:21 +03:00
|
|
|
import Hasura.EncJSON
|
2019-04-17 19:29:39 +03:00
|
|
|
import Hasura.Prelude
|
2019-03-01 12:17:22 +03:00
|
|
|
import Hasura.RQL.DDL.Relationship.Types
|
2019-11-20 21:21:30 +03:00
|
|
|
import Hasura.RQL.DDL.Schema (renameRelInCatalog)
|
2019-03-01 12:17:22 +03:00
|
|
|
import Hasura.RQL.Types
|
|
|
|
import Hasura.SQL.Types
|
|
|
|
|
2020-02-04 18:34:17 +03:00
|
|
|
import qualified Data.HashMap.Strict as Map
|
2019-03-01 12:17:22 +03:00
|
|
|
|
|
|
|
renameRelP2
|
2019-11-20 21:21:30 +03:00
|
|
|
:: (QErrM m, MonadTx m, CacheRM m)
|
2019-03-01 12:17:22 +03:00
|
|
|
=> QualifiedTable -> RelName -> RelInfo -> m ()
|
2019-08-14 02:34:37 +03:00
|
|
|
renameRelP2 qt newRN relInfo = withNewInconsistentObjsCheck $ do
|
2019-11-20 21:21:30 +03:00
|
|
|
tabInfo <- askTableCoreInfo qt
|
2019-03-01 12:17:22 +03:00
|
|
|
-- check for conflicts in fieldInfoMap
|
2020-02-04 18:34:17 +03:00
|
|
|
case Map.lookup (fromRel newRN) $ _tciFieldInfoMap tabInfo of
|
2019-03-01 12:17:22 +03:00
|
|
|
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
|
2020-01-09 02:19:02 +03:00
|
|
|
:: (MonadTx m, CacheRWM m)
|
2019-03-18 19:22:21 +03:00
|
|
|
=> RenameRel -> m EncJSON
|
2019-11-20 21:21:30 +03:00
|
|
|
runRenameRel (RenameRel qt rn newRN) = do
|
|
|
|
tabInfo <- askTableCoreInfo qt
|
|
|
|
ri <- askRelType (_tciFieldInfoMap tabInfo) rn ""
|
|
|
|
withNewInconsistentObjsCheck do
|
|
|
|
renameRelP2 qt newRN ri
|
|
|
|
buildSchemaCache
|
|
|
|
pure successMsg
|