klesh commented on code in PR #2504:
URL: https://github.com/apache/incubator-devlake/pull/2504#discussion_r924206026


##########
models/domainlayer/code/commit.go:
##########
@@ -46,12 +46,33 @@ func (Commit) TableName() string {
 
 type CommitFile struct {
        common.NoPKModel
-       CommitSha string `gorm:"primaryKey;type:varchar(40)"`
-       FilePath  string `gorm:"primaryKey;type:varchar(255)"`
+       ID        string `gorm:"primaryKey;type:varchar(255)"`
+       CommitSha string `gorm:"type:varchar(40)"`
+       FilePath  string `gorm:"type:varchar(255)"`
        Additions int
        Deletions int
 }
 
 func (CommitFile) TableName() string {
        return "commit_files"
 }
+
+type Component struct {
+       RepoId    string `gorm:"primaryKey;type:varchar(255)"`
+       Name      string `gorm:"type:varchar(255)"`

Review Comment:
   I think we both agreed that the PrimaryKey should be the `Name`.
   The `RepoId` alone is not a valid PK for the table



##########
models/domainlayer/code/commit.go:
##########
@@ -46,12 +46,33 @@ func (Commit) TableName() string {
 
 type CommitFile struct {
        common.NoPKModel
-       CommitSha string `gorm:"primaryKey;type:varchar(40)"`
-       FilePath  string `gorm:"primaryKey;type:varchar(255)"`
+       ID        string `gorm:"primaryKey;type:varchar(255)"`
+       CommitSha string `gorm:"type:varchar(40)"`
+       FilePath  string `gorm:"type:varchar(255)"`
        Additions int
        Deletions int
 }
 
 func (CommitFile) TableName() string {
        return "commit_files"
 }
+
+type Component struct {
+       RepoId    string `gorm:"primaryKey;type:varchar(255)"`
+       Name      string `gorm:"type:varchar(255)"`
+       PathRegex string `gorm:"type:varchar(255)"`
+}
+
+func (Component) TableName() string {
+       return "components"
+}
+
+type CommitFileComponent struct {
+       common.NoPKModel
+       CommitFileID string `gorm:"primaryKey;type:varchar(255)"`

Review Comment:
   This should b `CommitFileId` if we nested `domainlayer.DomainEntity` instead 
of `common.NoPKModel` within `CommitFiles`



##########
plugins/gitextractor/store/database.go:
##########
@@ -91,6 +91,14 @@ func (d *Database) CommitFiles(file *code.CommitFile) error {
        return batch.Add(file)
 }
 
+func (d *Database) FileComponent(commitfile *code.CommitFileComponent) error {

Review Comment:
   same as above



##########
plugins/gitextractor/store/csv.go:
##########
@@ -132,6 +132,9 @@ 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 {

Review Comment:
   the variable name and its type are uncorrelated... this is very confusing. 
is it a `component` or what? 😂.
   and insert an empty line between functions pls.



##########
models/migrationscripts/register.go:
##########
@@ -27,6 +27,7 @@ func All() []migration.Script {
                new(updateSchemas20220601),
                new(updateSchemas20220616),
                new(blueprintNormalMode),
+               new(updateSchemas20220711),

Review Comment:
   I would suggest that we give it a meaningful name like 
`commitfile_component` 



##########
models/domainlayer/code/commit.go:
##########
@@ -46,12 +46,33 @@ func (Commit) TableName() string {
 
 type CommitFile struct {
        common.NoPKModel
-       CommitSha string `gorm:"primaryKey;type:varchar(40)"`
-       FilePath  string `gorm:"primaryKey;type:varchar(255)"`
+       ID        string `gorm:"primaryKey;type:varchar(255)"`

Review Comment:
   Please use the `domainlayer.DomainEntity` instead, check other domain layer 
entities for reference.



##########
models/domainlayer/code/commit.go:
##########
@@ -46,12 +46,33 @@ func (Commit) TableName() string {
 
 type CommitFile struct {
        common.NoPKModel
-       CommitSha string `gorm:"primaryKey;type:varchar(40)"`
-       FilePath  string `gorm:"primaryKey;type:varchar(255)"`
+       ID        string `gorm:"primaryKey;type:varchar(255)"`
+       CommitSha string `gorm:"type:varchar(40)"`
+       FilePath  string `gorm:"type:varchar(255)"`
        Additions int
        Deletions int
 }
 
 func (CommitFile) TableName() string {
        return "commit_files"
 }
+
+type Component struct {
+       RepoId    string `gorm:"primaryKey;type:varchar(255)"`
+       Name      string `gorm:"type:varchar(255)"`
+       PathRegex string `gorm:"type:varchar(255)"`
+}
+
+func (Component) TableName() string {
+       return "components"
+}
+
+type CommitFileComponent struct {
+       common.NoPKModel
+       CommitFileID string `gorm:"primaryKey;type:varchar(255)"`
+       Component    string `gorm:"type:varchar(255)"`

Review Comment:
   It should be `ComponentName` if we agreed that `Name` is the PK of 
`Components` table.



##########
models/migrationscripts/updateSchemas20220711.go:
##########
@@ -0,0 +1,77 @@
+/*
+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"
+       "github.com/apache/incubator-devlake/models/common"
+       "gorm.io/gorm"
+)
+
+type Component struct {

Review Comment:
   the migration script should be updated if we agreed to the above comments



##########
plugins/gitextractor/models/interface.go:
##########
@@ -27,5 +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

Review Comment:
   Lets name it `CommitFileComponents`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to