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

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

commit a7b45969458bdb643cb712d7c4e195a0f4165fa5
Author: xgdyp <[email protected]>
AuthorDate: Wed Jul 20 12:20:07 2022 +0800

    fix: change migrationscript
---
 models/domainlayer/code/commit.go               | 12 ++++++------
 models/migrationscripts/commitfile_component.go | 18 +++++++++---------
 models/migrationscripts/register.go             |  3 +--
 plugins/gitextractor/models/interface.go        |  2 +-
 plugins/gitextractor/parser/repo.go             | 14 +++++++-------
 plugins/gitextractor/store/csv.go               |  4 ++--
 plugins/gitextractor/store/database.go          |  6 +++---
 7 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/models/domainlayer/code/commit.go 
b/models/domainlayer/code/commit.go
index 1fc76bc0..fd5707a1 100644
--- a/models/domainlayer/code/commit.go
+++ b/models/domainlayer/code/commit.go
@@ -18,6 +18,7 @@ limitations under the License.
 package code
 
 import (
+       "github.com/apache/incubator-devlake/models/domainlayer"
        "time"
 
        "github.com/apache/incubator-devlake/models/common"
@@ -45,8 +46,7 @@ func (Commit) TableName() string {
 }
 
 type CommitFile struct {
-       common.NoPKModel
-       ID        string `gorm:"primaryKey;type:varchar(255)"`
+       domainlayer.DomainEntity
        CommitSha string `gorm:"type:varchar(40)"`
        FilePath  string `gorm:"type:varchar(255)"`
        Additions int
@@ -58,8 +58,8 @@ func (CommitFile) TableName() string {
 }
 
 type Component struct {
-       RepoId    string `gorm:"primaryKey;type:varchar(255)"`
-       Name      string `gorm:"type:varchar(255)"`
+       RepoId    string `gorm:"type:varchar(255)"`
+       Name      string `gorm:"primaryKey;type:varchar(255)"`
        PathRegex string `gorm:"type:varchar(255)"`
 }
 
@@ -69,8 +69,8 @@ func (Component) TableName() string {
 
 type CommitFileComponent struct {
        common.NoPKModel
-       CommitFileID string `gorm:"primaryKey;type:varchar(255)"`
-       Component    string `gorm:"type:varchar(255)"`
+       CommitFileId  string `gorm:"primaryKey;type:varchar(255)"`
+       ComponentName string `gorm:"type:varchar(255)"`
 }
 
 func (CommitFileComponent) TableName() string {
diff --git a/models/migrationscripts/commitfile_component.go 
b/models/migrationscripts/commitfile_component.go
index 15ad50f7..9f1ee69c 100644
--- a/models/migrationscripts/commitfile_component.go
+++ b/models/migrationscripts/commitfile_component.go
@@ -20,6 +20,7 @@ package migrationscripts
 import (
        "context"
        "github.com/apache/incubator-devlake/models/common"
+       "github.com/apache/incubator-devlake/models/domainlayer"
        "gorm.io/gorm"
 )
 
@@ -34,8 +35,7 @@ func (Component) TableName() string {
 }
 
 type CommitFile struct {
-       common.NoPKModel
-       ID        string `gorm:"primaryKey;type:varchar(255)"`
+       domainlayer.DomainEntity
        CommitSha string `gorm:"type:varchar(40)"`
        FilePath  string `gorm:"type:varchar(255)"`
        Additions int
@@ -48,17 +48,17 @@ func (CommitFile) TableName() string {
 
 type CommitFileComponent struct {
        common.NoPKModel
-       CommitFileID string `gorm:"primaryKey;type:varchar(255)"`
-       Component    string `gorm:"type:varchar(255)"`
+       CommitFileId  string `gorm:"primaryKey;type:varchar(255)"`
+       ComponentName string `gorm:"type:varchar(255)"`
 }
 
 func (CommitFileComponent) TableName() string {
        return "commit_file_components"
 }
 
-type updateSchemas20220711 struct{}
+type commitfileComponent struct{}
 
-func (*updateSchemas20220711) Up(ctx context.Context, db *gorm.DB) error {
+func (*commitfileComponent) Up(ctx context.Context, db *gorm.DB) error {
 
        err := db.Migrator().AutoMigrate(Component{}, CommitFile{}, 
CommitFileComponent{})
        if err != nil {
@@ -68,10 +68,10 @@ func (*updateSchemas20220711) Up(ctx context.Context, db 
*gorm.DB) error {
 
 }
 
-func (*updateSchemas20220711) Version() uint64 {
-       return 202207151644
+func (*commitfileComponent) Version() uint64 {
+       return 202207201009
 }
 
-func (*updateSchemas20220711) Name() string {
+func (*commitfileComponent) Name() string {
        return "add commit_file_components components table,update commit_files 
table"
 }
diff --git a/models/migrationscripts/register.go 
b/models/migrationscripts/register.go
index 2f5351b3..2142ec9a 100644
--- a/models/migrationscripts/register.go
+++ b/models/migrationscripts/register.go
@@ -22,7 +22,6 @@ import "github.com/apache/incubator-devlake/migration"
 // All return all the migration scripts of framework
 func All() []migration.Script {
        return []migration.Script{
-
                new(addFrameTables),
                new(renameStepToStage),
                new(addSubtasksField),
@@ -30,6 +29,6 @@ func All() []migration.Script {
                new(renameTasksToPlan),
                new(addDomainTables),
                new(addTypeField),
-               new(updateSchemas20220711),
+               new(commitfileComponent),
        }
 }
diff --git a/plugins/gitextractor/models/interface.go 
b/plugins/gitextractor/models/interface.go
index b3e5ca6c..22b5d93e 100644
--- a/plugins/gitextractor/models/interface.go
+++ b/plugins/gitextractor/models/interface.go
@@ -27,6 +27,6 @@ type Store interface {
        Refs(ref *code.Ref) error
        CommitFiles(file *code.CommitFile) error
        CommitParents(pp []*code.CommitParent) error
-       FileComponent(component *code.CommitFileComponent) error
+       CommitFileComponents(commitFileComponent *code.CommitFileComponent) 
error
        Close() error
 }
diff --git a/plugins/gitextractor/parser/repo.go 
b/plugins/gitextractor/parser/repo.go
index 8807ded0..cf1d5655 100644
--- a/plugins/gitextractor/parser/repo.go
+++ b/plugins/gitextractor/parser/repo.go
@@ -327,19 +327,19 @@ func (r *GitRepo) storeCommitFilesFromDiff(commitSha 
string, diff *git.Diff, com
                commitFile = new(code.CommitFile)
                commitFile.CommitSha = commitSha
                commitFile.FilePath = file.NewFile.Path
-               commitFile.ID = commitSha + ":" + file.NewFile.Path
+               commitFile.Id = commitSha + ":" + file.NewFile.Path
                commitFileComponent = new(code.CommitFileComponent)
                for component, reg := range componentMap {
                        if reg.MatchString(commitFile.FilePath) {
-                               commitFileComponent.Component = component
+                               commitFileComponent.ComponentName = component
                                break
                        }
                }
-               commitFileComponent.CommitFileID = commitSha + ":" + 
file.NewFile.Path
+               commitFileComponent.CommitFileId = commitSha + ":" + 
file.NewFile.Path
                //commitFileComponent.FilePath = file.NewFile.Path
                //commitFileComponent.CommitSha = commitSha
-               if commitFileComponent.Component == "" {
-                       commitFileComponent.Component = "Default"
+               if commitFileComponent.ComponentName == "" {
+                       commitFileComponent.ComponentName = "Default"
                }
                return func(hunk git.DiffHunk) (git.DiffForEachLineCallback, 
error) {
                        return func(line git.DiffLine) error {
@@ -354,9 +354,9 @@ func (r *GitRepo) storeCommitFilesFromDiff(commitSha 
string, diff *git.Diff, com
                }, nil
        }, git.DiffDetailLines)
        if commitFileComponent != nil {
-               err = r.store.FileComponent(commitFileComponent)
+               err = r.store.CommitFileComponents(commitFileComponent)
                if err != nil {
-                       r.logger.Error("FileComponent error:", err)
+                       r.logger.Error("CommitFileComponents error:", err)
                }
        }
        if commitFile != nil {
diff --git a/plugins/gitextractor/store/csv.go 
b/plugins/gitextractor/store/csv.go
index fa2b8845..52820c7b 100644
--- a/plugins/gitextractor/store/csv.go
+++ b/plugins/gitextractor/store/csv.go
@@ -132,8 +132,8 @@ func (c *CsvStore) Refs(ref *code.Ref) error {
 func (c *CsvStore) CommitFiles(file *code.CommitFile) error {
        return c.commitFileWriter.Write(file)
 }
-func (c *CsvStore) FileComponent(component *code.CommitFileComponent) error {
-       return c.commitFileWriter.Write(component)
+func (c *CsvStore) CommitFileComponents(commitFileComponent 
*code.CommitFileComponent) error {
+       return c.commitFileWriter.Write(commitFileComponent)
 }
 
 func (c *CsvStore) CommitParents(pp []*code.CommitParent) error {
diff --git a/plugins/gitextractor/store/database.go 
b/plugins/gitextractor/store/database.go
index 8bca2147..9c85aff1 100644
--- a/plugins/gitextractor/store/database.go
+++ b/plugins/gitextractor/store/database.go
@@ -91,12 +91,12 @@ func (d *Database) CommitFiles(file *code.CommitFile) error 
{
        return batch.Add(file)
 }
 
-func (d *Database) FileComponent(commitfile *code.CommitFileComponent) error {
-       batch, err := d.driver.ForType(reflect.TypeOf(commitfile))
+func (d *Database) CommitFileComponents(commitFileComponent 
*code.CommitFileComponent) error {
+       batch, err := d.driver.ForType(reflect.TypeOf(commitFileComponent))
        if err != nil {
                return err
        }
-       return batch.Add(commitfile)
+       return batch.Add(commitFileComponent)
 }
 
 func (d *Database) CommitParents(pp []*code.CommitParent) error {

Reply via email to