Updated MessageChannelSyncStatus enum: changed COMPLETED to ACTIVE (#5965)
Fixes #5961 --------- Co-authored-by: bosiraphael <raphael.bosi@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -3077,8 +3077,8 @@ export type MessageChannelSyncStageEnumFilter = {
|
|||||||
|
|
||||||
/** Sync status */
|
/** Sync status */
|
||||||
export enum MessageChannelSyncStatusEnum {
|
export enum MessageChannelSyncStatusEnum {
|
||||||
/** Completed */
|
/** Active */
|
||||||
Completed = 'COMPLETED',
|
Active = 'ACTIVE',
|
||||||
/** Failed */
|
/** Failed */
|
||||||
Failed = 'FAILED',
|
Failed = 'FAILED',
|
||||||
/** Failed Insufficient Permissions */
|
/** Failed Insufficient Permissions */
|
||||||
|
|||||||
@ -0,0 +1,229 @@
|
|||||||
|
import { Logger } from '@nestjs/common';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
|
||||||
|
import chalk from 'chalk';
|
||||||
|
import { Command, CommandRunner, Option } from 'nest-commander';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
|
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
|
||||||
|
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 { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||||
|
import { WorkspaceCacheVersionService } from 'src/engine/metadata-modules/workspace-cache-version/workspace-cache-version.service';
|
||||||
|
import { WorkspaceStatusService } from 'src/engine/workspace-manager/workspace-status/services/workspace-status.service';
|
||||||
|
import { MessageChannelSyncStatus } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||||
|
|
||||||
|
interface MigrateMessageChannelSyncStatusEnumCommandOptions {
|
||||||
|
workspaceId?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command({
|
||||||
|
name: 'migrate-0.23:update-message-channel-sync-status-enum',
|
||||||
|
description: 'Migrate messageChannel syncStatus enum',
|
||||||
|
})
|
||||||
|
export class MigrateMessageChannelSyncStatusEnumCommand extends CommandRunner {
|
||||||
|
private readonly logger = new Logger(
|
||||||
|
MigrateMessageChannelSyncStatusEnumCommand.name,
|
||||||
|
);
|
||||||
|
constructor(
|
||||||
|
private readonly workspaceStatusService: WorkspaceStatusService,
|
||||||
|
@InjectRepository(FieldMetadataEntity, 'metadata')
|
||||||
|
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
||||||
|
@InjectRepository(ObjectMetadataEntity, 'metadata')
|
||||||
|
private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>,
|
||||||
|
private readonly typeORMService: TypeORMService,
|
||||||
|
private readonly dataSourceService: DataSourceService,
|
||||||
|
private readonly workspaceCacheVersionService: WorkspaceCacheVersionService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Option({
|
||||||
|
flags: '-w, --workspace-id [workspace_id]',
|
||||||
|
description: 'workspace id. Command runs on all workspaces if not provided',
|
||||||
|
required: false,
|
||||||
|
})
|
||||||
|
parseWorkspaceId(value: string): string {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(
|
||||||
|
_passedParam: string[],
|
||||||
|
options: MigrateMessageChannelSyncStatusEnumCommandOptions,
|
||||||
|
): Promise<void> {
|
||||||
|
let workspaceIds: string[] = [];
|
||||||
|
|
||||||
|
if (options.workspaceId) {
|
||||||
|
workspaceIds = [options.workspaceId];
|
||||||
|
} else {
|
||||||
|
workspaceIds = await this.workspaceStatusService.getActiveWorkspaceIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!workspaceIds.length) {
|
||||||
|
this.logger.log(chalk.yellow('No workspace found'));
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.logger.log(
|
||||||
|
chalk.green(`Running command on ${workspaceIds.length} workspaces`),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const workspaceId of workspaceIds) {
|
||||||
|
try {
|
||||||
|
const dataSourceMetadatas =
|
||||||
|
await this.dataSourceService.getDataSourcesMetadataFromWorkspaceId(
|
||||||
|
workspaceId,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const dataSourceMetadata of dataSourceMetadatas) {
|
||||||
|
const workspaceDataSource =
|
||||||
|
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
||||||
|
|
||||||
|
if (workspaceDataSource) {
|
||||||
|
const queryRunner = workspaceDataSource.createQueryRunner();
|
||||||
|
|
||||||
|
await queryRunner.connect();
|
||||||
|
await queryRunner.startTransaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TYPE "${dataSourceMetadata.schema}"."messageChannel_syncStatus_enum" RENAME TO "messageChannel_syncStatus_enum_old"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TYPE "${dataSourceMetadata.schema}"."messageChannel_syncStatus_enum" AS ENUM (
|
||||||
|
'ONGOING',
|
||||||
|
'NOT_SYNCED',
|
||||||
|
'ACTIVE',
|
||||||
|
'FAILED_INSUFFICIENT_PERMISSIONS',
|
||||||
|
'FAILED_UNKNOWN'
|
||||||
|
)`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "${dataSourceMetadata.schema}"."messageChannel" ALTER COLUMN "syncStatus" DROP DEFAULT`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "${dataSourceMetadata.schema}"."messageChannel" ALTER COLUMN "syncStatus" TYPE text`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await queryRunner.query(
|
||||||
|
`UPDATE "${dataSourceMetadata.schema}"."messageChannel" SET "syncStatus" = 'ACTIVE' WHERE "syncStatus" = 'COMPLETED'`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "${dataSourceMetadata.schema}"."messageChannel" ALTER COLUMN "syncStatus" TYPE "${dataSourceMetadata.schema}"."messageChannel_syncStatus_enum" USING "syncStatus"::text::"${dataSourceMetadata.schema}"."messageChannel_syncStatus_enum"`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "${dataSourceMetadata.schema}"."messageChannel" ALTER COLUMN "syncStatus" SET DEFAULT NULL`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await queryRunner.query(
|
||||||
|
`DROP TYPE "${dataSourceMetadata.schema}"."messageChannel_syncStatus_enum_old"`,
|
||||||
|
);
|
||||||
|
await queryRunner.commitTransaction();
|
||||||
|
} catch (error) {
|
||||||
|
await queryRunner.rollbackTransaction();
|
||||||
|
this.logger.log(
|
||||||
|
chalk.red(`Running command on workspace ${workspaceId} failed`),
|
||||||
|
);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
await queryRunner.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const messageChannelObjectMetadata =
|
||||||
|
await this.objectMetadataRepository.findOne({
|
||||||
|
where: { nameSingular: 'messageChannel', workspaceId },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!messageChannelObjectMetadata) {
|
||||||
|
this.logger.log(
|
||||||
|
chalk.yellow(
|
||||||
|
`Object metadata for messageChannel not found in workspace ${workspaceId}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const syncStatusFieldMetadata =
|
||||||
|
await this.fieldMetadataRepository.findOne({
|
||||||
|
where: {
|
||||||
|
name: 'syncStatus',
|
||||||
|
workspaceId,
|
||||||
|
objectMetadataId: messageChannelObjectMetadata.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!syncStatusFieldMetadata) {
|
||||||
|
this.logger.log(
|
||||||
|
chalk.yellow(
|
||||||
|
`Field metadata for syncStatus not found in workspace ${workspaceId}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newOptions = [
|
||||||
|
{
|
||||||
|
id: v4(),
|
||||||
|
value: MessageChannelSyncStatus.ONGOING,
|
||||||
|
label: 'Ongoing',
|
||||||
|
position: 1,
|
||||||
|
color: 'yellow',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: v4(),
|
||||||
|
value: MessageChannelSyncStatus.NOT_SYNCED,
|
||||||
|
label: 'Not Synced',
|
||||||
|
position: 2,
|
||||||
|
color: 'blue',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: v4(),
|
||||||
|
value: MessageChannelSyncStatus.ACTIVE,
|
||||||
|
label: 'Active',
|
||||||
|
position: 3,
|
||||||
|
color: 'green',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: v4(),
|
||||||
|
value: MessageChannelSyncStatus.FAILED_INSUFFICIENT_PERMISSIONS,
|
||||||
|
label: 'Failed Insufficient Permissions',
|
||||||
|
position: 4,
|
||||||
|
color: 'red',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: v4(),
|
||||||
|
value: MessageChannelSyncStatus.FAILED_UNKNOWN,
|
||||||
|
label: 'Failed Unknown',
|
||||||
|
position: 5,
|
||||||
|
color: 'red',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
await this.fieldMetadataRepository.update(syncStatusFieldMetadata.id, {
|
||||||
|
options: newOptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.workspaceCacheVersionService.incrementVersion(workspaceId);
|
||||||
|
|
||||||
|
this.logger.log(
|
||||||
|
chalk.green(`Running command on workspace ${workspaceId} done`),
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(
|
||||||
|
`Migration failed for workspace ${workspaceId}: ${error.message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.log(chalk.green(`Command completed!`));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import { Command, CommandRunner, Option } from 'nest-commander';
|
import { Command, CommandRunner, Option } from 'nest-commander';
|
||||||
|
|
||||||
import { MigrateLinkFieldsToLinksCommand } from 'src/database/commands/upgrade-version/0-23/0-23-migrate-link-fields-to-links.command';
|
import { MigrateLinkFieldsToLinksCommand } from 'src/database/commands/upgrade-version/0-23/0-23-migrate-link-fields-to-links.command';
|
||||||
|
import { MigrateMessageChannelSyncStatusEnumCommand } from 'src/database/commands/upgrade-version/0-23/0-23-migrate-message-channel-sync-status-enum.command';
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
workspaceId?: string;
|
workspaceId?: string;
|
||||||
@ -13,6 +14,7 @@ interface Options {
|
|||||||
export class UpgradeTo0_23Command extends CommandRunner {
|
export class UpgradeTo0_23Command extends CommandRunner {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly migrateLinkFieldsToLinks: MigrateLinkFieldsToLinksCommand,
|
private readonly migrateLinkFieldsToLinks: MigrateLinkFieldsToLinksCommand,
|
||||||
|
private readonly migrateMessageChannelSyncStatusEnumCommand: MigrateMessageChannelSyncStatusEnumCommand,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -29,5 +31,9 @@ export class UpgradeTo0_23Command extends CommandRunner {
|
|||||||
|
|
||||||
async run(_passedParam: string[], options: Options): Promise<void> {
|
async run(_passedParam: string[], options: Options): Promise<void> {
|
||||||
await this.migrateLinkFieldsToLinks.run(_passedParam, options);
|
await this.migrateLinkFieldsToLinks.run(_passedParam, options);
|
||||||
|
await this.migrateMessageChannelSyncStatusEnumCommand.run(
|
||||||
|
_passedParam,
|
||||||
|
options,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { Module } from '@nestjs/common';
|
|||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
|
||||||
import { MigrateLinkFieldsToLinksCommand } from 'src/database/commands/upgrade-version/0-23/0-23-migrate-link-fields-to-links.command';
|
import { MigrateLinkFieldsToLinksCommand } from 'src/database/commands/upgrade-version/0-23/0-23-migrate-link-fields-to-links.command';
|
||||||
|
import { MigrateMessageChannelSyncStatusEnumCommand } from 'src/database/commands/upgrade-version/0-23/0-23-migrate-message-channel-sync-status-enum.command';
|
||||||
import { UpgradeTo0_23Command } from 'src/database/commands/upgrade-version/0-23/0-23-upgrade-version.command';
|
import { UpgradeTo0_23Command } from 'src/database/commands/upgrade-version/0-23/0-23-upgrade-version.command';
|
||||||
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||||
@ -25,6 +26,10 @@ import { ViewModule } from 'src/modules/view/view.module';
|
|||||||
TypeORMModule,
|
TypeORMModule,
|
||||||
ViewModule,
|
ViewModule,
|
||||||
],
|
],
|
||||||
providers: [MigrateLinkFieldsToLinksCommand, UpgradeTo0_23Command],
|
providers: [
|
||||||
|
MigrateLinkFieldsToLinksCommand,
|
||||||
|
MigrateMessageChannelSyncStatusEnumCommand,
|
||||||
|
UpgradeTo0_23Command,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class UpgradeTo0_23CommandModule {}
|
export class UpgradeTo0_23CommandModule {}
|
||||||
|
|||||||
@ -197,7 +197,7 @@ export class MessageChannelRepository {
|
|||||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||||
|
|
||||||
const needsToUpdateSyncedAt =
|
const needsToUpdateSyncedAt =
|
||||||
syncStatus === MessageChannelSyncStatus.COMPLETED;
|
syncStatus === MessageChannelSyncStatus.ACTIVE;
|
||||||
|
|
||||||
await this.workspaceDataSourceService.executeRawQuery(
|
await this.workspaceDataSourceService.executeRawQuery(
|
||||||
`UPDATE ${dataSourceSchema}."messageChannel" SET "syncStatus" = $1 ${
|
`UPDATE ${dataSourceSchema}."messageChannel" SET "syncStatus" = $1 ${
|
||||||
|
|||||||
@ -102,7 +102,7 @@ export class MessagingChannelSyncStatusService {
|
|||||||
) {
|
) {
|
||||||
await this.messageChannelRepository.updateSyncStatus(
|
await this.messageChannelRepository.updateSyncStatus(
|
||||||
messageChannelId,
|
messageChannelId,
|
||||||
MessageChannelSyncStatus.COMPLETED,
|
MessageChannelSyncStatus.ACTIVE,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import { MessageChannelMessageAssociationWorkspaceEntity } from 'src/modules/mes
|
|||||||
export enum MessageChannelSyncStatus {
|
export enum MessageChannelSyncStatus {
|
||||||
NOT_SYNCED = 'NOT_SYNCED',
|
NOT_SYNCED = 'NOT_SYNCED',
|
||||||
ONGOING = 'ONGOING',
|
ONGOING = 'ONGOING',
|
||||||
COMPLETED = 'COMPLETED',
|
ACTIVE = 'ACTIVE',
|
||||||
FAILED_INSUFFICIENT_PERMISSIONS = 'FAILED_INSUFFICIENT_PERMISSIONS',
|
FAILED_INSUFFICIENT_PERMISSIONS = 'FAILED_INSUFFICIENT_PERMISSIONS',
|
||||||
FAILED_UNKNOWN = 'FAILED_UNKNOWN',
|
FAILED_UNKNOWN = 'FAILED_UNKNOWN',
|
||||||
}
|
}
|
||||||
@ -234,25 +234,25 @@ export class MessageChannelWorkspaceEntity extends BaseWorkspaceEntity {
|
|||||||
{
|
{
|
||||||
value: MessageChannelSyncStatus.NOT_SYNCED,
|
value: MessageChannelSyncStatus.NOT_SYNCED,
|
||||||
label: 'Not Synced',
|
label: 'Not Synced',
|
||||||
position: 4,
|
position: 2,
|
||||||
color: 'blue',
|
color: 'blue',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: MessageChannelSyncStatus.COMPLETED,
|
value: MessageChannelSyncStatus.ACTIVE,
|
||||||
label: 'Completed',
|
label: 'Active',
|
||||||
position: 5,
|
position: 3,
|
||||||
color: 'green',
|
color: 'green',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: MessageChannelSyncStatus.FAILED_INSUFFICIENT_PERMISSIONS,
|
value: MessageChannelSyncStatus.FAILED_INSUFFICIENT_PERMISSIONS,
|
||||||
label: 'Failed Insufficient Permissions',
|
label: 'Failed Insufficient Permissions',
|
||||||
position: 6,
|
position: 4,
|
||||||
color: 'red',
|
color: 'red',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: MessageChannelSyncStatus.FAILED_UNKNOWN,
|
value: MessageChannelSyncStatus.FAILED_UNKNOWN,
|
||||||
label: 'Failed Unknown',
|
label: 'Failed Unknown',
|
||||||
position: 7,
|
position: 5,
|
||||||
color: 'red',
|
color: 'red',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user