server: fetchTableMetadata does not send tables for CockroachDB

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5593
GitOrigin-RevId: 3a2f4ab30e8900494f32870b5e3d345877744071
This commit is contained in:
Daniel Harvey 2022-08-24 10:36:30 +01:00 committed by hasura-bot
parent e7522978c5
commit 066e2d6c7b
3 changed files with 54 additions and 5 deletions

View File

@ -27,7 +27,8 @@ import Database.PG.Query qualified as Q
import Hasura.Backends.Postgres.Connection.MonadTx
import Hasura.Backends.Postgres.DDL.EventTrigger
import Hasura.Backends.Postgres.DDL.Source
( ToMetadataFetchQuery,
( FetchTableMetadata,
ToMetadataFetchQuery,
fetchFunctionMetadata,
fetchTableMetadata,
)
@ -140,7 +141,7 @@ the metadata check as well. -}
-- | Fetch metadata of tracked tables/functions and build @'TableMeta'/@'FunctionMeta'
-- to calculate diff later in @'withMetadataCheck'.
fetchTablesFunctionsMetadata ::
(ToMetadataFetchQuery pgKind, BackendMetadata ('Postgres pgKind), MonadTx m) =>
(ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, BackendMetadata ('Postgres pgKind), MonadTx m) =>
TableCache ('Postgres pgKind) ->
[TableName ('Postgres pgKind)] ->
[FunctionName ('Postgres pgKind)] ->
@ -172,6 +173,7 @@ runRunSQL ::
forall (pgKind :: PostgresKind) m.
( BackendMetadata ('Postgres pgKind),
ToMetadataFetchQuery pgKind,
FetchTableMetadata pgKind,
CacheRWM m,
HasServerConfigCtx m,
MetadataM m,
@ -213,6 +215,7 @@ withMetadataCheck ::
forall (pgKind :: PostgresKind) a m.
( BackendMetadata ('Postgres pgKind),
ToMetadataFetchQuery pgKind,
FetchTableMetadata pgKind,
CacheRWM m,
HasServerConfigCtx m,
MetadataM m,
@ -263,6 +266,7 @@ runTxWithMetadataCheck ::
forall m a (pgKind :: PostgresKind).
( BackendMetadata ('Postgres pgKind),
ToMetadataFetchQuery pgKind,
FetchTableMetadata pgKind,
CacheRWM m,
MonadIO m,
MonadBaseControl IO m,

View File

@ -13,6 +13,7 @@
-- before adding any new migration if you haven't already looked at it.
module Hasura.Backends.Postgres.DDL.Source
( ToMetadataFetchQuery,
FetchTableMetadata,
fetchTableMetadata,
fetchFunctionMetadata,
prepareCatalog,
@ -151,7 +152,7 @@ logPGSourceCatalogMigrationLockedQueries logger sourceConfig = forever $ do
resolveDatabaseMetadata ::
forall pgKind m.
(Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, MonadIO m, MonadBaseControl IO m) =>
(Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, MonadIO m, MonadBaseControl IO m) =>
SourceMetadata ('Postgres pgKind) ->
SourceConfig ('Postgres pgKind) ->
SourceTypeCustomization ->
@ -323,13 +324,37 @@ upMigrationsUntil43 =
(migrationsFromFile [5 .. 40]) ++ migrationsFromFile [42 .. 43]
)
-- | We differentiate for CockroachDB and other PG implementations
-- as our CockroachDB table fetching SQL does not require table information,
-- and fails if it receives unused prepared arguments
-- this distinction should no longer be necessary if this issue is resolved:
-- https://github.com/cockroachdb/cockroach/issues/86375
class FetchTableMetadata (pgKind :: PostgresKind) where
fetchTableMetadata ::
forall m.
( Backend ('Postgres pgKind),
ToMetadataFetchQuery pgKind,
MonadTx m
) =>
[QualifiedTable] ->
m (DBTablesMetadata ('Postgres pgKind))
instance FetchTableMetadata 'Vanilla where
fetchTableMetadata = pgFetchTableMetadata
instance FetchTableMetadata 'Citus where
fetchTableMetadata = pgFetchTableMetadata
instance FetchTableMetadata 'Cockroach where
fetchTableMetadata = cockroachFetchTableMetadata
-- | Fetch Postgres metadata of all user tables
fetchTableMetadata ::
pgFetchTableMetadata ::
forall pgKind m.
(Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, MonadTx m) =>
[QualifiedTable] ->
m (DBTablesMetadata ('Postgres pgKind))
fetchTableMetadata tables = do
pgFetchTableMetadata tables = do
results <-
liftTx $
Q.withQE
@ -342,6 +367,25 @@ fetchTableMetadata tables = do
flip map results $
\(schema, table, Q.AltJ info) -> (QualifiedObject schema table, info)
-- | Fetch Cockroach metadata of all user tables
cockroachFetchTableMetadata ::
forall pgKind m.
(Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, MonadTx m) =>
[QualifiedTable] ->
m (DBTablesMetadata ('Postgres pgKind))
cockroachFetchTableMetadata _tables = do
results <-
liftTx $
Q.rawQE
defaultTxErrorHandler
(tableMetadata @pgKind)
[]
True
pure $
Map.fromList $
flip map results $
\(schema, table, Q.AltJ info) -> (QualifiedObject schema table, info)
-- | Fetch Postgres metadata for all user functions
fetchFunctionMetadata :: (MonadTx m) => [QualifiedFunction] -> m (DBFunctionsMetadata ('Postgres pgKind))
fetchFunctionMetadata functions = do

View File

@ -118,6 +118,7 @@ instance PostgresMetadata 'Cockroach where
instance
( Backend ('Postgres pgKind),
PostgresMetadata pgKind,
PG.FetchTableMetadata pgKind,
PG.ToMetadataFetchQuery pgKind
) =>
BackendMetadata ('Postgres pgKind)