refactor(server): upgrade command to more human friendly (#10858)
# Introduction Refactored the upgrade command to be more intuitive to anyone wanting to add a command to the next relase upgrade instance Also updated the upgrade command for the next 0.44 release
This commit is contained in:
@ -177,5 +177,5 @@ export abstract class ActiveOrSuspendedWorkspacesMigrationCommandRunner<
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract runOnWorkspace(args: RunOnWorkspaceArgs): Promise<void>;
|
public abstract runOnWorkspace(args: RunOnWorkspaceArgs): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { Module } from '@nestjs/common';
|
|||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
|
||||||
import { InitializePermissionsCommand } from 'src/database/commands/upgrade-version-command/0-44/0-44-initialize-permissions.command';
|
import { InitializePermissionsCommand } from 'src/database/commands/upgrade-version-command/0-44/0-44-initialize-permissions.command';
|
||||||
import { MigrateRelationsToFieldMetadataCommand } from 'src/database/commands/upgrade-version-command/0-44/0-44-migrate-relations-to-field-metadata.command';
|
|
||||||
import { UserWorkspace } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
|
import { UserWorkspace } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||||
@ -22,13 +21,7 @@ import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/works
|
|||||||
RoleModule,
|
RoleModule,
|
||||||
UserRoleModule,
|
UserRoleModule,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [InitializePermissionsCommand],
|
||||||
InitializePermissionsCommand,
|
exports: [InitializePermissionsCommand],
|
||||||
MigrateRelationsToFieldMetadataCommand,
|
|
||||||
],
|
|
||||||
exports: [
|
|
||||||
InitializePermissionsCommand,
|
|
||||||
MigrateRelationsToFieldMetadataCommand,
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
export class V0_44_UpgradeVersionCommandModule {}
|
export class V0_44_UpgradeVersionCommandModule {}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import {
|
|||||||
import { isFieldMetadataOfType } from 'src/engine/utils/is-field-metadata-of-type.util';
|
import { isFieldMetadataOfType } from 'src/engine/utils/is-field-metadata-of-type.util';
|
||||||
|
|
||||||
@Command({
|
@Command({
|
||||||
name: 'upgrade:0-44:migrate-relations-to-field-metadata',
|
name: 'upgrade:0-50:migrate-relations-to-field-metadata',
|
||||||
description: 'Migrate relations to field metadata',
|
description: 'Migrate relations to field metadata',
|
||||||
})
|
})
|
||||||
export class MigrateRelationsToFieldMetadataCommand extends ActiveOrSuspendedWorkspacesMigrationCommandRunner {
|
export class MigrateRelationsToFieldMetadataCommand extends ActiveOrSuspendedWorkspacesMigrationCommandRunner {
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
|
||||||
|
import { MigrateRelationsToFieldMetadataCommand } from 'src/database/commands/upgrade-version-command/0-50/0-50-migrate-relations-to-field-metadata.command';
|
||||||
|
import { UserWorkspace } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
|
||||||
|
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||||
|
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 { RoleModule } from 'src/engine/metadata-modules/role/role.module';
|
||||||
|
import { UserRoleModule } from 'src/engine/metadata-modules/user-role/user-role.module';
|
||||||
|
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([Workspace, UserWorkspace], 'core'),
|
||||||
|
TypeOrmModule.forFeature(
|
||||||
|
[FieldMetadataEntity, ObjectMetadataEntity],
|
||||||
|
'metadata',
|
||||||
|
),
|
||||||
|
WorkspaceDataSourceModule,
|
||||||
|
RoleModule,
|
||||||
|
UserRoleModule,
|
||||||
|
],
|
||||||
|
providers: [MigrateRelationsToFieldMetadataCommand],
|
||||||
|
exports: [MigrateRelationsToFieldMetadataCommand],
|
||||||
|
})
|
||||||
|
export class V0_50_UpgradeVersionCommandModule {}
|
||||||
@ -3,6 +3,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
|||||||
|
|
||||||
import { V0_43_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/0-43/0-43-upgrade-version-command.module';
|
import { V0_43_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/0-43/0-43-upgrade-version-command.module';
|
||||||
import { V0_44_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/0-44/0-44-upgrade-version-command.module';
|
import { V0_44_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/0-44/0-44-upgrade-version-command.module';
|
||||||
|
import { V0_50_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/0-50/0-50-upgrade-version-command.module';
|
||||||
import { UpgradeCommand } from 'src/database/commands/upgrade-version-command/upgrade.command';
|
import { UpgradeCommand } from 'src/database/commands/upgrade-version-command/upgrade.command';
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||||
import { WorkspaceSyncMetadataModule } from 'src/engine/workspace-manager/workspace-sync-metadata/workspace-sync-metadata.module';
|
import { WorkspaceSyncMetadataModule } from 'src/engine/workspace-manager/workspace-sync-metadata/workspace-sync-metadata.module';
|
||||||
@ -12,6 +13,7 @@ import { WorkspaceSyncMetadataModule } from 'src/engine/workspace-manager/worksp
|
|||||||
TypeOrmModule.forFeature([Workspace], 'core'),
|
TypeOrmModule.forFeature([Workspace], 'core'),
|
||||||
V0_43_UpgradeVersionCommandModule,
|
V0_43_UpgradeVersionCommandModule,
|
||||||
V0_44_UpgradeVersionCommandModule,
|
V0_44_UpgradeVersionCommandModule,
|
||||||
|
V0_50_UpgradeVersionCommandModule,
|
||||||
WorkspaceSyncMetadataModule,
|
WorkspaceSyncMetadataModule,
|
||||||
],
|
],
|
||||||
providers: [UpgradeCommand],
|
providers: [UpgradeCommand],
|
||||||
|
|||||||
@ -4,24 +4,34 @@ import { Command } from 'nest-commander';
|
|||||||
import { SemVer } from 'semver';
|
import { SemVer } from 'semver';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
import { RunOnWorkspaceArgs } from 'src/database/commands/command-runners/active-or-suspended-workspaces-migration.command-runner';
|
import {
|
||||||
|
ActiveOrSuspendedWorkspacesMigrationCommandRunner,
|
||||||
|
RunOnWorkspaceArgs,
|
||||||
|
} from 'src/database/commands/command-runners/active-or-suspended-workspaces-migration.command-runner';
|
||||||
import { UpgradeCommandRunner } from 'src/database/commands/command-runners/upgrade.command-runner';
|
import { UpgradeCommandRunner } from 'src/database/commands/command-runners/upgrade.command-runner';
|
||||||
import { AddTasksAssignedToMeViewCommand } from 'src/database/commands/upgrade-version-command/0-43/0-43-add-tasks-assigned-to-me-view.command';
|
import { AddTasksAssignedToMeViewCommand } from 'src/database/commands/upgrade-version-command/0-43/0-43-add-tasks-assigned-to-me-view.command';
|
||||||
import { MigrateIsSearchableForCustomObjectMetadataCommand } from 'src/database/commands/upgrade-version-command/0-43/0-43-migrate-is-searchable-for-custom-object-metadata.command';
|
import { MigrateIsSearchableForCustomObjectMetadataCommand } from 'src/database/commands/upgrade-version-command/0-43/0-43-migrate-is-searchable-for-custom-object-metadata.command';
|
||||||
import { MigrateRichTextContentPatchCommand } from 'src/database/commands/upgrade-version-command/0-43/0-43-migrate-rich-text-content-patch.command';
|
import { MigrateRichTextContentPatchCommand } from 'src/database/commands/upgrade-version-command/0-43/0-43-migrate-rich-text-content-patch.command';
|
||||||
import { MigrateSearchVectorOnNoteAndTaskEntitiesCommand } from 'src/database/commands/upgrade-version-command/0-43/0-43-migrate-search-vector-on-note-and-task-entities.command';
|
import { MigrateSearchVectorOnNoteAndTaskEntitiesCommand } from 'src/database/commands/upgrade-version-command/0-43/0-43-migrate-search-vector-on-note-and-task-entities.command';
|
||||||
import { UpdateDefaultViewRecordOpeningOnWorkflowObjectsCommand } from 'src/database/commands/upgrade-version-command/0-43/0-43-update-default-view-record-opening-on-workflow-objects.command';
|
import { UpdateDefaultViewRecordOpeningOnWorkflowObjectsCommand } from 'src/database/commands/upgrade-version-command/0-43/0-43-update-default-view-record-opening-on-workflow-objects.command';
|
||||||
|
import { InitializePermissionsCommand } from 'src/database/commands/upgrade-version-command/0-44/0-44-initialize-permissions.command';
|
||||||
|
import { MigrateRelationsToFieldMetadataCommand } from 'src/database/commands/upgrade-version-command/0-50/0-50-migrate-relations-to-field-metadata.command';
|
||||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||||
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';
|
||||||
|
|
||||||
|
type VersionCommands = {
|
||||||
|
beforeSyncMetadata: ActiveOrSuspendedWorkspacesMigrationCommandRunner[];
|
||||||
|
afterSyncMetadata: ActiveOrSuspendedWorkspacesMigrationCommandRunner[];
|
||||||
|
};
|
||||||
@Command({
|
@Command({
|
||||||
name: 'upgrade',
|
name: 'upgrade',
|
||||||
description: 'Upgrade workspaces to the latest version',
|
description: 'Upgrade workspaces to the latest version',
|
||||||
})
|
})
|
||||||
export class UpgradeCommand extends UpgradeCommandRunner {
|
export class UpgradeCommand extends UpgradeCommandRunner {
|
||||||
fromWorkspaceVersion = new SemVer('0.43.0');
|
fromWorkspaceVersion = new SemVer('0.43.0');
|
||||||
|
private commands: VersionCommands;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Workspace, 'core')
|
@InjectRepository(Workspace, 'core')
|
||||||
@ -30,11 +40,18 @@ export class UpgradeCommand extends UpgradeCommandRunner {
|
|||||||
protected readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
protected readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||||
protected readonly syncWorkspaceMetadataCommand: SyncWorkspaceMetadataCommand,
|
protected readonly syncWorkspaceMetadataCommand: SyncWorkspaceMetadataCommand,
|
||||||
|
|
||||||
|
// 0.43 Commands
|
||||||
protected readonly migrateRichTextContentPatchCommand: MigrateRichTextContentPatchCommand,
|
protected readonly migrateRichTextContentPatchCommand: MigrateRichTextContentPatchCommand,
|
||||||
protected readonly addTasksAssignedToMeViewCommand: AddTasksAssignedToMeViewCommand,
|
protected readonly addTasksAssignedToMeViewCommand: AddTasksAssignedToMeViewCommand,
|
||||||
protected readonly migrateIsSearchableForCustomObjectMetadataCommand: MigrateIsSearchableForCustomObjectMetadataCommand,
|
protected readonly migrateIsSearchableForCustomObjectMetadataCommand: MigrateIsSearchableForCustomObjectMetadataCommand,
|
||||||
protected readonly updateDefaultViewRecordOpeningOnWorkflowObjectsCommand: UpdateDefaultViewRecordOpeningOnWorkflowObjectsCommand,
|
protected readonly updateDefaultViewRecordOpeningOnWorkflowObjectsCommand: UpdateDefaultViewRecordOpeningOnWorkflowObjectsCommand,
|
||||||
protected readonly migrateSearchVectorOnNoteAndTaskEntitiesCommand: MigrateSearchVectorOnNoteAndTaskEntitiesCommand,
|
protected readonly migrateSearchVectorOnNoteAndTaskEntitiesCommand: MigrateSearchVectorOnNoteAndTaskEntitiesCommand,
|
||||||
|
|
||||||
|
// 0.44 Commands
|
||||||
|
protected readonly initializePermissionsCommand: InitializePermissionsCommand,
|
||||||
|
|
||||||
|
// 0.50 Commands
|
||||||
|
protected readonly migrateRelationsToFieldMetadataCommand: MigrateRelationsToFieldMetadataCommand,
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
workspaceRepository,
|
workspaceRepository,
|
||||||
@ -42,29 +59,40 @@ export class UpgradeCommand extends UpgradeCommandRunner {
|
|||||||
twentyORMGlobalManager,
|
twentyORMGlobalManager,
|
||||||
syncWorkspaceMetadataCommand,
|
syncWorkspaceMetadataCommand,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const _commands_043: VersionCommands = {
|
||||||
|
beforeSyncMetadata: [
|
||||||
|
this.migrateRichTextContentPatchCommand,
|
||||||
|
this.migrateIsSearchableForCustomObjectMetadataCommand,
|
||||||
|
this.migrateSearchVectorOnNoteAndTaskEntitiesCommand,
|
||||||
|
this.migrateIsSearchableForCustomObjectMetadataCommand,
|
||||||
|
],
|
||||||
|
afterSyncMetadata: [
|
||||||
|
this.updateDefaultViewRecordOpeningOnWorkflowObjectsCommand,
|
||||||
|
this.addTasksAssignedToMeViewCommand,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const commands_044: VersionCommands = {
|
||||||
|
beforeSyncMetadata: [this.initializePermissionsCommand],
|
||||||
|
afterSyncMetadata: [],
|
||||||
|
};
|
||||||
|
const _commands_050: VersionCommands = {
|
||||||
|
beforeSyncMetadata: [this.migrateRelationsToFieldMetadataCommand],
|
||||||
|
afterSyncMetadata: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
this.commands = commands_044;
|
||||||
}
|
}
|
||||||
|
|
||||||
override async runBeforeSyncMetadata(args: RunOnWorkspaceArgs) {
|
override async runBeforeSyncMetadata(args: RunOnWorkspaceArgs) {
|
||||||
await this.migrateRichTextContentPatchCommand.runOnWorkspace(args);
|
for (const command of this.commands.beforeSyncMetadata) {
|
||||||
|
await command.runOnWorkspace(args);
|
||||||
await this.migrateIsSearchableForCustomObjectMetadataCommand.runOnWorkspace(
|
}
|
||||||
args,
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.migrateSearchVectorOnNoteAndTaskEntitiesCommand.runOnWorkspace(
|
|
||||||
args,
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.migrateIsSearchableForCustomObjectMetadataCommand.runOnWorkspace(
|
|
||||||
args,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override async runAfterSyncMetadata(args: RunOnWorkspaceArgs) {
|
override async runAfterSyncMetadata(args: RunOnWorkspaceArgs) {
|
||||||
await this.updateDefaultViewRecordOpeningOnWorkflowObjectsCommand.runOnWorkspace(
|
for (const command of this.commands.afterSyncMetadata) {
|
||||||
args,
|
await command.runOnWorkspace(args);
|
||||||
);
|
}
|
||||||
|
|
||||||
await this.addTasksAssignedToMeViewCommand.runOnWorkspace(args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user