Update clean view command + add dry run to favorite backfill (#7268)
Clean favorites associated with activities
This commit is contained in:
@ -51,6 +51,7 @@ export class BackfillWorkspaceFavoritesCommand extends ActiveWorkspacesCommandRu
|
||||
await this.createViewWorkspaceFavorites(
|
||||
workspaceId,
|
||||
activeWorkspaceIndexViews.map((view) => view.id),
|
||||
_options.dryRun ?? false,
|
||||
);
|
||||
|
||||
this.logger.log(
|
||||
@ -117,6 +118,7 @@ export class BackfillWorkspaceFavoritesCommand extends ActiveWorkspacesCommandRu
|
||||
private async createViewWorkspaceFavorites(
|
||||
workspaceId: string,
|
||||
viewIds: string[],
|
||||
dryRun: boolean,
|
||||
) {
|
||||
const favoriteRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<FavoriteWorkspaceEntity>(
|
||||
@ -125,6 +127,7 @@ export class BackfillWorkspaceFavoritesCommand extends ActiveWorkspacesCommandRu
|
||||
);
|
||||
|
||||
let nextFavoritePosition = await favoriteRepository.count();
|
||||
let createdFavorites = 0;
|
||||
|
||||
for (const viewId of viewIds) {
|
||||
const existingFavorites = await favoriteRepository.find({
|
||||
@ -137,14 +140,23 @@ export class BackfillWorkspaceFavoritesCommand extends ActiveWorkspacesCommandRu
|
||||
continue;
|
||||
}
|
||||
|
||||
await favoriteRepository.insert(
|
||||
favoriteRepository.create({
|
||||
viewId,
|
||||
position: nextFavoritePosition,
|
||||
}),
|
||||
);
|
||||
if (!dryRun) {
|
||||
await favoriteRepository.insert(
|
||||
favoriteRepository.create({
|
||||
viewId,
|
||||
position: nextFavoritePosition,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
createdFavorites++;
|
||||
nextFavoritePosition++;
|
||||
}
|
||||
|
||||
this.logger.log(
|
||||
chalk.green(
|
||||
`Found ${createdFavorites} favorites to backfill in workspace ${workspaceId}.`,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,13 +11,15 @@ import {
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
||||
import { ViewWorkspaceEntity } from 'src/modules/view/standard-objects/view.workspace-entity';
|
||||
|
||||
@Command({
|
||||
name: 'upgrade-0.31:clean-views-with-deleted-object-metadata',
|
||||
description: 'Clean views with deleted object metadata',
|
||||
name: 'upgrade-0.31:clean-views-associated-with-outdated-objects',
|
||||
description:
|
||||
'Clean views associated with deleted object metadata or activities',
|
||||
})
|
||||
export class CleanViewsWithDeletedObjectMetadataCommand extends ActiveWorkspacesCommandRunner {
|
||||
export class CleanViewsAssociatedWithOutdatedObjectsCommand extends ActiveWorkspacesCommandRunner {
|
||||
constructor(
|
||||
@InjectRepository(Workspace, 'core')
|
||||
protected readonly workspaceRepository: Repository<Workspace>,
|
||||
@ -88,7 +90,9 @@ export class CleanViewsWithDeletedObjectMetadataCommand extends ActiveWorkspaces
|
||||
});
|
||||
|
||||
const validObjectMetadataIds = new Set(
|
||||
objectMetadataEntities.map((entity) => entity.id),
|
||||
objectMetadataEntities
|
||||
.filter((entity) => entity.standardId !== STANDARD_OBJECT_IDS.activity)
|
||||
.map((entity) => entity.id),
|
||||
);
|
||||
|
||||
const viewIdsToDelete = allViews
|
||||
@ -6,7 +6,7 @@ import { Repository } from 'typeorm';
|
||||
import { ActiveWorkspacesCommandRunner } from 'src/database/commands/active-workspaces.command';
|
||||
import { AddIndexKeyToTasksAndNotesViewsCommand } from 'src/database/commands/upgrade-version/0-31/0-31-add-index-key-to-tasks-and-notes-views.command';
|
||||
import { BackfillWorkspaceFavoritesCommand } from 'src/database/commands/upgrade-version/0-31/0-31-backfill-workspace-favorites.command';
|
||||
import { CleanViewsWithDeletedObjectMetadataCommand } from 'src/database/commands/upgrade-version/0-31/0-31-clean-views-with-deleted-object-metadata.command';
|
||||
import { CleanViewsAssociatedWithOutdatedObjectsCommand } from 'src/database/commands/upgrade-version/0-31/0-31-clean-views-associated-with-outdated-objects.command';
|
||||
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';
|
||||
|
||||
@ -24,7 +24,7 @@ export class UpgradeTo0_31Command extends ActiveWorkspacesCommandRunner {
|
||||
protected readonly workspaceRepository: Repository<Workspace>,
|
||||
private readonly syncWorkspaceMetadataCommand: SyncWorkspaceMetadataCommand,
|
||||
private readonly backfillWorkspaceFavoritesCommand: BackfillWorkspaceFavoritesCommand,
|
||||
private readonly cleanViewsWithDeletedObjectMetadataCommand: CleanViewsWithDeletedObjectMetadataCommand,
|
||||
private readonly cleanViewsAssociatedWithOutdatedObjectsCommand: CleanViewsAssociatedWithOutdatedObjectsCommand,
|
||||
private readonly addIndexKeyToTasksAndNotesViewsCommand: AddIndexKeyToTasksAndNotesViewsCommand,
|
||||
) {
|
||||
super(workspaceRepository);
|
||||
@ -43,7 +43,7 @@ export class UpgradeTo0_31Command extends ActiveWorkspacesCommandRunner {
|
||||
},
|
||||
workspaceIds,
|
||||
);
|
||||
await this.cleanViewsWithDeletedObjectMetadataCommand.executeActiveWorkspacesCommand(
|
||||
await this.cleanViewsAssociatedWithOutdatedObjectsCommand.executeActiveWorkspacesCommand(
|
||||
passedParam,
|
||||
options,
|
||||
workspaceIds,
|
||||
|
||||
@ -3,7 +3,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { AddIndexKeyToTasksAndNotesViewsCommand } from 'src/database/commands/upgrade-version/0-31/0-31-add-index-key-to-tasks-and-notes-views.command';
|
||||
import { BackfillWorkspaceFavoritesCommand } from 'src/database/commands/upgrade-version/0-31/0-31-backfill-workspace-favorites.command';
|
||||
import { CleanViewsWithDeletedObjectMetadataCommand } from 'src/database/commands/upgrade-version/0-31/0-31-clean-views-with-deleted-object-metadata.command';
|
||||
import { CleanViewsAssociatedWithOutdatedObjectsCommand } from 'src/database/commands/upgrade-version/0-31/0-31-clean-views-associated-with-outdated-objects.command';
|
||||
import { UpgradeTo0_31Command } from 'src/database/commands/upgrade-version/0-31/0-31-upgrade-version.command';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
@ -18,7 +18,7 @@ import { WorkspaceSyncMetadataCommandsModule } from 'src/engine/workspace-manage
|
||||
providers: [
|
||||
UpgradeTo0_31Command,
|
||||
BackfillWorkspaceFavoritesCommand,
|
||||
CleanViewsWithDeletedObjectMetadataCommand,
|
||||
CleanViewsAssociatedWithOutdatedObjectsCommand,
|
||||
AddIndexKeyToTasksAndNotesViewsCommand,
|
||||
],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user