diff --git a/backend/impls/dalgorm/dalgorm.go b/backend/impls/dalgorm/dalgorm.go index ba635355f41..0445995fd50 100644 --- a/backend/impls/dalgorm/dalgorm.go +++ b/backend/impls/dalgorm/dalgorm.go @@ -453,6 +453,9 @@ func (d *Dalgorm) RenameTable(oldName, newName string) errors.Error { // DropIndexes drops indexes for specified table func (d *Dalgorm) DropIndexes(table string, indexNames ...string) errors.Error { for _, indexName := range indexNames { + if !d.db.Migrator().HasIndex(table, indexName) { + continue + } err := d.db.Migrator().DropIndex(table, indexName) if err != nil { return d.convertGormError(err) diff --git a/backend/plugins/sonarqube/e2e/issue_code_block_long_component_test.go b/backend/plugins/sonarqube/e2e/issue_code_block_long_component_test.go index 8076fa3a859..e1a7d52b5a5 100644 --- a/backend/plugins/sonarqube/e2e/issue_code_block_long_component_test.go +++ b/backend/plugins/sonarqube/e2e/issue_code_block_long_component_test.go @@ -80,6 +80,12 @@ func TestSonarqubeIssueCodeBlockLongComponent(t *testing.T) { &sonarqubeIssueCodeBlockBeforeText{}, &cqIssueCodeBlockBeforeText{}, )) + require.NoError(t, dataflowTester.Db.Migrator().DropIndex( + "cq_issue_code_blocks", "idx_cq_issue_code_blocks_component", + )) + require.NoError(t, dataflowTester.Db.Migrator().DropIndex( + "_tool_sonarqube_issue_code_blocks", "idx__tool_sonarqube_issue_code_blocks_component", + )) existingComponent := "existing:component" require.NoError(t, dataflowTester.Db.Create(&sonarqubeIssueCodeBlockBeforeText{