Deprecate FieldMetadataInterface (#13264)
# Introduction
From the moment replaced the FieldMetadataInterface definition to:
```ts
import { FieldMetadataType } from 'twenty-shared/types';
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
export type FieldMetadataInterface<
T extends FieldMetadataType = FieldMetadataType,
> = FieldMetadataEntity<T>;
```
After this PR merge will create a new one removing the type and
replacing it to `FieldMetadataEntity`.
Did not renamed it here to avoid conflicts on naming + type issues fixs
within the same PR
## Field metadata entity RELATION or MORPH
Relations fields cannot be null for those field metadata entity instance
anymore, but are never for the others see
`packages/twenty-server/src/engine/metadata-modules/field-metadata/types/field-metadata-entity-test.type.ts`
( introduced TypeScript tests )
## Concerns
- TS_VECTOR is the most at risk with the `generatedType` and
`asExpression` removal from interface
## What's next
- `FielMetadataInterface` removal and rename ( see introduction )
- Depcrecating `ObjectMetadataInterface`
- Refactor `FieldMetadataEntity` optional fiels to be nullable only
- TO DIG `never` occurences on settings, defaultValue etc
- Some interfaces will be replaced by the `FlatFieldMetadata` when
deprecating the current sync and comparators tools
This commit is contained in:
@ -172,7 +172,16 @@ export class FieldMetadataHealthService {
|
||||
serializeDefaultValue(`'${option.value}'`),
|
||||
);
|
||||
|
||||
if (!enumValues.includes(columnDefaultValue)) {
|
||||
if (!isDefined(enumValues)) {
|
||||
issues.push({
|
||||
type: WorkspaceHealthIssueType.COLUMN_OPTIONS_NOT_VALID,
|
||||
fieldMetadata,
|
||||
columnStructure,
|
||||
message: `Column options of ${fieldMetadata.name} are not defined`,
|
||||
});
|
||||
}
|
||||
|
||||
if (isDefined(enumValues) && !enumValues.includes(columnDefaultValue)) {
|
||||
issues.push({
|
||||
type: WorkspaceHealthIssueType.COLUMN_DEFAULT_VALUE_NOT_VALID,
|
||||
fieldMetadata,
|
||||
@ -247,8 +256,17 @@ export class FieldMetadataHealthService {
|
||||
});
|
||||
}
|
||||
|
||||
if (!isDefined(fieldMetadata.options)) {
|
||||
issues.push({
|
||||
type: WorkspaceHealthIssueType.COLUMN_OPTIONS_NOT_VALID,
|
||||
fieldMetadata,
|
||||
message: `Column options of ${fieldMetadata.name} are not defined`,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
isEnumFieldMetadataType(fieldMetadata.type) &&
|
||||
isDefined(fieldMetadata.options) &&
|
||||
!validateOptionsForType(fieldMetadata.type, fieldMetadata.options)
|
||||
) {
|
||||
issues.push({
|
||||
@ -300,7 +318,7 @@ export class FieldMetadataHealthService {
|
||||
});
|
||||
} else {
|
||||
metadataDefaultValue.forEach((value) => {
|
||||
if (!enumValues.includes(value)) {
|
||||
if (isDefined(enumValues) && !enumValues.includes(value)) {
|
||||
issues.push({
|
||||
type: WorkspaceHealthIssueType.COLUMN_DEFAULT_VALUE_NOT_VALID,
|
||||
fieldMetadata,
|
||||
@ -309,7 +327,10 @@ export class FieldMetadataHealthService {
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (enumValues.includes(metadataDefaultValue as string)) {
|
||||
} else if (
|
||||
isDefined(enumValues) &&
|
||||
!enumValues.includes(metadataDefaultValue as string)
|
||||
) {
|
||||
issues.push({
|
||||
type: WorkspaceHealthIssueType.COLUMN_DEFAULT_VALUE_NOT_VALID,
|
||||
fieldMetadata,
|
||||
|
||||
@ -2,17 +2,30 @@ import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
import { RelationType } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-type.interface';
|
||||
|
||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { IndexMetadataEntity } from 'src/engine/metadata-modules/index-metadata/index-metadata.entity';
|
||||
import { createIndexMigration } from 'src/engine/workspace-manager/workspace-migration-builder/factories/utils/workspace-migration-index.factory.utils';
|
||||
import { getMockFieldMetadataEntity } from 'src/utils/__test__/get-field-metadata-entity.mock';
|
||||
|
||||
describe('WorkspaceMigrationIndexFactory', () => {
|
||||
it('should create index migrations for simple fields', async () => {
|
||||
const simpleField = getMockFieldMetadataEntity({
|
||||
workspaceId: '20202020-0000-0000-0000-000000000000',
|
||||
objectMetadataId: '20202020-0000-0000-0000-000000000001',
|
||||
id: 'f1',
|
||||
type: FieldMetadataType.TEXT,
|
||||
name: 'simpleField',
|
||||
label: 'Simple Field',
|
||||
isNullable: true,
|
||||
isLabelSyncedWithName: true,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
const objectMetadata = {
|
||||
id: 'obj1',
|
||||
workspaceId: 'ws1',
|
||||
id: '20202020-0000-0000-0000-000000000002',
|
||||
workspaceId: '20202020-0000-0000-0000-000000000000',
|
||||
nameSingular: 'Test',
|
||||
fields: [{ id: 'f1', name: 'simpleField', type: FieldMetadataType.TEXT }],
|
||||
fields: [simpleField],
|
||||
isCustom: false,
|
||||
};
|
||||
const indexMetadata = {
|
||||
@ -39,25 +52,28 @@ describe('WorkspaceMigrationIndexFactory', () => {
|
||||
});
|
||||
|
||||
it('should create index migrations for relation fields', async () => {
|
||||
const fieldMetadata: Pick<
|
||||
FieldMetadataEntity<FieldMetadataType.RELATION>,
|
||||
'id' | 'name' | 'type' | 'settings' | 'isCustom'
|
||||
> = {
|
||||
const relationField = getMockFieldMetadataEntity({
|
||||
workspaceId: '20202020-0000-0000-0000-000000000000',
|
||||
objectMetadataId: '20202020-0000-0000-0000-000000000001',
|
||||
id: 'f2',
|
||||
name: 'author',
|
||||
type: FieldMetadataType.RELATION,
|
||||
name: 'author',
|
||||
label: 'Author',
|
||||
isNullable: true,
|
||||
isLabelSyncedWithName: true,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
settings: {
|
||||
relationType: RelationType.MANY_TO_ONE,
|
||||
joinColumnName: 'authorId',
|
||||
},
|
||||
isCustom: false,
|
||||
};
|
||||
});
|
||||
|
||||
const objectMetadata = {
|
||||
id: 'obj2',
|
||||
workspaceId: 'ws1',
|
||||
id: '20202020-0000-0000-0000-000000000003',
|
||||
workspaceId: '20202020-0000-0000-0000-000000000000',
|
||||
nameSingular: 'Attachment',
|
||||
fields: [fieldMetadata],
|
||||
fields: [relationField],
|
||||
isCustom: false,
|
||||
};
|
||||
const indexMetadata = {
|
||||
|
||||
@ -11,13 +11,14 @@ type FlatFieldMetadataOverrides<
|
||||
Partial<FlatFieldMetadata<T>>;
|
||||
|
||||
export const getFlatFieldMetadataMock = <
|
||||
T extends FieldMetadataType = FieldMetadataType,
|
||||
T extends FieldMetadataType = FieldMetadataType.TEXT,
|
||||
>(
|
||||
overrides: FlatFieldMetadataOverrides<T>,
|
||||
): FlatFieldMetadata<T> => {
|
||||
const createdAt = faker.date.anytime();
|
||||
|
||||
return {
|
||||
type: FieldMetadataType.TEXT as T,
|
||||
createdAt,
|
||||
description: 'default flat field metadata description',
|
||||
icon: 'icon',
|
||||
@ -28,15 +29,18 @@ export const getFlatFieldMetadataMock = <
|
||||
label: 'flat field metadata label',
|
||||
isNullable: true,
|
||||
isUnique: false,
|
||||
relationTargetFieldMetadataId: undefined,
|
||||
relationTargetObjectMetadataId: undefined,
|
||||
type: FieldMetadataType.TEXT as T,
|
||||
isLabelSyncedWithName: false,
|
||||
isSystem: false,
|
||||
standardId: undefined,
|
||||
standardId: null,
|
||||
standardOverrides: undefined,
|
||||
updatedAt: createdAt,
|
||||
workspaceId: faker.string.uuid(),
|
||||
defaultValue: null,
|
||||
options: null,
|
||||
relationTargetFieldMetadata: undefined as never,
|
||||
relationTargetFieldMetadataId: undefined as never,
|
||||
relationTargetObjectMetadata: undefined as never,
|
||||
relationTargetObjectMetadataId: undefined as never,
|
||||
...overrides,
|
||||
};
|
||||
};
|
||||
|
||||
@ -11,8 +11,6 @@ type FieldMetadataEntityRelationProperties =
|
||||
>;
|
||||
|
||||
export type FlatFieldMetadata<T extends FieldMetadataType = FieldMetadataType> =
|
||||
Partial<
|
||||
Omit<FieldMetadataEntity<T>, FieldMetadataEntityRelationProperties>
|
||||
> & {
|
||||
Omit<FieldMetadataEntity<T>, FieldMetadataEntityRelationProperties> & {
|
||||
uniqueIdentifier: string;
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -104,20 +104,19 @@ const relationTestCases: WorkspaceMigrationBuilderTestCase[] = [
|
||||
context: {
|
||||
input: () => {
|
||||
const objectMetadataId = faker.string.uuid();
|
||||
const updatedFieldMetadata =
|
||||
getFlatFieldMetadataMock<FieldMetadataType.RELATION>({
|
||||
uniqueIdentifier: 'field-metadata-unique-identifier-1',
|
||||
objectMetadataId,
|
||||
type: FieldMetadataType.RELATION,
|
||||
settings: {
|
||||
relationType: RelationType.MANY_TO_ONE,
|
||||
isForeignKey: true,
|
||||
joinColumnName: 'column-name',
|
||||
onDelete: undefined,
|
||||
},
|
||||
relationTargetFieldMetadataId: faker.string.uuid(),
|
||||
relationTargetObjectMetadataId: faker.string.uuid(),
|
||||
});
|
||||
const updatedFieldMetadata = getFlatFieldMetadataMock({
|
||||
uniqueIdentifier: 'field-metadata-unique-identifier-1',
|
||||
objectMetadataId,
|
||||
type: FieldMetadataType.RELATION,
|
||||
settings: {
|
||||
relationType: RelationType.MANY_TO_ONE,
|
||||
isForeignKey: true,
|
||||
joinColumnName: 'column-name',
|
||||
onDelete: undefined,
|
||||
},
|
||||
relationTargetFieldMetadataId: faker.string.uuid(),
|
||||
relationTargetObjectMetadataId: faker.string.uuid(),
|
||||
});
|
||||
const flatObjectMetadata = getFlatObjectMetadataMock({
|
||||
uniqueIdentifier: 'object-metadata-unique-identifier-1',
|
||||
isLabelSyncedWithName: true,
|
||||
@ -130,7 +129,7 @@ const relationTestCases: WorkspaceMigrationBuilderTestCase[] = [
|
||||
{
|
||||
...flatObjectMetadata,
|
||||
flatFieldMetadatas: [
|
||||
{
|
||||
getFlatFieldMetadataMock({
|
||||
...updatedFieldMetadata,
|
||||
settings: {
|
||||
relationType: RelationType.ONE_TO_MANY,
|
||||
@ -140,7 +139,7 @@ const relationTestCases: WorkspaceMigrationBuilderTestCase[] = [
|
||||
},
|
||||
relationTargetFieldMetadataId: faker.string.uuid(),
|
||||
relationTargetObjectMetadataId: faker.string.uuid(),
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@ -195,6 +195,8 @@ export class WorkspaceFieldRelationComparator {
|
||||
throw new Error(`Field ${fieldId} not found in standardObjectMetadata`);
|
||||
}
|
||||
|
||||
const relationFieldMetadata = propertiesMap[fieldId];
|
||||
|
||||
if (relationTypeChange) {
|
||||
result.push({
|
||||
action: ComparatorAction.DELETE,
|
||||
@ -204,9 +206,11 @@ export class WorkspaceFieldRelationComparator {
|
||||
result.push({
|
||||
action: ComparatorAction.CREATE,
|
||||
object: {
|
||||
...propertiesMap[fieldId],
|
||||
...relationFieldMetadata,
|
||||
id: originalFieldMetadata.id,
|
||||
standardId: standardFieldMetadata.standardId ?? undefined,
|
||||
description: relationFieldMetadata.description ?? undefined,
|
||||
icon: relationFieldMetadata.icon ?? undefined,
|
||||
},
|
||||
});
|
||||
} else if (allOldPropertiesAreNull) {
|
||||
@ -216,6 +220,8 @@ export class WorkspaceFieldRelationComparator {
|
||||
...propertiesMap[fieldId],
|
||||
id: originalFieldMetadata.id,
|
||||
standardId: standardFieldMetadata.standardId ?? undefined,
|
||||
description: relationFieldMetadata.description ?? undefined,
|
||||
icon: relationFieldMetadata.icon ?? undefined,
|
||||
},
|
||||
});
|
||||
} else if (allNewPropertiesAreNull) {
|
||||
@ -230,6 +236,8 @@ export class WorkspaceFieldRelationComparator {
|
||||
...propertiesMap[fieldId],
|
||||
id: originalFieldMetadata.id,
|
||||
standardId: standardFieldMetadata.standardId ?? undefined,
|
||||
description: relationFieldMetadata.description ?? undefined,
|
||||
icon: relationFieldMetadata.icon ?? undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -143,8 +143,8 @@ export class StandardFieldFactory {
|
||||
icon: workspaceFieldMetadataArgs.icon,
|
||||
label: workspaceFieldMetadataArgs.label,
|
||||
description: workspaceFieldMetadataArgs.description,
|
||||
defaultValue: workspaceFieldMetadataArgs.defaultValue,
|
||||
options: workspaceFieldMetadataArgs.options,
|
||||
defaultValue: workspaceFieldMetadataArgs.defaultValue ?? null,
|
||||
options: workspaceFieldMetadataArgs.options ?? null,
|
||||
settings: workspaceFieldMetadataArgs.settings,
|
||||
workspaceId: context.workspaceId,
|
||||
isNullable: workspaceFieldMetadataArgs.isNullable,
|
||||
@ -155,6 +155,10 @@ export class StandardFieldFactory {
|
||||
asExpression: workspaceFieldMetadataArgs.asExpression,
|
||||
generatedType: workspaceFieldMetadataArgs.generatedType,
|
||||
isLabelSyncedWithName: workspaceFieldMetadataArgs.isLabelSyncedWithName,
|
||||
relationTargetFieldMetadata: null,
|
||||
relationTargetFieldMetadataId: null,
|
||||
relationTargetObjectMetadata: null,
|
||||
relationTargetObjectMetadataId: null,
|
||||
},
|
||||
];
|
||||
}
|
||||
@ -195,6 +199,12 @@ export class StandardFieldFactory {
|
||||
isActive: workspaceRelationMetadataArgs.isActive ?? true,
|
||||
isLabelSyncedWithName:
|
||||
workspaceRelationMetadataArgs.isLabelSyncedWithName,
|
||||
defaultValue: null,
|
||||
options: null,
|
||||
relationTargetFieldMetadata: null,
|
||||
relationTargetFieldMetadataId: null,
|
||||
relationTargetObjectMetadata: null,
|
||||
relationTargetObjectMetadataId: null,
|
||||
});
|
||||
|
||||
return fieldMetadataCollection;
|
||||
|
||||
@ -5,6 +5,7 @@ import { WorkspaceDynamicRelationMetadataArgsFactory } from 'src/engine/twenty-o
|
||||
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
|
||||
// Should get deprecated in favor of the FlatFieldMetadata
|
||||
export type PartialFieldMetadata<
|
||||
T extends FieldMetadataType = FieldMetadataType,
|
||||
> = Omit<
|
||||
@ -15,6 +16,15 @@ export type PartialFieldMetadata<
|
||||
| 'objectMetadataId'
|
||||
| 'createdAt'
|
||||
| 'updatedAt'
|
||||
| 'standardId'
|
||||
| 'icon'
|
||||
| 'isSystem'
|
||||
| 'workspaceId'
|
||||
| 'isActive'
|
||||
| 'asExpression'
|
||||
| 'indexFieldMetadatas'
|
||||
| 'fieldPermissions'
|
||||
| 'object'
|
||||
> & {
|
||||
standardId: string;
|
||||
label: string | ((objectMetadata: ObjectMetadataEntity) => string);
|
||||
@ -24,8 +34,8 @@ export type PartialFieldMetadata<
|
||||
workspaceId: string;
|
||||
objectMetadataId?: string;
|
||||
isActive?: boolean;
|
||||
asExpression?: string;
|
||||
generatedType?: 'STORED' | 'VIRTUAL';
|
||||
asExpression?: string; // not accurate
|
||||
generatedType?: 'STORED' | 'VIRTUAL'; // not accurate
|
||||
};
|
||||
|
||||
export type PartialComputedFieldMetadata = {
|
||||
|
||||
@ -48,6 +48,12 @@ export const computeStandardFields = (
|
||||
defaultValue: null,
|
||||
isNullable: true,
|
||||
isLabelSyncedWithName: true,
|
||||
isUnique: null,
|
||||
options: null,
|
||||
relationTargetFieldMetadata: null,
|
||||
relationTargetFieldMetadataId: null,
|
||||
relationTargetObjectMetadata: null,
|
||||
relationTargetObjectMetadataId: null,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user