The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
`[run-instance-commands]` Preserve `fast` `slow` sequentiality (#19757)
Paul Rastoin2413af0ba93a
diff --git a/packages/twenty-server/src/database/commands/run-instance-commands.command.ts b/packages/twenty-server/src/database/commands/run-instance-commands.command.tsindex cb241d64908..0db1dca6541 100644--- a/packages/twenty-server/src/database/commands/run-instance-commands.command.ts+++ b/packages/twenty-server/src/database/commands/run-instance-commands.command.ts@@ -9,6 +9,7 @@ import { TWENTY_PREVIOUS_VERSIONS } from 'src/engine/core-modules/upgrade/constaimport { InstanceCommandRunnerService } from 'src/engine/core-modules/upgrade/services/instance-command-runner.service';import { UpgradeCommandRegistryService } from 'src/engine/core-modules/upgrade/services/upgrade-command-registry.service';import { UpgradeMigrationService } from 'src/engine/core-modules/upgrade/services/upgrade-migration.service';+import { UpgradeSequenceReaderService } from 'src/engine/core-modules/upgrade/services/upgrade-sequence-reader.service';import { WorkspaceVersionService } from 'src/engine/workspace-manager/workspace-version/services/workspace-version.service';type RunInstanceCommandsOptions = {@@ -30,6 +31,7 @@ export class RunInstanceCommandsCommand extends CommandRunner {private readonly dataSource: DataSource,private readonly workspaceVersionService: WorkspaceVersionService,private readonly upgradeCommandRegistryService: UpgradeCommandRegistryService,+ private readonly upgradeSequenceReaderService: UpgradeSequenceReaderService,private readonly instanceUpgradeService: InstanceCommandRunnerService,private readonly upgradeMigrationService: UpgradeMigrationService,) {@@ -65,31 +67,26 @@ export class RunInstanceCommandsCommand extends CommandRunner {const activeOrSuspendedWorkspaceIds =await this.workspaceVersionService.getActiveOrSuspendedWorkspaceIds();- for (const {- command,- name,- } of this.upgradeCommandRegistryService.getCrossUpgradeSupportedFastInstanceCommands()) {- const result = await this.instanceUpgradeService.runFastInstanceCommand(- {- command,- name,- },- );-- if (result.status === 'failed') {- throw result.error;+ const sequence = this.upgradeSequenceReaderService.getUpgradeSequence();++ for (const step of sequence) {+ if (step.kind === 'fast-instance') {+ const result =+ await this.instanceUpgradeService.runFastInstanceCommand({+ command: step.command,+ name: step.name,+ });++ if (result.status === 'failed') {+ throw result.error;+ }}- }- if (options.includeSlow) {- for (const {- command,- name,- } of this.upgradeCommandRegistryService.getCrossUpgradeSupportedSlowInstanceCommands()) {+ if (step.kind === 'slow-instance' && options.includeSlow) {const result =await this.instanceUpgradeService.runSlowInstanceCommand({- command,- name,+ command: step.command,+ name: step.name,skipDataMigration: activeOrSuspendedWorkspaceIds.length === 0,});diff --git a/packages/twenty-server/src/engine/core-modules/upgrade/services/upgrade-migration.service.ts b/packages/twenty-server/src/engine/core-modules/upgrade/services/upgrade-migration.service.tsindex fe6f4ba0924..af8189325e2 100644--- a/packages/twenty-server/src/engine/core-modules/upgrade/services/upgrade-migration.service.ts+++ b/packages/twenty-server/src/engine/core-modules/upgrade/services/upgrade-migration.service.ts@@ -283,10 +283,10 @@ export class UpgradeMigrationService {return completedCount === workspaceIds.length;}- async getLastAttemptedInstanceCommandOrThrow(): Promise<{+ async getLastAttemptedInstanceCommand(): Promise<{name: string;status: UpgradeMigrationStatus;- }> {+ } | null> {const migration = await this.upgradeMigrationRepository.createQueryBuilder('migration').select(['migration.name', 'migration.status'])@@ -304,11 +304,24 @@ export class UpgradeMigrationService {.getOne();if (!migration) {+ return null;+ }++ return { name: migration.name, status: migration.status };+ }++ async getLastAttemptedInstanceCommandOrThrow(): Promise<{+ name: string;+ status: UpgradeMigrationStatus;+ }> {+ const result = await this.getLastAttemptedInstanceCommand();++ if (!result) {throw new Error('No instance command found — the database may not have been initialized',);}- return { name: migration.name, status: migration.status };+ return result;}}