diff --git a/packages/twenty-server/src/command.module.ts b/packages/twenty-server/src/command.module.ts index 9765e70b5..a99241a8d 100644 --- a/packages/twenty-server/src/command.module.ts +++ b/packages/twenty-server/src/command.module.ts @@ -10,6 +10,7 @@ import { WorkspaceHealthCommandModule } from 'src/workspace/workspace-health/com import { AppModule } from './app.module'; import { WorkspaceSyncMetadataCommandsModule } from './workspace/workspace-sync-metadata/commands/workspace-sync-metadata-commands.module'; +import { WorkspaceMigrationRunnerCommandsModule } from './workspace/workspace-migration-runner/commands/workspace-sync-metadata-commands.module'; @Module({ imports: [ @@ -21,6 +22,7 @@ import { WorkspaceSyncMetadataCommandsModule } from './workspace/workspace-sync- StopCleanInactiveWorkspacesCronCommand, CleanInactiveWorkspacesCommand, WorkspaceHealthCommandModule, + WorkspaceMigrationRunnerCommandsModule, ], }) export class CommandModule {} diff --git a/packages/twenty-server/src/workspace/workspace-migration-runner/commands/workspace-execute-pending-migrations.command.ts b/packages/twenty-server/src/workspace/workspace-migration-runner/commands/workspace-execute-pending-migrations.command.ts new file mode 100644 index 000000000..5b6ccb614 --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-migration-runner/commands/workspace-execute-pending-migrations.command.ts @@ -0,0 +1,37 @@ +import { Command, CommandRunner, Option } from 'nest-commander'; + +import { WorkspaceMigrationRunnerService } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.service'; + +interface ExecuteWorkspaceMigrationsOptions { + workspaceId: string; +} + +@Command({ + name: 'workspace:apply-pending-migrations', + description: 'Apply pending migrations', +}) +export class WorkspaceExecutePendingMigrationsCommand extends CommandRunner { + constructor( + private readonly workspaceMigrationRunnerService: WorkspaceMigrationRunnerService, + ) { + super(); + } + + async run( + _passedParam: string[], + options: ExecuteWorkspaceMigrationsOptions, + ): Promise { + await this.workspaceMigrationRunnerService.executeMigrationFromPendingMigrations( + options.workspaceId, + ); + } + + @Option({ + flags: '-w, --workspace-id [workspace_id]', + description: 'workspace id', + required: true, + }) + parseWorkspaceId(value: string): string { + return value; + } +} diff --git a/packages/twenty-server/src/workspace/workspace-migration-runner/commands/workspace-sync-metadata-commands.module.ts b/packages/twenty-server/src/workspace/workspace-migration-runner/commands/workspace-sync-metadata-commands.module.ts new file mode 100644 index 000000000..892afd2c1 --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-migration-runner/commands/workspace-sync-metadata-commands.module.ts @@ -0,0 +1,11 @@ +import { Module } from '@nestjs/common'; + +import { WorkspaceMigrationRunnerModule } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.module'; + +import { WorkspaceExecutePendingMigrationsCommand } from './workspace-execute-pending-migrations.command'; + +@Module({ + imports: [WorkspaceMigrationRunnerModule], + providers: [WorkspaceExecutePendingMigrationsCommand], +}) +export class WorkspaceMigrationRunnerCommandsModule {}