fix: check table existence before dropping columns in field delete action

https://sonarly.com/issue/18011?type=bug

Deleting a custom object fails with "Migration action 'delete' for 'fieldMetadata' failed" when the workspace schema table doesn't exist but metadata records for the object and its fields still do.
This commit is contained in:
Sonarly Claude Code
2026-03-24 16:31:01 +00:00
parent 8696e3b7ec
commit babd7b08ed
2 changed files with 26 additions and 0 deletions
@@ -49,6 +49,21 @@ export class WorkspaceSchemaTableManagerService {
await queryRunner.query(sql);
}
async tableExists({
queryRunner,
schemaName,
tableName,
}: {
queryRunner: QueryRunner;
schemaName: string;
tableName: string;
}): Promise<boolean> {
const sql = `SELECT to_regclass('${escapeIdentifier(schemaName)}.${escapeIdentifier(tableName)}') IS NOT NULL AS "exists"`;
const result = await queryRunner.query(sql);
return result?.[0]?.exists === true;
}
async renameTable({
queryRunner,
schemaName,
@@ -79,6 +79,17 @@ export class DeleteFieldActionHandlerService extends WorkspaceMigrationRunnerAct
objectMetadata: flatObjectMetadata,
});
const tableExists =
await this.workspaceSchemaManagerService.tableManager.tableExists({
queryRunner,
schemaName,
tableName,
});
if (!tableExists) {
return;
}
const columnDefinitions = generateColumnDefinitions({
flatFieldMetadata,
flatObjectMetadata,