2020-12-28 15:56:00 +03:00
|
|
|
module Hasura.RQL.DDL.Schema.Source where
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
import Control.Lens (at, (.~), (^.))
|
|
|
|
import Control.Monad.Trans.Control (MonadBaseControl)
|
|
|
|
import Data.Aeson
|
|
|
|
import Data.Aeson qualified as J
|
|
|
|
import Data.Aeson.TH
|
|
|
|
import Data.Has
|
|
|
|
import Data.HashMap.Strict qualified as HM
|
|
|
|
import Data.HashMap.Strict.InsOrd qualified as OMap
|
|
|
|
import Data.Text.Extended
|
|
|
|
import Hasura.Base.Error
|
|
|
|
import Hasura.EncJSON
|
|
|
|
import Hasura.Logging qualified as L
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.DDL.Deps
|
|
|
|
import Hasura.RQL.DDL.Schema.Common
|
|
|
|
import Hasura.RQL.Types
|
|
|
|
import Hasura.SQL.AnyBackend qualified as AB
|
|
|
|
import Hasura.Server.Logging (MetadataLog (..))
|
2020-12-28 15:56:00 +03:00
|
|
|
|
Clean metadata arguments
## Description
Thanks to #1664, the Metadata API types no longer require a `ToJSON` instance. This PR follows up with a cleanup of the types of the arguments to the metadata API:
- whenever possible, it moves those argument types to where they're used (RQL.DDL.*)
- it removes all unrequired instances (mostly `ToJSON`)
This PR does not attempt to do it for _all_ such argument types. For some of the metadata operations, the type used to describe the argument to the API and used to represent the value in the metadata are one and the same (like for `CreateEndpoint`). Sometimes, the two types are intertwined in complex ways (`RemoteRelationship` and `RemoteRelationshipDef`). In the spirit of only doing uncontroversial cleaning work, this PR only moves types that are not used outside of RQL.DDL.
Furthermore, this is a small step towards separating the different types all jumbled together in RQL.Types.
## Notes
This PR also improves several `FromJSON` instances to make use of `withObject`, and to use a human readable string instead of a type name in error messages whenever possible. For instance:
- before: `expected Object for Object, but encountered X`
after: `expected Object for add computed field, but encountered X`
- before: `Expecting an object for update query`
after: `expected Object for update query, but encountered X`
This PR also renames `CreateFunctionPermission` to `FunctionPermissionArgument`, to remove the quite surprising `type DropFunctionPermission = CreateFunctionPermission`.
This PR also deletes some dead code, mostly in RQL.DML.
This PR also moves a PG-specific source resolving function from DDL.Schema.Source to the only place where it is used: App.hs.
https://github.com/hasura/graphql-engine-mono/pull/1844
GitOrigin-RevId: a594521194bb7fe6a111b02a9e099896f9fed59c
2021-07-27 13:41:42 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Add source
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
data AddSource b = AddSource
|
|
|
|
{ _asName :: !SourceName,
|
|
|
|
_asConfiguration :: !(SourceConnConfiguration b),
|
|
|
|
_asReplaceConfiguration :: !Bool
|
Clean metadata arguments
## Description
Thanks to #1664, the Metadata API types no longer require a `ToJSON` instance. This PR follows up with a cleanup of the types of the arguments to the metadata API:
- whenever possible, it moves those argument types to where they're used (RQL.DDL.*)
- it removes all unrequired instances (mostly `ToJSON`)
This PR does not attempt to do it for _all_ such argument types. For some of the metadata operations, the type used to describe the argument to the API and used to represent the value in the metadata are one and the same (like for `CreateEndpoint`). Sometimes, the two types are intertwined in complex ways (`RemoteRelationship` and `RemoteRelationshipDef`). In the spirit of only doing uncontroversial cleaning work, this PR only moves types that are not used outside of RQL.DDL.
Furthermore, this is a small step towards separating the different types all jumbled together in RQL.Types.
## Notes
This PR also improves several `FromJSON` instances to make use of `withObject`, and to use a human readable string instead of a type name in error messages whenever possible. For instance:
- before: `expected Object for Object, but encountered X`
after: `expected Object for add computed field, but encountered X`
- before: `Expecting an object for update query`
after: `expected Object for update query, but encountered X`
This PR also renames `CreateFunctionPermission` to `FunctionPermissionArgument`, to remove the quite surprising `type DropFunctionPermission = CreateFunctionPermission`.
This PR also deletes some dead code, mostly in RQL.DML.
This PR also moves a PG-specific source resolving function from DDL.Schema.Source to the only place where it is used: App.hs.
https://github.com/hasura/graphql-engine-mono/pull/1844
GitOrigin-RevId: a594521194bb7fe6a111b02a9e099896f9fed59c
2021-07-27 13:41:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
instance (Backend b) => FromJSON (AddSource b) where
|
2021-09-20 22:49:33 +03:00
|
|
|
parseJSON = withObject "AddSource" $ \o ->
|
Clean metadata arguments
## Description
Thanks to #1664, the Metadata API types no longer require a `ToJSON` instance. This PR follows up with a cleanup of the types of the arguments to the metadata API:
- whenever possible, it moves those argument types to where they're used (RQL.DDL.*)
- it removes all unrequired instances (mostly `ToJSON`)
This PR does not attempt to do it for _all_ such argument types. For some of the metadata operations, the type used to describe the argument to the API and used to represent the value in the metadata are one and the same (like for `CreateEndpoint`). Sometimes, the two types are intertwined in complex ways (`RemoteRelationship` and `RemoteRelationshipDef`). In the spirit of only doing uncontroversial cleaning work, this PR only moves types that are not used outside of RQL.DDL.
Furthermore, this is a small step towards separating the different types all jumbled together in RQL.Types.
## Notes
This PR also improves several `FromJSON` instances to make use of `withObject`, and to use a human readable string instead of a type name in error messages whenever possible. For instance:
- before: `expected Object for Object, but encountered X`
after: `expected Object for add computed field, but encountered X`
- before: `Expecting an object for update query`
after: `expected Object for update query, but encountered X`
This PR also renames `CreateFunctionPermission` to `FunctionPermissionArgument`, to remove the quite surprising `type DropFunctionPermission = CreateFunctionPermission`.
This PR also deletes some dead code, mostly in RQL.DML.
This PR also moves a PG-specific source resolving function from DDL.Schema.Source to the only place where it is used: App.hs.
https://github.com/hasura/graphql-engine-mono/pull/1844
GitOrigin-RevId: a594521194bb7fe6a111b02a9e099896f9fed59c
2021-07-27 13:41:42 +03:00
|
|
|
AddSource
|
|
|
|
<$> o .: "name"
|
|
|
|
<*> o .: "configuration"
|
|
|
|
<*> o .:? "replace_configuration" .!= False
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
runAddSource ::
|
|
|
|
forall m b.
|
|
|
|
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
|
|
|
|
AddSource b ->
|
|
|
|
m EncJSON
|
2021-03-30 13:09:29 +03:00
|
|
|
runAddSource (AddSource name sourceConfig replaceConfiguration) = do
|
2021-02-23 20:37:27 +03:00
|
|
|
sources <- scSources <$> askSchemaCache
|
2021-03-30 13:09:29 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
metadataModifier <-
|
|
|
|
MetadataModifier
|
|
|
|
<$> if HM.member name sources
|
|
|
|
then
|
|
|
|
if replaceConfiguration
|
|
|
|
then pure $ metaSources . ix name . toSourceMetadata @b . smConfiguration .~ sourceConfig
|
|
|
|
else throw400 AlreadyExists $ "source with name " <> name <<> " already exists"
|
|
|
|
else do
|
|
|
|
let sourceMetadata = mkSourceMetadata @b name sourceConfig
|
|
|
|
pure $ metaSources %~ OMap.insert name sourceMetadata
|
2021-03-30 13:09:29 +03:00
|
|
|
|
|
|
|
buildSchemaCacheFor (MOSource name) metadataModifier
|
2021-01-07 12:04:22 +03:00
|
|
|
pure successMsg
|
|
|
|
|
Clean metadata arguments
## Description
Thanks to #1664, the Metadata API types no longer require a `ToJSON` instance. This PR follows up with a cleanup of the types of the arguments to the metadata API:
- whenever possible, it moves those argument types to where they're used (RQL.DDL.*)
- it removes all unrequired instances (mostly `ToJSON`)
This PR does not attempt to do it for _all_ such argument types. For some of the metadata operations, the type used to describe the argument to the API and used to represent the value in the metadata are one and the same (like for `CreateEndpoint`). Sometimes, the two types are intertwined in complex ways (`RemoteRelationship` and `RemoteRelationshipDef`). In the spirit of only doing uncontroversial cleaning work, this PR only moves types that are not used outside of RQL.DDL.
Furthermore, this is a small step towards separating the different types all jumbled together in RQL.Types.
## Notes
This PR also improves several `FromJSON` instances to make use of `withObject`, and to use a human readable string instead of a type name in error messages whenever possible. For instance:
- before: `expected Object for Object, but encountered X`
after: `expected Object for add computed field, but encountered X`
- before: `Expecting an object for update query`
after: `expected Object for update query, but encountered X`
This PR also renames `CreateFunctionPermission` to `FunctionPermissionArgument`, to remove the quite surprising `type DropFunctionPermission = CreateFunctionPermission`.
This PR also deletes some dead code, mostly in RQL.DML.
This PR also moves a PG-specific source resolving function from DDL.Schema.Source to the only place where it is used: App.hs.
https://github.com/hasura/graphql-engine-mono/pull/1844
GitOrigin-RevId: a594521194bb7fe6a111b02a9e099896f9fed59c
2021-07-27 13:41:42 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Rename source
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
data RenameSource = RenameSource
|
|
|
|
{ _rmName :: !SourceName,
|
|
|
|
_rmNewName :: !SourceName
|
Clean metadata arguments
## Description
Thanks to #1664, the Metadata API types no longer require a `ToJSON` instance. This PR follows up with a cleanup of the types of the arguments to the metadata API:
- whenever possible, it moves those argument types to where they're used (RQL.DDL.*)
- it removes all unrequired instances (mostly `ToJSON`)
This PR does not attempt to do it for _all_ such argument types. For some of the metadata operations, the type used to describe the argument to the API and used to represent the value in the metadata are one and the same (like for `CreateEndpoint`). Sometimes, the two types are intertwined in complex ways (`RemoteRelationship` and `RemoteRelationshipDef`). In the spirit of only doing uncontroversial cleaning work, this PR only moves types that are not used outside of RQL.DDL.
Furthermore, this is a small step towards separating the different types all jumbled together in RQL.Types.
## Notes
This PR also improves several `FromJSON` instances to make use of `withObject`, and to use a human readable string instead of a type name in error messages whenever possible. For instance:
- before: `expected Object for Object, but encountered X`
after: `expected Object for add computed field, but encountered X`
- before: `Expecting an object for update query`
after: `expected Object for update query, but encountered X`
This PR also renames `CreateFunctionPermission` to `FunctionPermissionArgument`, to remove the quite surprising `type DropFunctionPermission = CreateFunctionPermission`.
This PR also deletes some dead code, mostly in RQL.DML.
This PR also moves a PG-specific source resolving function from DDL.Schema.Source to the only place where it is used: App.hs.
https://github.com/hasura/graphql-engine-mono/pull/1844
GitOrigin-RevId: a594521194bb7fe6a111b02a9e099896f9fed59c
2021-07-27 13:41:42 +03:00
|
|
|
}
|
2021-09-24 01:56:37 +03:00
|
|
|
|
Clean metadata arguments
## Description
Thanks to #1664, the Metadata API types no longer require a `ToJSON` instance. This PR follows up with a cleanup of the types of the arguments to the metadata API:
- whenever possible, it moves those argument types to where they're used (RQL.DDL.*)
- it removes all unrequired instances (mostly `ToJSON`)
This PR does not attempt to do it for _all_ such argument types. For some of the metadata operations, the type used to describe the argument to the API and used to represent the value in the metadata are one and the same (like for `CreateEndpoint`). Sometimes, the two types are intertwined in complex ways (`RemoteRelationship` and `RemoteRelationshipDef`). In the spirit of only doing uncontroversial cleaning work, this PR only moves types that are not used outside of RQL.DDL.
Furthermore, this is a small step towards separating the different types all jumbled together in RQL.Types.
## Notes
This PR also improves several `FromJSON` instances to make use of `withObject`, and to use a human readable string instead of a type name in error messages whenever possible. For instance:
- before: `expected Object for Object, but encountered X`
after: `expected Object for add computed field, but encountered X`
- before: `Expecting an object for update query`
after: `expected Object for update query, but encountered X`
This PR also renames `CreateFunctionPermission` to `FunctionPermissionArgument`, to remove the quite surprising `type DropFunctionPermission = CreateFunctionPermission`.
This PR also deletes some dead code, mostly in RQL.DML.
This PR also moves a PG-specific source resolving function from DDL.Schema.Source to the only place where it is used: App.hs.
https://github.com/hasura/graphql-engine-mono/pull/1844
GitOrigin-RevId: a594521194bb7fe6a111b02a9e099896f9fed59c
2021-07-27 13:41:42 +03:00
|
|
|
$(deriveFromJSON hasuraJSON ''RenameSource)
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
runRenameSource ::
|
|
|
|
forall m.
|
|
|
|
(MonadError QErr m, CacheRWM m, MetadataM m) =>
|
|
|
|
RenameSource ->
|
|
|
|
m EncJSON
|
2021-05-24 16:13:08 +03:00
|
|
|
runRenameSource RenameSource {..} = do
|
|
|
|
sources <- scSources <$> askSchemaCache
|
|
|
|
|
|
|
|
unless (HM.member _rmName sources) $
|
|
|
|
throw400 NotExists $ "Could not find source with name " <>> _rmName
|
|
|
|
|
|
|
|
when (HM.member _rmNewName sources) $
|
|
|
|
throw400 AlreadyExists $ "Source with name " <> _rmNewName <<> " already exists"
|
|
|
|
|
|
|
|
let metadataModifier =
|
2021-09-24 01:56:37 +03:00
|
|
|
MetadataModifier $
|
|
|
|
metaSources %~ renameBackendSourceMetadata _rmName _rmNewName
|
2021-05-24 16:13:08 +03:00
|
|
|
buildSchemaCacheFor (MOSource _rmNewName) metadataModifier
|
|
|
|
|
|
|
|
pure successMsg
|
|
|
|
where
|
2021-09-24 01:56:37 +03:00
|
|
|
renameBackendSourceMetadata ::
|
|
|
|
SourceName ->
|
|
|
|
SourceName ->
|
|
|
|
OMap.InsOrdHashMap SourceName BackendSourceMetadata ->
|
|
|
|
OMap.InsOrdHashMap SourceName BackendSourceMetadata
|
2021-05-24 16:13:08 +03:00
|
|
|
renameBackendSourceMetadata oldKey newKey m =
|
|
|
|
case OMap.lookup oldKey m of
|
|
|
|
Just val ->
|
|
|
|
OMap.insert
|
|
|
|
newKey
|
|
|
|
(AB.mapBackend val (renameSource newKey))
|
2021-09-24 01:56:37 +03:00
|
|
|
. OMap.delete oldKey
|
|
|
|
$ m
|
2021-05-24 16:13:08 +03:00
|
|
|
Nothing -> m
|
|
|
|
|
|
|
|
renameSource :: forall b. SourceName -> SourceMetadata b -> SourceMetadata b
|
2021-09-24 01:56:37 +03:00
|
|
|
renameSource newName metadata = metadata {_smName = newName}
|
Clean metadata arguments
## Description
Thanks to #1664, the Metadata API types no longer require a `ToJSON` instance. This PR follows up with a cleanup of the types of the arguments to the metadata API:
- whenever possible, it moves those argument types to where they're used (RQL.DDL.*)
- it removes all unrequired instances (mostly `ToJSON`)
This PR does not attempt to do it for _all_ such argument types. For some of the metadata operations, the type used to describe the argument to the API and used to represent the value in the metadata are one and the same (like for `CreateEndpoint`). Sometimes, the two types are intertwined in complex ways (`RemoteRelationship` and `RemoteRelationshipDef`). In the spirit of only doing uncontroversial cleaning work, this PR only moves types that are not used outside of RQL.DDL.
Furthermore, this is a small step towards separating the different types all jumbled together in RQL.Types.
## Notes
This PR also improves several `FromJSON` instances to make use of `withObject`, and to use a human readable string instead of a type name in error messages whenever possible. For instance:
- before: `expected Object for Object, but encountered X`
after: `expected Object for add computed field, but encountered X`
- before: `Expecting an object for update query`
after: `expected Object for update query, but encountered X`
This PR also renames `CreateFunctionPermission` to `FunctionPermissionArgument`, to remove the quite surprising `type DropFunctionPermission = CreateFunctionPermission`.
This PR also deletes some dead code, mostly in RQL.DML.
This PR also moves a PG-specific source resolving function from DDL.Schema.Source to the only place where it is used: App.hs.
https://github.com/hasura/graphql-engine-mono/pull/1844
GitOrigin-RevId: a594521194bb7fe6a111b02a9e099896f9fed59c
2021-07-27 13:41:42 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Drop source
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
data DropSource = DropSource
|
|
|
|
{ _dsName :: !SourceName,
|
|
|
|
_dsCascade :: !Bool
|
|
|
|
}
|
|
|
|
deriving (Show, Eq)
|
Clean metadata arguments
## Description
Thanks to #1664, the Metadata API types no longer require a `ToJSON` instance. This PR follows up with a cleanup of the types of the arguments to the metadata API:
- whenever possible, it moves those argument types to where they're used (RQL.DDL.*)
- it removes all unrequired instances (mostly `ToJSON`)
This PR does not attempt to do it for _all_ such argument types. For some of the metadata operations, the type used to describe the argument to the API and used to represent the value in the metadata are one and the same (like for `CreateEndpoint`). Sometimes, the two types are intertwined in complex ways (`RemoteRelationship` and `RemoteRelationshipDef`). In the spirit of only doing uncontroversial cleaning work, this PR only moves types that are not used outside of RQL.DDL.
Furthermore, this is a small step towards separating the different types all jumbled together in RQL.Types.
## Notes
This PR also improves several `FromJSON` instances to make use of `withObject`, and to use a human readable string instead of a type name in error messages whenever possible. For instance:
- before: `expected Object for Object, but encountered X`
after: `expected Object for add computed field, but encountered X`
- before: `Expecting an object for update query`
after: `expected Object for update query, but encountered X`
This PR also renames `CreateFunctionPermission` to `FunctionPermissionArgument`, to remove the quite surprising `type DropFunctionPermission = CreateFunctionPermission`.
This PR also deletes some dead code, mostly in RQL.DML.
This PR also moves a PG-specific source resolving function from DDL.Schema.Source to the only place where it is used: App.hs.
https://github.com/hasura/graphql-engine-mono/pull/1844
GitOrigin-RevId: a594521194bb7fe6a111b02a9e099896f9fed59c
2021-07-27 13:41:42 +03:00
|
|
|
|
|
|
|
instance FromJSON DropSource where
|
2021-09-20 22:49:33 +03:00
|
|
|
parseJSON = withObject "DropSource" $ \o ->
|
Clean metadata arguments
## Description
Thanks to #1664, the Metadata API types no longer require a `ToJSON` instance. This PR follows up with a cleanup of the types of the arguments to the metadata API:
- whenever possible, it moves those argument types to where they're used (RQL.DDL.*)
- it removes all unrequired instances (mostly `ToJSON`)
This PR does not attempt to do it for _all_ such argument types. For some of the metadata operations, the type used to describe the argument to the API and used to represent the value in the metadata are one and the same (like for `CreateEndpoint`). Sometimes, the two types are intertwined in complex ways (`RemoteRelationship` and `RemoteRelationshipDef`). In the spirit of only doing uncontroversial cleaning work, this PR only moves types that are not used outside of RQL.DDL.
Furthermore, this is a small step towards separating the different types all jumbled together in RQL.Types.
## Notes
This PR also improves several `FromJSON` instances to make use of `withObject`, and to use a human readable string instead of a type name in error messages whenever possible. For instance:
- before: `expected Object for Object, but encountered X`
after: `expected Object for add computed field, but encountered X`
- before: `Expecting an object for update query`
after: `expected Object for update query, but encountered X`
This PR also renames `CreateFunctionPermission` to `FunctionPermissionArgument`, to remove the quite surprising `type DropFunctionPermission = CreateFunctionPermission`.
This PR also deletes some dead code, mostly in RQL.DML.
This PR also moves a PG-specific source resolving function from DDL.Schema.Source to the only place where it is used: App.hs.
https://github.com/hasura/graphql-engine-mono/pull/1844
GitOrigin-RevId: a594521194bb7fe6a111b02a9e099896f9fed59c
2021-07-27 13:41:42 +03:00
|
|
|
DropSource <$> o .: "name" <*> o .:? "cascade" .!= False
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
runDropSource ::
|
|
|
|
forall m r.
|
|
|
|
( MonadError QErr m,
|
|
|
|
CacheRWM m,
|
|
|
|
MonadIO m,
|
|
|
|
MonadBaseControl IO m,
|
|
|
|
MetadataM m,
|
|
|
|
MonadReader r m,
|
|
|
|
Has (L.Logger L.Hasura) r
|
|
|
|
) =>
|
|
|
|
DropSource ->
|
|
|
|
m EncJSON
|
2021-02-23 20:37:27 +03:00
|
|
|
runDropSource (DropSource name cascade) = do
|
2021-01-07 12:04:22 +03:00
|
|
|
sc <- askSchemaCache
|
2021-07-27 18:14:12 +03:00
|
|
|
logger <- asks getter
|
2021-02-23 20:37:27 +03:00
|
|
|
let sources = scSources sc
|
2021-03-02 07:26:31 +03:00
|
|
|
case HM.lookup name sources of
|
|
|
|
Just backendSourceInfo ->
|
2021-07-27 18:14:12 +03:00
|
|
|
AB.dispatchAnyBackend @BackendMetadata backendSourceInfo $ dropSource logger sc
|
2021-03-02 07:26:31 +03:00
|
|
|
Nothing -> do
|
|
|
|
metadata <- getMetadata
|
2021-09-24 01:56:37 +03:00
|
|
|
void $
|
|
|
|
onNothing (metadata ^. metaSources . at name) $
|
2021-03-02 07:26:31 +03:00
|
|
|
throw400 NotExists $ "source with name " <> name <<> " does not exist"
|
|
|
|
if cascade
|
2021-09-24 01:56:37 +03:00
|
|
|
then -- Without sourceInfo we can't cascade, so throw an error
|
2021-03-02 07:26:31 +03:00
|
|
|
throw400 Unexpected $ "source with name " <> name <<> " is inconsistent"
|
2021-09-24 01:56:37 +03:00
|
|
|
else -- Drop source from metadata
|
2021-03-02 07:26:31 +03:00
|
|
|
buildSchemaCacheFor (MOSource name) dropSourceMetadataModifier
|
2021-02-23 20:37:27 +03:00
|
|
|
pure successMsg
|
|
|
|
where
|
2021-07-27 18:14:12 +03:00
|
|
|
dropSource :: forall b. (BackendMetadata b) => L.Logger L.Hasura -> SchemaCache -> SourceInfo b -> m ()
|
|
|
|
dropSource logger sc sourceInfo = do
|
2021-02-23 20:37:27 +03:00
|
|
|
let sourceConfig = _siConfiguration sourceInfo
|
2021-09-24 01:56:37 +03:00
|
|
|
let indirectDeps =
|
|
|
|
mapMaybe getIndirectDep $
|
|
|
|
getDependentObjs sc (SOSource name)
|
2021-01-07 12:04:22 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
when (not cascade && indirectDeps /= []) $
|
|
|
|
reportDepsExt
|
|
|
|
(map (SOSourceObj name . AB.mkAnyBackend) indirectDeps)
|
|
|
|
[]
|
2021-01-07 12:04:22 +03:00
|
|
|
|
2021-02-23 20:37:27 +03:00
|
|
|
metadataModifier <- execWriterT $ do
|
|
|
|
mapM_ (purgeDependentObject name >=> tell) indirectDeps
|
2021-03-02 07:26:31 +03:00
|
|
|
tell dropSourceMetadataModifier
|
2021-01-07 12:04:22 +03:00
|
|
|
|
2021-02-23 20:37:27 +03:00
|
|
|
buildSchemaCacheFor (MOSource name) metadataModifier
|
2021-07-27 18:14:12 +03:00
|
|
|
|
|
|
|
-- We only log errors that arise from 'postDropSourceHook' here, and not
|
|
|
|
-- surface them as end-user errors. See comment
|
|
|
|
-- https://github.com/hasura/graphql-engine/issues/7092#issuecomment-873845282
|
|
|
|
runExceptT (postDropSourceHook @b sourceConfig) >>= either logDropSourceHookError pure
|
2021-02-23 20:37:27 +03:00
|
|
|
where
|
2021-07-27 18:14:12 +03:00
|
|
|
logDropSourceHookError err =
|
2021-09-24 01:56:37 +03:00
|
|
|
let msg =
|
|
|
|
"Error executing cleanup actions after removing source '" <> toTxt name
|
|
|
|
<> "'. Consider cleaning up tables in hdb_catalog schema manually."
|
|
|
|
in L.unLogger logger $ MetadataLog L.LevelWarn msg (J.toJSON err)
|
2021-07-27 18:14:12 +03:00
|
|
|
|
2021-02-23 20:37:27 +03:00
|
|
|
getIndirectDep :: SchemaObjId -> Maybe (SourceObjId b)
|
|
|
|
getIndirectDep = \case
|
2021-03-15 16:02:58 +03:00
|
|
|
SOSourceObj s o ->
|
|
|
|
if s == name
|
|
|
|
then Nothing
|
2021-09-24 01:56:37 +03:00
|
|
|
else -- consider only *this* backend specific dependencies
|
|
|
|
AB.unpackAnyBackend o
|
|
|
|
_ -> Nothing
|
2021-03-02 07:26:31 +03:00
|
|
|
|
|
|
|
dropSourceMetadataModifier = MetadataModifier $ metaSources %~ OMap.delete name
|