mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
Merge pull request #261 from bknd-io/fix/unique-indexes-without-required-first
refactor: remove unique field validation from `EntityIndex`
This commit is contained in:
@@ -23,11 +23,4 @@ describe("FieldIndex", async () => {
|
|||||||
expect(index.name).toEqual("idx_test_name");
|
expect(index.name).toEqual("idx_test_name");
|
||||||
expect(index.unique).toEqual(false);
|
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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,17 +15,6 @@ export class EntityIndex {
|
|||||||
throw new Error("All fields must be instances of Field");
|
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) {
|
if (!name) {
|
||||||
this.name = [
|
this.name = [
|
||||||
unique ? "idx_unique" : "idx",
|
unique ? "idx_unique" : "idx",
|
||||||
|
|||||||
Reference in New Issue
Block a user