Skip to content

Commit

Permalink
WIP - Host schema on collection
Browse files Browse the repository at this point in the history
It should no longer be accessed via [collection] desc
  • Loading branch information
AndrewSisley committed Oct 2, 2023
1 parent bb8300b commit 3c17d98
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ type collection struct {

schemaID string

desc client.CollectionDescription
desc client.CollectionDescription
schema client.SchemaDescription

indexes []CollectionIndex
fetcherFactory func() fetcher.Fetcher
Expand Down Expand Up @@ -87,7 +88,8 @@ func (db *db) newCollection(desc client.CollectionDescription) (*collection, err
Name: desc.Name,
Schema: desc.Schema,
},
colID: desc.ID,
schema: desc.Schema,
colID: desc.ID,
}, nil
}

Expand Down Expand Up @@ -159,6 +161,7 @@ func (db *db) createCollection(
schema.VersionID = schemaVersionID
schema.SchemaID = schemaID
col.desc.Schema = schema
col.schema = schema

// buffer must include all the ids, as it is saved and loaded from the store later.
buf, err := json.Marshal(col.desc)
Expand Down Expand Up @@ -639,6 +642,7 @@ func (db *db) getCollectionByVersionID(
col := &collection{
db: db,
desc: desc,
schema: desc.Schema,
colID: desc.ID,
schemaID: desc.Schema.SchemaID,
}
Expand Down Expand Up @@ -803,7 +807,7 @@ func (c *collection) Name() string {

// Schema returns the Schema of the collection.
func (c *collection) Schema() client.SchemaDescription {
return c.desc.Schema
return c.schema
}

// ID returns the ID of the collection.
Expand All @@ -822,6 +826,7 @@ func (c *collection) WithTxn(txn datastore.Txn) client.Collection {
db: c.db,
txn: immutable.Some(txn),
desc: c.desc,
schema: c.schema,
colID: c.colID,
schemaID: c.schemaID,
indexes: c.indexes,
Expand Down Expand Up @@ -881,7 +886,7 @@ func (c *collection) getKeysFromDoc(

func (c *collection) create(ctx context.Context, txn datastore.Txn, doc *client.Document) error {
// This has to be done before dockey verification happens in the next step.
if err := doc.RemapAliasFieldsAndDockey(c.desc.Schema.Fields); err != nil {
if err := doc.RemapAliasFieldsAndDockey(c.schema.Fields); err != nil {
return err
}

Expand Down Expand Up @@ -1037,7 +1042,7 @@ func (c *collection) save(
return cid.Undef, client.NewErrFieldNotExist(k)
}

fieldDescription, valid := c.desc.Schema.GetField(k)
fieldDescription, valid := c.schema.GetField(k)
if !valid {
return cid.Undef, client.NewErrFieldNotExist(k)
}
Expand Down Expand Up @@ -1139,7 +1144,7 @@ func (c *collection) validateOneToOneLinkDoesntAlreadyExist(
return nil
}

objFieldDescription, ok := c.desc.Schema.GetField(strings.TrimSuffix(fieldDescription.Name, request.RelatedObjectID))
objFieldDescription, ok := c.schema.GetField(strings.TrimSuffix(fieldDescription.Name, request.RelatedObjectID))
if !ok {
return client.NewErrFieldNotExist(strings.TrimSuffix(fieldDescription.Name, request.RelatedObjectID))
}
Expand Down

0 comments on commit 3c17d98

Please sign in to comment.