Fix upgrade command for 0.54

This commit is contained in:
Charles Bochet
2025-05-21 16:25:32 +02:00
parent 6c9d17eee7
commit dc2d7f7c94
2 changed files with 17 additions and 13 deletions

View File

@ -4,9 +4,9 @@ import { Command } from 'nest-commander';
import { Repository } from 'typeorm';
import {
ActiveOrSuspendedWorkspacesMigrationCommandRunner,
RunOnWorkspaceArgs,
} from 'src/database/commands/command-runners/active-or-suspended-workspaces-migration.command-runner';
MigrationCommandOptions,
MigrationCommandRunner,
} from 'src/database/commands/command-runners/migration.command-runner';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
@ -14,21 +14,19 @@ import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.
name: 'upgrade:0-53:copy-typeorm-migrations',
description: 'Copy _typeorm_migrations from metadata schema to core schema',
})
export class CopyTypeormMigrationsCommand extends ActiveOrSuspendedWorkspacesMigrationCommandRunner {
export class CopyTypeormMigrationsCommand extends MigrationCommandRunner {
constructor(
@InjectRepository(Workspace, 'core')
protected readonly workspaceRepository: Repository<Workspace>,
protected readonly twentyORMGlobalManager: TwentyORMGlobalManager,
) {
super(workspaceRepository, twentyORMGlobalManager);
super();
}
async runOnWorkspace(args: RunOnWorkspaceArgs): Promise<void> {
// This command doesn't need to run per workspace, only once
if (args.index !== 0) {
return;
}
override async runMigrationCommand(
_passedParams: string[],
options: MigrationCommandOptions,
): Promise<void> {
this.logger.log(
'Starting to copy _typeorm_migrations from metadata to core',
);
@ -48,7 +46,7 @@ export class CopyTypeormMigrationsCommand extends ActiveOrSuspendedWorkspacesMig
`Found ${metadataMigrations.length} migrations in metadata schema`,
);
if (args.options?.dryRun) {
if (options?.dryRun) {
this.logger.log('Dry run mode - no changes will be applied');
return;

View File

@ -47,6 +47,7 @@ export class DatabaseMigrationService {
constructor(
@InjectRepository(Workspace, 'core')
private readonly workspaceRepository: Repository<Workspace>,
protected readonly copyTypeormMigrationsCommand: CopyTypeormMigrationsCommand,
) {}
// TODO centralize with ActiveOrSuspendedRunner method
@ -86,6 +87,10 @@ export class DatabaseMigrationService {
try {
this.logger.log('Running metadata datasource migrations...');
await this.copyTypeormMigrationsCommand.runMigrationCommand([], {
dryRun: false,
verbose: false,
});
const metadataResult = await execPromise(
'npx -y typeorm migration:run -d dist/src/database/typeorm/metadata/metadata.datasource',
);
@ -251,7 +256,6 @@ export class UpgradeCommand extends UpgradeCommandRunner {
afterSyncMetadata: [
this.migrateWorkflowEventListenersToAutomatedTriggersCommand,
this.backfillWorkflowNextStepIdsCommand,
this.copyTypeormMigrationsCommand,
this.upgradeSearchVectorOnPersonEntityCommand,
],
};
@ -291,6 +295,8 @@ export class UpgradeCommand extends UpgradeCommandRunner {
throw new Error('Could not run migration aborting');
}
await this.databaseMigrationService.runMigrations();
await super.runMigrationCommand(passedParams, options);
}
}