This is an automated email from the ASF dual-hosted git repository.

klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 04795c2a8 fix(q_dev): replace MariaDB-specific IF NOT EXISTS syntax 
with DAL methods for MySQL 8.x compatibility (#8745)
04795c2a8 is described below

commit 04795c2a845641a292d26bc13916e1a91ad89ca3
Author: Tomoya Kawaguchi <[email protected]>
AuthorDate: Thu Mar 5 23:21:03 2026 +0900

    fix(q_dev): replace MariaDB-specific IF NOT EXISTS syntax with DAL methods 
for MySQL 8.x compatibility (#8745)
---
 .../20251209_add_scope_id_fields.go                | 26 +++++++++-------------
 .../20260220_add_account_id_to_s3_slice.go         | 12 +++++-----
 2 files changed, 16 insertions(+), 22 deletions(-)

diff --git 
a/backend/plugins/q_dev/models/migrationscripts/20251209_add_scope_id_fields.go 
b/backend/plugins/q_dev/models/migrationscripts/20251209_add_scope_id_fields.go
index d7819ff61..a4448b012 100644
--- 
a/backend/plugins/q_dev/models/migrationscripts/20251209_add_scope_id_fields.go
+++ 
b/backend/plugins/q_dev/models/migrationscripts/20251209_add_scope_id_fields.go
@@ -19,6 +19,7 @@ package migrationscripts
 
 import (
        "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/dal"
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/plugin"
 )
@@ -32,29 +33,24 @@ func (*addScopeIdFields) Up(basicRes context.BasicRes) 
errors.Error {
 
        // Add scope_id column to _tool_q_dev_user_data table
        // This field links user data to QDevS3Slice scope, which can then be 
mapped to projects via project_mapping
-       err := db.Exec(`
-               ALTER TABLE _tool_q_dev_user_data
-               ADD COLUMN IF NOT EXISTS scope_id VARCHAR(255) DEFAULT NULL
-       `)
-       if err != nil {
-               // Try alternative syntax for databases that don't support IF 
NOT EXISTS
-               _ = db.Exec(`ALTER TABLE _tool_q_dev_user_data ADD COLUMN 
scope_id VARCHAR(255) DEFAULT NULL`)
+       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 
to _tool_q_dev_user_data")
+               }
        }
 
        // Add index on scope_id for better query performance
-       _ = db.Exec(`CREATE INDEX IF NOT EXISTS idx_q_dev_user_data_scope_id ON 
_tool_q_dev_user_data(scope_id)`)
+       _ = db.Exec(`CREATE INDEX idx_q_dev_user_data_scope_id ON 
_tool_q_dev_user_data(scope_id)`)
 
        // Add scope_id column to _tool_q_dev_s3_file_meta table
-       err = db.Exec(`
-               ALTER TABLE _tool_q_dev_s3_file_meta
-               ADD COLUMN IF NOT EXISTS scope_id VARCHAR(255) DEFAULT NULL
-       `)
-       if err != nil {
-               _ = db.Exec(`ALTER TABLE _tool_q_dev_s3_file_meta ADD COLUMN 
scope_id VARCHAR(255) DEFAULT NULL`)
+       if !db.HasColumn("_tool_q_dev_s3_file_meta", "scope_id") {
+               if err := db.AddColumn("_tool_q_dev_s3_file_meta", "scope_id", 
dal.Varchar); err != nil {
+                       return errors.Default.Wrap(err, "failed to add scope_id 
to _tool_q_dev_s3_file_meta")
+               }
        }
 
        // Add index on scope_id
-       _ = db.Exec(`CREATE INDEX IF NOT EXISTS idx_q_dev_s3_file_meta_scope_id 
ON _tool_q_dev_s3_file_meta(scope_id)`)
+       _ = db.Exec(`CREATE INDEX idx_q_dev_s3_file_meta_scope_id ON 
_tool_q_dev_s3_file_meta(scope_id)`)
 
        return nil
 }
diff --git 
a/backend/plugins/q_dev/models/migrationscripts/20260220_add_account_id_to_s3_slice.go
 
b/backend/plugins/q_dev/models/migrationscripts/20260220_add_account_id_to_s3_slice.go
index 71a13c7b2..f0b0b897f 100644
--- 
a/backend/plugins/q_dev/models/migrationscripts/20260220_add_account_id_to_s3_slice.go
+++ 
b/backend/plugins/q_dev/models/migrationscripts/20260220_add_account_id_to_s3_slice.go
@@ -19,6 +19,7 @@ package migrationscripts
 
 import (
        "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/dal"
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/plugin"
 )
@@ -30,13 +31,10 @@ type addAccountIdToS3Slice struct{}
 func (*addAccountIdToS3Slice) Up(basicRes context.BasicRes) errors.Error {
        db := basicRes.GetDal()
 
-       err := db.Exec(`
-               ALTER TABLE _tool_q_dev_s3_slices
-               ADD COLUMN IF NOT EXISTS account_id VARCHAR(255) DEFAULT NULL
-       `)
-       if err != nil {
-               // Try alternative syntax for databases that don't support IF 
NOT EXISTS
-               _ = db.Exec(`ALTER TABLE _tool_q_dev_s3_slices ADD COLUMN 
account_id VARCHAR(255) DEFAULT NULL`)
+       if !db.HasColumn("_tool_q_dev_s3_slices", "account_id") {
+               if err := db.AddColumn("_tool_q_dev_s3_slices", "account_id", 
dal.Varchar); err != nil {
+                       return errors.Default.Wrap(err, "failed to add 
account_id to _tool_q_dev_s3_slices")
+               }
        }
 
        return nil

Reply via email to