Fix PIT migration batch issue with folders overflowing the batch size

This commit is contained in:
Carlos Monastyrski
2025-10-02 19:18:08 -03:00
parent e9e9fd1a25
commit 2ae68a171b

View File

@@ -265,12 +265,14 @@ export async function up(knex: Knex): Promise<void> {
}); });
// Create folder commit changes // Create folder commit changes
const currentBatchFolderIds = new Set(newCommitsInserted.map((commit) => commit.folderId));
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await knex.batchInsert( await knex.batchInsert(
TableName.FolderCommitChanges, TableName.FolderCommitChanges,
foldersCommitsList foldersCommitsList
.map((folderCommit) => folderCommit.changes) .map((folderCommit) => folderCommit.changes)
.flat() .flat()
.filter((change) => currentBatchFolderIds.has(change.folderId))
.map((change) => ({ .map((change) => ({
folderCommitId: newCommitsMap[change.folderId], folderCommitId: newCommitsMap[change.folderId],
changeType: change.changeType, changeType: change.changeType,
@@ -289,6 +291,7 @@ export async function up(knex: Knex): Promise<void> {
foldersCommitsList foldersCommitsList
.map((folderCommit) => folderCommit.changes) .map((folderCommit) => folderCommit.changes)
.flat() .flat()
.filter((change) => currentBatchFolderIds.has(change.folderId))
.map((change) => ({ .map((change) => ({
folderCheckpointId: newCheckpointsMap[change.folderId], folderCheckpointId: newCheckpointsMap[change.folderId],
folderVersionId: change.folderVersionId, folderVersionId: change.folderVersionId,
@@ -303,9 +306,11 @@ export async function up(knex: Knex): Promise<void> {
const newTreeCheckpoints = (await knex const newTreeCheckpoints = (await knex
.batchInsert( .batchInsert(
TableName.FolderTreeCheckpoint, TableName.FolderTreeCheckpoint,
Object.keys(rootFoldersMap).map((folderId) => ({ Object.keys(rootFoldersMap)
folderCommitId: newCommitsMap[folderId] .filter((folderId) => currentBatchFolderIds.has(folderId))
})) .map((folderId) => ({
folderCommitId: newCommitsMap[folderId]
}))
) )
.returning("*")) as TFolderTreeCheckpoints[]; .returning("*")) as TFolderTreeCheckpoints[];
@@ -321,11 +326,13 @@ export async function up(knex: Knex): Promise<void> {
await knex await knex
.batchInsert( .batchInsert(
TableName.FolderTreeCheckpointResources, TableName.FolderTreeCheckpointResources,
newCommitsInserted.map((folderCommit) => ({ newCommitsInserted
folderTreeCheckpointId: newTreeCheckpointsMap[folderCommit.envId], .filter((folderCommit) => newTreeCheckpointsMap[folderCommit.envId])
folderId: folderCommit.folderId, .map((folderCommit) => ({
folderCommitId: folderCommit.id folderTreeCheckpointId: newTreeCheckpointsMap[folderCommit.envId],
})) folderId: folderCommit.folderId,
folderCommitId: folderCommit.id
}))
) )
.returning("*"); .returning("*");