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
This commit is contained in:
Rakesh Emmadi 2021-06-09 17:42:25 +05:30 committed by hasura-bot
parent 8bfc56b7c4
commit 04e041b8cb
2 changed files with 6 additions and 4 deletions

View File

@ -4,6 +4,7 @@
### Bug fixes and improvements ### Bug fixes and improvements
(Add entries below in the order of server, console, cli, docs, others) (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: 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 tracking of custom SQL functions having composite type (rowtype) input arguments
- console: allow input object presets in remote schema permissions - console: allow input object presets in remote schema permissions

View File

@ -46,13 +46,14 @@ runAddSource
=> AddSource b -> m EncJSON => AddSource b -> m EncJSON
runAddSource (AddSource name sourceConfig replaceConfiguration) = do runAddSource (AddSource name sourceConfig replaceConfiguration) = do
sources <- scSources <$> askSchemaCache sources <- scSources <$> askSchemaCache
let sourceMetadata = mkSourceMetadata @b name sourceConfig
metadataModifier <- MetadataModifier <$> metadataModifier <- MetadataModifier <$>
if HM.member name sources then 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 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 buildSchemaCacheFor (MOSource name) metadataModifier
pure successMsg pure successMsg