Skip to content

Commit

Permalink
WIP - Add SetDefaultSchemaVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Sep 15, 2023
1 parent b21e0a9 commit 5f53462
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ type Store interface {
// [FieldKindStringToEnumMapping].
PatchSchema(context.Context, string) error

SetDefaultSchemaVersion(context.Context, string) error

// SetMigration sets the migration for the given source-destination schema version IDs. Is equivilent to
// calling `LensRegistry().SetMigration(ctx, cfg)`.
//
Expand Down
16 changes: 15 additions & 1 deletion db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (db *db) updateCollection(
return nil, err
}

err = db.setDefaultSchemaVersion(ctx, txn, desc.Name, desc.Schema.SchemaID, schemaVersionID)
err = db.setDefaultSchemaVersionExplicit(ctx, txn, desc.Name, desc.Schema.SchemaID, schemaVersionID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -585,6 +585,20 @@ func validateUpdateCollectionIndexes(
}

func (db *db) setDefaultSchemaVersion(
ctx context.Context,
txn datastore.Txn,
schemaVersionID string,
) error {
col, err := db.getCollectionByVersionID(ctx, txn, schemaVersionID)
if err != nil {
return err
}

desc := col.Description()
return db.setDefaultSchemaVersionExplicit(ctx, txn, desc.Name, desc.Schema.SchemaID, schemaVersionID)
}

func (db *db) setDefaultSchemaVersionExplicit(
ctx context.Context,
txn datastore.Txn,
collectionName string,
Expand Down
19 changes: 19 additions & 0 deletions db/txn_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,25 @@ func (db *explicitTxnDB) PatchSchema(ctx context.Context, patchString string) er
return db.patchSchema(ctx, db.txn, patchString)
}

func (db *implicitTxnDB) SetDefaultSchemaVersion(ctx context.Context, schemaVersionID string) error {
txn, err := db.NewTxn(ctx, false)
if err != nil {
return err
}
defer txn.Discard(ctx)

err = db.setDefaultSchemaVersion(ctx, txn, schemaVersionID)
if err != nil {
return err
}

return txn.Commit(ctx)
}

func (db *explicitTxnDB) SetDefaultSchemaVersion(ctx context.Context, schemaVersionID string) error {
return db.setDefaultSchemaVersion(ctx, db.txn, schemaVersionID)
}

func (db *implicitTxnDB) SetMigration(ctx context.Context, cfg client.LensConfig) error {
txn, err := db.NewTxn(ctx, false)
if err != nil {
Expand Down

0 comments on commit 5f53462

Please sign in to comment.