graphql-engine/server/src-rsr
Lyndon Maydwell 3d5fb984b0 Fix metadata defaults bug - Defaults serialised into metadata table - GDC-647
## Description

There is a bug in the metadata defaults code, see [the original PR](https://github.com/hasura/graphql-engine-mono/pull/6286).

Steps to reproduce this issue:

* Start a new HGE project
* Start HGE with a defaults argument: `HASURA_GRAPHQL_LOG_LEVEL=debug cabal run exe:graphql-engine -- serve --enable-console --console-assets-dir=./console/static/dist --metadata-defaults='{"backend_configs": {"dataconnector": {"mongo": {"display_name": "BONGOBB", "uri": "http://localhost:8123"}}}}'`
* Add a source (doesn't need to be related to the defaults)
* Export metadata
* See that the defaults are present in the exported metadata

## Related Issues

* Github Issue: https://github.com/hasura/graphql-engine/issues/9237
* Jira: https://hasurahq.atlassian.net/browse/GDC-647
* Original PR: https://github.com/hasura/graphql-engine-mono/pull/6286

## Solution

* The test for if defaults should be included for metadata api operations has been extended to check for updates
* Metadata inconsistencies have been hidden for `/capabilities` calls on startup

## TODO

* [x] Fix bug
* [x] Write tests
* [x] OSS Metadata Migration to correct persisted data - `server/src-rsr/migrations/47_to_48.sql`
* [x] Cloud Metadata Migration - `pro/server/res/cloud/migrations/6_to_7.sql`
* [x] Bump Catalog Version - `server/src-rsr/catalog_version.txt`
* [x] Update Catalog Versions - `server/src-rsr/catalog_versions.txt` (This will be done by Infra when creating a release)
* [x] Log connection error as it occurs *(Already being logged. Requires `--enabled-log-types startup,webhook-log,websocket-log,http-log,data-connector-log`)
* [x] Don't mark metadata inconsistencies for this call.

## Questions

* [ ] Does the `pro/server/res/cloud/migrations/6_to_7.sql` cover the cloud scenarios?
* [ ] Should we have `SET search_path` in migrations?
* [x] What should be in `server/src-rsr/catalog_versions.txt`?

## Testing

To test the solution locally run:

> docker compose up -d

and

> cabal run  -- exe:api-tests --skip BigQuery --skip SQLServer --skip '/Test.API.Explain/Postgres/'

## Solution

In `runMetadataQuery` in `server/src-lib/Hasura/Server/API/Metadata.hs`:

```diff
-        if (exportsMetadata _rqlMetadata)
+        if (exportsMetadata _rqlMetadata || queryModifiesMetadata _rqlMetadata)
```

This ensures that defaults aren't present in operations that serialise metadata.

Note: You might think that `X_add_source` would need the defaults to be present to add a source that references the defaults, but since the resolution occurs in the schema-cache building phase, the defaults can be excluded for the metadata modifications required for `X_add_source`.

In addition to the code-change, a metadata migration has been introduced in order to clean up serialised defaults.

The following scenarios need to be considered for both OSS and Cloud:

* The user has not had defaults serialised
* The user has had the defaults serialised and no other backends configured
* The user has had the defaults serialised and has also configured other backends

We want to remove as much of the metadata as possible without any user-specified data and this should be reflected in migration `server/src-rsr/migrations/47_to_48.sql`.

## Server checklist

### Catalog upgrade

Does this PR change Hasura Catalog version?
-  Yes

### Metadata
Does this PR add a new Metadata feature?
-  No

### GraphQL
-  No new GraphQL schema is generated

### Breaking changes
-  No Breaking changes

## Changelog

__Component__ : server
__Type__: bugfix
__Product__: community-edition

### Short Changelog

Fixes a metadata defaults serialization bug and introduces a metadata migration to correct data that has been persisted due to the bug.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7034
GitOrigin-RevId: ad7d4f748397a1a607f2c0c886bf0fbbc3f873f2
2022-12-06 22:35:19 +00:00
..
migrations Fix metadata defaults bug - Defaults serialised into metadata table - GDC-647 2022-12-06 22:35:19 +00:00
mssql server: add event_processing_time metric 2022-12-06 15:11:04 +00:00
pg_source_migrations server: add IF EXISTS while dropping the constraint in source migration 2022-10-21 04:44:08 +00:00
catalog_version.txt Fix metadata defaults bug - Defaults serialised into metadata table - GDC-647 2022-12-06 22:35:19 +00:00
catalog_versions.txt ci: tag release v2.16.0 2022-12-05 07:37:26 +00:00
citus_table_metadata.sql Fix zendesk-5146. Add check for empty columns in unique constraints g… 2022-06-17 07:49:20 +00:00
clear_system_metadata.sql Make catalog metadata migrations work on all schema versions (fix #2826) (#2379) 2019-10-11 00:13:57 -05:00
cockroach_table_metadata.sql NDAT-207 fix unique constraints and indexes for cockroachdb 2022-10-21 14:03:55 +00:00
console.html console: globally add missing <!DOCTYPE html> 2022-11-03 07:06:06 +00:00
drop_pg_source.sql server, pro: event trigger auto cleanup (increment 2) 2022-09-13 08:34:52 +00:00
init_pg_source.sql server, pro: event trigger auto cleanup (increment 2) 2022-09-13 08:34:52 +00:00
initialise.sql server: creating gen_hasura_uuid function should be idempotent 2021-11-10 07:59:31 +00:00
introspection.json adds basic support for remote schemas/schema stitching (#952) 2018-11-23 18:32:46 +05:30
mysql_table_metadata.sql mysql: Metadata awareness 2021-07-15 12:45:51 +00:00
pg_function_metadata.sql console: Hide timescaledb internal schema from data tab 2022-06-22 07:38:38 +00:00
pg_table_metadata.sql Fix zendesk-5146. Add check for empty columns in unique constraints g… 2022-06-17 07:49:20 +00:00
table_meta.sql console: Hide timescaledb internal schema from data tab 2022-06-22 07:38:38 +00:00
trigger.sql.shakespeare server: drop the dropping trigger logic while creating/recreating an event trigger 2022-04-01 10:39:35 +00:00