hasura / hasura/graphql-engine
Hasura 2.0 may export config v2 metadata that is incompatible with hasura 1.3
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: 1.3.3, 2.0.10
### Environment
### What is the expected behaviour?
Metadata exported with config v2 should be compatible with hasura 1.3 projects.
### Keywords
Error applying config v2 metadata from hasura 2.0 project to 1.3 project.
### What is the current behaviour?
hasura 2.0.10 may export config v2 metadata that is incompatible with hasura 1.3.3
### How to reproduce the issue?
1. Create a hasura 2.0.10 project
2. Run the following migration, and track both the `person` and `pet` table
```sql
CREATE TABLE person (
id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
name TEXT
);
CREATE TABLE pet (
id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
name TEXT,
person_id INTEGER NOT NULL UNIQUE REFERENCES person (id)
);
```
3. Notice the unique constraint on the person_id column. This means the suggested relationships will be one to one
4. Track both suggested relationships
5. Create a config.yaml file, in it paste the following content `version: 2`
6. Run `hasura metadata export`. Config v2 metadata will be exported.
7. The contents of the `tables.yaml` file will be the following:
```yaml
- table:
schema: public
name: person
object_relationships:
- name: pet
using:
foreign_key_constraint_on:
column: person_id
table:
schema: public
name: pet
- table:
schema: public
name: pet
object_relationships:
- name: person
using:
foreign_key_constraint_on: person_id
```
8. Bring up a 1.3.3 project
9. Apply the migration from step 2. Optionally track the tables, but _do not_ track the relationships.
10. Attempt to apply the metadata exported in step 6
11. The following error will be thrown:
```
msg="error applying metadata
{
"path": "$.tables[0].object_relationships[0].using",
"error": "parsing Text failed, expected String, but encountered Object",
"code": "parse-failed"
}"
```
This happens because 1.3.3 and 2.0.10 track one to one relationships differently.
Following steps 1-7 with version 1.3.3 generates the following tables.yaml file:
```yaml
- table:
schema: public
name: person
object_relationships:
- name: pet
using:
manual_configuration:
remote_table:
schema: public
name: pet
column_mapping:
id: person_id
- table:
schema: public
name: pet
object_relationships:
- name: person
using:
foreign_key_constraint_on: person_id
```
We can see that one to one relationships from the pet to the person is tracked differently.
This can be misleading for users, since the same UI operation generates different, incompatible metadata in 2.0
### Any possible solutions?
Currently this can be worked around by manually editing the metadata exported from 2.0.10 to use the same relationship definitions as 1.3.3
Users should note that this is not a high priority item, as the real-world circumstances where this becomes an issue are very peculiar.
Thus we encourage users to proactively take the measure described above should they encounter this issue.
Contributor guide
Assessment
This issue has not been assessed yet.