likyh commented on code in PR #2147:
URL: https://github.com/apache/incubator-devlake/pull/2147#discussion_r896507496
##########
plugins/gitlab/models/connection.go:
##########
@@ -17,11 +17,20 @@ limitations under the License.
package models
+import (
+ "github.com/apache/incubator-devlake/plugins/helper"
+)
+
// This object conforms to what the frontend currently sends.
type GitlabConnection struct {
- Endpoint string `mapstructure:"endpoint" validate:"required"
env:"GITLAB_ENDPOINT" json:"endpoint"`
- Auth string `mapstructure:"auth" validate:"required"
env:"GITLAB_AUTH" json:"auth"`
- Proxy string `mapstructure:"proxy" env:"GITLAB_PROXY" json:"proxy"`
+ helper.RestConnection `mapstructure:",squash"`
+ helper.AccessToken `mapstructure:",squash"`
Review Comment:
write column instead of using the helper.
##########
plugins/gitlab/models/migrationscripts/init_schema.go:
##########
@@ -19,15 +19,42 @@ package migrationscripts
import (
"context"
-
+ "fmt"
+ "github.com/apache/incubator-devlake/config"
"github.com/apache/incubator-devlake/plugins/gitlab/models/migrationscripts/archived"
"gorm.io/gorm"
+ "gorm.io/gorm/clause"
)
type InitSchemas struct{}
+type RawMr struct {
+}
+
+func (r RawMr) tableName() string {
+ return "_raw_gitlab_merge_requests"
+}
+
func (*InitSchemas) Up(ctx context.Context, db *gorm.DB) error {
- return db.Migrator().AutoMigrate(
+ rawTableList := []string{
+ "_raw_gitlab_api_children_on_pipeline",
+ "_raw_gitlab_api_commit",
+ "_raw_gitlab_api_issues",
+ "_raw_gitlab_api_merge_request_commits",
+ "_raw_gitlab_api_merge_request_notes",
+ "_raw_gitlab_api_merge_requests",
+ "_raw_gitlab_api_pipeline",
+ "_raw_gitlab_api_project",
+ "_raw_gitlab_api_tag",
+ }
+ for _, v := range rawTableList {
+ err := db.Exec(fmt.Sprintf("DROP TABLE IF EXISTS %s CASCADE",
v)).Error
+ if err != nil {
+ return err
+ }
+ }
+
+ err := db.Migrator().DropTable(
Review Comment:
Will droping a not exist table got the error?
##########
plugins/gitlab/models/migrationscripts/init_schema.go:
##########
@@ -19,15 +19,42 @@ package migrationscripts
import (
"context"
-
+ "fmt"
+ "github.com/apache/incubator-devlake/config"
"github.com/apache/incubator-devlake/plugins/gitlab/models/migrationscripts/archived"
"gorm.io/gorm"
+ "gorm.io/gorm/clause"
)
type InitSchemas struct{}
+type RawMr struct {
+}
+
+func (r RawMr) tableName() string {
+ return "_raw_gitlab_merge_requests"
+}
+
func (*InitSchemas) Up(ctx context.Context, db *gorm.DB) error {
- return db.Migrator().AutoMigrate(
+ rawTableList := []string{
+ "_raw_gitlab_api_children_on_pipeline",
+ "_raw_gitlab_api_commit",
+ "_raw_gitlab_api_issues",
+ "_raw_gitlab_api_merge_request_commits",
+ "_raw_gitlab_api_merge_request_notes",
+ "_raw_gitlab_api_merge_requests",
+ "_raw_gitlab_api_pipeline",
+ "_raw_gitlab_api_project",
+ "_raw_gitlab_api_tag",
+ }
+ for _, v := range rawTableList {
+ err := db.Exec(fmt.Sprintf("DROP TABLE IF EXISTS %s CASCADE",
v)).Error
+ if err != nil {
+ return err
+ }
+ }
+
+ err := db.Migrator().DropTable(
Review Comment:
Do you drop all tables that may appear? I notice that these are fewer tables
than AutoMigrate.
##########
plugins/gitlab/models/migrationscripts/init_schema.go:
##########
@@ -39,11 +66,55 @@ func (*InitSchemas) Up(ctx context.Context, db *gorm.DB)
error {
&archived.GitlabMergeRequestCommit{},
&archived.GitlabMergeRequestComment{},
&archived.GitlabUser{},
+ &archived.GitlabConnection{},
+ &archived.GitlabIssue{},
+ &archived.GitlabIssueLabel{},
)
+
+ if err != nil {
+ return err
+ }
+
+ err = db.Migrator().AutoMigrate(
+ &archived.GitlabProject{},
+ &archived.GitlabMergeRequest{},
+ &archived.GitlabCommit{},
+ &archived.GitlabTag{},
+ &archived.GitlabProjectCommit{},
+ &archived.GitlabPipeline{},
+ &archived.GitlabReviewer{},
+ &archived.GitlabMergeRequestNote{},
+ &archived.GitlabMergeRequestCommit{},
+ &archived.GitlabMergeRequestComment{},
+ &archived.GitlabUser{},
+ &archived.GitlabConnection{},
+ &archived.GitlabIssue{},
+ &archived.GitlabIssueLabel{},
+ )
+
+ if err != nil {
+ return err
+ }
+
+ conn := &archived.GitlabConnection{}
+ v := config.GetConfig()
+ conn.Name = "first connection"
+ conn.ID = 1
+ conn.Endpoint = v.GetString("GITLAB_ENDPOINT")
+ conn.Token = v.GetString("GITLAB_AUTH")
+ conn.Proxy = v.GetString("GITLAB_PROXY")
+ conn.RateLimit = v.GetInt("GITLAB_API_REQUESTS_PER_HOUR")
+ fmt.Println(conn.Endpoint)
+ err = db.Clauses(clause.OnConflict{DoNothing: true}).Create(conn).Error
+
+ if err != nil {
+ return err
+ }
+ return nil
}
func (*InitSchemas) Version() uint64 {
- return 20220407201136
+ return 202206147201136
Review Comment:
There is one more digit here. Mistakes? And what does `7201136` mean? use
the count of migration scripts (000001) instead?
--
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]