graphql-engine/server/src-lib/Hasura/RQL/DDL/Schema/Common.hs
Rakesh Emmadi e43d0273e0 server: mssql: apply schema changes by mssql_run_sql DDL on metadata (fix #779)
Co-authored-by: Antoine Leblanc <1618949+nicuveo@users.noreply.github.com>
GitOrigin-RevId: 6905d5914c8a698445c0ef03d6a8303747701e1c
2021-05-27 15:07:10 +00:00

35 lines
1.3 KiB
Haskell

module Hasura.RQL.DDL.Schema.Common where
import Hasura.Prelude
import qualified Hasura.SQL.AnyBackend as AB
import Hasura.Base.Error
import Hasura.RQL.DDL.ComputedField
import Hasura.RQL.DDL.EventTrigger
import Hasura.RQL.DDL.Permission
import Hasura.RQL.DDL.Relationship
import Hasura.RQL.DDL.RemoteRelationship
import Hasura.RQL.DDL.Schema.Function
import Hasura.RQL.Types
purgeDependentObject
:: forall b m
. (MonadError QErr m, BackendMetadata b)
=> SourceName -> SourceObjId b -> m MetadataModifier
purgeDependentObject source sourceObjId = case sourceObjId of
SOITableObj tn tableObj -> pure $ MetadataModifier $
tableMetadataSetter @b source tn %~ case tableObj of
TOPerm rn pt -> dropPermissionInMetadata rn pt
TORel rn -> dropRelationshipInMetadata rn
TOTrigger trn -> dropEventTriggerInMetadata trn
TOComputedField ccn -> dropComputedFieldInMetadata ccn
TORemoteRel rrn -> dropRemoteRelationshipInMetadata rrn
_ -> id
SOIFunction qf -> pure $ dropFunctionInMetadata @b source qf
_ ->
throw500
$ "unexpected dependent object: "
<> reportSchemaObj (SOSourceObj source $ AB.mkAnyBackend sourceObjId)