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(
|
await this.createViewWorkspaceFavorites(
|
||||||
workspaceId,
|
workspaceId,
|
||||||
activeWorkspaceIndexViews.map((view) => view.id),
|
activeWorkspaceIndexViews.map((view) => view.id),
|
||||||
|
_options.dryRun ?? false,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
@ -117,6 +118,7 @@ export class BackfillWorkspaceFavoritesCommand extends ActiveWorkspacesCommandRu
|
|||||||
private async createViewWorkspaceFavorites(
|
private async createViewWorkspaceFavorites(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
viewIds: string[],
|
viewIds: string[],
|
||||||
|
dryRun: boolean,
|
||||||
) {
|
) {
|
||||||
const favoriteRepository =
|
const favoriteRepository =
|
||||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<FavoriteWorkspaceEntity>(
|
await this.twentyORMGlobalManager.getRepositoryForWorkspace<FavoriteWorkspaceEntity>(
|
||||||
@ -125,6 +127,7 @@ export class BackfillWorkspaceFavoritesCommand extends ActiveWorkspacesCommandRu
|
|||||||
);
|
);
|
||||||
|
|
||||||
let nextFavoritePosition = await favoriteRepository.count();
|
let nextFavoritePosition = await favoriteRepository.count();
|
||||||
|
let createdFavorites = 0;
|
||||||
|
|
||||||
for (const viewId of viewIds) {
|
for (const viewId of viewIds) {
|
||||||
const existingFavorites = await favoriteRepository.find({
|
const existingFavorites = await favoriteRepository.find({
|
||||||
@ -137,14 +140,23 @@ export class BackfillWorkspaceFavoritesCommand extends ActiveWorkspacesCommandRu
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
await favoriteRepository.insert(
|
if (!dryRun) {
|
||||||
favoriteRepository.create({
|
await favoriteRepository.insert(
|
||||||
viewId,
|
favoriteRepository.create({
|
||||||
position: nextFavoritePosition,
|
viewId,
|
||||||
}),
|
position: nextFavoritePosition,
|
||||||
);
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
createdFavorites++;
|
||||||
nextFavoritePosition++;
|
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 { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.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 { 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';
|
import { ViewWorkspaceEntity } from 'src/modules/view/standard-objects/view.workspace-entity';
|
||||||
|
|
||||||
@Command({
|
@Command({
|
||||||
name: 'upgrade-0.31:clean-views-with-deleted-object-metadata',
|
name: 'upgrade-0.31:clean-views-associated-with-outdated-objects',
|
||||||
description: 'Clean views with deleted object metadata',
|
description:
|
||||||
|
'Clean views associated with deleted object metadata or activities',
|
||||||
})
|
})
|
||||||
export class CleanViewsWithDeletedObjectMetadataCommand extends ActiveWorkspacesCommandRunner {
|
export class CleanViewsAssociatedWithOutdatedObjectsCommand extends ActiveWorkspacesCommandRunner {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Workspace, 'core')
|
@InjectRepository(Workspace, 'core')
|
||||||
protected readonly workspaceRepository: Repository<Workspace>,
|
protected readonly workspaceRepository: Repository<Workspace>,
|
||||||
@ -88,7 +90,9 @@ export class CleanViewsWithDeletedObjectMetadataCommand extends ActiveWorkspaces
|
|||||||
});
|
});
|
||||||
|
|
||||||
const validObjectMetadataIds = new Set(
|
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
|
const viewIdsToDelete = allViews
|
||||||
@ -6,7 +6,7 @@ import { Repository } from 'typeorm';
|
|||||||
import { ActiveWorkspacesCommandRunner } from 'src/database/commands/active-workspaces.command';
|
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 { 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 { 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 { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||||
import { SyncWorkspaceMetadataCommand } from 'src/engine/workspace-manager/workspace-sync-metadata/commands/sync-workspace-metadata.command';
|
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>,
|
protected readonly workspaceRepository: Repository<Workspace>,
|
||||||
private readonly syncWorkspaceMetadataCommand: SyncWorkspaceMetadataCommand,
|
private readonly syncWorkspaceMetadataCommand: SyncWorkspaceMetadataCommand,
|
||||||
private readonly backfillWorkspaceFavoritesCommand: BackfillWorkspaceFavoritesCommand,
|
private readonly backfillWorkspaceFavoritesCommand: BackfillWorkspaceFavoritesCommand,
|
||||||
private readonly cleanViewsWithDeletedObjectMetadataCommand: CleanViewsWithDeletedObjectMetadataCommand,
|
private readonly cleanViewsAssociatedWithOutdatedObjectsCommand: CleanViewsAssociatedWithOutdatedObjectsCommand,
|
||||||
private readonly addIndexKeyToTasksAndNotesViewsCommand: AddIndexKeyToTasksAndNotesViewsCommand,
|
private readonly addIndexKeyToTasksAndNotesViewsCommand: AddIndexKeyToTasksAndNotesViewsCommand,
|
||||||
) {
|
) {
|
||||||
super(workspaceRepository);
|
super(workspaceRepository);
|
||||||
@ -43,7 +43,7 @@ export class UpgradeTo0_31Command extends ActiveWorkspacesCommandRunner {
|
|||||||
},
|
},
|
||||||
workspaceIds,
|
workspaceIds,
|
||||||
);
|
);
|
||||||
await this.cleanViewsWithDeletedObjectMetadataCommand.executeActiveWorkspacesCommand(
|
await this.cleanViewsAssociatedWithOutdatedObjectsCommand.executeActiveWorkspacesCommand(
|
||||||
passedParam,
|
passedParam,
|
||||||
options,
|
options,
|
||||||
workspaceIds,
|
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 { 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 { 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 { 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 { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.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: [
|
providers: [
|
||||||
UpgradeTo0_31Command,
|
UpgradeTo0_31Command,
|
||||||
BackfillWorkspaceFavoritesCommand,
|
BackfillWorkspaceFavoritesCommand,
|
||||||
CleanViewsWithDeletedObjectMetadataCommand,
|
CleanViewsAssociatedWithOutdatedObjectsCommand,
|
||||||
AddIndexKeyToTasksAndNotesViewsCommand,
|
AddIndexKeyToTasksAndNotesViewsCommand,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user