Skip to content

Commit 5326eac

Browse files
fix: use stable sort for migration operations (fixes #15)
Replace List.Sort() with OrderBy() in TimescaleMigrationsModelDiffer to preserve the ependency order from base.GetDifferences(). The unstable sort was causing CreateIndex operations to appear before CreateTable operations, breaking migrations. Added comprehensive tests for operation ordering including a regression test with 30+ operations that reliably fails with unstable sort.
1 parent b1f4321 commit 5326eac

2 files changed

Lines changed: 832 additions & 3 deletions

File tree

src/Eftdb/Internals/TimescaleMigrationsModelDiffer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ public override IReadOnlyList<MigrationOperation> GetDifferences(IRelationalMode
3737
}
3838

3939
// Sort the entire list based on the priority defined in the helper method
40-
allOperations.Sort((op1, op2) => GetOperationPriority(op1).CompareTo(GetOperationPriority(op2)));
41-
42-
return allOperations;
40+
List<MigrationOperation> sortedOperations = [.. allOperations.OrderBy(GetOperationPriority)];
41+
return sortedOperations;
4342
}
4443

4544
/// <summary>

0 commit comments

Comments
 (0)