Compare commits

...
Author SHA1 Message Date
Charles BochetandCharles Bochet 35817d5fae Fix upgrade command (#12210) 2025-05-22 12:23:36 +02:00
EtienneandCharles Bochet 0a75cbd06c clean not found file - add logs (#12198) 2025-05-22 11:40:20 +02:00
Charles BochetandCharles Bochet 3e731da69c Fix docker setup (#12209)
For fresh install, we need the migrations to happen before the upgrade
command is triggered as the upgrade command is a NestJS command and the
app will try to load env variables from db
2025-05-22 11:32:26 +02:00
3 changed files with 27 additions and 36 deletions
@@ -22,6 +22,7 @@ setup_and_migrate_db() {
# Run setup and migration scripts
NODE_OPTIONS="--max-old-space-size=1500" tsx ./scripts/setup-db.ts
yarn database:migrate:prod
fi
yarn command:prod upgrade
@@ -86,6 +86,8 @@ export class CleanNotFoundFilesCommand extends ActiveOrSuspendedWorkspacesMigrat
if (!isNonEmptyString(workspace.logo)) return;
this.logger.log('Processing workspace logo for workspace', workspace.id);
const isFileFound = await this.checkIfFileIsFound(
workspace.logo,
workspace.id,
@@ -122,6 +124,7 @@ export class CleanNotFoundFilesCommand extends ActiveOrSuspendedWorkspacesMigrat
const attachmentIdsToSoftDeleteChunk = await Promise.all(
attachmentsChunk.map(async (attachment) => {
this.logger.log('Processing attachment', attachment.id);
const isFileFound = await this.checkIfFileIsFound(
attachment.fullPath,
workspaceId,
@@ -164,6 +167,8 @@ export class CleanNotFoundFilesCommand extends ActiveOrSuspendedWorkspacesMigrat
const workspaceMemberIdsToUpdate: string[] = [];
for (const workspaceMember of workspaceMembers) {
this.logger.log('Processing workspaceMember', workspaceMember.id);
const isFileFound = await this.checkIfFileIsFound(
workspaceMember.avatarUrl,
workspaceId,
@@ -201,6 +206,8 @@ export class CleanNotFoundFilesCommand extends ActiveOrSuspendedWorkspacesMigrat
const personIdsToUpdate: string[] = [];
for (const person of people) {
this.logger.log('Processing person', person.id);
const isFileFound = await this.checkIfFileIsFound(
person.avatarUrl,
workspaceId,
@@ -69,20 +69,11 @@ export class DatabaseMigrationService {
});
}
async shouldRunMigrationsIfAllWorkspaceAreAboveVersion0_53(): Promise<boolean> {
const coreWorkspaceSchemaExists = await this.checkCoreWorkspaceExists();
async shouldSkipUpgradeIfFreshInstallation(): Promise<boolean> {
const activeWorkspaceOrSuspendedWorkspaceCount =
await this.loadActiveOrSuspendedWorkspace();
if (!coreWorkspaceSchemaExists) {
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();
return activeWorkspaceOrSuspendedWorkspaceCount.length === 0;
}
async runMigrations(): Promise<void> {
@@ -114,26 +105,7 @@ export class DatabaseMigrationService {
}
}
private async checkCoreWorkspaceExists(): 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> {
public async areAllWorkspacesAboveVersion0_53(): Promise<boolean> {
try {
const allActiveOrSuspendedWorkspaces =
await this.loadActiveOrSuspendedWorkspace();
@@ -293,10 +265,21 @@ export class UpgradeCommand extends UpgradeCommandRunner {
passedParams: string[],
options: ActiveOrSuspendedWorkspacesMigrationCommandOptions,
): Promise<void> {
const shouldRunMigrateAsPartOfUpgrade =
await this.databaseMigrationService.shouldRunMigrationsIfAllWorkspaceAreAboveVersion0_53();
const shouldSkipUpgradeIfFreshInstallation =
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(
chalk.red(
'Not able to run migrate command, aborting the whole migrate-upgrade operation',