incubator-devlake icon indicating copy to clipboard operation
incubator-devlake copied to clipboard

[Bug][azuredevops] DB migration issue blocks new deployment

Open jekader opened this issue 10 months ago • 1 comments

Search before asking

  • [x] I had searched in the issues and found no similar issues.

What happened

I tried deploying a fresh instance of DevLake v1.0.1 via Helm and got stuck with a failing migration:

[Execute] pending scripts: 65, executed scripts: 270, total: 335"
[migrator] applying migration script add updated_date field in _tool_azuredevops_gitrepositories:20240223170000"
"\x1b[31;1m/app/impls/dalgorm/dalgorm.go:146 \x1b[35;1mError 1060 (42S21): Duplicate column name 'updated_date'\n\x1b[0m\x1b[33m[16.018ms] \x1b[34;1m[rows:0]\x1b[0m ALTER TABLE _tool_azuredevops_gitrepositories add COLUMN updated_date datetime(3) DEFAULT NULL"
failed to execute migration\n\tcaused by: Error 1060 (42S21): Duplicate column name 'updated_date' (400)\n\tWraps: (2) Error 1060 (42S21): Duplicate column name 'updated_date'\n\tError types: (1) *hintdetail.withDetail (2) *mysql.MySQLError"
HTTP 400 error\n\tcaused by: error executing migration (400)\n\tWraps: (2) Error 1060 (42S21): Duplicate column name 'updated_date' (400)\n\tWraps: (3) Error 1060 (42S21): Duplicate column name 'updated_date'\n\tError types: (1) *hintdetail.withDetail (2) *hintdetail.withDetail (3) *mysql.MySQLError"

What do you expect to happen

All migrations should succeed

How to reproduce

Simple helm deploy with all defaults

Anything else

This seems to be caused by the migration not checking if the column exists in the first place: https://github.com/apache/incubator-devlake/blob/main/backend/python/plugins/azuredevops/azuredevops/migrations.py#L197-L201

A workaround is removing the column manually, then re-triggering migrations ALTER TABLE _tool_azuredevops_gitrepositories drop COLUMN updated_date;

A proper solution is checking if the column exists before attempting to alter the table. This is done for some migrations but a couple are inconsistent and should be fixed.

Version

v1.0.1

Are you willing to submit PR?

  • [x] Yes I am willing to submit a PR!

Code of Conduct

jekader avatar Apr 28 '25 20:04 jekader

Hello @jekader! I'm Dosu, your friendly bot here to help you with bugs, answer questions, and guide you in becoming a contributor. I'm here while you wait for a human maintainer. Let's tackle this issue together!

To resolve the "Duplicate column name 'updated_date'" error during the migration process, you can modify the migration script to check for the existence of the column before attempting to add it. Here's an example of how you might adjust the migration script:

func (script *addUpdatedDateToAzureDevOpsGitRepositories) Up(basicRes context.BasicRes) errors.Error {
    dal := basicRes.GetDal()
    if !dal.HasColumn(&azureDevOpsGitRepositories{}, "updated_date") {
        return dal.AutoMigrate(&azureDevOpsGitRepositories{})
    }
    return nil
}

This code uses the HasColumn method to check if the 'updated_date' column already exists in the _tool_azuredevops_gitrepositories table. If it does not exist, it proceeds with the migration; otherwise, it skips the migration to prevent the duplicate column error [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Apr 28 '25 20:04 dosubot[bot]

This issue has been automatically marked as stale because it has been inactive for 60 days. It will be closed in next 7 days if no further activity occurs.

github-actions[bot] avatar Jun 28 '25 00:06 github-actions[bot]

This issue has been closed because it has been inactive for a long time. You can reopen it if you encounter the similar problem in the future.

github-actions[bot] avatar Jul 06 '25 00:07 github-actions[bot]