From 04e041b8cb2064e7dcf975ad56219972965d88f6 Mon Sep 17 00:00:00 2001 From: Rakesh Emmadi <12475069+rakeshkky@users.noreply.github.com> Date: Wed, 9 Jun 2021 17:42:25 +0530 Subject: [PATCH] server: fix replace configuration in add source metadata API > ### Description > ### Changelog - [x] `CHANGELOG.md` is updated with user-facing content relevant to this PR. If no changelog is required, then add the `no-changelog-required` label. ### Affected components - [x] Server ### Related Issues -> Fixes #1528 ### Solution and Design > Only replace connection configuration instead of replacing entire metadata with empty one. GitOrigin-RevId: f9a16dcc7b1219ec1af915bf083622fcb7dde69a --- CHANGELOG.md | 3 ++- server/src-lib/Hasura/RQL/DDL/Schema/Source.hs | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e216151edff..b9ab36e2bb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Bug fixes and improvements (Add entries below in the order of server, console, cli, docs, others) +- server: fix add source API wiping out source's metadata when replace_configuration is true - console: add foreign key CRUD functionality to ms sql server tables - console: allow tracking of custom SQL functions having composite type (rowtype) input arguments - console: allow input object presets in remote schema permissions @@ -18,7 +19,7 @@ - server: fix asymptotic performance of fetching from the event_log table - console: add `pool_timeout`, `connection_lifetime` and `isolation_level` connection params to connect database form - console: add check constraints and comments to MS SQL Server tables' read-only modify page -- console: add create table functionality for MS SQL Server +- console: add create table functionality for MS SQL Server - console: update connect database form with SSL certificates - console: add drop table functionality to MS SQL Server tables - console: allow renaming data sources diff --git a/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs b/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs index 884961ed66b..ad8c207878f 100644 --- a/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs +++ b/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs @@ -46,13 +46,14 @@ runAddSource => AddSource b -> m EncJSON runAddSource (AddSource name sourceConfig replaceConfiguration) = do sources <- scSources <$> askSchemaCache - let sourceMetadata = mkSourceMetadata @b name sourceConfig metadataModifier <- MetadataModifier <$> if HM.member name sources then - if replaceConfiguration then pure $ metaSources.ix name .~ sourceMetadata + if replaceConfiguration then pure $ metaSources.ix name.toSourceMetadata @b.smConfiguration .~ sourceConfig else throw400 AlreadyExists $ "source with name " <> name <<> " already exists" - else pure $ metaSources %~ OMap.insert name sourceMetadata + else do + let sourceMetadata = mkSourceMetadata @b name sourceConfig + pure $ metaSources %~ OMap.insert name sourceMetadata buildSchemaCacheFor (MOSource name) metadataModifier pure successMsg