diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eb8f8d8e47..6b90150f306 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Event Triggers support has been added for MS SQL Server. Now, you can invoke ext ### Bug fixes and improvements +- server: add `*_update_source` API and modify behaviour of `*_add_source` API (See [docs](https://hasura.io/docs/latest/graphql/core/api-reference/metadata-api/source/) ) - server: support limit in BigQuery computed fields (fix #8562) - server: improve GraphQL query parsing time and per-query memory allocation - console: allow schemas prefixed with `pg`, but not `pg_` (fix #8435) diff --git a/docs/docs/graphql/core/api-reference/metadata-api/index.mdx b/docs/docs/graphql/core/api-reference/metadata-api/index.mdx index b9e07cb34ee..33adbd2f01d 100644 --- a/docs/docs/graphql/core/api-reference/metadata-api/index.mdx +++ b/docs/docs/graphql/core/api-reference/metadata-api/index.mdx @@ -73,6 +73,7 @@ The various types of queries are listed in the following table: | [pg_drop_source](/graphql/core/api-reference/metadata-api/source.mdx#metadata-pg-drop-source) | [pg_drop_source_args](/graphql/core/api-reference/metadata-api/source.mdx#metadata-pg-drop-source-syntax) | 1 | Remove a Postgres database | | [pg_track_table](/graphql/core/api-reference/metadata-api/table-view.mdx#metadata-pg-track-table) | [pg_track_table_args](/graphql/core/api-reference/metadata-api/table-view.mdx#metadata-pg-track-table-syntax) | 1 | Add a Postgres table/view with configuration | | [pg_untrack_table](/graphql/core/api-reference/metadata-api/table-view.mdx#metadata-pg-untrack-table) | [pg_untrack_table_args](/graphql/core/api-reference/metadata-api/table-view.mdx#metadata-pg-untrack-table-syntax) | 1 | Remove a Postgres table/view | +| [pg_update_source](/graphql/core/api-reference/metadata-api/source.mdx#metadata-pg-update-source) | [pg_update_source_args](/graphql/core/api-reference/metadata-api/source.mdx#metadata-pg-update-source-syntax) | 1 | Update a Postgres database | | [pg_set_table_customization](/graphql/core/api-reference/metadata-api/table-view.mdx#metadata-pg-set-table-customization) | [pg_set_table_customization_args](/graphql/core/api-reference/metadata-api/table-view.mdx#metadata-pg-set-table-customization-syntax) | 1 | Set table customization of an already tracked Postgres table | | [pg_set_table_is_enum](/graphql/core/api-reference/metadata-api/table-view.mdx#metadata-pg-set-table-is-enum) | [pg_set_table_is_enum_args](/graphql/core/api-reference/metadata-api/table-view.mdx#metadata-pg-set-table-is-enum-syntax) | 1 | Set a tracked Postgres table as an enum table | | [pg_track_function](/graphql/core/api-reference/metadata-api/custom-functions.mdx#metadata-pg-track-function) | [pg_track_function_args](/graphql/core/api-reference/metadata-api/custom-functions.mdx#metadata-pg-track-function-syntax) | 1 | Add a Postgres SQL function with configuration | @@ -109,6 +110,7 @@ The various types of queries are listed in the following table: | [mssql_drop_source](/graphql/core/api-reference/metadata-api/source.mdx#mssql-drop-source) | [mssql_drop_source_args](/graphql/core/api-reference/metadata-api/source.mdx#mssql-drop-source-syntax) | 1 | Remove an MS SQL Server database | | [mssql_track_table](/graphql/core/api-reference/metadata-api/table-view.mdx#mssql-track-table) | [mssql_track_table_args](/graphql/core/api-reference/metadata-api/table-view.mdx#mssql-track-table-syntax) | 1 | Add an MS SQL Server table/view with configuration | | [mssql_untrack_table](/graphql/core/api-reference/metadata-api/table-view.mdx#mssql-untrack-table) | [mssql_untrack_table_args](/graphql/core/api-reference/metadata-api/table-view.mdx#mssql-untrack-table-syntax) | 1 | Remove an MS SQL Server table/view | +| [mssql_update_source](/graphql/core/api-reference/metadata-api/source.mdx#mssql-update-source) | [mssql_update_source_args](/graphql/core/api-reference/metadata-api/source.mdx#mssql-update-source-syntax) | 1 | Update an MS SQL Server database | | [mssql_create_object_relationship](/graphql/core/api-reference/metadata-api/relationship.mdx#mssql-create-object-relationship) | [mssql_create_object_relationship_args](/graphql/core/api-reference/metadata-api/relationship.mdx#mssql-create-object-relationship-syntax) | 1 | Define a new object relationship between MS SQL Server tables/views | | [mssql_create_array_relationship](/graphql/core/api-reference/metadata-api/relationship.mdx#mssql-create-array-relationship) | [mssql_create_array_relationship_args](/graphql/core/api-reference/metadata-api/relationship.mdx#mssql-create-array-relationship-syntax) | 1 | Define a new array relationship between MS SQL Server tables/views | | [mssql_drop_relationship](/graphql/core/api-reference/metadata-api/relationship.mdx#mssql-drop-relationship) | [mssql_drop_relationship_args](/graphql/core/api-reference/metadata-api/relationship.mdx#mssql-drop-relationship-syntax) | 1 | Drop an existing MS SQL Server relationship | diff --git a/docs/docs/graphql/core/api-reference/metadata-api/source.mdx b/docs/docs/graphql/core/api-reference/metadata-api/source.mdx index 01819509bd9..6e28525a5e6 100644 --- a/docs/docs/graphql/core/api-reference/metadata-api/source.mdx +++ b/docs/docs/graphql/core/api-reference/metadata-api/source.mdx @@ -74,12 +74,19 @@ X-Hasura-Role: admin ### Args syntax {#metadata-pg-add-source-syntax} -| Key | Required | Schema | Description | -|-----------------------|----------|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------| -| name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the Postgres database | -| configuration | true | [PGConfiguration](/graphql/core/api-reference/syntax-defs.mdx#pgconfiguration) | Database connection configuration | -| replace_configuration | false | Boolean | If set to `true` the configuration will be replaced if the source with given name already exists (default: `false`) | -| customization | false | [SourceCustomization](/graphql/core/api-reference/syntax-defs.mdx#sourcecustomization) | Customize root fields and type names for the source | +| Key | Required | Schema | Description | +|-----------------------|----------|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------| +| name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the Postgres database | +| configuration | true | [PGConfiguration](/graphql/core/api-reference/syntax-defs.mdx#pgconfiguration) | Database connection configuration | +| replace_configuration | false | Boolean | If set to `true` the configuration and customization will be replaced if the source with given name already exists (default: `false`) | +| customization | false | [SourceCustomization](/graphql/core/api-reference/syntax-defs.mdx#sourcecustomization) | Customize root fields and type names for the source | + +:::tip Deprecated field + +The `replace_configuration` field is deprecated in favour of the +[pg_update_source API](/graphql/core/api-reference/metadata-api/source.mdx#metadata-pg-update-source). + +::: ## pg_drop_source {#metadata-pg-drop-source} @@ -137,6 +144,61 @@ Note that all settings are kept, only the name is changed. | name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the database | | new_name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the database | +## pg_update_source {#metadata-pg-update-source} + +`pg_update_source` is used to update Postgres source in Hasura. + +Update a database with name `pg1`: + +```http +POST /v1/metadata HTTP/1.1 +Content-Type: application/json +X-Hasura-Role: admin + +{ + "type": "pg_update_source", + "args": { + "name": "pg1", + "configuration": { + "connection_info": { + "database_url": { + "from_env": "" + }, + "pool_settings": { + "max_connections": 50, + "idle_timeout": 180, + "retries": 1, + "pool_timeout": 360, + "connection_lifetime": 600 + }, + "use_prepared_statements": true, + "isolation_level": "read-committed", + } + }, + "customization": { + "root_fields": { + "namespace": "some_field_name", + "prefix": "some_field_name_prefix", + "suffix": "some_field_name_suffix" + }, + "type_names": { + "prefix": "some_type_name_prefix", + "suffix": "some_type_name_suffix" + }, + "naming_convention": "hasura-default" + } + } +} +``` + +### Args syntax {#metadata-pg-update-source-syntax} + +| Key | Required | Schema | Description | +|-----------------------|----------|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------| +| name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the Postgres database | +| configuration | false | [PGConfiguration](/graphql/core/api-reference/syntax-defs.mdx#pgconfiguration) | Database connection configuration | +| customization | false | [SourceCustomization](/graphql/core/api-reference/syntax-defs.mdx#sourcecustomization) | Customize root fields and type names for the source | + ## mssql_add_source {#mssql-add-source} `mssql_add_source` is used to connect an MS SQL Server database to Hasura. @@ -180,12 +242,19 @@ X-Hasura-Role: admin ### Args syntax {#mssql-add-source-syntax} -| Key | Required | Schema | Description | -|-----------------------|----------|-------------------------------------------|---------------------------------------------------------------------------------------------------------------------| -| name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the MS SQL Server database | -| configuration | true | [MsSQLConfiguration](/graphql/core/api-reference/syntax-defs.mdx#mssqlconfiguration) | Database connection configuration | -| replace_configuration | false | Boolean | If set to `true` the configuration will be replaced if the source with given name already exists (default: `false`) | -| customization | false | [SourceCustomization](/graphql/core/api-reference/syntax-defs.mdx#sourcecustomization) | Customize root fields and type names for the source | +| Key | Required | Schema | Description | +|-----------------------|----------|----------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------| +| name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the MS SQL Server database | +| configuration | true | [MsSQLConfiguration](/graphql/core/api-reference/syntax-defs.mdx#mssqlconfiguration) | Database connection configuration | +| replace_configuration | false | Boolean | If set to `true` the configuration and customization will be replaced if the source with given name already exists (default: `false`) | +| customization | false | [SourceCustomization](/graphql/core/api-reference/syntax-defs.mdx#sourcecustomization) | Customize root fields and type names for the source | + +:::tip Deprecated field + +The `replace_configuration` field is deprecated in favour of the +[mssql_update_source API](/graphql/core/api-reference/metadata-api/source.mdx#mssql-update-source). + +::: ## mssql_drop_source {#mssql-drop-source} @@ -213,6 +282,55 @@ X-Hasura-Role: admin | name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the MS SQL Server database | | cascade | false | Boolean | When set to `true`, the effect (if possible) is cascaded to any metadata dependent objects (relationships, permissions etc.) from other sources (default: `false`) | +## mssql_update_source {#mssql-update-source} + +`mssql_update_source` is used to update an already existing MS SQL Server source in Hasura. + +Update a database with name `mssql1`: + +```http +POST /v1/metadata HTTP/1.1 +Content-Type: application/json +X-Hasura-Role: admin + +{ + "type": "mssql_update_source", + "args": { + "name": "mssql1", + "configuration": { + "connection_info": { + "connection_string": { + "from_env": "" + }, + "pool_settings": { + "max_connections": 50, + "idle_timeout": 180 + } + } + }, + "customization": { + "root_fields": { + "namespace": "some_field_name", + "prefix": "some_field_name_prefix", + "suffix": "some_field_name_suffix" + }, + "type_names": { + "prefix": "some_type_name_prefix", + "suffix": "some_type_name_suffix" + } + } + } +} +``` + +### Args syntax {#mssql-update-source-syntax} + +| Key | Required | Schema | Description | +|-----------------------|----------|----------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------| +| name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the MS SQL Server database | +| configuration | false | [MsSQLConfiguration](/graphql/core/api-reference/syntax-defs.mdx#mssqlconfiguration) | Database connection configuration | +| customization | false | [SourceCustomization](/graphql/core/api-reference/syntax-defs.mdx#sourcecustomization) | Customize root fields and type names for the source | + ## bigquery_add_source {#metadata-bigquery-add-source} `bigquery_add_source` is used to connect a BigQuery database to Hasura. @@ -250,12 +368,19 @@ X-Hasura-Role: admin ### Args syntax {#metadata-bigquery-add-source-syntax} -| Key | Required | Schema | Description | -|-----------------------|----------|-------------------------------------------------|---------------------------------------------------------------------------------------------------------------------| -| name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the BigQuery database | -| configuration | true | [BigQueryConfiguration](/graphql/core/api-reference/syntax-defs.mdx#bigqueryconfiguration) | Database connection configuration | -| replace_configuration | false | Boolean | If set to `true` the configuration will be replaced if the source with given name already exists (default: `false`) | -| customization | false | [SourceCustomization](/graphql/core/api-reference/syntax-defs.mdx#sourcecustomization) | Customize root fields and type names for the source | +| Key | Required | Schema | Description | +|-----------------------|----------|--------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------| +| name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the BigQuery database | +| configuration | true | [BigQueryConfiguration](/graphql/core/api-reference/syntax-defs.mdx#bigqueryconfiguration) | Database connection configuration | +| replace_configuration | false | Boolean | If set to `true` the configuration and customization will be replaced if the source with given name already exists (default: `false`) | +| customization | false | [SourceCustomization](/graphql/core/api-reference/syntax-defs.mdx#sourcecustomization) | Customize root fields and type names for the source | + +:::tip Deprecated field + +The `replace_configuration` field is deprecated in favour of the +[bigquery_update_source API](/graphql/core/api-reference/metadata-api/source.mdx#metadata-bigquery-update-source). + +::: ## bigquery_drop_source {#metadata-bigquery-drop-source} @@ -282,3 +407,46 @@ X-Hasura-Role: admin |---------|----------|---------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| | name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the BigQuery database | | cascade | false | Boolean | When set to `true`, the effect (if possible) is cascaded to any metadata dependent objects (relationships, permissions etc.) from other sources (default: `false`) | + +## bigquery_update_source {#metadata-bigquery-update-source} + +`bigquery_update_source` is used to update an already existing BigQuery source in Hasura. + +Update a database with name `bigquery1`: + +```http +POST /v1/metadata HTTP/1.1 +Content-Type: application/json +X-Hasura-Role: admin + +{ + "type": "bigquery_update_source", + "args": { + "name": "bigquery1", + "configuration": { + "service_account": "bigquery_service_account", + "project_id": "bigquery_project_id", + "datasets": "dataset1, dataset2" + }, + "customization": { + "root_fields": { + "namespace": "some_field_name", + "prefix": "some_field_name_prefix", + "suffix": "some_field_name_suffix" + }, + "type_names": { + "prefix": "some_type_name_prefix", + "suffix": "some_type_name_suffix" + } + } + } +} +``` + +### Args syntax {#metadata-bigquery-update-source-syntax} + +| Key | Required | Schema | Description | +|-----------------------|----------|--------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------| +| name | true | [SourceName](/graphql/core/api-reference/syntax-defs.mdx#sourcename) | Name of the BigQuery database | +| configuration | false | [BigQueryConfiguration](/graphql/core/api-reference/syntax-defs.mdx#bigqueryconfiguration) | Database connection configuration | +| customization | false | [SourceCustomization](/graphql/core/api-reference/syntax-defs.mdx#sourcecustomization) | Customize root fields and type names for the source | diff --git a/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs b/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs index b0d85c6a712..354d6e36fb6 100644 --- a/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs +++ b/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs @@ -4,11 +4,13 @@ module Hasura.RQL.DDL.Schema.Source ( AddSource, DropSource (..), RenameSource, + UpdateSource, runAddSource, runDropSource, runRenameSource, dropSource, runPostDropSourceHook, + runUpdateSource, ) where @@ -73,7 +75,11 @@ runAddSource (AddSource name backendKind sourceConfig replaceConfiguration sourc <$> if HM.member name sources then if replaceConfiguration - then pure $ metaSources . ix name . toSourceMetadata @b . smConfiguration .~ sourceConfig + then do + let sMetadata = metaSources . ix name . toSourceMetadata @b + updateConfig = sMetadata . smConfiguration .~ sourceConfig + updateCustomization = sMetadata . smCustomization .~ sourceCustomization + pure $ updateConfig . updateCustomization else throw400 AlreadyExists $ "source with name " <> name <<> " already exists" else do let sourceMetadata = mkSourceMetadata @b name backendKind sourceConfig sourceCustomization @@ -231,3 +237,41 @@ runPostDropSourceHook sourceName sourceInfo = do "Error executing cleanup actions after removing source '" <> toTxt sourceName <> "'. Consider cleaning up tables in hdb_catalog schema manually." in L.unLogger logger $ MetadataLog L.LevelWarn msg (J.toJSON err) + +-------------------------------------------------------------------------------- +-- update source + +data UpdateSource b = UpdateSource + { _usName :: !SourceName, + _usConfiguration :: !(Maybe (SourceConnConfiguration b)), + _usCustomization :: !(Maybe SourceCustomization) + } + +instance (Backend b) => FromJSONWithContext (BackendSourceKind b) (UpdateSource b) where + parseJSONWithContext _ = withObject "UpdateSource" $ \o -> + UpdateSource + <$> o .: "name" + <*> o .:? "configuration" + <*> o .:? "customization" + +runUpdateSource :: + forall m b. + (MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) => + UpdateSource b -> + m EncJSON +runUpdateSource (UpdateSource name sourceConfig sourceCustomization) = do + sources <- scSources <$> askSchemaCache + + metadataModifier <- + MetadataModifier + <$> if HM.member name sources + then do + let sMetadata = metaSources . ix name . toSourceMetadata @b + updateConfig = maybe id (\scc -> sMetadata . smConfiguration .~ scc) sourceConfig + updateCustomization = maybe id (\scc -> sMetadata . smCustomization .~ scc) sourceCustomization + pure $ updateConfig . updateCustomization + else do + throw400 NotExists $ "source with name " <> name <<> " does not exist" + + buildSchemaCacheFor (MOSource name) metadataModifier + pure successMsg diff --git a/server/src-lib/Hasura/Server/API/Backend.hs b/server/src-lib/Hasura/Server/API/Backend.hs index fca30236c9e..4e316d8ed7e 100644 --- a/server/src-lib/Hasura/Server/API/Backend.hs +++ b/server/src-lib/Hasura/Server/API/Backend.hs @@ -103,7 +103,8 @@ sourceCommands, sourceCommands = [ commandParserWithBackendKind "add_source" $ RMAddSource . mkAnyBackend @b, commandParser "drop_source" $ RMDropSource, - commandParser "set_table_customization" $ RMSetTableCustomization . mkAnyBackend @b + commandParser "set_table_customization" $ RMSetTableCustomization . mkAnyBackend @b, + commandParserWithBackendKind "update_source" $ RMUpdateSource . mkAnyBackend @b ] tableCommands = [ commandParser "track_table" $ RMTrackTable . mkAnyBackend @b, diff --git a/server/src-lib/Hasura/Server/API/Metadata.hs b/server/src-lib/Hasura/Server/API/Metadata.hs index e8fe968b930..9e8efc3ff02 100644 --- a/server/src-lib/Hasura/Server/API/Metadata.hs +++ b/server/src-lib/Hasura/Server/API/Metadata.hs @@ -78,6 +78,7 @@ data RQLMetadataV1 RMAddSource !(AnyBackend AddSource) | RMDropSource DropSource | RMRenameSource !RenameSource + | RMUpdateSource !(AnyBackend UpdateSource) | -- Tables RMTrackTable !(AnyBackend TrackTableV2) | RMUntrackTable !(AnyBackend UntrackTable) @@ -430,6 +431,7 @@ runMetadataQueryV1M env currentResourceVersion = \case RMAddSource q -> dispatchMetadata runAddSource q RMDropSource q -> runDropSource q RMRenameSource q -> runRenameSource q + RMUpdateSource q -> dispatchMetadata runUpdateSource q RMTrackTable q -> dispatchMetadata runTrackTableV2Q q RMUntrackTable q -> dispatchMetadata runUntrackTableQ q RMSetFunctionCustomization q -> dispatchMetadata runSetFunctionCustomization q diff --git a/server/src-lib/Hasura/Server/API/Metadata.hs-boot b/server/src-lib/Hasura/Server/API/Metadata.hs-boot index 526b9162fe2..42cd32ce349 100644 --- a/server/src-lib/Hasura/Server/API/Metadata.hs-boot +++ b/server/src-lib/Hasura/Server/API/Metadata.hs-boot @@ -34,6 +34,7 @@ data RQLMetadataV1 RMAddSource !(AnyBackend AddSource) | RMDropSource DropSource | RMRenameSource !RenameSource + | RMUpdateSource !(AnyBackend UpdateSource) | -- Tables RMTrackTable !(AnyBackend TrackTableV2) | RMUntrackTable !(AnyBackend UntrackTable) diff --git a/server/tests-py/test_metadata.py b/server/tests-py/test_metadata.py index 393bdc6bbd8..52d35756f10 100644 --- a/server/tests-py/test_metadata.py +++ b/server/tests-py/test_metadata.py @@ -175,6 +175,132 @@ class TestMetadata: def test_pg_add_source(self, hge_ctx): check_query_f(hge_ctx, self.dir() + '/pg_add_source.yaml') + def test_pg_add_source_with_replace_config(self, hge_ctx): + st_code, resp = hge_ctx.v1metadataq({ + "type": "pg_add_source", + "args": { + "name": "pg1", + "configuration": { + "connection_info": { + "database_url": { + "from_env": "HASURA_GRAPHQL_PG_SOURCE_URL_1" + } + } + } + } + }) + assert st_code == 200, resp + st_code, resp = hge_ctx.v1metadataq({ + "type": "pg_add_source", + "args": { + "name": "pg1", + "configuration": { + "connection_info": { + "database_url": { + "from_env": "HASURA_GRAPHQL_PG_SOURCE_URL_1" + } + } + }, + "customization": { + "root_fields": { + "namespace": "some_namespace" + } + }, + "replace_configuration": True + } + }) + assert st_code == 200, resp + st_code, resp = hge_ctx.v1metadataq({"type": "export_metadata", "args": {}}) + assert st_code == 200, resp + assert resp["sources"][1]["customization"]["root_fields"]["namespace"] == "some_namespace" + st_code, resp = hge_ctx.v1metadataq({ + "type": "pg_drop_source", + "args": { + "name": "pg1" + } + }) + assert st_code == 200, resp + + def test_pg_update_unknown_source(self, hge_ctx): + st_code, resp = hge_ctx.v1metadataq({ + "type": "pg_update_source", + "args": { + "name": "pg-not-previously-added", + "configuration": { + "connection_info": { + "database_url": { + "from_env": "HASURA_GRAPHQL_PG_SOURCE_URL_1" + } + } + } + } + }) + assert st_code == 400, resp + assert resp["error"] == "source with name \"pg-not-previously-added\" does not exist" + + def test_pg_update_source(self, hge_ctx): + st_code, resp = hge_ctx.v1metadataq({ + "type": "pg_add_source", + "args": { + "name": "pg1", + "configuration": { + "connection_info": { + "database_url": { + "from_env": "HASURA_GRAPHQL_PG_SOURCE_URL_1" + }, + "pool_settings": { + "max_connections": 10 + } + } + } + } + }) + assert st_code == 200, resp + st_code, resp = hge_ctx.v1metadataq({ + "type": "pg_update_source", + "args": { + "name": "pg1", + "customization": { + "root_fields": { + "namespace": "some_namespace" + } + } + } + }) + assert st_code == 200, resp + st_code, resp = hge_ctx.v1metadataq({"type": "export_metadata", "args": {}}) + assert st_code == 200, resp + assert resp["sources"][1]["customization"]["root_fields"]["namespace"] == "some_namespace" + assert resp["sources"][1]["configuration"]["connection_info"]["pool_settings"]["max_connections"] == 10 + st_code, resp = hge_ctx.v1metadataq({ + "type": "pg_update_source", + "args": { + "name": "pg1", + "configuration": { + "connection_info": { + "database_url": { + "from_env": "HASURA_GRAPHQL_PG_SOURCE_URL_1" + }, + "pool_settings": { + "max_connections": 50 + } + } + } + } + }) + assert st_code == 200, resp + st_code, resp = hge_ctx.v1metadataq({"type": "export_metadata", "args": {}}) + assert st_code == 200, resp + assert resp["sources"][1]["customization"]["root_fields"]["namespace"] == "some_namespace" + assert resp["sources"][1]["configuration"]["connection_info"]["pool_settings"]["max_connections"] == 50 + st_code, resp = hge_ctx.v1metadataq({ + "type": "pg_drop_source", + "args": { + "name": "pg1" + } + }) + assert st_code == 200, resp + @pytest.mark.skipif( os.getenv('HASURA_GRAPHQL_PG_SOURCE_URL_1') != 'postgresql://gql_test@localhost:5432/pg_source_1', reason="This test relies on hardcoded connection parameters that match Circle's setup.")