DoDiODev opened a new pull request, #9001: URL: https://github.com/apache/devlake/pull/9001
### Summary Make `Dalgorm.DropIndexes` idempotent by skipping indexes that are not present, so dropping an already-absent index no longer aborts a migration. ### Problem `Dalgorm.DropIndexes` calls GORM's `Migrator().DropIndex`, which emits a bare `DROP INDEX` **without** `IF EXISTS`. On PostgreSQL this fails hard with `ERROR: index "..." does not exist (SQLSTATE 42704)` when the target index is missing, causing the migrator to panic and the server to crash on startup. This is reproducible on PostgreSQL with the migration `change _tool_sonarqube_issue_code_blocks.component type to text`, which unconditionally drops `idx__tool_sonarqube_issue_code_blocks_component`. That index is no longer present after the earlier `modify component type to varchar(500)` migration rewrites the column via `ChangeColumnsType` (rename column, then AutoMigrate skips the name-colliding index, then the old column and its index are dropped). The result is a table with `component varchar(500)` and **no** component index, so the later unconditional `DropIndexes` aborts. Observed panic: ``` ERROR: index "idx__tool_sonarqube_issue_code_blocks_component" does not exist (SQLSTATE 42704) DROP INDEX "idx__tool_sonarqube_issue_code_blocks_component" panic: ... (500) server/services.InitExecuteMigration() ``` ### Fix Guard each drop with `migrator.HasIndex(table, indexName)` and skip indexes that do not exist. This makes the operation idempotent and database-neutral while still surfacing genuine drop errors (it does not blanket-swallow errors). ### Testing - `go build ./impls/dalgorm/...` - Manual PostgreSQL migration run: with the fix, the previously-crashing migration chain completes and the server reaches ready state; without it, PostgreSQL aborts on the missing index. A DB-backed unit test was intentionally omitted to avoid introducing an sqlite driver dependency that is not currently in `go.mod`. ### Rollback Revert this single-file change; behaviour returns to the unconditional drop. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
