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:
+15
@@ -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,
|
||||
|
||||
+11
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user