mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-25 21:13:01 +03:00
fix: use proper variable name (#2938)
This commit is contained in:
parent
032894e448
commit
44f1fe54e1
@ -43,14 +43,14 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
|||||||
}
|
}
|
||||||
|
|
||||||
override async createOne(
|
override async createOne(
|
||||||
record: CreateFieldInput,
|
fieldMetadataInput: CreateFieldInput,
|
||||||
): Promise<FieldMetadataEntity> {
|
): Promise<FieldMetadataEntity> {
|
||||||
const objectMetadata =
|
const objectMetadata =
|
||||||
await this.objectMetadataService.findOneWithinWorkspace(
|
await this.objectMetadataService.findOneWithinWorkspace(
|
||||||
record.workspaceId,
|
fieldMetadataInput.workspaceId,
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
id: record.objectMetadataId,
|
id: fieldMetadataInput.objectMetadataId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -61,9 +61,9 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
|||||||
|
|
||||||
const fieldAlreadyExists = await this.fieldMetadataRepository.findOne({
|
const fieldAlreadyExists = await this.fieldMetadataRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
name: record.name,
|
name: fieldMetadataInput.name,
|
||||||
objectMetadataId: record.objectMetadataId,
|
objectMetadataId: fieldMetadataInput.objectMetadataId,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: fieldMetadataInput.workspaceId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -72,10 +72,14 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
|||||||
}
|
}
|
||||||
|
|
||||||
const createdFieldMetadata = await super.createOne({
|
const createdFieldMetadata = await super.createOne({
|
||||||
...record,
|
...fieldMetadataInput,
|
||||||
targetColumnMap: generateTargetColumnMap(record.type, true, record.name),
|
targetColumnMap: generateTargetColumnMap(
|
||||||
options: record.options
|
fieldMetadataInput.type,
|
||||||
? record.options.map((option) => ({
|
true,
|
||||||
|
fieldMetadataInput.name,
|
||||||
|
),
|
||||||
|
options: fieldMetadataInput.options
|
||||||
|
? fieldMetadataInput.options.map((option) => ({
|
||||||
...option,
|
...option,
|
||||||
id: uuidV4(),
|
id: uuidV4(),
|
||||||
}))
|
}))
|
||||||
@ -85,7 +89,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
|||||||
});
|
});
|
||||||
|
|
||||||
await this.workspaceMigrationService.createCustomMigration(
|
await this.workspaceMigrationService.createCustomMigration(
|
||||||
record.workspaceId,
|
fieldMetadataInput.workspaceId,
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
name: objectMetadata.targetTableName,
|
name: objectMetadata.targetTableName,
|
||||||
@ -99,13 +103,13 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
|||||||
);
|
);
|
||||||
|
|
||||||
await this.workspaceMigrationRunnerService.executeMigrationFromPendingMigrations(
|
await this.workspaceMigrationRunnerService.executeMigrationFromPendingMigrations(
|
||||||
record.workspaceId,
|
fieldMetadataInput.workspaceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: Move viewField creation to a cdc scheduler
|
// TODO: Move viewField creation to a cdc scheduler
|
||||||
const dataSourceMetadata =
|
const dataSourceMetadata =
|
||||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceIdOrFail(
|
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceIdOrFail(
|
||||||
record.workspaceId,
|
fieldMetadataInput.workspaceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const workspaceDataSource = await this.typeORMService.connectToDataSource(
|
const workspaceDataSource = await this.typeORMService.connectToDataSource(
|
||||||
@ -146,12 +150,12 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
|||||||
|
|
||||||
override async updateOne(
|
override async updateOne(
|
||||||
id: string,
|
id: string,
|
||||||
record: UpdateFieldInput,
|
fieldMetadataInput: UpdateFieldInput,
|
||||||
): Promise<FieldMetadataEntity> {
|
): Promise<FieldMetadataEntity> {
|
||||||
const existingFieldMetadata = await this.fieldMetadataRepository.findOne({
|
const existingFieldMetadata = await this.fieldMetadataRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: fieldMetadataInput.workspaceId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -161,16 +165,16 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
|||||||
|
|
||||||
if (existingFieldMetadata.isCustom === false) {
|
if (existingFieldMetadata.isCustom === false) {
|
||||||
// We can only update the isActive field for standard fields
|
// We can only update the isActive field for standard fields
|
||||||
record = {
|
fieldMetadataInput = {
|
||||||
id: record.id,
|
id: fieldMetadataInput.id,
|
||||||
isActive: record.isActive,
|
isActive: fieldMetadataInput.isActive,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: fieldMetadataInput.workspaceId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const objectMetadata =
|
const objectMetadata =
|
||||||
await this.objectMetadataService.findOneWithinWorkspace(
|
await this.objectMetadataService.findOneWithinWorkspace(
|
||||||
record.workspaceId,
|
fieldMetadataInput.workspaceId,
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
id: existingFieldMetadata?.objectMetadataId,
|
id: existingFieldMetadata?.objectMetadataId,
|
||||||
@ -183,17 +187,17 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the id of the options has been provided
|
// Check if the id of the options has been provided
|
||||||
if (record.options) {
|
if (fieldMetadataInput.options) {
|
||||||
for (const option of record.options) {
|
for (const option of fieldMetadataInput.options) {
|
||||||
if (!option.id) {
|
if (!option.id) {
|
||||||
throw new BadRequestException('Option id is required');
|
throw new BadRequestException('Option id is required');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedFieldMetadata = await super.updateOne(id, record);
|
const updatedFieldMetadata = await super.updateOne(id, fieldMetadataInput);
|
||||||
|
|
||||||
if (record.options || record.defaultValue) {
|
if (fieldMetadataInput.options || fieldMetadataInput.defaultValue) {
|
||||||
await this.workspaceMigrationService.createCustomMigration(
|
await this.workspaceMigrationService.createCustomMigration(
|
||||||
existingFieldMetadata.workspaceId,
|
existingFieldMetadata.workspaceId,
|
||||||
[
|
[
|
||||||
|
@ -48,23 +48,26 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
|||||||
}
|
}
|
||||||
|
|
||||||
override async createOne(
|
override async createOne(
|
||||||
record: CreateObjectInput,
|
objectMetadataInput: CreateObjectInput,
|
||||||
): Promise<ObjectMetadataEntity> {
|
): Promise<ObjectMetadataEntity> {
|
||||||
const lastDataSourceMetadata =
|
const lastDataSourceMetadata =
|
||||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceIdOrFail(
|
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceIdOrFail(
|
||||||
record.workspaceId,
|
objectMetadataInput.workspaceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (record.nameSingular.toLowerCase() === record.namePlural.toLowerCase()) {
|
if (
|
||||||
|
objectMetadataInput.nameSingular.toLowerCase() ===
|
||||||
|
objectMetadataInput.namePlural.toLowerCase()
|
||||||
|
) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'The singular and plural name cannot be the same for an object',
|
'The singular and plural name cannot be the same for an object',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const createdObjectMetadata = await super.createOne({
|
const createdObjectMetadata = await super.createOne({
|
||||||
...record,
|
...objectMetadataInput,
|
||||||
dataSourceId: lastDataSourceMetadata.id,
|
dataSourceId: lastDataSourceMetadata.id,
|
||||||
targetTableName: createCustomColumnName(record.nameSingular),
|
targetTableName: createCustomColumnName(objectMetadataInput.nameSingular),
|
||||||
isActive: true,
|
isActive: true,
|
||||||
isCustom: true,
|
isCustom: true,
|
||||||
isSystem: false,
|
isSystem: false,
|
||||||
@ -86,7 +89,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
|||||||
isActive: true,
|
isActive: true,
|
||||||
isCustom: false,
|
isCustom: false,
|
||||||
isSystem: true,
|
isSystem: true,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: objectMetadataInput.workspaceId,
|
||||||
defaultValue: { type: 'uuid' },
|
defaultValue: { type: 'uuid' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -101,7 +104,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
|||||||
isNullable: true,
|
isNullable: true,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
isCustom: false,
|
isCustom: false,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: objectMetadataInput.workspaceId,
|
||||||
defaultValue: { value: 'Untitled' },
|
defaultValue: { value: 'Untitled' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -116,7 +119,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
|||||||
isNullable: true,
|
isNullable: true,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
isCustom: false,
|
isCustom: false,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: objectMetadataInput.workspaceId,
|
||||||
defaultValue: { type: 'now' },
|
defaultValue: { type: 'now' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -132,7 +135,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
|||||||
isActive: true,
|
isActive: true,
|
||||||
isCustom: false,
|
isCustom: false,
|
||||||
isSystem: true,
|
isSystem: true,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: objectMetadataInput.workspaceId,
|
||||||
defaultValue: { type: 'now' },
|
defaultValue: { type: 'now' },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -141,7 +144,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
|||||||
const activityTargetObjectMetadata =
|
const activityTargetObjectMetadata =
|
||||||
await this.objectMetadataRepository.findOneByOrFail({
|
await this.objectMetadataRepository.findOneByOrFail({
|
||||||
nameSingular: 'activityTarget',
|
nameSingular: 'activityTarget',
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: objectMetadataInput.workspaceId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const activityTargetRelationFieldMetadata =
|
const activityTargetRelationFieldMetadata =
|
||||||
@ -149,44 +152,44 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
|||||||
// FROM
|
// FROM
|
||||||
{
|
{
|
||||||
objectMetadataId: createdObjectMetadata.id,
|
objectMetadataId: createdObjectMetadata.id,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: objectMetadataInput.workspaceId,
|
||||||
isCustom: true,
|
isCustom: true,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
type: FieldMetadataType.RELATION,
|
type: FieldMetadataType.RELATION,
|
||||||
name: 'activityTargets',
|
name: 'activityTargets',
|
||||||
label: 'Activities',
|
label: 'Activities',
|
||||||
targetColumnMap: {},
|
targetColumnMap: {},
|
||||||
description: `Activities tied to the ${record.labelSingular}`,
|
description: `Activities tied to the ${objectMetadataInput.labelSingular}`,
|
||||||
icon: 'IconCheckbox',
|
icon: 'IconCheckbox',
|
||||||
isNullable: true,
|
isNullable: true,
|
||||||
},
|
},
|
||||||
// TO
|
// TO
|
||||||
{
|
{
|
||||||
objectMetadataId: activityTargetObjectMetadata.id,
|
objectMetadataId: activityTargetObjectMetadata.id,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: objectMetadataInput.workspaceId,
|
||||||
isCustom: true,
|
isCustom: true,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
type: FieldMetadataType.RELATION,
|
type: FieldMetadataType.RELATION,
|
||||||
name: record.nameSingular,
|
name: objectMetadataInput.nameSingular,
|
||||||
label: record.labelSingular,
|
label: objectMetadataInput.labelSingular,
|
||||||
targetColumnMap: {
|
targetColumnMap: {
|
||||||
value: `${createdObjectMetadata.targetTableName}Id`,
|
value: `${createdObjectMetadata.targetTableName}Id`,
|
||||||
},
|
},
|
||||||
description: `ActivityTarget ${record.labelSingular}`,
|
description: `ActivityTarget ${objectMetadataInput.labelSingular}`,
|
||||||
icon: 'IconBuildingSkyscraper',
|
icon: 'IconBuildingSkyscraper',
|
||||||
isNullable: true,
|
isNullable: true,
|
||||||
},
|
},
|
||||||
// Foreign key
|
// Foreign key
|
||||||
{
|
{
|
||||||
objectMetadataId: activityTargetObjectMetadata.id,
|
objectMetadataId: activityTargetObjectMetadata.id,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: objectMetadataInput.workspaceId,
|
||||||
isCustom: true,
|
isCustom: true,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
type: FieldMetadataType.UUID,
|
type: FieldMetadataType.UUID,
|
||||||
name: `${createdObjectMetadata.targetTableName}Id`,
|
name: `${createdObjectMetadata.targetTableName}Id`,
|
||||||
label: `${record.labelSingular} ID (foreign key)`,
|
label: `${objectMetadataInput.labelSingular} ID (foreign key)`,
|
||||||
targetColumnMap: {},
|
targetColumnMap: {},
|
||||||
description: `ActivityTarget ${record.labelSingular} id foreign key`,
|
description: `ActivityTarget ${objectMetadataInput.labelSingular} id foreign key`,
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
isNullable: true,
|
isNullable: true,
|
||||||
isSystem: true,
|
isSystem: true,
|
||||||
@ -208,7 +211,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
|||||||
|
|
||||||
await this.relationMetadataRepository.save([
|
await this.relationMetadataRepository.save([
|
||||||
{
|
{
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: objectMetadataInput.workspaceId,
|
||||||
relationType: RelationMetadataType.ONE_TO_MANY,
|
relationType: RelationMetadataType.ONE_TO_MANY,
|
||||||
fromObjectMetadataId: createdObjectMetadata.id,
|
fromObjectMetadataId: createdObjectMetadata.id,
|
||||||
toObjectMetadataId: activityTargetObjectMetadata.id,
|
toObjectMetadataId: activityTargetObjectMetadata.id,
|
||||||
|
@ -64,9 +64,11 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
|||||||
}
|
}
|
||||||
|
|
||||||
override async createOne(
|
override async createOne(
|
||||||
record: CreateRelationInput,
|
relationMetadataInput: CreateRelationInput,
|
||||||
): Promise<RelationMetadataEntity> {
|
): Promise<RelationMetadataEntity> {
|
||||||
if (record.relationType === RelationMetadataType.MANY_TO_MANY) {
|
if (
|
||||||
|
relationMetadataInput.relationType === RelationMetadataType.MANY_TO_MANY
|
||||||
|
) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
'Many to many relations are not supported yet',
|
'Many to many relations are not supported yet',
|
||||||
);
|
);
|
||||||
@ -87,10 +89,13 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
|||||||
|
|
||||||
const objectMetadataEntries =
|
const objectMetadataEntries =
|
||||||
await this.objectMetadataService.findManyWithinWorkspace(
|
await this.objectMetadataService.findManyWithinWorkspace(
|
||||||
record.workspaceId,
|
relationMetadataInput.workspaceId,
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
id: In([record.fromObjectMetadataId, record.toObjectMetadataId]),
|
id: In([
|
||||||
|
relationMetadataInput.fromObjectMetadataId,
|
||||||
|
relationMetadataInput.toObjectMetadataId,
|
||||||
|
]),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -102,16 +107,18 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
|||||||
}, {} as { [key: string]: ObjectMetadataEntity });
|
}, {} as { [key: string]: ObjectMetadataEntity });
|
||||||
|
|
||||||
if (
|
if (
|
||||||
objectMetadataMap[record.fromObjectMetadataId] === undefined ||
|
objectMetadataMap[relationMetadataInput.fromObjectMetadataId] ===
|
||||||
objectMetadataMap[record.toObjectMetadataId] === undefined
|
undefined ||
|
||||||
|
objectMetadataMap[relationMetadataInput.toObjectMetadataId] === undefined
|
||||||
) {
|
) {
|
||||||
throw new NotFoundException(
|
throw new NotFoundException(
|
||||||
'Can\t find an existing object matching fromObjectMetadataId or toObjectMetadataId',
|
'Can\t find an existing object matching fromObjectMetadataId or toObjectMetadataId',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseColumnName = `${camelCase(record.toName)}Id`;
|
const baseColumnName = `${camelCase(relationMetadataInput.toName)}Id`;
|
||||||
const isToCustom = objectMetadataMap[record.toObjectMetadataId].isCustom;
|
const isToCustom =
|
||||||
|
objectMetadataMap[relationMetadataInput.toObjectMetadataId].isCustom;
|
||||||
const foreignKeyColumnName = isToCustom
|
const foreignKeyColumnName = isToCustom
|
||||||
? createCustomColumnName(baseColumnName)
|
? createCustomColumnName(baseColumnName)
|
||||||
: baseColumnName;
|
: baseColumnName;
|
||||||
@ -119,40 +126,40 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
|||||||
const createdFields = await this.fieldMetadataService.createMany([
|
const createdFields = await this.fieldMetadataService.createMany([
|
||||||
// FROM
|
// FROM
|
||||||
{
|
{
|
||||||
name: record.fromName,
|
name: relationMetadataInput.fromName,
|
||||||
label: record.fromLabel,
|
label: relationMetadataInput.fromLabel,
|
||||||
description: record.fromDescription,
|
description: relationMetadataInput.fromDescription,
|
||||||
icon: record.fromIcon,
|
icon: relationMetadataInput.fromIcon,
|
||||||
isCustom: true,
|
isCustom: true,
|
||||||
targetColumnMap: {},
|
targetColumnMap: {},
|
||||||
isActive: true,
|
isActive: true,
|
||||||
type: FieldMetadataType.RELATION,
|
type: FieldMetadataType.RELATION,
|
||||||
objectMetadataId: record.fromObjectMetadataId,
|
objectMetadataId: relationMetadataInput.fromObjectMetadataId,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: relationMetadataInput.workspaceId,
|
||||||
},
|
},
|
||||||
// TO
|
// TO
|
||||||
{
|
{
|
||||||
name: record.toName,
|
name: relationMetadataInput.toName,
|
||||||
label: record.toLabel,
|
label: relationMetadataInput.toLabel,
|
||||||
description: record.toDescription,
|
description: relationMetadataInput.toDescription,
|
||||||
icon: record.toIcon,
|
icon: relationMetadataInput.toIcon,
|
||||||
isCustom: true,
|
isCustom: true,
|
||||||
targetColumnMap: {
|
targetColumnMap: {
|
||||||
value: isToCustom
|
value: isToCustom
|
||||||
? createCustomColumnName(record.toName)
|
? createCustomColumnName(relationMetadataInput.toName)
|
||||||
: record.toName,
|
: relationMetadataInput.toName,
|
||||||
},
|
},
|
||||||
isActive: true,
|
isActive: true,
|
||||||
type: FieldMetadataType.RELATION,
|
type: FieldMetadataType.RELATION,
|
||||||
objectMetadataId: record.toObjectMetadataId,
|
objectMetadataId: relationMetadataInput.toObjectMetadataId,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: relationMetadataInput.workspaceId,
|
||||||
},
|
},
|
||||||
// FOREIGN KEY
|
// FOREIGN KEY
|
||||||
{
|
{
|
||||||
name: baseColumnName,
|
name: baseColumnName,
|
||||||
label: `${record.toLabel} Foreign Key`,
|
label: `${relationMetadataInput.toLabel} Foreign Key`,
|
||||||
description: record.toDescription
|
description: relationMetadataInput.toDescription
|
||||||
? `${record.toDescription} Foreign Key`
|
? `${relationMetadataInput.toDescription} Foreign Key`
|
||||||
: undefined,
|
: undefined,
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
isCustom: true,
|
isCustom: true,
|
||||||
@ -163,8 +170,8 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
|||||||
// Should not be visible on the front side
|
// Should not be visible on the front side
|
||||||
isSystem: true,
|
isSystem: true,
|
||||||
type: FieldMetadataType.UUID,
|
type: FieldMetadataType.UUID,
|
||||||
objectMetadataId: record.toObjectMetadataId,
|
objectMetadataId: relationMetadataInput.toObjectMetadataId,
|
||||||
workspaceId: record.workspaceId,
|
workspaceId: relationMetadataInput.workspaceId,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -177,17 +184,18 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
|||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const createdRelationMetadata = await super.createOne({
|
const createdRelationMetadata = await super.createOne({
|
||||||
...record,
|
...relationMetadataInput,
|
||||||
fromFieldMetadataId: createdFieldMap[record.fromName].id,
|
fromFieldMetadataId: createdFieldMap[relationMetadataInput.fromName].id,
|
||||||
toFieldMetadataId: createdFieldMap[record.toName].id,
|
toFieldMetadataId: createdFieldMap[relationMetadataInput.toName].id,
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.workspaceMigrationService.createCustomMigration(
|
await this.workspaceMigrationService.createCustomMigration(
|
||||||
record.workspaceId,
|
relationMetadataInput.workspaceId,
|
||||||
[
|
[
|
||||||
// Create the column
|
// Create the column
|
||||||
{
|
{
|
||||||
name: objectMetadataMap[record.toObjectMetadataId].targetTableName,
|
name: objectMetadataMap[relationMetadataInput.toObjectMetadataId]
|
||||||
|
.targetTableName,
|
||||||
action: 'alter',
|
action: 'alter',
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
@ -199,16 +207,20 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
|||||||
},
|
},
|
||||||
// Create the foreignKey
|
// Create the foreignKey
|
||||||
{
|
{
|
||||||
name: objectMetadataMap[record.toObjectMetadataId].targetTableName,
|
name: objectMetadataMap[relationMetadataInput.toObjectMetadataId]
|
||||||
|
.targetTableName,
|
||||||
action: 'alter',
|
action: 'alter',
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
action: WorkspaceMigrationColumnActionType.RELATION,
|
action: WorkspaceMigrationColumnActionType.RELATION,
|
||||||
columnName: foreignKeyColumnName,
|
columnName: foreignKeyColumnName,
|
||||||
referencedTableName:
|
referencedTableName:
|
||||||
objectMetadataMap[record.fromObjectMetadataId].targetTableName,
|
objectMetadataMap[relationMetadataInput.fromObjectMetadataId]
|
||||||
|
.targetTableName,
|
||||||
referencedTableColumnName: 'id',
|
referencedTableColumnName: 'id',
|
||||||
isUnique: record.relationType === RelationMetadataType.ONE_TO_ONE,
|
isUnique:
|
||||||
|
relationMetadataInput.relationType ===
|
||||||
|
RelationMetadataType.ONE_TO_ONE,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -216,7 +228,7 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
|||||||
);
|
);
|
||||||
|
|
||||||
await this.workspaceMigrationRunnerService.executeMigrationFromPendingMigrations(
|
await this.workspaceMigrationRunnerService.executeMigrationFromPendingMigrations(
|
||||||
record.workspaceId,
|
relationMetadataInput.workspaceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
return createdRelationMetadata;
|
return createdRelationMetadata;
|
||||||
|
Loading…
Reference in New Issue
Block a user