Do not upgrade if no migrate (#12187)

This commit is contained in:
Paul Rastoin
2025-05-21 16:01:03 +02:00
committed by GitHub
parent a5b212369b
commit 85a17a54b3

View File

@ -4,6 +4,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { exec } from 'child_process';
import { promisify } from 'util';
import chalk from 'chalk';
import { Command } from 'nest-commander';
import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
import { In, Repository } from 'typeorm';
@ -278,17 +279,18 @@ export class UpgradeCommand extends UpgradeCommandRunner {
passedParams: string[],
options: ActiveOrSuspendedWorkspacesMigrationCommandOptions,
): Promise<void> {
// Only run migrations if we have at least one workspace on version 0.53
const shouldRunMigrateAsPartOfUpgrade =
await this.databaseMigrationService.shouldRunMigrationsIfAllWorkspaceAreAboveVersion0_53();
if (shouldRunMigrateAsPartOfUpgrade) {
await this.databaseMigrationService.runMigrations();
} else {
this.logger.log('Skipping database migrations.');
if (!shouldRunMigrateAsPartOfUpgrade) {
this.logger.log(
chalk.red(
'Not able to run migrate command, aborting the whole migrate-upgrade operation',
),
);
throw new Error('Could not run migration aborting');
}
// Continue with the regular upgrade process
await super.runMigrationCommand(passedParams, options);
}
}