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 (validateRelP1)
|
|
|
|
import Hasura.RQL.DDL.Relationship.Types
|
2019-08-14 02:34:37 +03:00
|
|
|
import Hasura.RQL.DDL.Schema (buildSchemaCache,
|
|
|
|
renameRelInCatalog,
|
|
|
|
withNewInconsistentObjsCheck)
|
2019-03-01 12:17:22 +03:00
|
|
|
import Hasura.RQL.Types
|
|
|
|
import Hasura.SQL.Types
|
|
|
|
|
|
|
|
import qualified Data.HashMap.Strict as HM
|
|
|
|
|
|
|
|
renameRelP2
|
2019-03-01 14:45:04 +03:00
|
|
|
:: ( QErrM m
|
|
|
|
, MonadTx m
|
|
|
|
, CacheRWM m
|
|
|
|
, MonadIO m
|
|
|
|
, HasHttpManager m
|
2019-10-11 08:13:57 +03:00
|
|
|
, HasSystemDefined m
|
2019-03-01 14:45:04 +03:00
|
|
|
, HasSQLGenCtx 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-03-01 12:17:22 +03:00
|
|
|
tabInfo <- askTabInfo qt
|
|
|
|
-- check for conflicts in fieldInfoMap
|
2019-07-22 15:47:13 +03:00
|
|
|
case HM.lookup (fromRel newRN) $ _tiFieldInfoMap 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
|
|
|
|
-- update schema cache
|
|
|
|
buildSchemaCache
|
|
|
|
where
|
|
|
|
oldRN = riName relInfo
|
|
|
|
|
|
|
|
runRenameRel
|
2019-03-01 14:45:04 +03:00
|
|
|
:: ( QErrM m
|
|
|
|
, CacheRWM m
|
|
|
|
, MonadTx m
|
|
|
|
, UserInfoM m
|
|
|
|
, MonadIO m
|
|
|
|
, HasHttpManager m
|
2019-10-11 08:13:57 +03:00
|
|
|
, HasSystemDefined m
|
2019-03-01 14:45:04 +03:00
|
|
|
, HasSQLGenCtx m
|
|
|
|
)
|
2019-03-18 19:22:21 +03:00
|
|
|
=> RenameRel -> m EncJSON
|
2019-03-01 12:17:22 +03:00
|
|
|
runRenameRel defn = do
|
|
|
|
ri <- validateRelP1 qt rn
|
|
|
|
renameRelP2 qt newRN ri
|
|
|
|
return successMsg
|
|
|
|
where
|
|
|
|
RenameRel qt rn newRN = defn
|