Skip to content

Commit

Permalink
feat: Rename Schema.SchemaID to Schema.Root (sourcenetwork#2005)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves sourcenetwork#2004

## Description

Renames Schema.SchemaID to Schema.Root.

A `Schema` doesn't really exist outside of its version, and this name
change will hopefully help clarify that.
  • Loading branch information
AndrewSisley authored Oct 26, 2023
1 parent 0bcc1ed commit c90a88d
Show file tree
Hide file tree
Showing 80 changed files with 509 additions and 540 deletions.
18 changes: 9 additions & 9 deletions cli/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
func MakeCollectionCommand(cfg *config.Config) *cobra.Command {
var txID uint64
var name string
var schemaID string
var schemaRoot string
var versionID string
var cmd = &cobra.Command{
Use: "collection [--name <name> --schema <schemaID> --version <versionID>]",
Use: "collection [--name <name> --schema <schemaRoot> --version <versionID>]",
Short: "Interact with a collection.",
Long: `Create, read, update, and delete documents within a collection.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -48,8 +48,8 @@ func MakeCollectionCommand(cfg *config.Config) *cobra.Command {
case versionID != "":
cols, err = store.GetCollectionsByVersionID(cmd.Context(), versionID)

case schemaID != "":
cols, err = store.GetCollectionsBySchemaID(cmd.Context(), schemaID)
case schemaRoot != "":
cols, err = store.GetCollectionsBySchemaRoot(cmd.Context(), schemaRoot)

case name != "":
col, err = store.GetCollectionByName(cmd.Context(), name)
Expand All @@ -63,12 +63,12 @@ func MakeCollectionCommand(cfg *config.Config) *cobra.Command {
return err
}

if schemaID != "" && versionID != "" && len(cols) > 0 {
if cols[0].SchemaID() != schemaID {
// If the a versionID has been provided that does not pair up with the given schemaID
if schemaRoot != "" && versionID != "" && len(cols) > 0 {
if cols[0].SchemaRoot() != schemaRoot {
// If the a versionID has been provided that does not pair up with the given schema root
// we should error and let the user know they have provided impossible params.
// We only need to check the first item - they will all be the same.
return NewErrSchemaVersionNotOfSchema(schemaID, versionID)
return NewErrSchemaVersionNotOfSchema(schemaRoot, versionID)
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func MakeCollectionCommand(cfg *config.Config) *cobra.Command {
}
cmd.PersistentFlags().Uint64Var(&txID, "tx", 0, "Transaction ID")
cmd.PersistentFlags().StringVar(&name, "name", "", "Collection name")
cmd.PersistentFlags().StringVar(&schemaID, "schema", "", "Collection schema ID")
cmd.PersistentFlags().StringVar(&schemaRoot, "schema", "", "Collection schema Root")
cmd.PersistentFlags().StringVar(&versionID, "version", "", "Collection version ID")
return cmd
}
4 changes: 2 additions & 2 deletions cli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func NewErrInvalidLensConfig(inner error) error {
return errors.Wrap(errInvalidLensConfig, inner)
}

func NewErrSchemaVersionNotOfSchema(schemaID string, schemaVersionID string) error {
func NewErrSchemaVersionNotOfSchema(schemaRoot string, schemaVersionID string) error {
return errors.New(
errSchemaVersionNotOfSchema,
errors.NewKV("SchemaID", schemaID),
errors.NewKV("SchemaRoot", schemaRoot),
errors.NewKV("SchemaVersionID", schemaVersionID),
)
}
4 changes: 2 additions & 2 deletions client/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ type Collection interface {
Name() string
// ID returns the ID of this Collection.
ID() uint32
// SchemaID returns the ID of the Schema used to define this Collection.
SchemaID() string
// SchemaRoot returns the Root of the Schema used to define this Collection.
SchemaRoot() string

// Definition contains the metadata defining what a Collection is.
Definition() CollectionDefinition
Expand Down
4 changes: 2 additions & 2 deletions client/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ type Store interface {
// If no matching collection is found an error will be returned.
GetCollectionByName(context.Context, CollectionName) (Collection, error)

// GetCollectionsBySchemaID attempts to retrieve all collections using the given schema ID.
// GetCollectionsBySchemaRoot attempts to retrieve all collections using the given schema ID.
//
// If no matching collection is found an empty set will be returned.
GetCollectionsBySchemaID(context.Context, string) ([]Collection, error)
GetCollectionsBySchemaRoot(context.Context, string) ([]Collection, error)

// GetCollectionsByVersionID attempts to retrieve all collections using the given schema version ID.
//
Expand Down
4 changes: 2 additions & 2 deletions client/descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ func (col CollectionDescription) GetFieldByRelation(

// SchemaDescription describes a Schema and its associated metadata.
type SchemaDescription struct {
// SchemaID is the version agnostic identifier for this schema.
// Root is the version agnostic identifier for this schema.
//
// It remains constant throughout the lifetime of this schema.
SchemaID string
Root string

// VersionID is the version-specific identifier for this schema.
//
Expand Down
4 changes: 2 additions & 2 deletions client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ func NewErrCollectionNotFoundForSchemaVersion(schemaVersionID string) error {
)
}

func NewErrCollectionNotFoundForSchema(schemaID string) error {
func NewErrCollectionNotFoundForSchema(schemaRoot string) error {
return errors.New(
errCollectionNotFound,
errors.NewKV("SchemaID", schemaID),
errors.NewKV("SchemaRoot", schemaRoot),
)
}
20 changes: 10 additions & 10 deletions client/mocks/collection.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions client/mocks/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/crdt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ func NewCompositeDAG(
}
}

// GetSchemaID returns the schema ID of the composite DAG CRDT.
// ID returns the schema ID of the composite DAG CRDT.
func (c CompositeDAG) ID() string {
return c.key.ToString()
}

// GetSchemaID returns the schema ID of the composite DAG CRDT.
// Value returns the schema ID of the composite DAG CRDT.
func (c CompositeDAG) Value(ctx context.Context) ([]byte, error) {
return nil, nil
}
Expand Down
6 changes: 0 additions & 6 deletions core/delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ type CompositeDelta interface {
Links() []DAGLink
}

type NetDelta interface {
Delta
GetSchemaID() string
// DocKey() client.DocKey
}

// DAGLink represents a link to another object in a DAG.
type DAGLink struct {
Name string
Expand Down
12 changes: 6 additions & 6 deletions core/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ var _ Key = (*SchemaVersionKey)(nil)
// If a SchemaHistoryKey does not exist for a given SchemaVersionID it means
// that that SchemaVersionID is for the latest version.
type SchemaHistoryKey struct {
SchemaID string
SchemaRoot string
PreviousSchemaVersionID string
}

Expand Down Expand Up @@ -344,9 +344,9 @@ func NewSchemaVersionKey(schemaVersionID string) SchemaVersionKey {
return SchemaVersionKey{SchemaVersionID: schemaVersionID}
}

func NewSchemaHistoryKey(schemaId string, previousSchemaVersionID string) SchemaHistoryKey {
func NewSchemaHistoryKey(schemaRoot string, previousSchemaVersionID string) SchemaHistoryKey {
return SchemaHistoryKey{
SchemaID: schemaId,
SchemaRoot: schemaRoot,
PreviousSchemaVersionID: previousSchemaVersionID,
}
}
Expand All @@ -363,7 +363,7 @@ func NewSchemaHistoryKeyFromString(keyString string) (SchemaHistoryKey, error) {
}

return SchemaHistoryKey{
SchemaID: elements[0],
SchemaRoot: elements[0],
PreviousSchemaVersionID: elements[1],
}, nil
}
Expand Down Expand Up @@ -675,8 +675,8 @@ func (k SchemaVersionKey) ToDS() ds.Key {
func (k SchemaHistoryKey) ToString() string {
result := SCHEMA_VERSION_HISTORY

if k.SchemaID != "" {
result = result + "/" + k.SchemaID
if k.SchemaRoot != "" {
result = result + "/" + k.SchemaRoot
}

if k.PreviousSchemaVersionID != "" {
Expand Down
28 changes: 0 additions & 28 deletions core/log.go

This file was deleted.

36 changes: 18 additions & 18 deletions db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ func (db *db) validateUpdateSchema(
return false, NewErrAddCollectionWithPatch(proposedDesc.Name)
}

if proposedDesc.SchemaID != existingDesc.SchemaID {
return false, NewErrSchemaIDDoesntMatch(
if proposedDesc.Root != existingDesc.Root {
return false, NewErrSchemaRootDoesntMatch(
proposedDesc.Name,
existingDesc.SchemaID,
proposedDesc.SchemaID,
existingDesc.Root,
proposedDesc.Root,
)
}

Expand Down Expand Up @@ -467,7 +467,7 @@ func (db *db) setDefaultSchemaVersion(
return err
}

colDescs, err := description.GetCollectionsBySchemaID(ctx, txn, schema.SchemaID)
colDescs, err := description.GetCollectionsBySchemaRoot(ctx, txn, schema.Root)
if err != nil {
return err
}
Expand Down Expand Up @@ -570,17 +570,17 @@ func (db *db) getCollectionByName(ctx context.Context, txn datastore.Txn, name s
return collection, nil
}

// getCollectionsBySchemaID returns all existing collections using the schema hash ID.
func (db *db) getCollectionsBySchemaID(
// getCollectionsBySchemaRoot returns all existing collections using the schema root.
func (db *db) getCollectionsBySchemaRoot(
ctx context.Context,
txn datastore.Txn,
schemaID string,
schemaRoot string,
) ([]client.Collection, error) {
if schemaID == "" {
return nil, ErrSchemaIDEmpty
if schemaRoot == "" {
return nil, ErrSchemaRootEmpty
}

cols, err := description.GetCollectionsBySchemaID(ctx, txn, schemaID)
cols, err := description.GetCollectionsBySchemaRoot(ctx, txn, schemaRoot)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -721,8 +721,8 @@ func (c *collection) ID() uint32 {
return c.Description().ID
}

func (c *collection) SchemaID() string {
return c.Schema().SchemaID
func (c *collection) SchemaRoot() string {
return c.Schema().Root
}

func (c *collection) Definition() client.CollectionDefinition {
Expand Down Expand Up @@ -1018,11 +1018,11 @@ func (c *collection) save(
func() {
c.db.events.Updates.Value().Publish(
events.Update{
DocKey: doc.Key().String(),
Cid: headNode.Cid(),
SchemaID: c.Schema().SchemaID,
Block: headNode,
Priority: priority,
DocKey: doc.Key().String(),
Cid: headNode.Cid(),
SchemaRoot: c.Schema().Root,
Block: headNode,
Priority: priority,
},
)
},
Expand Down
Loading

0 comments on commit c90a88d

Please sign in to comment.