dosubot[bot] commented on issue #8744:
URL: 
https://github.com/apache/incubator-devlake/issues/8744#issuecomment-3983630055

   <!-- Greeting -->
   Hi @yamoyamoto! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the 
incubator-devlake team.
   
   <!-- Answer -->
   Thanks for the detailed bug report! Your analysis is spot-on. The issue is 
that `ADD COLUMN IF NOT EXISTS` and `CREATE INDEX IF NOT EXISTS` are 
MariaDB-specific extensions not supported in MySQL 8.x.
   
   Your suggested fix aligns well with DevLake's established patterns. Looking 
at other plugins in the codebase:
   
   **For adding columns**, the [TAPD 
plugin](https://github.com/apache/incubator-devlake/blob/2c15ad880dce830c6512fa58039527cbf4745b8b/backend/plugins/tapd/models/migrationscripts/20230411_modify_custom_field_name.go#L74-L89)
 demonstrates the recommended pattern:
   
   ```go
   if !db.HasColumn("_tool_q_dev_user_data", "scope_id") {
       if err := db.AddColumn("_tool_q_dev_user_data", "scope_id", 
dal.Varchar); err != nil {
           return errors.Default.Wrap(err, "failed to add scope_id")
       }
   }
   ```
   
   **Alternatively**, you can use `migrationhelper.AutoMigrateTables()` which 
handles database differences automatically—this is the [primary pattern used 
across DevLake 
plugins](https://github.com/apache/incubator-devlake/blob/2c15ad880dce830c6512fa58039527cbf4745b8b/backend/helpers/migrationhelper/migrationhelper.go#L36-L46).
   
   **For indexes**, your approach of dropping `IF NOT EXISTS` and letting 
duplicate errors be handled at runtime is correct—it's a safe runtime error 
rather than a syntax error.
   
   [PR #8565](https://github.com/apache/incubator-devlake/pull/8565) which 
fixed the PostgreSQL compatibility issue in q_dev is a good reference for the 
dialect-aware pattern when more complex operations are needed.
   
   
   <!-- Dosu Comment Footer -->
   *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
   
   ---
   <sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/1a4b4786-12ec-4bf6-b47a-59ecbc736cf9?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/1a4b4786-12ec-4bf6-b47a-59ecbc736cf9?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/1a4b4786-12ec-4bf6-b47a-59ecbc736cf9?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/1a4b4786-12ec-4bf6-b47a-59ecbc736cf9?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/1a4b4786-12ec-4bf6-b47a-59ecbc736cf9?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/1a4b4786-12ec-4bf6-b47a-59ecbc736cf9?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/1a4b4786-12ec-4bf6-b47a-59ecbc736cf9?feedback_type=other)</sup>
   
   [![Chat with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/b4e8e847-d479-4541-83a8-d88d83fea5c9/ask?utm_source=github)&nbsp;[![Open
 in 
Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Thanks%20for%20the%20detailed%20bug%20report%21%20Your%20analysis%20is%20spot-on.%20The%20issue%20is%20that%20%60ADD%20COLUMN%20IF%20NOT%20EXISTS%60%20and%20%60CREATE%20INDEX%20IF%20NOT%20EXISTS%60%20are%20MariaDB-specific%20extensions%20not%20supported%20in%20MySQL%208.x.%0A%0AYour%20suggested%20fix%20aligns%20well%20with%20DevLake%27s%20established%20patterns.%20Looking%20at%20other%20plugins%20in%20the%20codebase%3A%0A%0A%2A%2AFor%20adding%20columns%2A%2A%2C%20the%20%5BTAPD%20plugin%5D%28https%3A//github.com/apache/incubator-devlake/blob/2c15ad880dce830c6512fa58039527cbf4745b8b/backend/plugins/tapd/models/migrationscripts/20230411_modify_custom_field_name.go%23L74-L89%29%20demonstrates%20the%20recommended%20pattern%3A%0A%0A%60%60%60go%0Aif%20%21
 
db.HasColumn%28%22_tool_q_dev_user_data%22%2C%20%22scope_id%22%29%20%7B%0A%20%20%20%20if%20err%20%3A%3D%20db.AddColumn%28%22_tool_q_dev_user_data%22%2C%20%22scope_id%22%2C%20dal.Varchar%29%3B%20err%20%21%3D%20nil%20%7B%0A%20%20%20%20%20%20%20%20return%20errors.Default.Wrap%28err%2C%20%22failed%20to%20add%20scope_id%22%29%0A%20%20%20%20%7D%0A%7D%0A%60%60%60%0A%0A%2A%2AAlternatively%2A%2A%2C%20you%20can%20use%20%60migrationhelper.AutoMigrateTables%28%29%60%20which%20handles%20database%20differences%20automatically%E2%80%94this%20is%20the%20%5Bprimary%20pattern%20used%20across%20DevLake%20plugins%5D%28https%3A//github.com/apache/incubator-devlake/blob/2c15ad880dce830c6512fa58039527cbf4745b8b/backend/helpers/migrationhelper/migrationhelper.go%23L36-L46%29.%0A%0A%2A%2AFor%20indexes%2A%2A%2C%20your%20approach%20of%20dropping%20%60IF%20NOT%20EXISTS%60%20and%20letting%20duplicate%20errors%20be%20handled%20at%20runtime%20is%20correct%E2%80%94it%27s%20a%20safe%20runtime%20error%20rather%20tha
 
n%20a%20syntax%20error.%0A%0A%5BPR%20%238565%5D%28https%3A//github.com/apache/incubator-devlake/pull/8565%29%20which%20fixed%20the%20PostgreSQL%20compatibility%20issue%20in%20q_dev%20is%20a%20good%20reference%20for%20the%20dialect-aware%20pattern%20when%20more%20complex%20operations%20are%20needed.)&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/incubator-devlake/issues/8744)


-- 
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]

Reply via email to