You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by kl...@apache.org on 2022/09/07 14:33:46 UTC
[incubator-devlake] branch main updated: feat: change duration from text to float8 (#2993)
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 6ed93082 feat: change duration from text to float8 (#2993)
6ed93082 is described below
commit 6ed930829090999a41843f00d62c9c1cd2ab644e
Author: likyh <l...@likyh.com>
AuthorDate: Wed Sep 7 22:33:42 2022 +0800
feat: change duration from text to float8 (#2993)
Co-authored-by: linyh <ya...@meri.co>
---
plugins/gitlab/models/job.go | 2 +-
.../20220906_fix_duration_to_float8.go | 79 ++++++++++++++++++++++
plugins/gitlab/models/migrationscripts/register.go | 1 +
3 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/plugins/gitlab/models/job.go b/plugins/gitlab/models/job.go
index 7d733433..51c14e37 100644
--- a/plugins/gitlab/models/job.go
+++ b/plugins/gitlab/models/job.go
@@ -35,7 +35,7 @@ type GitlabJob struct {
Ref string `gorm:"type:varchar(255)"`
Tag bool `gorm:"type:boolean"`
AllowFailure bool `json:"allow_failure"`
- Duration float64 `gorm:"type:text"`
+ Duration float64 `gorm:"type:float8"`
WebUrl string `gorm:"type:varchar(255)"`
GitlabCreatedAt *time.Time
diff --git a/plugins/gitlab/models/migrationscripts/20220906_fix_duration_to_float8.go b/plugins/gitlab/models/migrationscripts/20220906_fix_duration_to_float8.go
new file mode 100644
index 00000000..dab8c632
--- /dev/null
+++ b/plugins/gitlab/models/migrationscripts/20220906_fix_duration_to_float8.go
@@ -0,0 +1,79 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+ "context"
+ "gorm.io/gorm"
+)
+
+type fixDurationToFloat8 struct{}
+
+type GitlabJob20220906 struct {
+ ConnectionId uint64 `gorm:"primaryKey"`
+ GitlabId int `gorm:"primaryKey"`
+
+ Duration float64 `gorm:"type:text"`
+ Duration2 float64 `gorm:"type:float8"`
+}
+
+func (GitlabJob20220906) TableName() string {
+ return "_tool_gitlab_jobs"
+}
+
+func (*fixDurationToFloat8) Up(ctx context.Context, db *gorm.DB) error {
+ err := db.Migrator().AddColumn(&GitlabJob20220906{}, `duration2`)
+ if err != nil {
+ return err
+ }
+
+ cursor, err := db.Model(&GitlabJob20220906{}).Select([]string{"connection_id", "gitlab_id", "duration"}).Rows()
+ for cursor.Next() {
+ job := GitlabJob20220906{}
+ err = db.ScanRows(cursor, &job)
+ if err != nil {
+ return err
+ }
+ err = db.
+ Model(job).
+ Where(`connection_id=? AND gitlab_id=?`, job.ConnectionId, job.GitlabId).
+ Update(`duration2`, job.Duration).
+ Error
+ if err != nil {
+ return err
+ }
+ }
+
+ err = db.Migrator().DropColumn(&GitlabJob20220906{}, `duration`)
+ if err != nil {
+ return err
+ }
+ err = db.Migrator().RenameColumn(&GitlabJob20220906{}, `duration2`, `duration`)
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+func (*fixDurationToFloat8) Version() uint64 {
+ return 20220906000005
+}
+
+func (*fixDurationToFloat8) Name() string {
+ return "UpdateSchemas for fixDurationToFloat8"
+}
diff --git a/plugins/gitlab/models/migrationscripts/register.go b/plugins/gitlab/models/migrationscripts/register.go
index f349677e..aba5abaf 100644
--- a/plugins/gitlab/models/migrationscripts/register.go
+++ b/plugins/gitlab/models/migrationscripts/register.go
@@ -28,5 +28,6 @@ func All() []migration.Script {
new(modifyGitlabCI),
new(addPipelineID),
new(addPipelineProjects),
+ new(fixDurationToFloat8),
}
}