interface

DataTransaction

Transaction-bound content operations available to a compiled migration callback.

Example

go
posts, err := tx.Collection("posts")
if err != nil {
  return err
}
_, err = tx.Update(ctx, migration.UpdateRequest{
  Request: store.Request{Collection: posts, ID: "hello"},
  Values:  store.Values{"summary": store.String("Hello")},
})
return err

Properties

PropertyTypeDescription
Collectionfunc(slug string) (schema.Collection, error)Returns the collection as this migration leaves it, or as it was before when the migration removes it. Pass it to every request so the transform keeps replaying after later migrations change the collection.
Globalfunc(slug string) (schema.Collection, error)Returns the global with this slug, resolved like Collection.
Createfunc(context.Context, store.CreateRequest) (store.Document, error)Creates a document with the given ID and values.
Findfunc(context.Context, store.Request) (store.Document, error)Reads one stored document by ID.
Listfunc(context.Context, store.Request) (store.Page, error)Reads a page of stored documents. Loop while HasNextPage is true to visit every match.
Updatefunc(context.Context, UpdateRequest) (store.Document, error)Locks the stored document and patches its values, or replaces them when ReplaceValues is set.
Trashfunc(context.Context, store.Request) (store.Document, error)Moves a document to the trash.
Restorefunc(context.Context, store.Request) (store.Document, error)Restores a trashed document.
Deletefunc(context.Context, store.Request) (store.Document, error)Deletes a document and the framework state it owns, such as its versions, sessions and preferences.

How it works

Every request runs inside the migration's transaction, so the schema change and the content change commit or roll back together.

A transform can't change a versioned collection or global; backfill those in an earlier, data-only migration.

Full signature

type DataTransaction interface { // Collection returns the collection with this slug as the running // migration leaves it, or as it was before when the migration removes it. // Every request must use a shape from the migration itself, so a // transform keeps replaying after later migrations change the collection. Collection(slug string) (schema.Collection, error) // Global returns the global with this slug, resolved like Collection. Global(slug string) (schema.Collection, error) Create(context.Context, store.CreateRequest) (store.Document, error) Find(context.Context, store.Request) (store.Document, error) List(context.Context, store.Request) (store.Page, error) Update(context.Context, UpdateRequest) (store.Document, error) Trash(context.Context, store.Request) (store.Document, error) Restore(context.Context, store.Request) (store.Document, error) Delete(context.Context, store.Request) (store.Document, error) }

Source migration/migration.go:128

Related guides