Fix upgrade command (#12210)
This commit is contained in:
@ -69,20 +69,11 @@ export class DatabaseMigrationService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async shouldRunMigrationsIfAllWorkspaceAreAboveVersion0_53(): Promise<boolean> {
|
async shouldSkipUpgradeIfFreshInstallation(): Promise<boolean> {
|
||||||
const coreWorkspaceSchemaExists = await this.checkCoreWorkspaceExists();
|
const activeWorkspaceOrSuspendedWorkspaceCount =
|
||||||
|
await this.loadActiveOrSuspendedWorkspace();
|
||||||
|
|
||||||
if (!coreWorkspaceSchemaExists) {
|
return activeWorkspaceOrSuspendedWorkspaceCount.length === 0;
|
||||||
this.logger.log(
|
|
||||||
'core.workspace does not exist. Running migrations for fresh installation.',
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.log('Not a first installation, checking workspace versions...');
|
|
||||||
|
|
||||||
return await this.areAllWorkspacesAboveVersion0_53();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async runMigrations(): Promise<void> {
|
async runMigrations(): Promise<void> {
|
||||||
@ -114,26 +105,7 @@ export class DatabaseMigrationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async checkCoreWorkspaceExists(): Promise<boolean> {
|
public async areAllWorkspacesAboveVersion0_53(): Promise<boolean> {
|
||||||
try {
|
|
||||||
const result = await this.workspaceRepository.query(`
|
|
||||||
SELECT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM information_schema.tables
|
|
||||||
WHERE table_schema = 'core'
|
|
||||||
AND table_name = 'workspace'
|
|
||||||
);
|
|
||||||
`);
|
|
||||||
|
|
||||||
return result[0].exists;
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error('Error checking core.workspace existence:', error);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async areAllWorkspacesAboveVersion0_53(): Promise<boolean> {
|
|
||||||
try {
|
try {
|
||||||
const allActiveOrSuspendedWorkspaces =
|
const allActiveOrSuspendedWorkspaces =
|
||||||
await this.loadActiveOrSuspendedWorkspace();
|
await this.loadActiveOrSuspendedWorkspace();
|
||||||
@ -293,10 +265,21 @@ export class UpgradeCommand extends UpgradeCommandRunner {
|
|||||||
passedParams: string[],
|
passedParams: string[],
|
||||||
options: ActiveOrSuspendedWorkspacesMigrationCommandOptions,
|
options: ActiveOrSuspendedWorkspacesMigrationCommandOptions,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const shouldRunMigrateAsPartOfUpgrade =
|
const shouldSkipUpgradeIfFreshInstallation =
|
||||||
await this.databaseMigrationService.shouldRunMigrationsIfAllWorkspaceAreAboveVersion0_53();
|
await this.databaseMigrationService.shouldSkipUpgradeIfFreshInstallation();
|
||||||
|
|
||||||
if (!shouldRunMigrateAsPartOfUpgrade) {
|
if (shouldSkipUpgradeIfFreshInstallation) {
|
||||||
|
this.logger.log(
|
||||||
|
chalk.blue('Fresh installation detected, skipping migration'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const shouldPreventFromUpgradingIfWorkspaceIsBelowVersion0_53 =
|
||||||
|
!(await this.databaseMigrationService.areAllWorkspacesAboveVersion0_53());
|
||||||
|
|
||||||
|
if (shouldPreventFromUpgradingIfWorkspaceIsBelowVersion0_53) {
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
chalk.red(
|
chalk.red(
|
||||||
'Not able to run migrate command, aborting the whole migrate-upgrade operation',
|
'Not able to run migrate command, aborting the whole migrate-upgrade operation',
|
||||||
|
|||||||
Reference in New Issue
Block a user