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

ka94 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 40cbc3e71 fix: azuredevops reported jobs.start_time missing (#5789)
40cbc3e71 is described below

commit 40cbc3e71805c3023a54d1bf54836e02afe70057
Author: Klesh Wong <[email protected]>
AuthorDate: Fri Aug 4 01:06:29 2023 +0800

    fix: azuredevops reported jobs.start_time missing (#5789)
---
 backend/impls/dalgorm/dalgorm.go                         |  2 +-
 .../python/plugins/azuredevops/azuredevops/migrations.py | 11 +++++++++--
 backend/python/pydevlake/pydevlake/migration.py          |  5 +++--
 backend/server/services/remote/models/migration.go       | 16 +++++++++++-----
 4 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/backend/impls/dalgorm/dalgorm.go b/backend/impls/dalgorm/dalgorm.go
index 2ef94fcc8..21c0f5bdc 100644
--- a/backend/impls/dalgorm/dalgorm.go
+++ b/backend/impls/dalgorm/dalgorm.go
@@ -462,5 +462,5 @@ func (d *Dalgorm) convertGormError(err error) errors.Error {
                return errors.BadInput.WrapRaw(err)
        }
 
-       panic(err)
+       return errors.Internal.WrapRaw(err)
 }
diff --git a/backend/python/plugins/azuredevops/azuredevops/migrations.py 
b/backend/python/plugins/azuredevops/azuredevops/migrations.py
index bac187be1..c017dcb58 100644
--- a/backend/python/plugins/azuredevops/azuredevops/migrations.py
+++ b/backend/python/plugins/azuredevops/azuredevops/migrations.py
@@ -120,8 +120,8 @@ def init_schemas(b: MigrationScriptBuilder):
         id: str = Field(primary_key=True)
         build_id: str
         name: str
-        start_time: Optional[datetime.datetime]
-        finish_time: Optional[datetime.datetime]
+        startTime: Optional[datetime.datetime]
+        finishTime: Optional[datetime.datetime]
         state: JobState
         result: Optional[JobResult]
 
@@ -163,3 +163,10 @@ def add_entities_column_to_scope_config(b: 
MigrationScriptBuilder):
 @migration(20230630000001, name="populated _raw_data_table column for 
azuredevops git repos")
 def add_raw_data_params_table_to_scope(b: MigrationScriptBuilder):
     b.execute(f'''UPDATE _tool_azuredevops_gitrepositories SET _raw_data_table 
= '_raw_azuredevops_scopes' WHERE 1=1''')
+
+@migration(20230802000001, name="rename startTime/finishTime to 
start_time/finish_time")
+def rename_starttime_and_finishtime_for_job(b: MigrationScriptBuilder):
+    b.execute(f'ALTER TABLE _tool_azuredevops_jobs RENAME COLUMN startTime TO 
start_time', Dialect.MYSQL, ignore_error=True)
+    b.execute(f'ALTER TABLE _tool_azuredevops_jobs RENAME COLUMN finishTime TO 
finish_time', Dialect.MYSQL, ignore_error=True)
+    b.execute(f'ALTER TABLE _tool_azuredevops_jobs RENAME COLUMN `startTime` 
TO start_time', Dialect.POSTGRESQL, ignore_error=True)
+    b.execute(f'ALTER TABLE _tool_azuredevops_jobs RENAME COLUMN `finishTime` 
TO finish_time', Dialect.POSTGRESQL, ignore_error=True)
\ No newline at end of file
diff --git a/backend/python/pydevlake/pydevlake/migration.py 
b/backend/python/pydevlake/pydevlake/migration.py
index f6244c4d3..e4cd1f37d 100644
--- a/backend/python/pydevlake/pydevlake/migration.py
+++ b/backend/python/pydevlake/pydevlake/migration.py
@@ -34,6 +34,7 @@ class Execute(BaseModel):
     type: Literal["execute"] = "execute"
     sql: str
     dialect: Optional[Dialect] = None
+    ignore_error: bool = False
 
 
 class AddColumn(BaseModel):
@@ -88,12 +89,12 @@ class MigrationScriptBuilder:
     def __init__(self):
         self.operations = []
 
-    def execute(self, sql: str, dialect: Optional[Dialect] = None):
+    def execute(self, sql: str, dialect: Optional[Dialect] = None, 
ignore_error = False):
         """
         Executes a raw SQL statement.
         If dialect is specified the statement will be executed only if the db 
dialect matches.
         """
-        self.operations.append(Execute(sql=sql, dialect=dialect))
+        self.operations.append(Execute(sql=sql, dialect=dialect, 
ignore_error=ignore_error))
 
     def add_column(self, table: str, column: str, type: str):
         """
diff --git a/backend/server/services/remote/models/migration.go 
b/backend/server/services/remote/models/migration.go
index e84b6e4bd..ce7b4f1e6 100644
--- a/backend/server/services/remote/models/migration.go
+++ b/backend/server/services/remote/models/migration.go
@@ -19,6 +19,7 @@ package models
 
 import (
        "encoding/json"
+
        "github.com/apache/incubator-devlake/core/context"
        "github.com/apache/incubator-devlake/core/dal"
        "github.com/apache/incubator-devlake/core/errors"
@@ -33,20 +34,25 @@ type Operation interface {
 }
 
 type ExecuteOperation struct {
-       Sql     string  `json:"sql"`
-       Dialect *string `json:"dialect"`
+       Sql         string  `json:"sql"`
+       Dialect     *string `json:"dialect"`
+       IgnoreError bool    `json:"ignore_error"`
 }
 
 func (o ExecuteOperation) Execute(basicRes context.BasicRes) errors.Error {
+       var err errors.Error
        db := basicRes.GetDal()
        if o.Dialect != nil {
                if db.Dialect() == *o.Dialect {
-                       return db.Exec(o.Sql)
+                       err = db.Exec(o.Sql)
                }
-               return nil
        } else {
-               return db.Exec(o.Sql)
+               err = db.Exec(o.Sql)
+       }
+       if o.IgnoreError {
+               return nil
        }
+       return err
 }
 
 var _ Operation = (*ExecuteOperation)(nil)

Reply via email to