Fix upgrade command for 0.54
This commit is contained in:
@ -4,9 +4,9 @@ import { Command } from 'nest-commander';
|
|||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ActiveOrSuspendedWorkspacesMigrationCommandRunner,
|
MigrationCommandOptions,
|
||||||
RunOnWorkspaceArgs,
|
MigrationCommandRunner,
|
||||||
} from 'src/database/commands/command-runners/active-or-suspended-workspaces-migration.command-runner';
|
} from 'src/database/commands/command-runners/migration.command-runner';
|
||||||
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';
|
||||||
|
|
||||||
@ -14,21 +14,19 @@ import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.
|
|||||||
name: 'upgrade:0-53:copy-typeorm-migrations',
|
name: 'upgrade:0-53:copy-typeorm-migrations',
|
||||||
description: 'Copy _typeorm_migrations from metadata schema to core schema',
|
description: 'Copy _typeorm_migrations from metadata schema to core schema',
|
||||||
})
|
})
|
||||||
export class CopyTypeormMigrationsCommand extends ActiveOrSuspendedWorkspacesMigrationCommandRunner {
|
export class CopyTypeormMigrationsCommand extends MigrationCommandRunner {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Workspace, 'core')
|
@InjectRepository(Workspace, 'core')
|
||||||
protected readonly workspaceRepository: Repository<Workspace>,
|
protected readonly workspaceRepository: Repository<Workspace>,
|
||||||
protected readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
protected readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||||
) {
|
) {
|
||||||
super(workspaceRepository, twentyORMGlobalManager);
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
async runOnWorkspace(args: RunOnWorkspaceArgs): Promise<void> {
|
override async runMigrationCommand(
|
||||||
// This command doesn't need to run per workspace, only once
|
_passedParams: string[],
|
||||||
if (args.index !== 0) {
|
options: MigrationCommandOptions,
|
||||||
return;
|
): Promise<void> {
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
'Starting to copy _typeorm_migrations from metadata to core',
|
'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`,
|
`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');
|
this.logger.log('Dry run mode - no changes will be applied');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -47,6 +47,7 @@ export class DatabaseMigrationService {
|
|||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Workspace, 'core')
|
@InjectRepository(Workspace, 'core')
|
||||||
private readonly workspaceRepository: Repository<Workspace>,
|
private readonly workspaceRepository: Repository<Workspace>,
|
||||||
|
protected readonly copyTypeormMigrationsCommand: CopyTypeormMigrationsCommand,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
// TODO centralize with ActiveOrSuspendedRunner method
|
// TODO centralize with ActiveOrSuspendedRunner method
|
||||||
@ -86,6 +87,10 @@ export class DatabaseMigrationService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
this.logger.log('Running metadata datasource migrations...');
|
this.logger.log('Running metadata datasource migrations...');
|
||||||
|
await this.copyTypeormMigrationsCommand.runMigrationCommand([], {
|
||||||
|
dryRun: false,
|
||||||
|
verbose: false,
|
||||||
|
});
|
||||||
const metadataResult = await execPromise(
|
const metadataResult = await execPromise(
|
||||||
'npx -y typeorm migration:run -d dist/src/database/typeorm/metadata/metadata.datasource',
|
'npx -y typeorm migration:run -d dist/src/database/typeorm/metadata/metadata.datasource',
|
||||||
);
|
);
|
||||||
@ -251,7 +256,6 @@ export class UpgradeCommand extends UpgradeCommandRunner {
|
|||||||
afterSyncMetadata: [
|
afterSyncMetadata: [
|
||||||
this.migrateWorkflowEventListenersToAutomatedTriggersCommand,
|
this.migrateWorkflowEventListenersToAutomatedTriggersCommand,
|
||||||
this.backfillWorkflowNextStepIdsCommand,
|
this.backfillWorkflowNextStepIdsCommand,
|
||||||
this.copyTypeormMigrationsCommand,
|
|
||||||
this.upgradeSearchVectorOnPersonEntityCommand,
|
this.upgradeSearchVectorOnPersonEntityCommand,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@ -291,6 +295,8 @@ export class UpgradeCommand extends UpgradeCommandRunner {
|
|||||||
throw new Error('Could not run migration aborting');
|
throw new Error('Could not run migration aborting');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.databaseMigrationService.runMigrations();
|
||||||
|
|
||||||
await super.runMigrationCommand(passedParams, options);
|
await super.runMigrationCommand(passedParams, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user