Remove deprecated EMAIL, PHONE, LINK (#7551)
In this PR: - remove deprecated EMAIL, PHONE, LINK field types (except for Zapier package as there is another work ongoing) - remove composite currency filter on currencyCode, actor filter on name and workspaceMember as the UX is not great yet
This commit is contained in:
@ -7,7 +7,6 @@ import { DataSeedDemoWorkspaceCommand } from 'src/database/commands/data-seed-de
|
||||
import { DataSeedDemoWorkspaceModule } from 'src/database/commands/data-seed-demo-workspace/data-seed-demo-workspace.module';
|
||||
import { DataSeedWorkspaceCommand } from 'src/database/commands/data-seed-dev-workspace.command';
|
||||
import { ConfirmationQuestion } from 'src/database/commands/questions/confirmation.question';
|
||||
import { UpgradeTo0_30CommandModule } from 'src/database/commands/upgrade-version/0-30/0-30-upgrade-version.module';
|
||||
import { UpgradeTo0_31CommandModule } from 'src/database/commands/upgrade-version/0-31/0-31-upgrade-version.module';
|
||||
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
||||
import { BillingSubscription } from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
|
||||
@ -47,7 +46,6 @@ import { WorkspaceSyncMetadataModule } from 'src/engine/workspace-manager/worksp
|
||||
DataSeedDemoWorkspaceModule,
|
||||
WorkspaceCacheStorageModule,
|
||||
WorkspaceMetadataVersionModule,
|
||||
UpgradeTo0_30CommandModule,
|
||||
UpgradeTo0_31CommandModule,
|
||||
FeatureFlagModule,
|
||||
],
|
||||
|
||||
@ -1,161 +0,0 @@
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import chalk from 'chalk';
|
||||
import { isDefined } from 'class-validator';
|
||||
import { Command } from 'nest-commander';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import {
|
||||
ActiveWorkspacesCommandOptions,
|
||||
ActiveWorkspacesCommandRunner,
|
||||
} from 'src/database/commands/active-workspaces.command';
|
||||
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
|
||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service';
|
||||
import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
import { ViewService } from 'src/modules/view/services/view.service';
|
||||
@Command({
|
||||
name: 'upgrade-0.30:fix-email-field-migration',
|
||||
description:
|
||||
'Fix migration - delete deprecated email fields and add emails to person views',
|
||||
})
|
||||
export class FixEmailFieldsToEmailsCommand extends ActiveWorkspacesCommandRunner {
|
||||
constructor(
|
||||
@InjectRepository(Workspace, 'core')
|
||||
protected readonly workspaceRepository: Repository<Workspace>,
|
||||
@InjectRepository(FieldMetadataEntity, 'metadata')
|
||||
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
||||
private readonly fieldMetadataService: FieldMetadataService,
|
||||
private readonly typeORMService: TypeORMService,
|
||||
private readonly dataSourceService: DataSourceService,
|
||||
private readonly viewService: ViewService,
|
||||
) {
|
||||
super(workspaceRepository);
|
||||
}
|
||||
|
||||
async executeActiveWorkspacesCommand(
|
||||
_passedParam: string[],
|
||||
_options: ActiveWorkspacesCommandOptions,
|
||||
workspaceIds: string[],
|
||||
): Promise<void> {
|
||||
this.logger.log('Running command to fix migration');
|
||||
|
||||
for (const workspaceId of workspaceIds) {
|
||||
let dataSourceMetadata;
|
||||
|
||||
this.logger.log(`Running command for workspace ${workspaceId}`);
|
||||
try {
|
||||
dataSourceMetadata =
|
||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceId(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (!dataSourceMetadata) {
|
||||
throw new Error(
|
||||
`Could not find dataSourceMetadata for workspace ${workspaceId}`,
|
||||
);
|
||||
}
|
||||
|
||||
const workspaceDataSource =
|
||||
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
||||
|
||||
if (!workspaceDataSource) {
|
||||
throw new Error(
|
||||
`Could not connect to dataSource for workspace ${workspaceId}`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.log(
|
||||
chalk.red(
|
||||
`Could not connect to workspace data source for workspace ${workspaceId}`,
|
||||
),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const deprecatedPersonEmailFieldsMetadata =
|
||||
await this.fieldMetadataRepository.findBy({
|
||||
standardId: PERSON_STANDARD_FIELD_IDS.email,
|
||||
workspaceId: workspaceId,
|
||||
});
|
||||
|
||||
const migratedEmailFieldMetadata = await this.fieldMetadataRepository
|
||||
.findBy({
|
||||
standardId: PERSON_STANDARD_FIELD_IDS.emails,
|
||||
workspaceId: workspaceId,
|
||||
})
|
||||
.then((fields) => fields[0]);
|
||||
|
||||
const personEmailFieldWasMigratedButHasDuplicate =
|
||||
deprecatedPersonEmailFieldsMetadata.length > 0 &&
|
||||
isDefined(migratedEmailFieldMetadata);
|
||||
|
||||
if (!personEmailFieldWasMigratedButHasDuplicate) {
|
||||
this.logger.log(
|
||||
chalk.yellow('No fields to migrate for workspace ' + workspaceId),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const deprecatedEmailFieldMetadata of deprecatedPersonEmailFieldsMetadata) {
|
||||
await this.fieldMetadataService.deleteOneField(
|
||||
{ id: deprecatedEmailFieldMetadata.id },
|
||||
workspaceId,
|
||||
);
|
||||
this.logger.log(
|
||||
chalk.green(`Deleted email field for workspace ${workspaceId}.`),
|
||||
);
|
||||
}
|
||||
|
||||
const personObjectMetadaIdForWorkspace =
|
||||
migratedEmailFieldMetadata.objectMetadataId;
|
||||
|
||||
if (!isDefined(personObjectMetadaIdForWorkspace)) {
|
||||
this.logger.log(
|
||||
chalk.red(
|
||||
`Could not find person object for workspace ${workspaceId}. Could not add emails to person view`,
|
||||
),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
const personViewsIds =
|
||||
await this.viewService.getViewsIdsForObjectMetadataId({
|
||||
workspaceId,
|
||||
objectMetadataId: personObjectMetadaIdForWorkspace as string,
|
||||
});
|
||||
|
||||
await this.viewService.addFieldToViews({
|
||||
workspaceId: workspaceId,
|
||||
fieldId: migratedEmailFieldMetadata.id,
|
||||
viewsIds: personViewsIds,
|
||||
positions: personViewsIds.reduce((acc, personView) => {
|
||||
if (!personView.id) {
|
||||
return acc;
|
||||
}
|
||||
acc[personView.id] = 4;
|
||||
|
||||
return acc;
|
||||
}, []),
|
||||
});
|
||||
this.logger.log(chalk.green(`Added emails to view ${workspaceId}.`));
|
||||
} catch (error) {
|
||||
this.logger.log(
|
||||
chalk.red(
|
||||
`Running command on workspace ${workspaceId} failed with error: ${error}`,
|
||||
),
|
||||
);
|
||||
continue;
|
||||
} finally {
|
||||
this.logger.log(
|
||||
chalk.green(`Finished running command for workspace ${workspaceId}.`),
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.log(chalk.green(`Command completed!`));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,110 +0,0 @@
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import chalk from 'chalk';
|
||||
import { Command } from 'nest-commander';
|
||||
import { Any, Repository } from 'typeorm';
|
||||
|
||||
import {
|
||||
ActiveWorkspacesCommandOptions,
|
||||
ActiveWorkspacesCommandRunner,
|
||||
} from 'src/database/commands/active-workspaces.command';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
|
||||
import {
|
||||
FieldMetadataEntity,
|
||||
FieldMetadataType,
|
||||
} from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { ViewFilterWorkspaceEntity } from 'src/modules/view/standard-objects/view-filter.workspace-entity';
|
||||
|
||||
@Command({
|
||||
name: 'upgrade-0.30:fix-view-filter-operand-for-date-time',
|
||||
description: 'Fix the view filter operand for date time fields',
|
||||
})
|
||||
export class FixViewFilterOperandForDateTimeCommand extends ActiveWorkspacesCommandRunner {
|
||||
constructor(
|
||||
@InjectRepository(Workspace, 'core')
|
||||
protected readonly workspaceRepository: Repository<Workspace>,
|
||||
@InjectRepository(FieldMetadataEntity, 'metadata')
|
||||
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
||||
private readonly dataSourceService: DataSourceService,
|
||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||
) {
|
||||
super(workspaceRepository);
|
||||
}
|
||||
|
||||
async executeActiveWorkspacesCommand(
|
||||
_passedParam: string[],
|
||||
_options: ActiveWorkspacesCommandOptions,
|
||||
workspaceIds: string[],
|
||||
): Promise<void> {
|
||||
for (const workspaceId of workspaceIds) {
|
||||
try {
|
||||
const dataSourceMetadata =
|
||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceId(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (!dataSourceMetadata) {
|
||||
throw new Error(
|
||||
`Could not find dataSourceMetadata for workspace ${workspaceId}`,
|
||||
);
|
||||
}
|
||||
|
||||
const viewFilterRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<ViewFilterWorkspaceEntity>(
|
||||
workspaceId,
|
||||
'viewFilter',
|
||||
);
|
||||
|
||||
const dateTimeFieldMetadata = await this.fieldMetadataRepository.find({
|
||||
where: {
|
||||
workspaceId,
|
||||
type: FieldMetadataType.DATE_TIME,
|
||||
},
|
||||
});
|
||||
|
||||
const dateTimeFieldMetadataIds = dateTimeFieldMetadata.map(
|
||||
(fieldMetadata) => fieldMetadata.id,
|
||||
);
|
||||
|
||||
const lessThanUpdatedResult = await viewFilterRepository.update(
|
||||
{
|
||||
operand: 'lessThan',
|
||||
fieldMetadataId: Any(dateTimeFieldMetadataIds),
|
||||
},
|
||||
{
|
||||
operand: 'isBefore',
|
||||
},
|
||||
);
|
||||
|
||||
const greaterThanUpdatedResult = await viewFilterRepository.update(
|
||||
{
|
||||
operand: 'greaterThan',
|
||||
fieldMetadataId: Any(dateTimeFieldMetadataIds),
|
||||
},
|
||||
{
|
||||
operand: 'isAfter',
|
||||
},
|
||||
);
|
||||
|
||||
this.logger.log(
|
||||
`Updated ${(lessThanUpdatedResult.affected ?? 0) + (greaterThanUpdatedResult.affected ?? 0)} view filters for workspace ${workspaceId}`,
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.log(
|
||||
chalk.red(
|
||||
`Error running command for workspace ${workspaceId}: ${error}`,
|
||||
),
|
||||
);
|
||||
continue;
|
||||
} finally {
|
||||
this.logger.log(
|
||||
chalk.green(`Finished running command for workspace ${workspaceId}.`),
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.log(chalk.green(`Command completed!`));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,360 +0,0 @@
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import chalk from 'chalk';
|
||||
import { Command } from 'nest-commander';
|
||||
import { QueryRunner, Repository } from 'typeorm';
|
||||
|
||||
import {
|
||||
ActiveWorkspacesCommandOptions,
|
||||
ActiveWorkspacesCommandRunner,
|
||||
} from 'src/database/commands/active-workspaces.command';
|
||||
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity';
|
||||
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
|
||||
import { CreateFieldInput } from 'src/engine/metadata-modules/field-metadata/dtos/create-field.input';
|
||||
import {
|
||||
FieldMetadataEntity,
|
||||
FieldMetadataType,
|
||||
} from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { computeTableName } from 'src/engine/utils/compute-table-name.util';
|
||||
import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
import { ViewService } from 'src/modules/view/services/view.service';
|
||||
import { ViewFieldWorkspaceEntity } from 'src/modules/view/standard-objects/view-field.workspace-entity';
|
||||
@Command({
|
||||
name: 'upgrade-0.30:migrate-email-fields-to-emails',
|
||||
description: 'Migrating fields of deprecated type EMAIL to type EMAILS',
|
||||
})
|
||||
export class MigrateEmailFieldsToEmailsCommand extends ActiveWorkspacesCommandRunner {
|
||||
constructor(
|
||||
@InjectRepository(Workspace, 'core')
|
||||
protected readonly workspaceRepository: Repository<Workspace>,
|
||||
@InjectRepository(FieldMetadataEntity, 'metadata')
|
||||
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
||||
@InjectRepository(ObjectMetadataEntity, 'metadata')
|
||||
private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>,
|
||||
private readonly fieldMetadataService: FieldMetadataService,
|
||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||
private readonly typeORMService: TypeORMService,
|
||||
private readonly dataSourceService: DataSourceService,
|
||||
private readonly viewService: ViewService,
|
||||
) {
|
||||
super(workspaceRepository);
|
||||
}
|
||||
|
||||
async executeActiveWorkspacesCommand(
|
||||
_passedParam: string[],
|
||||
_options: ActiveWorkspacesCommandOptions,
|
||||
workspaceIds: string[],
|
||||
): Promise<void> {
|
||||
this.logger.log(
|
||||
'Running command to migrate email type fields to emails type',
|
||||
);
|
||||
|
||||
for (const workspaceId of workspaceIds) {
|
||||
let dataSourceMetadata;
|
||||
let workspaceQueryRunner;
|
||||
|
||||
this.logger.log(`Running command for workspace ${workspaceId}`);
|
||||
try {
|
||||
dataSourceMetadata =
|
||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceId(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (!dataSourceMetadata) {
|
||||
throw new Error(
|
||||
`Could not find dataSourceMetadata for workspace ${workspaceId}`,
|
||||
);
|
||||
}
|
||||
|
||||
const workspaceDataSource =
|
||||
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
||||
|
||||
if (!workspaceDataSource) {
|
||||
throw new Error(
|
||||
`Could not connect to dataSource for workspace ${workspaceId}`,
|
||||
);
|
||||
}
|
||||
|
||||
workspaceQueryRunner = workspaceDataSource.createQueryRunner();
|
||||
|
||||
await workspaceQueryRunner.connect();
|
||||
} catch (error) {
|
||||
this.logger.log(
|
||||
chalk.red(
|
||||
`Could not connect to workspace data source for workspace ${workspaceId}`,
|
||||
),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.migratePersonEmailFieldToEmailsField(
|
||||
workspaceId,
|
||||
workspaceQueryRunner,
|
||||
dataSourceMetadata,
|
||||
);
|
||||
|
||||
const customFieldsWithEmailType =
|
||||
await this.fieldMetadataRepository.find({
|
||||
where: {
|
||||
workspaceId,
|
||||
type: FieldMetadataType.EMAIL,
|
||||
isCustom: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (const customFieldWithEmailType of customFieldsWithEmailType) {
|
||||
const objectMetadata = await this.objectMetadataRepository.findOne({
|
||||
where: { id: customFieldWithEmailType.objectMetadataId },
|
||||
});
|
||||
|
||||
if (!objectMetadata) {
|
||||
throw new Error(
|
||||
`Could not find objectMetadata for field ${customFieldWithEmailType.name}`,
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.log(
|
||||
`Attempting to migrate custom field ${customFieldWithEmailType.name} on ${objectMetadata.nameSingular}.`,
|
||||
);
|
||||
|
||||
const fieldName = customFieldWithEmailType.name;
|
||||
const { id: _id, ...fieldWithEmailTypeWithoutId } =
|
||||
customFieldWithEmailType;
|
||||
|
||||
const emailDefaultValue = fieldWithEmailTypeWithoutId.defaultValue;
|
||||
|
||||
const defaultValueForEmailsField = {
|
||||
primaryEmail: emailDefaultValue,
|
||||
additionalEmails: null,
|
||||
};
|
||||
|
||||
try {
|
||||
const tmpNewEmailsField = await this.fieldMetadataService.createOne(
|
||||
{
|
||||
...fieldWithEmailTypeWithoutId,
|
||||
type: FieldMetadataType.EMAILS,
|
||||
defaultValue: defaultValueForEmailsField,
|
||||
name: `${fieldName}Tmp`,
|
||||
} satisfies CreateFieldInput,
|
||||
);
|
||||
|
||||
const tableName = computeTableName(
|
||||
objectMetadata.nameSingular,
|
||||
objectMetadata.isCustom,
|
||||
);
|
||||
|
||||
// Migrate data from email to emails.primaryEmail
|
||||
await this.migrateDataWithinTable({
|
||||
sourceColumnName: `${customFieldWithEmailType.name}`,
|
||||
targetColumnName: `${tmpNewEmailsField.name}PrimaryEmail`,
|
||||
tableName,
|
||||
workspaceQueryRunner,
|
||||
dataSourceMetadata,
|
||||
});
|
||||
|
||||
// Duplicate email field's views behaviour for new emails field
|
||||
await this.viewService.removeFieldFromViews({
|
||||
workspaceId: workspaceId,
|
||||
fieldId: tmpNewEmailsField.id,
|
||||
});
|
||||
|
||||
const viewFieldRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<ViewFieldWorkspaceEntity>(
|
||||
workspaceId,
|
||||
'viewField',
|
||||
);
|
||||
const viewFieldsWithDeprecatedField =
|
||||
await viewFieldRepository.find({
|
||||
where: {
|
||||
fieldMetadataId: customFieldWithEmailType.id,
|
||||
isVisible: true,
|
||||
},
|
||||
});
|
||||
|
||||
await this.viewService.addFieldToViews({
|
||||
workspaceId: workspaceId,
|
||||
fieldId: tmpNewEmailsField.id,
|
||||
viewsIds: viewFieldsWithDeprecatedField
|
||||
.filter((viewField) => viewField.viewId !== null)
|
||||
.map((viewField) => viewField.viewId as string),
|
||||
positions: viewFieldsWithDeprecatedField.reduce(
|
||||
(acc, viewField) => {
|
||||
if (!viewField.viewId) {
|
||||
return acc;
|
||||
}
|
||||
acc[viewField.viewId] = viewField.position;
|
||||
|
||||
return acc;
|
||||
},
|
||||
[],
|
||||
),
|
||||
});
|
||||
|
||||
// Delete email field
|
||||
await this.fieldMetadataService.deleteOneField(
|
||||
{ id: customFieldWithEmailType.id },
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
// Rename temporary emails field
|
||||
await this.fieldMetadataService.updateOne(tmpNewEmailsField.id, {
|
||||
id: tmpNewEmailsField.id,
|
||||
workspaceId: tmpNewEmailsField.workspaceId,
|
||||
name: `${fieldName}`,
|
||||
isCustom: false,
|
||||
});
|
||||
|
||||
this.logger.log(
|
||||
`Migration of ${customFieldWithEmailType.name} on ${objectMetadata.nameSingular} done!`,
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.log(
|
||||
`Failed to migrate field ${customFieldWithEmailType.name} on ${objectMetadata.nameSingular}, rolling back.`,
|
||||
);
|
||||
|
||||
// Re-create initial field if it was deleted
|
||||
const initialField =
|
||||
await this.fieldMetadataService.findOneWithinWorkspace(
|
||||
workspaceId,
|
||||
{
|
||||
where: {
|
||||
name: `${customFieldWithEmailType.name}`,
|
||||
objectMetadataId: customFieldWithEmailType.objectMetadataId,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const tmpNewEmailsField =
|
||||
await this.fieldMetadataService.findOneWithinWorkspace(
|
||||
workspaceId,
|
||||
{
|
||||
where: {
|
||||
name: `${customFieldWithEmailType.name}Tmp`,
|
||||
objectMetadataId: customFieldWithEmailType.objectMetadataId,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!initialField) {
|
||||
this.logger.log(
|
||||
`Re-creating initial Email field ${customFieldWithEmailType.name} but of type emails`, // Cannot create email fields anymore
|
||||
);
|
||||
const restoredField = await this.fieldMetadataService.createOne({
|
||||
...customFieldWithEmailType,
|
||||
defaultValue: defaultValueForEmailsField,
|
||||
type: FieldMetadataType.EMAILS,
|
||||
});
|
||||
const tableName = computeTableName(
|
||||
objectMetadata.nameSingular,
|
||||
objectMetadata.isCustom,
|
||||
);
|
||||
|
||||
if (tmpNewEmailsField) {
|
||||
this.logger.log(
|
||||
`Restoring data in field ${customFieldWithEmailType.name}`,
|
||||
);
|
||||
await this.migrateDataWithinTable({
|
||||
sourceColumnName: `${tmpNewEmailsField.name}PrimaryEmail`,
|
||||
targetColumnName: `${restoredField.name}PrimaryEmail`,
|
||||
tableName,
|
||||
workspaceQueryRunner,
|
||||
dataSourceMetadata,
|
||||
});
|
||||
} else {
|
||||
this.logger.log(
|
||||
`Failed to restore data in link field ${customFieldWithEmailType.name}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (tmpNewEmailsField) {
|
||||
await this.fieldMetadataService.deleteOneField(
|
||||
{ id: tmpNewEmailsField.id },
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
await workspaceQueryRunner.release();
|
||||
|
||||
this.logger.log(
|
||||
chalk.red(
|
||||
`Running command on workspace ${workspaceId} failed with error: ${error}`,
|
||||
),
|
||||
);
|
||||
continue;
|
||||
} finally {
|
||||
await workspaceQueryRunner.release();
|
||||
}
|
||||
|
||||
this.logger.log(chalk.green(`Command completed!`));
|
||||
}
|
||||
}
|
||||
|
||||
private async migratePersonEmailFieldToEmailsField(
|
||||
workspaceId: string,
|
||||
workspaceQueryRunner: any,
|
||||
dataSourceMetadata: any,
|
||||
) {
|
||||
this.logger.log(`Migrating person email field of type EMAIL to EMAILS`);
|
||||
|
||||
const personEmailFieldMetadata = await this.fieldMetadataRepository.findOne(
|
||||
{
|
||||
where: {
|
||||
workspaceId,
|
||||
standardId: PERSON_STANDARD_FIELD_IDS.email,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!personEmailFieldMetadata) {
|
||||
this.logger.log(
|
||||
`Could not find person email field with standardId ${PERSON_STANDARD_FIELD_IDS.email}, skipping migration`,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await this.migrateDataWithinTable({
|
||||
sourceColumnName: 'email',
|
||||
targetColumnName: 'emailsPrimaryEmail',
|
||||
tableName: 'person',
|
||||
workspaceQueryRunner,
|
||||
dataSourceMetadata,
|
||||
});
|
||||
|
||||
if (personEmailFieldMetadata) {
|
||||
await this.fieldMetadataService.deleteOneField(
|
||||
{
|
||||
id: personEmailFieldMetadata.id,
|
||||
},
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async migrateDataWithinTable({
|
||||
sourceColumnName,
|
||||
targetColumnName,
|
||||
tableName,
|
||||
workspaceQueryRunner,
|
||||
dataSourceMetadata,
|
||||
}: {
|
||||
sourceColumnName: string;
|
||||
targetColumnName: string;
|
||||
tableName: string;
|
||||
workspaceQueryRunner: QueryRunner;
|
||||
dataSourceMetadata: DataSourceEntity;
|
||||
}) {
|
||||
await workspaceQueryRunner.query(
|
||||
`UPDATE "${dataSourceMetadata.schema}"."${tableName}" SET "${targetColumnName}" = "${sourceColumnName}"`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,366 +0,0 @@
|
||||
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import chalk from 'chalk';
|
||||
import { isDefined, isEmpty } from 'class-validator';
|
||||
import { parsePhoneNumber } from 'libphonenumber-js';
|
||||
import { Command } from 'nest-commander';
|
||||
import { DataSource, QueryRunner, Repository } from 'typeorm';
|
||||
|
||||
import {
|
||||
ActiveWorkspacesCommandOptions,
|
||||
ActiveWorkspacesCommandRunner,
|
||||
} from 'src/database/commands/active-workspaces.command';
|
||||
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
|
||||
import { CreateFieldInput } from 'src/engine/metadata-modules/field-metadata/dtos/create-field.input';
|
||||
import {
|
||||
FieldMetadataEntity,
|
||||
FieldMetadataType,
|
||||
} from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service';
|
||||
import { computeColumnName } from 'src/engine/metadata-modules/field-metadata/utils/compute-column-name.util';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { computeTableName } from 'src/engine/utils/compute-table-name.util';
|
||||
import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
import { ViewService } from 'src/modules/view/services/view.service';
|
||||
import { ViewFieldWorkspaceEntity } from 'src/modules/view/standard-objects/view-field.workspace-entity';
|
||||
|
||||
type MigratePhoneFieldsToPhonesCommandOptions = ActiveWorkspacesCommandOptions;
|
||||
@Command({
|
||||
name: 'upgrade-0.30:migrate-phone-fields-to-phones',
|
||||
description: 'Migrating fields of deprecated type PHONE to type PHONES',
|
||||
})
|
||||
export class MigratePhoneFieldsToPhonesCommand extends ActiveWorkspacesCommandRunner {
|
||||
constructor(
|
||||
@InjectRepository(Workspace, 'core')
|
||||
protected readonly workspaceRepository: Repository<Workspace>,
|
||||
@InjectRepository(FieldMetadataEntity, 'metadata')
|
||||
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
||||
@InjectRepository(ObjectMetadataEntity, 'metadata')
|
||||
private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>,
|
||||
@InjectDataSource('metadata')
|
||||
private readonly metadataDataSource: DataSource,
|
||||
private readonly fieldMetadataService: FieldMetadataService,
|
||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||
private readonly typeORMService: TypeORMService,
|
||||
private readonly dataSourceService: DataSourceService,
|
||||
private readonly viewService: ViewService,
|
||||
) {
|
||||
super(workspaceRepository);
|
||||
}
|
||||
|
||||
async executeActiveWorkspacesCommand(
|
||||
_passedParam: string[],
|
||||
_options: MigratePhoneFieldsToPhonesCommandOptions,
|
||||
workspaceIds: string[],
|
||||
): Promise<void> {
|
||||
this.logger.log(
|
||||
'Running command to migrate phone type fields to phones type',
|
||||
);
|
||||
for (const workspaceId of workspaceIds) {
|
||||
this.logger.log(`Running command for workspace ${workspaceId}`);
|
||||
try {
|
||||
const dataSourceMetadata =
|
||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceId(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (!dataSourceMetadata) {
|
||||
throw new Error(
|
||||
`Could not find dataSourceMetadata for workspace ${workspaceId}`,
|
||||
);
|
||||
}
|
||||
const workspaceDataSource =
|
||||
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
||||
|
||||
if (!workspaceDataSource) {
|
||||
throw new Error(
|
||||
`Could not connect to dataSource for workspace ${workspaceId}`,
|
||||
);
|
||||
}
|
||||
const standardPersonPhoneFieldWithTextType =
|
||||
await this.fieldMetadataRepository.findOneBy({
|
||||
workspaceId,
|
||||
standardId: PERSON_STANDARD_FIELD_IDS.phone,
|
||||
});
|
||||
|
||||
if (!standardPersonPhoneFieldWithTextType) {
|
||||
throw new Error(
|
||||
`Could not find standard phone field on person for workspace ${workspaceId}`,
|
||||
);
|
||||
}
|
||||
|
||||
await this.migrateStandardPersonPhoneField({
|
||||
standardPersonPhoneField: standardPersonPhoneFieldWithTextType,
|
||||
workspaceDataSource,
|
||||
workspaceSchemaName: dataSourceMetadata.schema,
|
||||
});
|
||||
|
||||
const fieldsWithPhoneType = await this.fieldMetadataRepository.find({
|
||||
where: {
|
||||
workspaceId,
|
||||
type: FieldMetadataType.PHONE,
|
||||
},
|
||||
});
|
||||
|
||||
for (const deprecatedPhoneField of fieldsWithPhoneType) {
|
||||
await this.migrateCustomPhoneField({
|
||||
phoneField: deprecatedPhoneField,
|
||||
workspaceDataSource,
|
||||
workspaceSchemaName: dataSourceMetadata.schema,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.log(
|
||||
chalk.red(
|
||||
`Field migration on workspace ${workspaceId} failed with error: ${error}`,
|
||||
),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
this.logger.log(chalk.green(`Command completed!`));
|
||||
}
|
||||
}
|
||||
|
||||
private async migrateStandardPersonPhoneField({
|
||||
standardPersonPhoneField,
|
||||
workspaceDataSource,
|
||||
workspaceSchemaName,
|
||||
}: {
|
||||
standardPersonPhoneField: FieldMetadataEntity;
|
||||
workspaceDataSource: DataSource;
|
||||
workspaceSchemaName: string;
|
||||
}) {
|
||||
const personObjectMetadata = await this.objectMetadataRepository.findOne({
|
||||
where: { id: standardPersonPhoneField.objectMetadataId },
|
||||
});
|
||||
|
||||
if (!personObjectMetadata) {
|
||||
throw new Error(
|
||||
`Could not find Person objectMetadata (id ${standardPersonPhoneField.objectMetadataId})`,
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.log(`Attempting to migrate standard person phone field.`);
|
||||
const workspaceQueryRunner = workspaceDataSource.createQueryRunner();
|
||||
|
||||
await workspaceQueryRunner.connect();
|
||||
const { id: _id, ...deprecatedPhoneFieldWithoutId } =
|
||||
standardPersonPhoneField;
|
||||
|
||||
const workspaceId = standardPersonPhoneField.workspaceId;
|
||||
|
||||
try {
|
||||
let standardPersonPhonesField =
|
||||
await this.fieldMetadataRepository.findOneBy({
|
||||
workspaceId,
|
||||
standardId: PERSON_STANDARD_FIELD_IDS.phones,
|
||||
});
|
||||
|
||||
if (!standardPersonPhonesField) {
|
||||
standardPersonPhonesField = await this.fieldMetadataService.createOne({
|
||||
...deprecatedPhoneFieldWithoutId,
|
||||
label: 'Phones',
|
||||
type: FieldMetadataType.PHONES,
|
||||
defaultValue: null,
|
||||
name: 'phones',
|
||||
} satisfies CreateFieldInput);
|
||||
|
||||
// StandardId and isCustom are not exposed in CreateFieldInput
|
||||
await this.metadataDataSource.query(
|
||||
`UPDATE "metadata"."fieldMetadata" SET "standardId" = $1, "isCustom" = $2 where "id"=$3`,
|
||||
[
|
||||
PERSON_STANDARD_FIELD_IDS.phones,
|
||||
'false',
|
||||
standardPersonPhonesField.id,
|
||||
],
|
||||
);
|
||||
|
||||
await this.viewService.removeFieldFromViews({
|
||||
workspaceId: workspaceId,
|
||||
fieldId: standardPersonPhonesField.id,
|
||||
});
|
||||
}
|
||||
|
||||
// Copy phone data from Text type to Phones type
|
||||
await this.copyAndParseDeprecatedPhoneFieldDataIntoNewPhonesField({
|
||||
workspaceQueryRunner,
|
||||
workspaceSchemaName,
|
||||
});
|
||||
|
||||
// Add (deprecated) to Phone field label
|
||||
await this.metadataDataSource.query(
|
||||
`UPDATE "metadata"."fieldMetadata" SET "label" = $1 where "id"=$2`,
|
||||
['Phone (deprecated)', standardPersonPhoneField.id],
|
||||
);
|
||||
|
||||
// Add new phones field to views and hide deprecated phone field
|
||||
const viewFieldRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<ViewFieldWorkspaceEntity>(
|
||||
workspaceId,
|
||||
'viewField',
|
||||
);
|
||||
const viewFieldsWithDeprecatedPhoneField = await viewFieldRepository.find(
|
||||
{
|
||||
where: {
|
||||
fieldMetadataId: standardPersonPhoneField.id,
|
||||
isVisible: true,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
await this.viewService.addFieldToViews({
|
||||
workspaceId: workspaceId,
|
||||
fieldId: standardPersonPhonesField.id,
|
||||
viewsIds: viewFieldsWithDeprecatedPhoneField
|
||||
.filter((viewField) => viewField.viewId !== null)
|
||||
.map((viewField) => viewField.viewId as string),
|
||||
positions: viewFieldsWithDeprecatedPhoneField.reduce(
|
||||
(acc, viewField) => {
|
||||
if (!viewField.viewId) {
|
||||
return acc;
|
||||
}
|
||||
acc[viewField.viewId] = viewField.position;
|
||||
|
||||
return acc;
|
||||
},
|
||||
[],
|
||||
),
|
||||
size: 150,
|
||||
});
|
||||
|
||||
await this.viewService.removeFieldFromViews({
|
||||
workspaceId: workspaceId,
|
||||
fieldId: standardPersonPhoneField.id,
|
||||
});
|
||||
|
||||
this.logger.log(
|
||||
`Migration of standard person phone field to phones is done!`,
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.log(
|
||||
chalk.red(
|
||||
`Failed to migrate field standard person phone field to phones, rolling back. (Error: ${error})`,
|
||||
),
|
||||
);
|
||||
|
||||
// Delete new phones field if it was created
|
||||
const newPhonesField =
|
||||
await this.fieldMetadataService.findOneWithinWorkspace(workspaceId, {
|
||||
where: {
|
||||
name: 'phones',
|
||||
objectMetadataId: standardPersonPhoneField.objectMetadataId,
|
||||
},
|
||||
});
|
||||
|
||||
if (newPhonesField) {
|
||||
this.logger.log(
|
||||
`Deleting phones field of type Phone as part of rolling back.`,
|
||||
);
|
||||
await this.fieldMetadataService.deleteOneField(
|
||||
{ id: newPhonesField.id },
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
|
||||
// Revert Phone field label (remove (deprecated))
|
||||
await this.metadataDataSource.query(
|
||||
`UPDATE "metadata"."fieldMetadata" SET "label" = $1 where "id"=$2`,
|
||||
['Phone', standardPersonPhoneField.id],
|
||||
);
|
||||
} finally {
|
||||
await workspaceQueryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
private async migrateCustomPhoneField({
|
||||
phoneField,
|
||||
workspaceDataSource,
|
||||
workspaceSchemaName,
|
||||
}: {
|
||||
phoneField: FieldMetadataEntity;
|
||||
workspaceDataSource: DataSource;
|
||||
workspaceSchemaName: string;
|
||||
}) {
|
||||
if (!phoneField) return;
|
||||
const objectMetadata = await this.objectMetadataRepository.findOne({
|
||||
where: { id: phoneField.objectMetadataId },
|
||||
});
|
||||
|
||||
if (!objectMetadata) {
|
||||
throw new Error(
|
||||
`Could not find objectMetadata for field ${phoneField.name}`,
|
||||
);
|
||||
}
|
||||
this.logger.log(
|
||||
`Attempting to migrate field ${phoneField.name} on ${objectMetadata.nameSingular} from Phone to Text.`,
|
||||
);
|
||||
const workspaceQueryRunner = workspaceDataSource.createQueryRunner();
|
||||
|
||||
await workspaceQueryRunner.connect();
|
||||
|
||||
try {
|
||||
await this.metadataDataSource.query(
|
||||
`UPDATE "metadata"."fieldMetadata" SET "type" = $1 where "id"=$2`,
|
||||
[FieldMetadataType.TEXT, phoneField.id],
|
||||
);
|
||||
|
||||
await workspaceQueryRunner.query(
|
||||
`ALTER TABLE "${workspaceSchemaName}"."${computeTableName(objectMetadata.nameSingular, objectMetadata.isCustom)}" ALTER COLUMN "${computeColumnName(phoneField.name)}" TYPE TEXT`,
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.log(
|
||||
chalk.red(
|
||||
`Failed to migrate field ${phoneField.name} on ${objectMetadata.nameSingular} from Phone to Text.`,
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
await workspaceQueryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
private async copyAndParseDeprecatedPhoneFieldDataIntoNewPhonesField({
|
||||
workspaceQueryRunner,
|
||||
workspaceSchemaName,
|
||||
}: {
|
||||
workspaceQueryRunner: QueryRunner;
|
||||
workspaceSchemaName: string;
|
||||
}) {
|
||||
const deprecatedPhoneFieldRows = await workspaceQueryRunner.query(
|
||||
`SELECT id, phone FROM "${workspaceSchemaName}"."person" WHERE
|
||||
phone IS NOT null`,
|
||||
);
|
||||
|
||||
for (const row of deprecatedPhoneFieldRows) {
|
||||
const phoneColumnValue = row['phone'];
|
||||
|
||||
if (isDefined(phoneColumnValue) && !isEmpty(phoneColumnValue)) {
|
||||
const query = `UPDATE "${workspaceSchemaName}"."person" SET "phonesPrimaryPhoneCountryCode" = $1,"phonesPrimaryPhoneNumber" = $2 where "id"=$3 AND ("phonesPrimaryPhoneCountryCode" IS NULL OR "phonesPrimaryPhoneCountryCode" = '');`;
|
||||
|
||||
try {
|
||||
const parsedPhoneColumnValue = parsePhoneNumber(phoneColumnValue);
|
||||
|
||||
await workspaceQueryRunner.query(query, [
|
||||
`+${parsedPhoneColumnValue.countryCallingCode}`,
|
||||
parsedPhoneColumnValue.nationalNumber,
|
||||
row.id,
|
||||
]);
|
||||
} catch (error) {
|
||||
this.logger.log(
|
||||
chalk.red(
|
||||
`Could not save phone number ${phoneColumnValue}, will try again storing value as is without parsing, with default country code.`,
|
||||
),
|
||||
);
|
||||
// Store the invalid string for invalid phone numbers
|
||||
await workspaceQueryRunner.query(query, [
|
||||
'',
|
||||
phoneColumnValue,
|
||||
row.id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,90 +0,0 @@
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import chalk from 'chalk';
|
||||
import { Command } from 'nest-commander';
|
||||
import { IsNull, Repository } from 'typeorm';
|
||||
|
||||
import {
|
||||
ActiveWorkspacesCommandOptions,
|
||||
ActiveWorkspacesCommandRunner,
|
||||
} from 'src/database/commands/active-workspaces.command';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import {
|
||||
MessageChannelSyncStage,
|
||||
MessageChannelWorkspaceEntity,
|
||||
} from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
@Command({
|
||||
name: 'upgrade-0.30:set-stale-message-sync-back-to-pending',
|
||||
description: 'Set stale message sync back to pending',
|
||||
})
|
||||
export class SetStaleMessageSyncBackToPendingCommand extends ActiveWorkspacesCommandRunner {
|
||||
constructor(
|
||||
@InjectRepository(Workspace, 'core')
|
||||
protected readonly workspaceRepository: Repository<Workspace>,
|
||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||
) {
|
||||
super(workspaceRepository);
|
||||
}
|
||||
|
||||
async executeActiveWorkspacesCommand(
|
||||
_passedParam: string[],
|
||||
_options: ActiveWorkspacesCommandOptions,
|
||||
workspaceIds: string[],
|
||||
): Promise<void> {
|
||||
this.logger.log(
|
||||
'Running command to set stale message sync back to pending',
|
||||
);
|
||||
|
||||
for (const workspaceId of workspaceIds) {
|
||||
this.logger.log(`Running command for workspace ${workspaceId}`);
|
||||
|
||||
try {
|
||||
const dataSource =
|
||||
await this.twentyORMGlobalManager.getDataSourceForWorkspace(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const messageChannelRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<MessageChannelWorkspaceEntity>(
|
||||
workspaceId,
|
||||
'messageChannel',
|
||||
);
|
||||
|
||||
dataSource.transaction(async (entityManager) => {
|
||||
await messageChannelRepository.update(
|
||||
{
|
||||
syncStage: MessageChannelSyncStage.MESSAGES_IMPORT_ONGOING,
|
||||
syncStageStartedAt: IsNull(),
|
||||
},
|
||||
{
|
||||
syncStage: MessageChannelSyncStage.MESSAGES_IMPORT_PENDING,
|
||||
},
|
||||
entityManager,
|
||||
);
|
||||
|
||||
await messageChannelRepository.update(
|
||||
{
|
||||
syncStage: MessageChannelSyncStage.MESSAGE_LIST_FETCH_ONGOING,
|
||||
syncStageStartedAt: IsNull(),
|
||||
},
|
||||
{
|
||||
syncStage:
|
||||
MessageChannelSyncStage.PARTIAL_MESSAGE_LIST_FETCH_PENDING,
|
||||
},
|
||||
entityManager,
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.log(
|
||||
chalk.red(
|
||||
`Running command on workspace ${workspaceId} failed with error: ${error}`,
|
||||
),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
this.logger.log(chalk.green(`Command completed!`));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,76 +0,0 @@
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { Command } from 'nest-commander';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { ActiveWorkspacesCommandRunner } from 'src/database/commands/active-workspaces.command';
|
||||
import { FixEmailFieldsToEmailsCommand } from 'src/database/commands/upgrade-version/0-30/0-30-fix-email-field-migration.command';
|
||||
import { FixViewFilterOperandForDateTimeCommand } from 'src/database/commands/upgrade-version/0-30/0-30-fix-view-filter-operand-for-date-time.command';
|
||||
import { MigrateEmailFieldsToEmailsCommand } from 'src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command';
|
||||
import { MigratePhoneFieldsToPhonesCommand } from 'src/database/commands/upgrade-version/0-30/0-30-migrate-phone-fields-to-phones.command';
|
||||
import { SetStaleMessageSyncBackToPendingCommand } from 'src/database/commands/upgrade-version/0-30/0-30-set-stale-message-sync-back-to-pending';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { SyncWorkspaceMetadataCommand } from 'src/engine/workspace-manager/workspace-sync-metadata/commands/sync-workspace-metadata.command';
|
||||
|
||||
interface UpdateTo0_30CommandOptions {
|
||||
workspaceId?: string;
|
||||
}
|
||||
|
||||
@Command({
|
||||
name: 'upgrade-0.30',
|
||||
description: 'Upgrade to 0.30',
|
||||
})
|
||||
export class UpgradeTo0_30Command extends ActiveWorkspacesCommandRunner {
|
||||
constructor(
|
||||
@InjectRepository(Workspace, 'core')
|
||||
protected readonly workspaceRepository: Repository<Workspace>,
|
||||
private readonly syncWorkspaceMetadataCommand: SyncWorkspaceMetadataCommand,
|
||||
private readonly migrateEmailFieldsToEmails: MigrateEmailFieldsToEmailsCommand,
|
||||
private readonly setStaleMessageSyncBackToPendingCommand: SetStaleMessageSyncBackToPendingCommand,
|
||||
private readonly fixEmailFieldsToEmailsCommand: FixEmailFieldsToEmailsCommand,
|
||||
private readonly migratePhoneFieldsToPhones: MigratePhoneFieldsToPhonesCommand,
|
||||
private readonly fixViewFilterOperandForDateTimeCommand: FixViewFilterOperandForDateTimeCommand,
|
||||
) {
|
||||
super(workspaceRepository);
|
||||
}
|
||||
|
||||
async executeActiveWorkspacesCommand(
|
||||
passedParam: string[],
|
||||
options: UpdateTo0_30CommandOptions,
|
||||
workspaceIds: string[],
|
||||
): Promise<void> {
|
||||
await this.syncWorkspaceMetadataCommand.executeActiveWorkspacesCommand(
|
||||
passedParam,
|
||||
{
|
||||
...options,
|
||||
force: true,
|
||||
},
|
||||
workspaceIds,
|
||||
);
|
||||
await this.migrateEmailFieldsToEmails.executeActiveWorkspacesCommand(
|
||||
passedParam,
|
||||
options,
|
||||
workspaceIds,
|
||||
);
|
||||
await this.setStaleMessageSyncBackToPendingCommand.executeActiveWorkspacesCommand(
|
||||
passedParam,
|
||||
options,
|
||||
workspaceIds,
|
||||
);
|
||||
await this.fixEmailFieldsToEmailsCommand.executeActiveWorkspacesCommand(
|
||||
passedParam,
|
||||
options,
|
||||
workspaceIds,
|
||||
);
|
||||
await this.migratePhoneFieldsToPhones.executeActiveWorkspacesCommand(
|
||||
passedParam,
|
||||
options,
|
||||
workspaceIds,
|
||||
);
|
||||
await this.fixViewFilterOperandForDateTimeCommand.executeActiveWorkspacesCommand(
|
||||
passedParam,
|
||||
options,
|
||||
workspaceIds,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { FixEmailFieldsToEmailsCommand } from 'src/database/commands/upgrade-version/0-30/0-30-fix-email-field-migration.command';
|
||||
import { FixViewFilterOperandForDateTimeCommand } from 'src/database/commands/upgrade-version/0-30/0-30-fix-view-filter-operand-for-date-time.command';
|
||||
import { MigrateEmailFieldsToEmailsCommand } from 'src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command';
|
||||
import { MigratePhoneFieldsToPhonesCommand } from 'src/database/commands/upgrade-version/0-30/0-30-migrate-phone-fields-to-phones.command';
|
||||
import { SetStaleMessageSyncBackToPendingCommand } from 'src/database/commands/upgrade-version/0-30/0-30-set-stale-message-sync-back-to-pending';
|
||||
import { UpgradeTo0_30Command } from 'src/database/commands/upgrade-version/0-30/0-30-upgrade-version.command';
|
||||
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { DataSourceModule } from 'src/engine/metadata-modules/data-source/data-source.module';
|
||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { FieldMetadataModule } from 'src/engine/metadata-modules/field-metadata/field-metadata.module';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { WorkspaceMetadataVersionModule } from 'src/engine/metadata-modules/workspace-metadata-version/workspace-metadata-version.module';
|
||||
import { WorkspaceSyncMetadataCommandsModule } from 'src/engine/workspace-manager/workspace-sync-metadata/commands/workspace-sync-metadata-commands.module';
|
||||
import { ViewModule } from 'src/modules/view/view.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Workspace], 'core'),
|
||||
WorkspaceSyncMetadataCommandsModule,
|
||||
DataSourceModule,
|
||||
WorkspaceMetadataVersionModule,
|
||||
FieldMetadataModule,
|
||||
TypeOrmModule.forFeature(
|
||||
[FieldMetadataEntity, ObjectMetadataEntity],
|
||||
'metadata',
|
||||
),
|
||||
TypeORMModule,
|
||||
ViewModule,
|
||||
],
|
||||
providers: [
|
||||
UpgradeTo0_30Command,
|
||||
MigrateEmailFieldsToEmailsCommand,
|
||||
SetStaleMessageSyncBackToPendingCommand,
|
||||
FixEmailFieldsToEmailsCommand,
|
||||
MigratePhoneFieldsToPhonesCommand,
|
||||
FixViewFilterOperandForDateTimeCommand,
|
||||
],
|
||||
})
|
||||
export class UpgradeTo0_30CommandModule {}
|
||||
@ -104,20 +104,6 @@ const fieldUuidMock = {
|
||||
defaultValue: null,
|
||||
};
|
||||
|
||||
const fieldPhoneMock = {
|
||||
name: 'fieldPhone',
|
||||
type: FieldMetadataType.PHONE,
|
||||
isNullable: true,
|
||||
defaultValue: null,
|
||||
};
|
||||
|
||||
const fieldEmailMock = {
|
||||
name: 'fieldEmail',
|
||||
type: FieldMetadataType.EMAIL,
|
||||
isNullable: true,
|
||||
defaultValue: null,
|
||||
};
|
||||
|
||||
const fieldDateTimeMock = {
|
||||
name: 'fieldDateTime',
|
||||
type: FieldMetadataType.DATE_TIME,
|
||||
@ -253,9 +239,7 @@ const fieldPhonesMock = {
|
||||
export const fields = [
|
||||
fieldUuidMock,
|
||||
fieldTextMock,
|
||||
fieldPhoneMock,
|
||||
fieldPhonesMock,
|
||||
fieldEmailMock,
|
||||
fieldEmailsMock,
|
||||
fieldDateTimeMock,
|
||||
fieldDateMock,
|
||||
|
||||
@ -61,8 +61,6 @@ export class TypeMapperService {
|
||||
const typeScalarMapping = new Map<FieldMetadataType, GraphQLScalarType>([
|
||||
[FieldMetadataType.UUID, UUIDScalarType],
|
||||
[FieldMetadataType.TEXT, GraphQLString],
|
||||
[FieldMetadataType.PHONE, GraphQLString],
|
||||
[FieldMetadataType.EMAIL, GraphQLString],
|
||||
[FieldMetadataType.DATE_TIME, GraphQLISODateTime],
|
||||
[FieldMetadataType.DATE, GraphQLISODateTime],
|
||||
[FieldMetadataType.BOOLEAN, GraphQLBoolean],
|
||||
@ -101,8 +99,6 @@ export class TypeMapperService {
|
||||
>([
|
||||
[FieldMetadataType.UUID, IDFilterType],
|
||||
[FieldMetadataType.TEXT, StringFilterType],
|
||||
[FieldMetadataType.PHONE, StringFilterType],
|
||||
[FieldMetadataType.EMAIL, StringFilterType],
|
||||
[FieldMetadataType.DATE_TIME, DateFilterType],
|
||||
[FieldMetadataType.DATE, DateFilterType],
|
||||
[FieldMetadataType.BOOLEAN, BooleanFilterType],
|
||||
@ -129,8 +125,6 @@ export class TypeMapperService {
|
||||
const typeOrderByMapping = new Map<FieldMetadataType, GraphQLEnumType>([
|
||||
[FieldMetadataType.UUID, OrderByDirectionType],
|
||||
[FieldMetadataType.TEXT, OrderByDirectionType],
|
||||
[FieldMetadataType.PHONE, OrderByDirectionType],
|
||||
[FieldMetadataType.EMAIL, OrderByDirectionType],
|
||||
[FieldMetadataType.DATE_TIME, OrderByDirectionType],
|
||||
[FieldMetadataType.DATE, OrderByDirectionType],
|
||||
[FieldMetadataType.BOOLEAN, OrderByDirectionType],
|
||||
|
||||
@ -18,8 +18,6 @@ export const mapFieldMetadataToGraphqlQuery = (
|
||||
const fieldIsSimpleValue = [
|
||||
FieldMetadataType.UUID,
|
||||
FieldMetadataType.TEXT,
|
||||
FieldMetadataType.PHONE,
|
||||
FieldMetadataType.EMAIL,
|
||||
FieldMetadataType.DATE_TIME,
|
||||
FieldMetadataType.DATE,
|
||||
FieldMetadataType.BOOLEAN,
|
||||
@ -89,14 +87,6 @@ export const mapFieldMetadataToGraphqlQuery = (
|
||||
}
|
||||
}
|
||||
}`;
|
||||
} else if (fieldType === FieldMetadataType.LINK) {
|
||||
return `
|
||||
${field.name}
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
`;
|
||||
} else if (fieldType === FieldMetadataType.LINKS) {
|
||||
return `
|
||||
${field.name}
|
||||
|
||||
@ -1,20 +1,8 @@
|
||||
import {
|
||||
fields,
|
||||
objectMetadataItemMock,
|
||||
} from 'src/engine/api/__mocks__/object-metadata-item.mock';
|
||||
import { objectMetadataItemMock } from 'src/engine/api/__mocks__/object-metadata-item.mock';
|
||||
import { computeSchemaComponents } from 'src/engine/core-modules/open-api/utils/components.utils';
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
|
||||
describe('computeSchemaComponents', () => {
|
||||
it('should test all non-deprecated field types', () => {
|
||||
expect(fields.map((field) => field.type)).toEqual(
|
||||
Object.keys(FieldMetadataType).filter(
|
||||
(key) =>
|
||||
key !== FieldMetadataType.LINK && key !== FieldMetadataType.TS_VECTOR,
|
||||
),
|
||||
);
|
||||
});
|
||||
it('should compute schema components', () => {
|
||||
expect(
|
||||
computeSchemaComponents([
|
||||
@ -32,9 +20,6 @@ describe('computeSchemaComponents', () => {
|
||||
fieldText: {
|
||||
type: 'string',
|
||||
},
|
||||
fieldPhone: {
|
||||
type: 'string',
|
||||
},
|
||||
fieldPhones: {
|
||||
properties: {
|
||||
additionalPhones: {
|
||||
@ -49,10 +34,6 @@ describe('computeSchemaComponents', () => {
|
||||
},
|
||||
type: 'object',
|
||||
},
|
||||
fieldEmail: {
|
||||
type: 'string',
|
||||
format: 'email',
|
||||
},
|
||||
fieldEmails: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@ -216,9 +197,6 @@ describe('computeSchemaComponents', () => {
|
||||
fieldText: {
|
||||
type: 'string',
|
||||
},
|
||||
fieldPhone: {
|
||||
type: 'string',
|
||||
},
|
||||
fieldPhones: {
|
||||
properties: {
|
||||
additionalPhones: {
|
||||
@ -233,10 +211,6 @@ describe('computeSchemaComponents', () => {
|
||||
},
|
||||
type: 'object',
|
||||
},
|
||||
fieldEmail: {
|
||||
type: 'string',
|
||||
format: 'email',
|
||||
},
|
||||
fieldEmails: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@ -399,9 +373,6 @@ describe('computeSchemaComponents', () => {
|
||||
fieldText: {
|
||||
type: 'string',
|
||||
},
|
||||
fieldPhone: {
|
||||
type: 'string',
|
||||
},
|
||||
fieldPhones: {
|
||||
properties: {
|
||||
additionalPhones: {
|
||||
@ -416,10 +387,6 @@ describe('computeSchemaComponents', () => {
|
||||
},
|
||||
type: 'object',
|
||||
},
|
||||
fieldEmail: {
|
||||
type: 'string',
|
||||
format: 'email',
|
||||
},
|
||||
fieldEmails: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
|
||||
@ -56,11 +56,8 @@ const getFieldProperties = (
|
||||
case FieldMetadataType.UUID:
|
||||
return { type: 'string', format: 'uuid' };
|
||||
case FieldMetadataType.TEXT:
|
||||
case FieldMetadataType.PHONE:
|
||||
case FieldMetadataType.RICH_TEXT:
|
||||
return { type: 'string' };
|
||||
case FieldMetadataType.EMAIL:
|
||||
return { type: 'string', format: 'email' };
|
||||
case FieldMetadataType.DATE_TIME:
|
||||
return { type: 'string', format: 'date-time' };
|
||||
case FieldMetadataType.DATE:
|
||||
@ -139,7 +136,6 @@ const getSchemaComponentsProperties = ({
|
||||
enum: field.options.map((option: { value: string }) => option.value),
|
||||
};
|
||||
break;
|
||||
case FieldMetadataType.LINK:
|
||||
case FieldMetadataType.LINKS:
|
||||
case FieldMetadataType.CURRENCY:
|
||||
case FieldMetadataType.FULL_NAME:
|
||||
|
||||
@ -5,7 +5,6 @@ import { addressCompositeType } from 'src/engine/metadata-modules/field-metadata
|
||||
import { currencyCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/currency.composite-type';
|
||||
import { emailsCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/emails.composite-type';
|
||||
import { fullNameCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/full-name.composite-type';
|
||||
import { linkCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/link.composite-type';
|
||||
import { linksCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/links.composite-type';
|
||||
import { phonesCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/phones.composite-type';
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
@ -14,7 +13,6 @@ export const compositeTypeDefinitions = new Map<
|
||||
FieldMetadataType,
|
||||
CompositeType
|
||||
>([
|
||||
[FieldMetadataType.LINK, linkCompositeType],
|
||||
[FieldMetadataType.LINKS, linksCompositeType],
|
||||
[FieldMetadataType.CURRENCY, currencyCompositeType],
|
||||
[FieldMetadataType.FULL_NAME, fullNameCompositeType],
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
import { CompositeType } from 'src/engine/metadata-modules/field-metadata/interfaces/composite-type.interface';
|
||||
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
|
||||
export const linkCompositeType: CompositeType = {
|
||||
type: FieldMetadataType.LINK,
|
||||
properties: [
|
||||
{
|
||||
name: 'label',
|
||||
type: FieldMetadataType.TEXT,
|
||||
hidden: false,
|
||||
isRequired: false,
|
||||
},
|
||||
{
|
||||
name: 'url',
|
||||
type: FieldMetadataType.TEXT,
|
||||
hidden: false,
|
||||
isRequired: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export type LinkMetadata = {
|
||||
label: string;
|
||||
url: string;
|
||||
};
|
||||
@ -71,16 +71,6 @@ export class FieldMetadataDefaultValueDate {
|
||||
value: Date | null;
|
||||
}
|
||||
|
||||
export class FieldMetadataDefaultValueLink {
|
||||
@ValidateIf((object, value) => value !== null)
|
||||
@IsQuotedString()
|
||||
label: string | null;
|
||||
|
||||
@ValidateIf((object, value) => value !== null)
|
||||
@IsQuotedString()
|
||||
url: string | null;
|
||||
}
|
||||
|
||||
export class FieldMetadataDefaultValueCurrency {
|
||||
@ValidateIf((object, value) => value !== null)
|
||||
@IsNumberString()
|
||||
|
||||
@ -24,16 +24,13 @@ import { RelationMetadataEntity } from 'src/engine/metadata-modules/relation-met
|
||||
export enum FieldMetadataType {
|
||||
UUID = 'UUID',
|
||||
TEXT = 'TEXT',
|
||||
PHONE = 'PHONE',
|
||||
PHONES = 'PHONES',
|
||||
EMAIL = 'EMAIL',
|
||||
EMAILS = 'EMAILS',
|
||||
DATE_TIME = 'DATE_TIME',
|
||||
DATE = 'DATE',
|
||||
BOOLEAN = 'BOOLEAN',
|
||||
NUMBER = 'NUMBER',
|
||||
NUMERIC = 'NUMERIC',
|
||||
LINK = 'LINK',
|
||||
LINKS = 'LINKS',
|
||||
CURRENCY = 'CURRENCY',
|
||||
FULL_NAME = 'FULL_NAME',
|
||||
|
||||
@ -145,20 +145,6 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
||||
fieldMetadataInput.options = generateRatingOptions();
|
||||
}
|
||||
|
||||
if (fieldMetadataInput.type === FieldMetadataType.LINK) {
|
||||
throw new FieldMetadataException(
|
||||
'"Link" field types are being deprecated, please use Links type instead',
|
||||
FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
);
|
||||
}
|
||||
|
||||
if (fieldMetadataInput.type === FieldMetadataType.EMAIL) {
|
||||
throw new FieldMetadataException(
|
||||
'"Email" field types are being deprecated, please use Emails type instead',
|
||||
FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
);
|
||||
}
|
||||
|
||||
const fieldMetadataForCreate = {
|
||||
id: v4(),
|
||||
createdAt: new Date(),
|
||||
|
||||
@ -6,7 +6,6 @@ import {
|
||||
FieldMetadataDefaultValueDateTime,
|
||||
FieldMetadataDefaultValueEmails,
|
||||
FieldMetadataDefaultValueFullName,
|
||||
FieldMetadataDefaultValueLink,
|
||||
FieldMetadataDefaultValueLinks,
|
||||
FieldMetadataDefaultValueNowFunction,
|
||||
FieldMetadataDefaultValueNumber,
|
||||
@ -27,9 +26,7 @@ type FieldMetadataDefaultValueMapping = {
|
||||
| FieldMetadataDefaultValueString
|
||||
| FieldMetadataDefaultValueUuidFunction;
|
||||
[FieldMetadataType.TEXT]: FieldMetadataDefaultValueString;
|
||||
[FieldMetadataType.PHONE]: FieldMetadataDefaultValueString;
|
||||
[FieldMetadataType.PHONES]: FieldMetadataDefaultValuePhones;
|
||||
[FieldMetadataType.EMAIL]: FieldMetadataDefaultValueString;
|
||||
[FieldMetadataType.EMAILS]: FieldMetadataDefaultValueEmails;
|
||||
[FieldMetadataType.DATE_TIME]:
|
||||
| FieldMetadataDefaultValueDateTime
|
||||
@ -41,7 +38,6 @@ type FieldMetadataDefaultValueMapping = {
|
||||
[FieldMetadataType.NUMBER]: FieldMetadataDefaultValueNumber;
|
||||
[FieldMetadataType.POSITION]: FieldMetadataDefaultValueNumber;
|
||||
[FieldMetadataType.NUMERIC]: FieldMetadataDefaultValueString;
|
||||
[FieldMetadataType.LINK]: FieldMetadataDefaultValueLink;
|
||||
[FieldMetadataType.LINKS]: FieldMetadataDefaultValueLinks;
|
||||
[FieldMetadataType.CURRENCY]: FieldMetadataDefaultValueCurrency;
|
||||
[FieldMetadataType.FULL_NAME]: FieldMetadataDefaultValueFullName;
|
||||
|
||||
@ -4,16 +4,10 @@ import { generateNullable } from 'src/engine/metadata-modules/field-metadata/uti
|
||||
describe('generateNullable', () => {
|
||||
it('should generate a nullable value false for TEXT, EMAIL, PHONE no matter what the input is', () => {
|
||||
expect(generateNullable(FieldMetadataType.TEXT, false)).toEqual(false);
|
||||
expect(generateNullable(FieldMetadataType.PHONE, false)).toEqual(false);
|
||||
expect(generateNullable(FieldMetadataType.EMAIL, false)).toEqual(false);
|
||||
|
||||
expect(generateNullable(FieldMetadataType.TEXT, true)).toEqual(false);
|
||||
expect(generateNullable(FieldMetadataType.PHONE, true)).toEqual(false);
|
||||
expect(generateNullable(FieldMetadataType.EMAIL, true)).toEqual(false);
|
||||
|
||||
expect(generateNullable(FieldMetadataType.TEXT)).toEqual(false);
|
||||
expect(generateNullable(FieldMetadataType.PHONE)).toEqual(false);
|
||||
expect(generateNullable(FieldMetadataType.EMAIL)).toEqual(false);
|
||||
});
|
||||
|
||||
it('should should return true if no input is given', () => {
|
||||
|
||||
@ -40,32 +40,6 @@ describe('validateDefaultValueForType', () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('should validate string default value for PHONE type', () => {
|
||||
expect(
|
||||
validateDefaultValueForType(FieldMetadataType.PHONE, "'+123456789'")
|
||||
.isValid,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for invalid string default value for PHONE type', () => {
|
||||
expect(
|
||||
validateDefaultValueForType(FieldMetadataType.PHONE, 123).isValid,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('should validate string default value for EMAIL type', () => {
|
||||
expect(
|
||||
validateDefaultValueForType(FieldMetadataType.EMAIL, "'test@example.com'")
|
||||
.isValid,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for invalid string default value for EMAIL type', () => {
|
||||
expect(
|
||||
validateDefaultValueForType(FieldMetadataType.EMAIL, 123).isValid,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('should validate number default value for NUMBER type', () => {
|
||||
expect(
|
||||
validateDefaultValueForType(FieldMetadataType.NUMBER, 100).isValid,
|
||||
@ -90,27 +64,6 @@ describe('validateDefaultValueForType', () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
// LINK type
|
||||
it('should validate LINK default value', () => {
|
||||
expect(
|
||||
validateDefaultValueForType(FieldMetadataType.LINK, {
|
||||
label: "'http://example.com'",
|
||||
url: "'Example'",
|
||||
}).isValid,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for invalid LINK default value', () => {
|
||||
expect(
|
||||
validateDefaultValueForType(
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error Just for testing purposes
|
||||
{ label: 123, url: {} },
|
||||
FieldMetadataType.LINK,
|
||||
).isValid,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
// CURRENCY type
|
||||
it('should validate CURRENCY default value', () => {
|
||||
expect(
|
||||
|
||||
@ -7,8 +7,6 @@ export function generateDefaultValue(
|
||||
): FieldMetadataDefaultValue {
|
||||
switch (type) {
|
||||
case FieldMetadataType.TEXT:
|
||||
case FieldMetadataType.PHONE:
|
||||
case FieldMetadataType.EMAIL:
|
||||
return "''";
|
||||
case FieldMetadataType.EMAILS:
|
||||
return {
|
||||
@ -31,11 +29,6 @@ export function generateDefaultValue(
|
||||
addressLat: null,
|
||||
addressLng: null,
|
||||
};
|
||||
case FieldMetadataType.LINK:
|
||||
return {
|
||||
url: "''",
|
||||
label: "''",
|
||||
};
|
||||
case FieldMetadataType.CURRENCY:
|
||||
return {
|
||||
amountMicros: null,
|
||||
|
||||
@ -11,8 +11,6 @@ export function generateNullable(
|
||||
|
||||
switch (type) {
|
||||
case FieldMetadataType.TEXT:
|
||||
case FieldMetadataType.PHONE:
|
||||
case FieldMetadataType.EMAIL:
|
||||
return false;
|
||||
default:
|
||||
return inputNullableValue ?? true;
|
||||
|
||||
@ -3,7 +3,6 @@ import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/fi
|
||||
export const isCompositeFieldMetadataType = (
|
||||
type: FieldMetadataType,
|
||||
): type is
|
||||
| FieldMetadataType.LINK
|
||||
| FieldMetadataType.CURRENCY
|
||||
| FieldMetadataType.FULL_NAME
|
||||
| FieldMetadataType.ADDRESS
|
||||
@ -12,7 +11,6 @@ export const isCompositeFieldMetadataType = (
|
||||
| FieldMetadataType.EMAILS
|
||||
| FieldMetadataType.PHONES => {
|
||||
return [
|
||||
FieldMetadataType.LINK,
|
||||
FieldMetadataType.CURRENCY,
|
||||
FieldMetadataType.FULL_NAME,
|
||||
FieldMetadataType.ADDRESS,
|
||||
|
||||
@ -15,7 +15,6 @@ import {
|
||||
FieldMetadataDefaultValueDateTime,
|
||||
FieldMetadataDefaultValueEmails,
|
||||
FieldMetadataDefaultValueFullName,
|
||||
FieldMetadataDefaultValueLink,
|
||||
FieldMetadataDefaultValueLinks,
|
||||
FieldMetadataDefaultValueNowFunction,
|
||||
FieldMetadataDefaultValueNumber,
|
||||
@ -34,8 +33,6 @@ export const defaultValueValidatorsMap = {
|
||||
FieldMetadataDefaultValueUuidFunction,
|
||||
],
|
||||
[FieldMetadataType.TEXT]: [FieldMetadataDefaultValueString],
|
||||
[FieldMetadataType.PHONE]: [FieldMetadataDefaultValueString],
|
||||
[FieldMetadataType.EMAIL]: [FieldMetadataDefaultValueString],
|
||||
[FieldMetadataType.DATE_TIME]: [
|
||||
FieldMetadataDefaultValueDateTime,
|
||||
FieldMetadataDefaultValueNowFunction,
|
||||
@ -44,7 +41,6 @@ export const defaultValueValidatorsMap = {
|
||||
[FieldMetadataType.BOOLEAN]: [FieldMetadataDefaultValueBoolean],
|
||||
[FieldMetadataType.NUMBER]: [FieldMetadataDefaultValueNumber],
|
||||
[FieldMetadataType.NUMERIC]: [FieldMetadataDefaultValueString],
|
||||
[FieldMetadataType.LINK]: [FieldMetadataDefaultValueLink],
|
||||
[FieldMetadataType.CURRENCY]: [FieldMetadataDefaultValueCurrency],
|
||||
[FieldMetadataType.FULL_NAME]: [FieldMetadataDefaultValueFullName],
|
||||
[FieldMetadataType.RATING]: [FieldMetadataDefaultValueString],
|
||||
|
||||
@ -21,8 +21,6 @@ import {
|
||||
export type BasicFieldMetadataType =
|
||||
| FieldMetadataType.UUID
|
||||
| FieldMetadataType.TEXT
|
||||
| FieldMetadataType.PHONE
|
||||
| FieldMetadataType.EMAIL
|
||||
| FieldMetadataType.NUMERIC
|
||||
| FieldMetadataType.NUMBER
|
||||
| FieldMetadataType.BOOLEAN
|
||||
|
||||
@ -23,7 +23,6 @@ export type CompositeFieldMetadataType =
|
||||
| FieldMetadataType.ADDRESS
|
||||
| FieldMetadataType.CURRENCY
|
||||
| FieldMetadataType.FULL_NAME
|
||||
| FieldMetadataType.LINK
|
||||
| FieldMetadataType.LINKS
|
||||
| FieldMetadataType.EMAILS
|
||||
| FieldMetadataType.PHONES;
|
||||
|
||||
@ -18,9 +18,6 @@ export const fieldMetadataTypeToColumnType = <Type extends FieldMetadataType>(
|
||||
case FieldMetadataType.RICH_TEXT:
|
||||
case FieldMetadataType.ARRAY:
|
||||
return 'text';
|
||||
case FieldMetadataType.PHONE:
|
||||
case FieldMetadataType.EMAIL:
|
||||
return 'varchar';
|
||||
case FieldMetadataType.NUMERIC:
|
||||
return 'numeric';
|
||||
case FieldMetadataType.NUMBER:
|
||||
|
||||
@ -52,24 +52,6 @@ export class WorkspaceMigrationFactory {
|
||||
},
|
||||
},
|
||||
],
|
||||
[
|
||||
FieldMetadataType.PHONE,
|
||||
{
|
||||
factory: this.basicColumnActionFactory,
|
||||
options: {
|
||||
defaultValue: '',
|
||||
},
|
||||
},
|
||||
],
|
||||
[
|
||||
FieldMetadataType.EMAIL,
|
||||
{
|
||||
factory: this.basicColumnActionFactory,
|
||||
options: {
|
||||
defaultValue: '',
|
||||
},
|
||||
},
|
||||
],
|
||||
[FieldMetadataType.NUMERIC, { factory: this.basicColumnActionFactory }],
|
||||
[FieldMetadataType.NUMBER, { factory: this.basicColumnActionFactory }],
|
||||
[FieldMetadataType.POSITION, { factory: this.basicColumnActionFactory }],
|
||||
@ -84,7 +66,6 @@ export class WorkspaceMigrationFactory {
|
||||
FieldMetadataType.MULTI_SELECT,
|
||||
{ factory: this.enumColumnActionFactory },
|
||||
],
|
||||
[FieldMetadataType.LINK, { factory: this.compositeColumnActionFactory }],
|
||||
[
|
||||
FieldMetadataType.CURRENCY,
|
||||
{ factory: this.compositeColumnActionFactory },
|
||||
|
||||
@ -32,10 +32,7 @@ export class CalendarEventParticipantPersonListener {
|
||||
>,
|
||||
) {
|
||||
for (const eventPayload of payload.events) {
|
||||
if (
|
||||
eventPayload.properties.after.emails?.primaryEmail === null &&
|
||||
eventPayload.properties.after.email === null
|
||||
) {
|
||||
if (eventPayload.properties.after.emails?.primaryEmail === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -44,9 +41,7 @@ export class CalendarEventParticipantPersonListener {
|
||||
CalendarEventParticipantMatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email:
|
||||
eventPayload.properties.after.emails?.primaryEmail ??
|
||||
eventPayload.properties.after.email, // TODO
|
||||
email: eventPayload.properties.after.emails?.primaryEmail,
|
||||
personId: eventPayload.recordId,
|
||||
},
|
||||
);
|
||||
@ -64,16 +59,14 @@ export class CalendarEventParticipantPersonListener {
|
||||
objectRecordUpdateEventChangedProperties(
|
||||
eventPayload.properties.before,
|
||||
eventPayload.properties.after,
|
||||
).includes('email')
|
||||
).includes('emails')
|
||||
) {
|
||||
// TODO: modify this job to take an array of participants to match
|
||||
await this.messageQueueService.add<CalendarEventParticipantUnmatchParticipantJobData>(
|
||||
CalendarEventParticipantUnmatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email:
|
||||
eventPayload.properties.before.emails?.primaryEmail ??
|
||||
eventPayload.properties.before.email,
|
||||
email: eventPayload.properties.before.emails?.primaryEmail,
|
||||
personId: eventPayload.recordId,
|
||||
},
|
||||
);
|
||||
@ -82,9 +75,7 @@ export class CalendarEventParticipantPersonListener {
|
||||
CalendarEventParticipantMatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email:
|
||||
eventPayload.properties.after.emails?.primaryEmail ??
|
||||
eventPayload.properties.after.email,
|
||||
email: eventPayload.properties.after.emails?.primaryEmail,
|
||||
personId: eventPayload.recordId,
|
||||
},
|
||||
);
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { isDefined } from 'class-validator';
|
||||
import chunk from 'lodash.chunk';
|
||||
import compact from 'lodash.compact';
|
||||
import { Any, EntityManager, Repository } from 'typeorm';
|
||||
@ -13,7 +12,6 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { WorkspaceEventEmitter } from 'src/engine/workspace-event-emitter/workspace-event-emitter';
|
||||
import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import { CONTACTS_CREATION_BATCH_SIZE } from 'src/modules/contact-creation-manager/constants/contacts-creation-batch-size.constant';
|
||||
@ -54,13 +52,6 @@ export class CreateCompanyAndContactService {
|
||||
return [];
|
||||
}
|
||||
|
||||
const emailsFieldMetadata = await this.fieldMetadataRepository.findOne({
|
||||
where: {
|
||||
workspaceId: workspaceId,
|
||||
standardId: PERSON_STANDARD_FIELD_IDS.emails,
|
||||
},
|
||||
});
|
||||
|
||||
const personRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
||||
workspaceId,
|
||||
@ -89,16 +80,14 @@ export class CreateCompanyAndContactService {
|
||||
}
|
||||
|
||||
const alreadyCreatedContacts = await personRepository.find({
|
||||
where: isDefined(emailsFieldMetadata)
|
||||
? {
|
||||
emails: { primaryEmail: Any(uniqueHandles) },
|
||||
}
|
||||
: { email: Any(uniqueHandles) },
|
||||
where: {
|
||||
emails: { primaryEmail: Any(uniqueHandles) },
|
||||
},
|
||||
});
|
||||
|
||||
const alreadyCreatedContactEmails: string[] = isDefined(emailsFieldMetadata)
|
||||
? alreadyCreatedContacts?.map(({ emails }) => emails?.primaryEmail)
|
||||
: alreadyCreatedContacts?.map(({ email }) => email);
|
||||
const alreadyCreatedContactEmails: string[] = alreadyCreatedContacts?.map(
|
||||
({ emails }) => emails?.primaryEmail,
|
||||
);
|
||||
|
||||
const filteredContactsToCreate = uniqueContacts.filter(
|
||||
(participant) =>
|
||||
|
||||
@ -7,7 +7,6 @@ import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/
|
||||
import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/scoped-workspace-context.factory';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { WorkspaceEventEmitter } from 'src/engine/workspace-event-emitter/workspace-event-emitter';
|
||||
import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity';
|
||||
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
||||
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
||||
@ -60,35 +59,19 @@ export class MatchParticipantService<
|
||||
...new Set(participants.map((participant) => participant.handle)),
|
||||
];
|
||||
|
||||
const emailsFieldMetadata = await this.fieldMetadataRepository.findOne({
|
||||
where: {
|
||||
workspaceId: workspaceId,
|
||||
standardId: PERSON_STANDARD_FIELD_IDS.emails,
|
||||
},
|
||||
});
|
||||
|
||||
const personRepository =
|
||||
await this.twentyORMManager.getRepository<PersonWorkspaceEntity>(
|
||||
'person',
|
||||
);
|
||||
|
||||
const people = emailsFieldMetadata
|
||||
? await personRepository.find(
|
||||
{
|
||||
where: {
|
||||
emails: Any(uniqueParticipantsHandles),
|
||||
},
|
||||
},
|
||||
transactionManager,
|
||||
)
|
||||
: await personRepository.find(
|
||||
{
|
||||
where: {
|
||||
email: Any(uniqueParticipantsHandles),
|
||||
},
|
||||
},
|
||||
transactionManager,
|
||||
);
|
||||
const people = await personRepository.find(
|
||||
{
|
||||
where: {
|
||||
emails: Any(uniqueParticipantsHandles),
|
||||
},
|
||||
},
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
const workspaceMemberRepository =
|
||||
await this.twentyORMManager.getRepository<WorkspaceMemberWorkspaceEntity>(
|
||||
@ -105,10 +88,8 @@ export class MatchParticipantService<
|
||||
);
|
||||
|
||||
for (const handle of uniqueParticipantsHandles) {
|
||||
const person = people.find((person) =>
|
||||
emailsFieldMetadata
|
||||
? person.emails?.primaryEmail === handle
|
||||
: person.email === handle,
|
||||
const person = people.find(
|
||||
(person) => person.emails?.primaryEmail === handle,
|
||||
);
|
||||
|
||||
const workspaceMember = workspaceMembers.find(
|
||||
|
||||
@ -32,10 +32,7 @@ export class MessageParticipantPersonListener {
|
||||
>,
|
||||
) {
|
||||
for (const eventPayload of payload.events) {
|
||||
if (
|
||||
!eventPayload.properties.after.emails?.primaryEmail &&
|
||||
!eventPayload.properties.after.email
|
||||
) {
|
||||
if (!eventPayload.properties.after.emails?.primaryEmail) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -43,9 +40,7 @@ export class MessageParticipantPersonListener {
|
||||
MessageParticipantMatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email:
|
||||
eventPayload.properties.after.emails?.primaryEmail ??
|
||||
eventPayload.properties.after.email,
|
||||
email: eventPayload.properties.after.emails?.primaryEmail,
|
||||
personId: eventPayload.recordId,
|
||||
},
|
||||
);
|
||||
@ -60,10 +55,6 @@ export class MessageParticipantPersonListener {
|
||||
) {
|
||||
for (const eventPayload of payload.events) {
|
||||
if (
|
||||
objectRecordUpdateEventChangedProperties(
|
||||
eventPayload.properties.before,
|
||||
eventPayload.properties.after,
|
||||
).includes('email') ||
|
||||
objectRecordUpdateEventChangedProperties(
|
||||
eventPayload.properties.before,
|
||||
eventPayload.properties.after,
|
||||
@ -73,9 +64,7 @@ export class MessageParticipantPersonListener {
|
||||
MessageParticipantUnmatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email:
|
||||
eventPayload.properties.before.emails?.primaryEmail ??
|
||||
eventPayload.properties.before.email,
|
||||
email: eventPayload.properties.before.emails?.primaryEmail,
|
||||
personId: eventPayload.recordId,
|
||||
},
|
||||
);
|
||||
@ -84,9 +73,7 @@ export class MessageParticipantPersonListener {
|
||||
MessageParticipantMatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email:
|
||||
eventPayload.properties.after.emails?.primaryEmail ??
|
||||
eventPayload.properties.after.email,
|
||||
email: eventPayload.properties.after.emails?.primaryEmail,
|
||||
personId: eventPayload.recordId,
|
||||
},
|
||||
);
|
||||
|
||||
@ -63,16 +63,6 @@ export class PersonWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
@WorkspaceIsNullable()
|
||||
[NAME_FIELD_NAME]: FullNameMetadata | null;
|
||||
|
||||
@WorkspaceField({
|
||||
standardId: PERSON_STANDARD_FIELD_IDS.email,
|
||||
type: FieldMetadataType.EMAIL,
|
||||
label: 'Email',
|
||||
description: 'Contact’s Email',
|
||||
icon: 'IconMail',
|
||||
})
|
||||
@WorkspaceIsDeprecated()
|
||||
email: string;
|
||||
|
||||
@WorkspaceField({
|
||||
standardId: PERSON_STANDARD_FIELD_IDS.emails,
|
||||
type: FieldMetadataType.EMAILS,
|
||||
|
||||
Reference in New Issue
Block a user