server: Default SourceMetadata's kind to Postgres Vanilla

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4514
Co-authored-by: David Overton <7734777+dmoverton@users.noreply.github.com>
GitOrigin-RevId: 37572758c3722a85ac005f5bd13a9bf6a407bad4
This commit is contained in:
Daniel Chambers 2022-05-24 11:15:42 +07:00 committed by hasura-bot
parent 78b94ce765
commit 9e5f860a29
3 changed files with 41 additions and 8 deletions

View File

@ -5,6 +5,7 @@
### Bug fixes and improvements
- server: do not serialize env vars in logs or errors for remote schemas
- server: fix regression introduced in v2.7.0-beta.1: the `kind` field in source metadata was inadvertently made a required field, breaking upgrades from v1 and new cloud projects
## v2.6.2

View File

@ -103,7 +103,7 @@ where
import Control.Lens hiding (set, (.=))
import Data.Aeson.Casing
import Data.Aeson.Extended (mapWithJSONPath)
import Data.Aeson.Extended (FromJSONWithContext (..), mapWithJSONPath)
import Data.Aeson.Ordered qualified as AO
import Data.Aeson.TH
import Data.Aeson.Types
@ -465,10 +465,9 @@ deriving instance (Backend b) => Eq (SourceMetadata b)
instance (Backend b) => Cacheable (SourceMetadata b)
instance (Backend b) => FromJSON (SourceMetadata b) where
parseJSON = withObject "Object" $ \o -> do
instance (Backend b) => FromJSONWithContext (BackendSourceKind b) (SourceMetadata b) where
parseJSONWithContext _smKind = withObject "Object" $ \o -> do
_smName <- o .: "name"
_smKind <- o .: "kind"
_smTables <- oMapFromL _tmTable <$> o .: "tables"
_smFunctions <- oMapFromL _fmFunction <$> o .:? "functions" .!= []
_smConfiguration <- o .: "configuration"
@ -620,11 +619,11 @@ instance FromJSON Metadata where
where
parseSourceMetadata :: Value -> Parser (AB.AnyBackend SourceMetadata)
parseSourceMetadata = withObject "SourceMetadata" \o -> do
backendSourceKind <- explicitParseField AB.parseBackendSourceKindFromJSON o "kind"
AB.dispatchAnyBackend'' @FromJSON @Backend
backendSourceKind <- explicitParseFieldMaybe AB.parseBackendSourceKindFromJSON o "kind" .!= AB.mkAnyBackend PostgresVanillaKind
AB.dispatchAnyBackend @Backend
backendSourceKind
( \(_kind :: BackendSourceKind b) ->
AB.mkAnyBackend @b <$> parseJSON (Object o)
( \(kind :: BackendSourceKind b) ->
AB.mkAnyBackend @b <$> parseJSONWithContext kind (Object o)
)
emptyMetadata :: Metadata

View File

@ -136,6 +136,39 @@ class TestMetadata:
"code": "unexpected"
}
"""Test that missing "kind" key in metadata source defaults to "postgres".
Regression test for https://github.com/hasura/graphql-engine-mono/issues/4501"""
def test_replace_metadata_default_kind(self, hge_ctx):
st_code, resp = hge_ctx.v1metadataq({"type": "export_metadata", "args": {}})
assert st_code == 200, resp
default_source_config = {}
default_source = list(filter(lambda source: (source["name"] == "default"), resp["sources"]))
if default_source:
default_source_config = default_source[0]["configuration"]
else:
assert False, "default source config not found"
return
st_code, resp = hge_ctx.v1metadataq({
"type": "replace_metadata",
"version": 2,
"args": {
"metadata": {
"version": 3,
"sources": [
{
"name": "default",
"tables": [],
"configuration": default_source_config
}
]
}
}
})
assert st_code == 200, resp
st_code, resp = hge_ctx.v1metadataq({"type": "export_metadata", "args": {}})
assert st_code == 200, resp
assert resp["sources"][0]["kind"] == "postgres"
def test_dump_internal_state(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/dump_internal_state.yaml')