Interface Migrator<D>

Represents the general interface of a migrator.

interface Migrator {
    traverser: Traverser<D>;
    deleteField(field): Promise<MigrationResult>;
    deleteFields(...fields): Promise<MigrationResult>;
    onAfterBatchComplete(callback): void;
    onBeforeBatchStart(callback): void;
    renameField(oldField, newField): Promise<MigrationResult>;
    renameFields(...changes): Promise<MigrationResult>;
    set(data): Promise<MigrationResult>;
    set(data, options): Promise<MigrationResult>;
    setWithDerivedData(getData): Promise<MigrationResult>;
    setWithDerivedData(getData, options): Promise<MigrationResult>;
    update(data, precondition?): Promise<MigrationResult>;
    update(field, value, ...moreFieldsOrPrecondition): Promise<MigrationResult>;
    updateWithDerivedData(getData, precondition?): Promise<MigrationResult>;
    updateWithDerivedData(getData): Promise<MigrationResult>;
    withPredicate(predicate): Migrator<D>;
    withTraverser(traverser): Migrator<D>;
}

Type Parameters

  • D = firestore.DocumentData

Hierarchy

Properties

traverser: Traverser<D>

The underlying traverser.

Methods

  • Deletes the specified field from all documents in this collection.

    Parameters

    • field: string | FieldPath

      The field to delete.

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser
  • Deletes the specified fields from all documents in this collection.

    Parameters

    • Rest ...fields: (string | FieldPath)[]

      A list of fields to delete.

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser

    Example

    const field1 = new firestore.FieldPath('name', 'last');
    const field2 = 'lastModifiedAt';
    await migrator.deleteFields(field1, field2);
  • Registers a callback function that fires after a batch is processed. You can register at most 1 callback. If you call this function multiple times, only the last callback will be registered.

    Parameters

    • callback: BatchCallback<D>

      A synchronous callback that takes batch doc snapshots and the 0-based batch index as its arguments.

    Returns void

  • Registers a callback function that fires right before a batch starts processing. You can register at most 1 callback. If you call this function multiple times, only the last callback will be registered.

    Parameters

    • callback: BatchCallback<D>

      A synchronous callback that takes batch doc snapshots and the 0-based batch index as its arguments.

    Returns void

  • Renames the specified field in all documents in this collection. Ignores the fields that are missing.

    Parameters

    • oldField: string | FieldPath

      The old field.

    • newField: string | FieldPath

      The new field.

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser
  • Renames the specified fields in all documents in this collection. Ignores the fields that are missing.

    Parameters

    • Rest ...changes: [oldField: string | FieldPath, newField: string | FieldPath][]

      A list of [oldField, newField] tuples. Each tuple is an array of 2 elements: the old field to rename and the new field.

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser

    Example

    const change1 = [new firestore.FieldPath('name', 'last'), 'lastName'];
    const change2 = ['lastModifiedAt', 'lastUpdatedAt'];
    await migrator.renameFields(change1, change2);
  • Sets all documents in this collection with the provided data.

    Parameters

    • data: D

      A data object with which to set each document.

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser
  • Sets all documents in this collection with the provided data.

    Parameters

    • data: Partial<D>

      A data object with which to set each document.

    • options: SetOptions

      An object to configure the set behavior.

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser
  • Sets all documents in this collection with the provided data.

    Parameters

    • getData: SetDataGetter<D>

      A function that takes a document snapshot and returns a data object with which to set each document.

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser
  • Sets all documents in this collection with the provided data.

    Parameters

    • getData: SetDataGetter<Partial<D>>

      A function that takes a document snapshot and returns a data object with which to set each document.

    • options: SetOptions

      An object to configure the set behavior.

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser
  • Updates all documents in this collection with the provided data.

    Parameters

    • data: UpdateData

      A non-empty data object with which to update each document.

    • Optional precondition: Precondition

      A Precondition to enforce on this update.

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser
  • Updates all documents in this collection with the provided field-value pair.

    Parameters

    • field: string | FieldPath

      The first field to update in each document.

    • value: any

      The first value corresponding to the first field. Must not be undefined.

    • Rest ...moreFieldsOrPrecondition: any[]

      An alternating list of field paths and values to update, optionally followed by a Precondition to enforce on this update.

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser
  • Updates all documents in this collection with the provided data.

    Parameters

    • getData: UpdateDataGetter<D>

      A function that takes a document snapshot and returns a non-empty data object with which to update each document.

    • Optional precondition: Precondition

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser
  • Updates all documents in this collection with the provided data.

    Parameters

    • getData: UpdateFieldValueGetter<D>

      A function that takes a document snapshot and returns an alternating list of field paths and values to update, optionally followed by a Precondition to enforce on this update.

    Returns Promise<MigrationResult>

    A Promise resolving to an object representing the details of the migration.

    Remarks

    Complexity:

    • Time complexity: TC(traverser) where C(batchSize) = W(batchSize)
    • Space complexity: SC(traverser) where S = O(batchSize)
    • Billing: max(1, N) reads, K writes

    where:

    • N: number of docs in the traversable
    • K: number of docs that passed the migration predicate (K<=N)
    • W(batchSize): average batch write time
    • TC(traverser): time complexity of the underlying traverser
    • SC(traverser): space complexity of the underlying traverser
  • Applies a migration predicate that indicates whether to migrate the current document or not. By default, all documents are migrated.

    Parameters

    • predicate: MigrationPredicate<D>

      A function that takes a document snapshot and returns a boolean indicating whether to migrate it.

    Returns Migrator<D>

    A new Migrator object.

    Remarks

    If you have already applied other migration predicates to this migrator, this and all the other predicates will be evaluated and the resulting booleans will be AND'd to get the boolean that indicates whether to migrate the document or not. This is consistent with the intuitive default behavior that all documents are migrated.

    Example

    const newMigrator = migrator
    .withPredicate((doc) => doc.get('name') !== undefined)
    .withPredicate((doc) => doc.ref.path.startsWith('users/'));

    In the above case newMigrator will migrate only the documents whose name field is not missing AND whose path starts with "users/".

Generated using TypeDoc