Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FieldKind points to schema and collection by name but they are not always the same #2493

Closed
AndrewSisley opened this issue Apr 4, 2024 · 1 comment
Assignees
Labels
area/collections Related to the collections system area/schema Related to the schema system bug Something isn't working
Milestone

Comments

@AndrewSisley
Copy link
Contributor

AndrewSisley commented Apr 4, 2024

And collection name is mutable, and thus a poor way of linking them.

We likely have a few references in the codebase that still assume they are the same and use the wrong means of getting a definition (relations).

Can only be done after #2451 as schemaField.Kind must point to the schema, and collectionField.Kind must point to the collection - at the moment they are the same property and thus cannot be detangled.

I suggest that collectionField.Kind references the linked collection by RootID, not by name, so that name mutations do not require a horrible cross-object update.

@AndrewSisley AndrewSisley added bug Something isn't working area/schema Related to the schema system area/collections Related to the collections system labels Apr 4, 2024
@AndrewSisley AndrewSisley changed the title FieldKind points to schema and collection by name by they are not always the same FieldKind points to schema and collection by name but they are not always the same Apr 19, 2024
@AndrewSisley AndrewSisley self-assigned this May 8, 2024
@AndrewSisley AndrewSisley added this to the DefraDB v0.12 milestone May 8, 2024
@AndrewSisley
Copy link
Contributor Author

Note, I have a (early) WIP branch of name 2493-field-kind-schema-vs-col, breaking #2619 out of this task and working on that first.

@AndrewSisley AndrewSisley removed their assignment Jun 27, 2024
@AndrewSisley AndrewSisley removed this from the DefraDB v0.12 milestone Jun 27, 2024
@AndrewSisley AndrewSisley added this to the DefraDB v0.14 milestone Aug 26, 2024
@AndrewSisley AndrewSisley self-assigned this Aug 26, 2024
AndrewSisley added a commit that referenced this issue Sep 7, 2024
## Relevant issue(s)

Resolves #2619 #2493

## Description

Reworks relation field kinds so that relations are not defined by names
(which are mutable).

This PR replaces the old `ObjectKind` and `ObjectArrayKind`s with
`CollectionKind`, `SchemaKind` and `SelfKind`. `NamedKind` has also been
added - it allows users to interact with the definitions using their
names (like before), before the kind gets translated into one of the
other new kinds before storage.

Because Schemas must form a DAG (because of their CIDs (SchemaVersionID
and Root), Schemas defined within the same action that form circular
relations (e.g. User=>Dog=>User) have their CIDs grouped into a set with
the same base id, plus an index relative to their lexographical order
(name) within the set suffixed onto their CIDs. This change is not user
visible, besides the `-[index]` suffix on their CIDs.

Quite a lot had to change to facilitate this, and only a handful of
things have been broken out to separate commits. Most of the work is in
commit `Rework relation field kinds` - when reviewing that commit, I
suggest starting with
`tests/integration/collection_description/updates/replace/name_one_many_test.go`
to see the original bug, followed by a quick scan of
`client/schema_field_description.go`, then a look at
`tests/integration/schema/self_ref_test.go` before properly reviewing
the changes. The bulk of the self reference logic is in
`internal/db/schema_id.go`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/collections Related to the collections system area/schema Related to the schema system bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant