fireway
fireway copied to clipboard
Problem with forceWait
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`);
};
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