From 9dd7432e6b7e24da874e256eb58761f9e339acab Mon Sep 17 00:00:00 2001 From: dswbx Date: Thu, 18 Sep 2025 09:50:05 +0200 Subject: [PATCH 1/2] refactor: remove unique field validation from `EntityIndex` Eliminated validation requiring the first field in unique indices to be mandatory. This simplifies the logic as the requirement is no longer necessary. --- app/src/data/fields/indices/EntityIndex.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/src/data/fields/indices/EntityIndex.ts b/app/src/data/fields/indices/EntityIndex.ts index e8af2e6..ec69ecc 100644 --- a/app/src/data/fields/indices/EntityIndex.ts +++ b/app/src/data/fields/indices/EntityIndex.ts @@ -15,17 +15,6 @@ export class EntityIndex { throw new Error("All fields must be instances of Field"); } - if (unique) { - const firstRequired = fields[0]?.isRequired(); - if (!firstRequired) { - throw new Error( - `Unique indices must have first field as required: ${fields - .map((f) => f.name) - .join(", ")}`, - ); - } - } - if (!name) { this.name = [ unique ? "idx_unique" : "idx", From ffdf453fea8c9ea70f1d54954f4fd4d88f2db8e6 Mon Sep 17 00:00:00 2001 From: dswbx Date: Thu, 18 Sep 2025 09:52:05 +0200 Subject: [PATCH 2/2] fix: remove non-unique index test The removed test no longer aligns with the current `EntityIndex` implementation, as non-unique validation is not applicable anymore. --- app/__test__/data/specs/fields/FieldIndex.spec.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/__test__/data/specs/fields/FieldIndex.spec.ts b/app/__test__/data/specs/fields/FieldIndex.spec.ts index ab94214..fbcfabf 100644 --- a/app/__test__/data/specs/fields/FieldIndex.spec.ts +++ b/app/__test__/data/specs/fields/FieldIndex.spec.ts @@ -23,11 +23,4 @@ describe("FieldIndex", async () => { expect(index.name).toEqual("idx_test_name"); expect(index.unique).toEqual(false); }); - - test("it fails on non-unique", async () => { - const field = new TestField("name", { required: false }); - - expect(() => new EntityIndex(entity, [field], true)).toThrowError(); - expect(() => new EntityIndex(entity, [field])).toBeDefined(); - }); });