From 72f95aa0db3f497651726d6b06b47693d5f5a226 Mon Sep 17 00:00:00 2001 From: "soroush.asadi" Date: Tue, 2 Jun 2026 11:55:06 +0330 Subject: [PATCH] fix(demo-seed): stop truncating ingredient/table ids to 36 chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BuildDemoIngredients/BuildDemoTables built ids as "{cafeId}_ing_{guid}"[..36]. For a real cafe (32-char hex id) the first 36 chars are just "{cafeId}_ing" — the unique guid is cut off, so all 15 ingredients (and all 10 tables) get the SAME id, causing a primary-key collision on SaveChanges -> 500. cafe_demo_001 has a short id so the guid survived, which is why the bug only hit real cafes. The Id columns are text (no length limit), so the truncation served no purpose. Removed [..36] from both so the full unique id is kept. Co-Authored-By: Claude Opus 4.8 --- src/Meezi.API/Services/DemoSeedService.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Meezi.API/Services/DemoSeedService.cs b/src/Meezi.API/Services/DemoSeedService.cs index 60e875d..a7c0de9 100644 --- a/src/Meezi.API/Services/DemoSeedService.cs +++ b/src/Meezi.API/Services/DemoSeedService.cs @@ -130,7 +130,10 @@ public class DemoSeedService : IDemoSeedService decimal qty, decimal reorder, decimal cost, decimal par) => new() { - Id = $"{cafeId}_ing_{Guid.NewGuid():N}"[..36], + // No [..36] truncation: Id is a text column, and truncating to 36 chars + // cuts off the unique guid for real (32-char) café ids → every row gets + // the same id → PK collision → 500. Keep the full unique id. + Id = $"{cafeId}_ing_{Guid.NewGuid():N}", CafeId = cafeId, Name = name, Unit = unit, @@ -160,7 +163,9 @@ public class DemoSeedService : IDemoSeedService string cafeId, string branchId, string number, int capacity, string floor, int sortOrder) => new() { - Id = $"{cafeId}_tbl_{Guid.NewGuid():N}"[..36], + // No [..36] truncation (see Ingredient above): truncating cuts the guid + // for real 32-char café ids → identical ids → PK collision → 500. + Id = $"{cafeId}_tbl_{Guid.NewGuid():N}", CafeId = cafeId, BranchId = branchId, Number = number,