Unique fields - add unicity toggle on data model settings (#13592)
To review after https://github.com/twentyhq/twenty/pull/13539 closes https://github.com/twentyhq/core-team-issues/issues/1224 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
-4
@@ -8,7 +8,6 @@ describe('validateCanCreateUniqueIndex', () => {
|
||||
const field = {
|
||||
name: 'testField',
|
||||
type: FieldMetadataType.MORPH_RELATION,
|
||||
isCustom: true,
|
||||
};
|
||||
|
||||
expect(() => validateCanCreateUniqueIndex(field)).toThrow(
|
||||
@@ -23,7 +22,6 @@ describe('validateCanCreateUniqueIndex', () => {
|
||||
const field = {
|
||||
name: 'testField',
|
||||
type: FieldMetadataType.RELATION,
|
||||
isCustom: true,
|
||||
};
|
||||
|
||||
expect(() => validateCanCreateUniqueIndex(field)).toThrow(
|
||||
@@ -38,7 +36,6 @@ describe('validateCanCreateUniqueIndex', () => {
|
||||
const field = {
|
||||
name: 'testField',
|
||||
type: FieldMetadataType.FULL_NAME,
|
||||
isCustom: true,
|
||||
};
|
||||
|
||||
expect(() => validateCanCreateUniqueIndex(field)).toThrow(
|
||||
@@ -53,7 +50,6 @@ describe('validateCanCreateUniqueIndex', () => {
|
||||
const field = {
|
||||
name: 'testField',
|
||||
type: FieldMetadataType.ADDRESS,
|
||||
isCustom: true,
|
||||
};
|
||||
|
||||
expect(() => validateCanCreateUniqueIndex(field)).toThrow(
|
||||
|
||||
+1
-10
@@ -10,17 +10,8 @@ import {
|
||||
import { isCompositeFieldMetadataType } from 'src/engine/metadata-modules/field-metadata/utils/is-composite-field-metadata-type.util';
|
||||
|
||||
export const validateCanCreateUniqueIndex = (
|
||||
field: Pick<FieldMetadataEntity, 'type' | 'name' | 'isCustom'>,
|
||||
field: Pick<FieldMetadataEntity, 'type' | 'name'>,
|
||||
) => {
|
||||
if (field.isCustom === false)
|
||||
throw new FieldMetadataException(
|
||||
`Unique index cannot be created on standard field`,
|
||||
FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
{
|
||||
userFriendlyMessage: t`Standard fields cannot be unique.`,
|
||||
},
|
||||
);
|
||||
|
||||
const isCompositeFieldWithNonIncludedUniqueConstraint =
|
||||
isCompositeFieldMetadataType(field.type) &&
|
||||
!compositeTypeDefinitions
|
||||
|
||||
Reference in New Issue
Block a user