Files v2 - File table migration + data migration command (#17661)

To add also in 1.16 patch
This commit is contained in:
Etienne
2026-02-04 11:28:55 +01:00
committed by GitHub
parent 50ef231704
commit f6b210dd0d
6 changed files with 124 additions and 21 deletions
@@ -40,6 +40,7 @@ export class DeleteFileRecordsCommand extends ActiveOrSuspendedWorkspacesMigrati
);
const files = await this.fileRepository.find({
select: ['id'],
where: { workspaceId },
withDeleted: true,
});
@@ -0,0 +1,66 @@
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { Command } from 'nest-commander';
import { DataSource, Repository } from 'typeorm';
import { ActiveOrSuspendedWorkspacesMigrationCommandRunner } from 'src/database/commands/command-runners/active-or-suspended-workspaces-migration.command-runner';
import { RunOnWorkspaceArgs } from 'src/database/commands/command-runners/workspaces-migration.command-runner';
import { updateFileTableQueries } from 'src/database/typeorm/core/migrations/utils/1768572831179-updateFileTable.util';
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
import { GlobalWorkspaceOrmManager } from 'src/engine/twenty-orm/global-workspace-datasource/global-workspace-orm.manager';
@Command({
name: 'upgrade:1-17:update-file-table-migration',
description: 'Update file table schema with applicationId and new columns',
})
export class UpdateFileTableMigrationCommand extends ActiveOrSuspendedWorkspacesMigrationCommandRunner {
private hasRunOnce = false;
constructor(
@InjectRepository(WorkspaceEntity)
protected readonly workspaceRepository: Repository<WorkspaceEntity>,
protected readonly twentyORMGlobalManager: GlobalWorkspaceOrmManager,
protected readonly dataSourceService: DataSourceService,
@InjectDataSource()
private readonly coreDataSource: DataSource,
) {
super(workspaceRepository, twentyORMGlobalManager, dataSourceService);
}
override async runOnWorkspace({
options,
}: RunOnWorkspaceArgs): Promise<void> {
if (this.hasRunOnce) {
this.logger.warn(
'Skipping has already been run once UpdateFileTableMigrationCommand',
);
return;
}
if (options.dryRun) {
return;
}
const queryRunner = this.coreDataSource.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
await updateFileTableQueries(queryRunner);
await queryRunner.commitTransaction();
this.logger.log('Successfully run UpdateFileTableMigrationCommand');
this.hasRunOnce = true;
} catch (error) {
await queryRunner.rollbackTransaction();
this.logger.error(
`Rolling back UpdateFileTableMigrationCommand: ${error.message}`,
);
} finally {
await queryRunner.release();
}
}
}
@@ -11,6 +11,7 @@ import { MigrateSendEmailRecipientsCommand } from 'src/database/commands/upgrade
import { MigrateTaskTargetToMorphRelationsCommand } from 'src/database/commands/upgrade-version-command/1-17/1-17-migrate-task-target-to-morph-relations.command';
import { MigrateWorkflowCodeStepsCommand } from 'src/database/commands/upgrade-version-command/1-17/1-17-migrate-workflow-code-steps.command';
import { SeedWorkflowV1_16Command } from 'src/database/commands/upgrade-version-command/1-17/1-17-seed-workflow-v1-16.command';
import { UpdateFileTableMigrationCommand } from 'src/database/commands/upgrade-version-command/1-17/1-17-update-file-table-migration.command';
import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { FeatureFlagModule } from 'src/engine/core-modules/feature-flag/feature-flag.module';
@@ -72,6 +73,7 @@ import { TaskTargetWorkspaceEntity } from 'src/modules/task/standard-objects/tas
MigrateWorkflowCodeStepsCommand,
SeedWorkflowV1_16Command,
BackfillApplicationPackageFilesCommand,
UpdateFileTableMigrationCommand,
],
exports: [
MigrateAttachmentToMorphRelationsCommand,
@@ -84,6 +86,7 @@ import { TaskTargetWorkspaceEntity } from 'src/modules/task/standard-objects/tas
MigrateWorkflowCodeStepsCommand,
SeedWorkflowV1_16Command,
BackfillApplicationPackageFilesCommand,
UpdateFileTableMigrationCommand,
],
})
export class V1_17_UpgradeVersionCommandModule {}
@@ -17,6 +17,7 @@ import { MigrateAttachmentToMorphRelationsCommand } from 'src/database/commands/
import { MigrateNoteTargetToMorphRelationsCommand } from 'src/database/commands/upgrade-version-command/1-17/1-17-migrate-note-target-to-morph-relations.command';
import { MigrateTaskTargetToMorphRelationsCommand } from 'src/database/commands/upgrade-version-command/1-17/1-17-migrate-task-target-to-morph-relations.command';
import { MigrateWorkflowCodeStepsCommand } from 'src/database/commands/upgrade-version-command/1-17/1-17-migrate-workflow-code-steps.command';
import { UpdateFileTableMigrationCommand } from 'src/database/commands/upgrade-version-command/1-17/1-17-update-file-table-migration.command';
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
@@ -45,6 +46,7 @@ export class UpgradeCommand extends UpgradeCommandRunner {
protected readonly identifyWebhookMetadataCommand: IdentifyWebhookMetadataCommand,
protected readonly makeWebhookUniversalIdentifierAndApplicationIdNotNullableMigrationCommand: MakeWebhookUniversalIdentifierAndApplicationIdNotNullableMigrationCommand,
protected readonly migrateWorkflowCodeStepsCommand: MigrateWorkflowCodeStepsCommand,
protected readonly updateFileTableMigrationCommand: UpdateFileTableMigrationCommand,
) {
super(
workspaceRepository,
@@ -66,6 +68,7 @@ export class UpgradeCommand extends UpgradeCommandRunner {
this.migrateWorkflowCodeStepsCommand,
this.deleteFileRecordsCommand,
this.backfillApplicationPackageFilesCommand,
this.updateFileTableMigrationCommand,
];
this.allCommands = {