Skip to content

Commit

Permalink
WIP - Break out setting of schema version to func
Browse files Browse the repository at this point in the history
It will be called from other locations shortly, and may be optional within the original source function.
  • Loading branch information
AndrewSisley committed Sep 15, 2023
1 parent 575e21e commit b21e0a9
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,7 @@ func (db *db) updateCollection(
return nil, err
}

collectionSchemaKey := core.NewCollectionSchemaKey(desc.Schema.SchemaID)
err = txn.Systemstore().Put(ctx, collectionSchemaKey.ToDS(), []byte(schemaVersionID))
if err != nil {
return nil, err
}

collectionKey := core.NewCollectionKey(desc.Name)
err = txn.Systemstore().Put(ctx, collectionKey.ToDS(), []byte(schemaVersionID))
err = db.setDefaultSchemaVersion(ctx, txn, desc.Name, desc.Schema.SchemaID, schemaVersionID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -591,6 +584,23 @@ func validateUpdateCollectionIndexes(
return false, nil
}

func (db *db) setDefaultSchemaVersion(
ctx context.Context,
txn datastore.Txn,
collectionName string,
schemaID string,
schemaVersionID string,
) error {
collectionSchemaKey := core.NewCollectionSchemaKey(schemaID)
err := txn.Systemstore().Put(ctx, collectionSchemaKey.ToDS(), []byte(schemaVersionID))
if err != nil {
return err
}

collectionKey := core.NewCollectionKey(collectionName)
return txn.Systemstore().Put(ctx, collectionKey.ToDS(), []byte(schemaVersionID))
}

// getCollectionByVersionId returns the [*collection] at the given [schemaVersionId] version.
//
// Will return an error if the given key is empty, or not found.
Expand Down

0 comments on commit b21e0a9

Please sign in to comment.