Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Problem with forceWait #51

Open
dzbrozek opened this issue Oct 25, 2021 · 1 comment
Open

Problem with forceWait #51

dzbrozek opened this issue Oct 25, 2021 · 1 comment

Comments

@dzbrozek
Copy link

dzbrozek commented Oct 25, 2021

I have a problem with forceWait. When I run migrations with forceWait fireway runs only the first migration and stops working after that without writing migration result to firestore. Without forceWait I works as expected but I get a lot of warnings. Any idea what's going on?

Example migration:

import { firestoreRoutes } from '@travel-together/core/routes';
import { MigrateOptions } from 'fireway';
import { createTraverser } from '@firecode/admin';

export const migrate = async ({ firestore, FieldValue }: MigrateOptions) => {
  const usersCollection = firestore
    .collection(firestoreRoutes.users)
    .where('active', '==', true)
    .where('deleted', '==', false);
  const storiesCollection = firestore.collection(firestoreRoutes.stories);
  const usersTraverser = createTraverser(usersCollection);

  const { docCount } = await usersTraverser.traverse(
    async (batchDocs, batchIndex) => {
      const batchSize = batchDocs.length;
      for (const doc of batchDocs) {
        const userData = doc.data();
        const storyData = {
          creatorId: doc.id,
          createdAt: userData.createdAt,
          lastActivityAt: userData.createdAt,
        };
        await storiesCollection.add(storyData);
        await doc.ref.update({
          numStories: FieldValue.increment(1),
        });
      }
      console.log(
        `Batch ${batchIndex} done! Migrated ${batchSize} users in this batch.`,
      );
    },
  );

  console.log(`Migrated ${docCount} users`);
};
@MatteoTamine1709
Copy link

MatteoTamine1709 commented Jun 27, 2022

The issue still remains. Here is a small sample code:

const { TRANSACTION_COLLECTION, ORGANIZATION_COLLECTION, ESTABLISHMENT_COLLECTION, ARTWORK_COLLECTION, CLIENT_COLLECTION, EVALUATION_COLLECTION, USER_COLLECTION } = require('./globals')
const { chunk } = require('lodash')
module.exports.migrate = async ({ firestore }) => {
  const users = await firestore.collection(USER_COLLECTION).get()
  chunk(users.docs, 500).map(userDocs =>
    userDocs.map(user => {
      const newEstablishmentRef = firestore.collection(ESTABLISHMENT_COLLECTION).doc()
    })
  )
}

I removed all the unnecessary code to replicate the bug

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants