From 6b03f8b0af5b7ac25d142ae783b1883512e87044 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Wed, 13 Jul 2022 16:19:59 +0100 Subject: [PATCH] server: remove systemDefined field from CoreFieldInfo PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5028 GitOrigin-RevId: 168dc2aeae12258231ddb8300a0aa2fe5817927c --- server/src-lib/Hasura/GraphQL/Schema/Common.hs | 3 +-- server/src-lib/Hasura/RQL/DDL/Schema/Table.hs | 5 +---- server/src-lib/Hasura/RQL/Types/SchemaCache.hs | 1 - server/src-lib/Hasura/RQL/Types/Table.hs | 2 -- server/src-lib/Hasura/Server/Telemetry.hs | 15 +++++++-------- server/src-test/Test/Parser/Internal.hs | 3 +-- 6 files changed, 10 insertions(+), 19 deletions(-) diff --git a/server/src-lib/Hasura/GraphQL/Schema/Common.hs b/server/src-lib/Hasura/GraphQL/Schema/Common.hs index 4b0d96bd8fa..f1db0e9afa8 100644 --- a/server/src-lib/Hasura/GraphQL/Schema/Common.hs +++ b/server/src-lib/Hasura/GraphQL/Schema/Common.hs @@ -283,9 +283,8 @@ mkDescriptionWith descM defaultTxt = G.Description $ case descM of -- got removed in PDV. OTOH, I’m not sure how prevalent this feature -- actually is takeValidTables :: forall b. Backend b => TableCache b -> TableCache b -takeValidTables = Map.filterWithKey graphQLTableFilter . Map.filter tableFilter +takeValidTables = Map.filterWithKey graphQLTableFilter where - tableFilter = not . isSystemDefined . _tciSystemDefined . _tiCoreInfo graphQLTableFilter tableName tableInfo = -- either the table name should be GraphQL compliant -- or it should have a GraphQL custom name set with it diff --git a/server/src-lib/Hasura/RQL/DDL/Schema/Table.hs b/server/src-lib/Hasura/RQL/DDL/Schema/Table.hs index e880ff52128..bd324ed7e32 100644 --- a/server/src-lib/Hasura/RQL/DDL/Schema/Table.hs +++ b/server/src-lib/Hasura/RQL/DDL/Schema/Table.hs @@ -334,11 +334,9 @@ unTrackExistingTableOrViewP1 :: m () unTrackExistingTableOrViewP1 (UntrackTable source vn _) = do schemaCache <- askSchemaCache - tableInfo <- + void $ unsafeTableInfo @b source vn (scSources schemaCache) `onNothing` throw400 AlreadyUntracked ("view/table already untracked : " <>> vn) - when (isSystemDefined $ _tciSystemDefined $ _tiCoreInfo tableInfo) $ - throw400 NotSupported $ vn <<> " is system defined, cannot untrack" unTrackExistingTableOrViewP2 :: forall b m. @@ -499,7 +497,6 @@ buildTableCache = Inc.cache proc (source, sourceConfig, dbTablesMeta, tableBuild -< TableCoreInfo { _tciName = name, - _tciSystemDefined = SystemDefined False, _tciFieldInfoMap = columnMap, _tciPrimaryKey = primaryKey, _tciUniqueConstraints = _ptmiUniqueConstraints metadataTable, diff --git a/server/src-lib/Hasura/RQL/Types/SchemaCache.hs b/server/src-lib/Hasura/RQL/Types/SchemaCache.hs index 89e7525d2c9..7d9ba592882 100644 --- a/server/src-lib/Hasura/RQL/Types/SchemaCache.hs +++ b/server/src-lib/Hasura/RQL/Types/SchemaCache.hs @@ -36,7 +36,6 @@ module Hasura.RQL.Types.SchemaCache TableCoreInfo, tciName, tciDescription, - tciSystemDefined, tciFieldInfoMap, tciPrimaryKey, tciUniqueConstraints, diff --git a/server/src-lib/Hasura/RQL/Types/Table.hs b/server/src-lib/Hasura/RQL/Types/Table.hs index 17dfd9a4a56..a83490f7f1e 100644 --- a/server/src-lib/Hasura/RQL/Types/Table.hs +++ b/server/src-lib/Hasura/RQL/Types/Table.hs @@ -71,7 +71,6 @@ module Hasura.RQL.Types.Table tciForeignKeys, tciName, tciPrimaryKey, - tciSystemDefined, tciUniqueConstraints, tciUniqueOrPrimaryKeyConstraints, tciViewInfo, @@ -854,7 +853,6 @@ instance Backend b => FromJSON (ForeignKey b) where data TableCoreInfoG (b :: BackendType) field primaryKeyColumn = TableCoreInfo { _tciName :: TableName b, _tciDescription :: Maybe PG.PGDescription, -- TODO make into type family? - _tciSystemDefined :: SystemDefined, _tciFieldInfoMap :: FieldInfoMap field, _tciPrimaryKey :: Maybe (PrimaryKey b primaryKeyColumn), -- | Does /not/ include the primary key; use 'tciUniqueOrPrimaryKeyConstraints' if you need both. diff --git a/server/src-lib/Hasura/Server/Telemetry.hs b/server/src-lib/Hasura/Server/Telemetry.hs index c4696e93735..819be84151f 100644 --- a/server/src-lib/Hasura/Server/Telemetry.hs +++ b/server/src-lib/Hasura/Server/Telemetry.hs @@ -231,13 +231,13 @@ computeMetrics :: Maybe ActionCache -> Metrics computeMetrics sourceInfo _mtServiceTimings remoteSchemaMap actionCache = - let _mtTables = countUserTables (isNothing . _tciViewInfo . _tiCoreInfo) - _mtViews = countUserTables (isJust . _tciViewInfo . _tiCoreInfo) - _mtEnumTables = countUserTables (isJust . _tciEnumValues . _tiCoreInfo) - allRels = join $ Map.elems $ Map.map (getRels . _tciFieldInfoMap . _tiCoreInfo) userTables + let _mtTables = countSourceTables (isNothing . _tciViewInfo . _tiCoreInfo) + _mtViews = countSourceTables (isJust . _tciViewInfo . _tiCoreInfo) + _mtEnumTables = countSourceTables (isJust . _tciEnumValues . _tiCoreInfo) + allRels = join $ Map.elems $ Map.map (getRels . _tciFieldInfoMap . _tiCoreInfo) sourceTableCache (manualRels, autoRels) = L.partition riIsManual allRels _mtRelationships = RelationshipMetric (length manualRels) (length autoRels) - rolePerms = join $ Map.elems $ Map.map permsOfTbl userTables + rolePerms = join $ Map.elems $ Map.map permsOfTbl sourceTableCache _pmRoles = length $ L.uniques $ fst <$> rolePerms allPerms = snd <$> rolePerms _pmInsert = calcPerms _permIns allPerms @@ -249,7 +249,7 @@ computeMetrics sourceInfo _mtServiceTimings remoteSchemaMap actionCache = _mtEventTriggers = Map.size $ Map.filter (not . Map.null) $ - Map.map _tiEventTriggerInfoMap userTables + Map.map _tiEventTriggerInfoMap sourceTableCache _mtRemoteSchemas = Map.size <$> remoteSchemaMap _mtFunctions = Map.size $ Map.filter (not . isSystemDefined . _fiSystemDefined) sourceFunctionCache _mtActions = computeActionsMetrics <$> actionCache @@ -257,8 +257,7 @@ computeMetrics sourceInfo _mtServiceTimings remoteSchemaMap actionCache = where sourceTableCache = _siTables sourceInfo sourceFunctionCache = _siFunctions sourceInfo - userTables = Map.filter (not . isSystemDefined . _tciSystemDefined . _tiCoreInfo) sourceTableCache - countUserTables predicate = length . filter predicate $ Map.elems userTables + countSourceTables predicate = length . filter predicate $ Map.elems sourceTableCache calcPerms :: (RolePermInfo b -> Maybe a) -> [RolePermInfo b] -> Int calcPerms fn perms = length $ mapMaybe fn perms diff --git a/server/src-test/Test/Parser/Internal.hs b/server/src-test/Test/Parser/Internal.hs index 89b85811299..7b902a334bc 100644 --- a/server/src-test/Test/Parser/Internal.hs +++ b/server/src-test/Test/Parser/Internal.hs @@ -23,7 +23,7 @@ import Hasura.RQL.IR.Root (RemoteRelationshipField) import Hasura.RQL.IR.Update (AnnotatedUpdateG (..)) import Hasura.RQL.IR.Value (UnpreparedValue (..)) import Hasura.RQL.Types.Column (ColumnInfo (..), ColumnMutability (..), ColumnType (..)) -import Hasura.RQL.Types.Common (Comment (..), FieldName (..), SystemDefined (..)) +import Hasura.RQL.Types.Common (Comment (..), FieldName (..)) import Hasura.RQL.Types.Instances () import Hasura.RQL.Types.Permission (AllowedRootFields (..)) import Hasura.RQL.Types.Source (SourceInfo) @@ -136,7 +136,6 @@ mkParser table cib = TableCoreInfo { _tciName = table, _tciDescription = Nothing, - _tciSystemDefined = SystemDefined False, _tciFieldInfoMap = fieldInfoMap, _tciPrimaryKey = Nothing, _tciUniqueConstraints = mempty,