Safe Haskell | None |
---|---|
Language | Haskell2010 |
Postgres DDL Source
A Source is a connected database. One can have multiple sources of the same kind (e.g. Postgres).
This module provides ways to fetch, update, and deal with table and function metadata and hdb_catalog migrations for a Postgres Source.
NOTE: Please have a look at the `serverdocumentationmigration-guidelines.md` before adding any new migration if you haven't already looked at it.
Synopsis
- class ToMetadataFetchQuery (pgKind :: PostgresKind) where
- tableMetadata :: Query
- resolveSourceConfig :: (MonadIO m, MonadResolveSource m) => Logger Hasura -> SourceName -> PostgresConnConfiguration -> BackendSourceKind ('Postgres pgKind) -> BackendConfig ('Postgres pgKind) -> Environment -> manager -> m (Either QErr (SourceConfig ('Postgres pgKind)))
- data PGSourceLockQuery = PGSourceLockQuery {
- _psqaQuery :: Text
- _psqaLockGranted :: Maybe Bool
- _psqaLockMode :: Text
- _psqaTransactionStartTime :: UTCTime
- _psqaQueryStartTime :: UTCTime
- _psqaWaitEventType :: Text
- _psqaBlockingQuery :: Text
- newtype PGSourceLockQueryError = PGSourceLockQueryError QErr
- logPGSourceCatalogMigrationLockedQueries :: MonadIO m => Logger Hasura -> PGSourceConfig -> m Void
- resolveDatabaseMetadata :: forall pgKind m. (Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchFunctionMetadata pgKind, FetchTableMetadata pgKind, MonadIO m, MonadBaseControl IO m) => SourceMetadata ('Postgres pgKind) -> SourceConfig ('Postgres pgKind) -> SourceTypeCustomization -> m (Either QErr (ResolvedSource ('Postgres pgKind)))
- prepareCatalog :: (MonadIO m, MonadBaseControl IO m) => SourceConfig ('Postgres pgKind) -> ExceptT QErr m RecreateEventTriggers
- migrateSourceCatalog :: MonadTx m => m RecreateEventTriggers
- migrateSourceCatalogFrom :: MonadTx m => SourceCatalogVersion pgKind -> m RecreateEventTriggers
- sourceMigrations :: [(SourceCatalogVersion pgKind, TxE QErr ())]
- upMigrationsUntil43 :: [(MetadataCatalogVersion, TxE QErr ())]
- class FetchTableMetadata (pgKind :: PostgresKind) where
- fetchTableMetadata :: forall m. (Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, MonadTx m) => [QualifiedTable] -> m (DBTablesMetadata ('Postgres pgKind))
- pgFetchTableMetadata :: forall pgKind m. (Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, MonadTx m) => [QualifiedTable] -> m (DBTablesMetadata ('Postgres pgKind))
- cockroachFetchTableMetadata :: forall pgKind m. (Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, MonadTx m) => [QualifiedTable] -> m (DBTablesMetadata ('Postgres pgKind))
- class FetchFunctionMetadata (pgKind :: PostgresKind) where
- fetchFunctionMetadata :: MonadTx m => [QualifiedFunction] -> m (DBFunctionsMetadata ('Postgres pgKind))
- pgFetchFunctionMetadata :: MonadTx m => [QualifiedFunction] -> m (DBFunctionsMetadata ('Postgres pgKind))
- fetchPgScalars :: MonadTx m => m (HashSet PGScalarType)
- postDropSourceHook :: (MonadIO m, MonadError QErr m, MonadBaseControl IO m) => SourceConfig ('Postgres pgKind) -> TableEventTriggers ('Postgres pgKind) -> m ()
Documentation
class ToMetadataFetchQuery (pgKind :: PostgresKind) where Source #
We differentiate the handling of metadata between Citus, Cockroach and Vanilla Postgres because Citus imposes limitations on the types of joins that it permits, which then limits the types of relations that we can track.
tableMetadata :: Query Source #
Instances
ToMetadataFetchQuery 'Vanilla Source # | |
Defined in Hasura.Backends.Postgres.DDL.Source tableMetadata :: Query Source # | |
ToMetadataFetchQuery 'Citus Source # | |
Defined in Hasura.Backends.Postgres.DDL.Source tableMetadata :: Query Source # | |
ToMetadataFetchQuery 'Cockroach Source # | |
Defined in Hasura.Backends.Postgres.DDL.Source tableMetadata :: Query Source # |
resolveSourceConfig :: (MonadIO m, MonadResolveSource m) => Logger Hasura -> SourceName -> PostgresConnConfiguration -> BackendSourceKind ('Postgres pgKind) -> BackendConfig ('Postgres pgKind) -> Environment -> manager -> m (Either QErr (SourceConfig ('Postgres pgKind))) Source #
data PGSourceLockQuery Source #
PGSourceLockQuery
is a data type which represents the contents of a single object of the
locked queries which are queried from the pg_stat_activity
. See logPGSourceCatalogMigrationLockedQueries
.
PGSourceLockQuery | |
|
logPGSourceCatalogMigrationLockedQueries :: MonadIO m => Logger Hasura -> PGSourceConfig -> m Void Source #
logPGSourceCatalogMigrationLockedQueries
as the name suggests logs
the queries which are blocking in the database. This function is called
asynchronously from initCatalogIfNeeded
while the source catalog is being
migrated.
NOTE: When there are no locking queries present in the database, nothing will be logged.
resolveDatabaseMetadata :: forall pgKind m. (Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchFunctionMetadata pgKind, FetchTableMetadata pgKind, MonadIO m, MonadBaseControl IO m) => SourceMetadata ('Postgres pgKind) -> SourceConfig ('Postgres pgKind) -> SourceTypeCustomization -> m (Either QErr (ResolvedSource ('Postgres pgKind))) Source #
prepareCatalog :: (MonadIO m, MonadBaseControl IO m) => SourceConfig ('Postgres pgKind) -> ExceptT QErr m RecreateEventTriggers Source #
Initialise catalog tables for a source, including those required by the event delivery subsystem.
migrateSourceCatalog :: MonadTx m => m RecreateEventTriggers Source #
migrateSourceCatalogFrom :: MonadTx m => SourceCatalogVersion pgKind -> m RecreateEventTriggers Source #
migrateSourceCatalogFrom
migrates the catalog from a lower to a higher version.
When there are any changes in the source catalog, then re-create the existing event
triggers in the metadata. This is done so that the event triggers be compatible with the
changes introduced in the newly added source catalog migrations. When the source is already
in the latest catalog version, we do nothing because nothing has changed w.r.t the source catalog
so recreating the event triggers will only be extraneous.
sourceMigrations :: [(SourceCatalogVersion pgKind, TxE QErr ())] Source #
upMigrationsUntil43 :: [(MetadataCatalogVersion, TxE QErr ())] Source #
class FetchTableMetadata (pgKind :: PostgresKind) where Source #
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
fetchTableMetadata :: forall m. (Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, MonadTx m) => [QualifiedTable] -> m (DBTablesMetadata ('Postgres pgKind)) Source #
Instances
FetchTableMetadata 'Vanilla Source # | |
Defined in Hasura.Backends.Postgres.DDL.Source fetchTableMetadata :: (Backend ('Postgres 'Vanilla), ToMetadataFetchQuery 'Vanilla, MonadTx m) => [QualifiedTable] -> m (DBTablesMetadata ('Postgres 'Vanilla)) Source # | |
FetchTableMetadata 'Citus Source # | |
Defined in Hasura.Backends.Postgres.DDL.Source fetchTableMetadata :: (Backend ('Postgres 'Citus), ToMetadataFetchQuery 'Citus, MonadTx m) => [QualifiedTable] -> m (DBTablesMetadata ('Postgres 'Citus)) Source # | |
FetchTableMetadata 'Cockroach Source # | |
Defined in Hasura.Backends.Postgres.DDL.Source fetchTableMetadata :: (Backend ('Postgres 'Cockroach), ToMetadataFetchQuery 'Cockroach, MonadTx m) => [QualifiedTable] -> m (DBTablesMetadata ('Postgres 'Cockroach)) Source # |
pgFetchTableMetadata :: forall pgKind m. (Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, MonadTx m) => [QualifiedTable] -> m (DBTablesMetadata ('Postgres pgKind)) Source #
Fetch Postgres metadata of all user tables
cockroachFetchTableMetadata :: forall pgKind m. (Backend ('Postgres pgKind), ToMetadataFetchQuery pgKind, MonadTx m) => [QualifiedTable] -> m (DBTablesMetadata ('Postgres pgKind)) Source #
Fetch Cockroach metadata of all user tables
class FetchFunctionMetadata (pgKind :: PostgresKind) where Source #
fetchFunctionMetadata :: MonadTx m => [QualifiedFunction] -> m (DBFunctionsMetadata ('Postgres pgKind)) Source #
Instances
FetchFunctionMetadata 'Vanilla Source # | |
Defined in Hasura.Backends.Postgres.DDL.Source fetchFunctionMetadata :: MonadTx m => [QualifiedFunction] -> m (DBFunctionsMetadata ('Postgres 'Vanilla)) Source # | |
FetchFunctionMetadata 'Citus Source # | |
Defined in Hasura.Backends.Postgres.DDL.Source fetchFunctionMetadata :: MonadTx m => [QualifiedFunction] -> m (DBFunctionsMetadata ('Postgres 'Citus)) Source # | |
FetchFunctionMetadata 'Cockroach Source # | |
Defined in Hasura.Backends.Postgres.DDL.Source fetchFunctionMetadata :: MonadTx m => [QualifiedFunction] -> m (DBFunctionsMetadata ('Postgres 'Cockroach)) Source # |
pgFetchFunctionMetadata :: MonadTx m => [QualifiedFunction] -> m (DBFunctionsMetadata ('Postgres pgKind)) Source #
Fetch Postgres metadata for all user functions
fetchPgScalars :: MonadTx m => m (HashSet PGScalarType) Source #
Fetch all scalar types from Postgres
postDropSourceHook :: (MonadIO m, MonadError QErr m, MonadBaseControl IO m) => SourceConfig ('Postgres pgKind) -> TableEventTriggers ('Postgres pgKind) -> m () Source #
Clean source database after dropping in metadata