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 977e6f0
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 131 deletions.
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
43 changes: 43 additions & 0 deletions client/mocks/db.go

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

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
130 changes: 0 additions & 130 deletions db/fetcher/mocks/fetcher.go

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

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
12 changes: 12 additions & 0 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,18 @@ func (c *Client) PatchSchema(ctx context.Context, patch string) error {
return err
}

func (c *Client) SetDefaultSchemaVersion(ctx context.Context, schemaVersionID string) error {
methodURL := c.http.baseURL.JoinPath("schema")
panic("todo")

req, err := http.NewRequestWithContext(ctx, http.MethodPatch, methodURL.String(), strings.NewReader(schemaVersionID))
if err != nil {
return err
}
_, err = c.http.request(req)
return err
}

func (c *Client) SetMigration(ctx context.Context, config client.LensConfig) error {
return c.LensRegistry().SetMigration(ctx, config)
}
Expand Down
4 changes: 4 additions & 0 deletions http/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (w *Wrapper) PatchSchema(ctx context.Context, patch string) error {
return w.client.PatchSchema(ctx, patch)
}

func (w *Wrapper) SetDefaultSchemaVersion(ctx context.Context, schemaVersionID string) error {
return w.client.SetDefaultSchemaVersion(ctx, schemaVersionID)
}

func (w *Wrapper) SetMigration(ctx context.Context, config client.LensConfig) error {
return w.client.SetMigration(ctx, config)
}
Expand Down

0 comments on commit 977e6f0

Please sign in to comment.