Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type CicdDeploymentCommit struct {
domainlayer.DomainEntity
CicdScopeId string `gorm:"index;type:varchar(255)"`
CicdDeploymentId string `gorm:"type:varchar(255)"` // if it is converted from a cicd_pipeline_commit
Name string `gorm:"type:varchar(255)"`
Name string `gorm:"type:text"`
DisplayTitle string
Url string
Result string `gorm:"type:varchar(100)"`
Expand All @@ -39,11 +39,11 @@ type CicdDeploymentCommit struct {
QueuedDurationSec *float64
CommitSha string `gorm:"primaryKey;type:varchar(255)"`
CommitMsg string
RefName string `gorm:"type:varchar(255)"` // to delete?
RefName string `gorm:"type:text"` // to delete?
RepoId string `gorm:"type:varchar(255)"`
RepoUrl string `gorm:"index;not null"`
PrevSuccessDeploymentCommitId string `gorm:"type:varchar(255)"`
SubtaskName string `gorm:"type:varchar(255)"`
SubtaskName string `gorm:"type:text"`
}

func (cicdDeploymentCommit CicdDeploymentCommit) TableName() string {
Expand Down
2 changes: 1 addition & 1 deletion backend/core/models/domainlayer/devops/cicd_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

type CICDPipeline struct {
domainlayer.DomainEntity
Name string `gorm:"type:varchar(255)"`
Name string `gorm:"type:text"`
DisplayTitle string
Url string
Result string `gorm:"type:varchar(100)"`
Expand Down
4 changes: 2 additions & 2 deletions backend/core/models/domainlayer/devops/cicd_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type CicdRelease struct {

CicdScopeId string `gorm:"index;type:varchar(255)"`

Name string `gorm:"type:varchar(255)"`
DisplayTitle string `gorm:"type:varchar(255)"`
Name string `gorm:"type:text"`
DisplayTitle string `gorm:"type:text"`
Description string `json:"description"`
URL string `json:"url"`

Expand Down
2 changes: 1 addition & 1 deletion backend/core/models/domainlayer/devops/cicd_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ plugin.Scope = (*CicdScope)(nil)

type CicdScope struct {
domainlayer.DomainEntity
Name string `gorm:"type:varchar(255)"`
Name string `gorm:"type:text"`
Description string
Url string `gorm:"type:varchar(255)"`
CreatedDate *time.Time
Expand Down
2 changes: 1 addition & 1 deletion backend/core/models/domainlayer/devops/cicd_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ENV_NAME_PATTERN = "ENV_NAME_PATTERN"

type CICDTask struct {
domainlayer.DomainEntity
Name string `gorm:"type:varchar(255)"`
Name string `gorm:"type:text"`
PipelineId string `gorm:"index;type:varchar(255)"`
Result string `gorm:"type:varchar(100)"`
Status string `gorm:"type:varchar(100)"`
Expand Down
51 changes: 51 additions & 0 deletions backend/core/models/domainlayer/devops/text_columns_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
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 devops

import (
"reflect"
"strings"
"testing"
)

func TestUnboundedStringFieldsUseText(t *testing.T) {
tests := []struct {
model any
field string
}{
{CICDTask{}, "Name"},
{CicdScope{}, "Name"},
{CicdRelease{}, "Name"},
{CicdRelease{}, "DisplayTitle"},
{CicdDeploymentCommit{}, "Name"},
{CicdDeploymentCommit{}, "SubtaskName"},
{CicdDeploymentCommit{}, "RefName"},
{CICDPipeline{}, "Name"},
}

for _, test := range tests {
modelType := reflect.TypeOf(test.model)
field, found := modelType.FieldByName(test.field)
if !found {
t.Fatalf("%s.%s not found", modelType.Name(), test.field)
}
if !strings.Contains(field.Tag.Get("gorm"), "type:text") {
t.Errorf("%s.%s gorm tag = %q, want type:text", modelType.Name(), test.field, field.Tag.Get("gorm"))
}
}
}
2 changes: 1 addition & 1 deletion backend/core/models/domainlayer/ticket/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Incident struct {
Priority string `gorm:"type:varchar(255)"`
Severity string `gorm:"type:varchar(255)"`
Urgency string `gorm:"type:varchar(255)"`
Component string `gorm:"type:varchar(255)"`
Component string `gorm:"type:text"`
OriginalProject string `gorm:"type:varchar(255)"`
Table string `gorm:"index:idx_table_scope_id;type:varchar(255)"`
ScopeId string `gorm:"index:idx_table_scope_id;type:varchar(255)"`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
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 ticket

import (
"reflect"
"strings"
"testing"
)

func TestIncidentComponentUsesText(t *testing.T) {
field, found := reflect.TypeOf(Incident{}).FieldByName("Component")
if !found {
t.Fatal("Incident.Component not found")
}
if !strings.Contains(field.Tag.Get("gorm"), "type:text") {
t.Fatalf("Incident.Component gorm tag = %q, want type:text", field.Tag.Get("gorm"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
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 (
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/helpers/migrationhelper"
)

type addBlueprintIdIndexToPipelines struct{}

type pipeline20260818 struct {
BlueprintId uint64 `gorm:"index"`
}

func (pipeline20260818) TableName() string {
return "_devlake_pipelines"
}

func (u *addBlueprintIdIndexToPipelines) Up(basicRes context.BasicRes) errors.Error {
return migrationhelper.AutoMigrateTables(basicRes, &pipeline20260818{})
}

func (*addBlueprintIdIndexToPipelines) Version() uint64 {
return 20260818000001
}

func (*addBlueprintIdIndexToPipelines) Name() string {
return "add blueprint_id index for _devlake_pipelines"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
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 (
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
)

var _ plugin.MigrationScript = (*expandDomainTextColumns)(nil)

type expandDomainTextColumns struct{}

func (*expandDomainTextColumns) Up(basicRes context.BasicRes) errors.Error {
db := basicRes.GetDal()
columns := []struct {
tableName string
columnName string
}{
{"cicd_tasks", "name"},
{"cicd_scopes", "name"},
{"cicd_releases", "name"},
{"cicd_releases", "display_title"},
{"cicd_deployment_commits", "name"},
{"cicd_deployment_commits", "subtask_name"},
{"cicd_deployment_commits", "ref_name"},
{"incidents", "component"},
}
for _, column := range columns {
if err := db.ModifyColumnType(column.tableName, column.columnName, "text"); err != nil {
return err
}
}
return nil
}

func (*expandDomainTextColumns) Version() uint64 {
return 20260819000001
}

func (*expandDomainTextColumns) Name() string {
return "expand domain text columns"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
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 (
"reflect"
"testing"

"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
)

type domainTextColumnCall struct {
tableName string
columnName string
columnType string
}

type domainTextColumnRecordingDal struct {
dal.Dal
calls []domainTextColumnCall
}

func (d *domainTextColumnRecordingDal) ModifyColumnType(tableName, columnName, columnType string) errors.Error {
d.calls = append(d.calls, domainTextColumnCall{tableName, columnName, columnType})
return nil
}

type domainTextColumnBasicRes struct {
context.BasicRes
database dal.Dal
}

func (r *domainTextColumnBasicRes) GetDal() dal.Dal {
return r.database
}

func TestExpandDomainTextColumns(t *testing.T) {
database := new(domainTextColumnRecordingDal)
script := new(expandDomainTextColumns)

if err := script.Up(&domainTextColumnBasicRes{database: database}); err != nil {
t.Fatalf("migration failed: %v", err)
}

want := []domainTextColumnCall{
{"cicd_tasks", "name", "text"},
{"cicd_scopes", "name", "text"},
{"cicd_releases", "name", "text"},
{"cicd_releases", "display_title", "text"},
{"cicd_deployment_commits", "name", "text"},
{"cicd_deployment_commits", "subtask_name", "text"},
{"cicd_deployment_commits", "ref_name", "text"},
{"incidents", "component", "text"},
}
if !reflect.DeepEqual(database.calls, want) {
t.Fatalf("ModifyColumnType calls = %#v, want %#v", database.calls, want)
}
if script.Version() != 20260819000001 {
t.Fatalf("Version() = %d, want 20260819000001", script.Version())
}
if script.Name() != "expand domain text columns" {
t.Fatalf("Name() = %q, want %q", script.Name(), "expand domain text columns")
}

for _, registeredScript := range All() {
if registeredScript.Version() == script.Version() {
return
}
}
t.Fatalf("migration version %d is not registered", script.Version())
}
2 changes: 2 additions & 0 deletions backend/core/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,7 @@ func All() []plugin.MigrationScript {
new(addCqProjectMetricsHistory),
new(addIsBotToAccounts),
new(addSprintVelocityFields),
new(addBlueprintIdIndexToPipelines),
new(expandDomainTextColumns),
}
}
2 changes: 1 addition & 1 deletion backend/core/models/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (plan PipelinePlan) IsEmpty() bool {
type Pipeline struct {
common.Model
Name string `json:"name" gorm:"index"`
BlueprintId uint64 `json:"blueprintId"`
BlueprintId uint64 `json:"blueprintId" gorm:"index"`
Plan PipelinePlan `json:"plan" gorm:"serializer:encdec"`
TotalTasks int `json:"totalTasks"`
FinishedTasks int `json:"finishedTasks"`
Expand Down
4 changes: 2 additions & 2 deletions backend/plugins/github/models/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type GithubAccount struct {
ConnectionId uint64 `gorm:"primaryKey"`
Id int `json:"id" gorm:"primaryKey;autoIncrement:false"`
Login string `json:"login" gorm:"type:varchar(255)"`
Name string `json:"name" gorm:"type:varchar(255)"`
Company string `json:"company" gorm:"type:varchar(255)"`
Name string `json:"name" gorm:"type:text"`
Company string `json:"company" gorm:"type:text"`
Email string `json:"Email" gorm:"type:varchar(255)"`
AvatarUrl string `json:"avatar_url" gorm:"type:varchar(255)"`
Url string `json:"url" gorm:"type:varchar(255)"`
Expand Down
6 changes: 3 additions & 3 deletions backend/plugins/github/models/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ type GithubDeployment struct {
Url string
DatabaseId uint `json:"database_id"`
CommitOid string `json:"commit_oid" gorm:"type:varchar(255)"`
Description string `json:"description" gorm:"type:varchar(255)"`
Environment string `json:"environment" gorm:"type:varchar(255)"`
Description string `json:"description" gorm:"type:text"`
Environment string `json:"environment" gorm:"type:text"`
State string `json:"state" gorm:"type:varchar(255)"`
LatestStatusState string `json:"latest_status_state" gorm:"type:varchar(255)"`
LatestUpdatedDate *time.Time `json:"latest_status_update_date"`
RepositoryID string `json:"repository_id" gorm:"type:varchar(255)"`
RepositoryName string `json:"repository_name" gorm:"type:varchar(255)"`
RepositoryUrl string `json:"repository_url" gorm:"type:varchar(255)"`
RefName string `json:"ref_name" gorm:"type:varchar(255)"`
RefName string `json:"ref_name" gorm:"type:text"`
Payload string `json:"payload" gorm:"type:text"`
FinishedDate *time.Time `json:"finished_at"`
CreatedDate time.Time `json:"created_at"`
Expand Down
Loading