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

mappjzc 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 9be33ca6 refactor(github): refactor migrationscripts (#3559)
9be33ca6 is described below

commit 9be33ca6e155dd52f0950bafaeae0d1b05d75663
Author: Warren Chen <[email protected]>
AuthorDate: Mon Oct 24 15:20:23 2022 +0800

    refactor(github): refactor migrationscripts (#3559)
    
    closes #3558
---
 plugins/github/impl/impl.go                        |  3 +-
 .../migrationscripts/20220715_add_init_tables.go   | 34 +++++++-------
 .../migrationscripts/20220728_add_runs_table.go    | 49 +++-----------------
 .../migrationscripts/20220729_add_jobs_table.go    | 41 ++---------------
 .../20220802_add_pipeline_table.go                 | 29 ++----------
 .../20220908_delete_pipeline_table.go              | 11 +++--
 .../20220919_add_headrepoId_field_in_githubPr.go   | 52 +++++-----------------
 .../job.go}                                        | 32 ++-----------
 .../pipeline.go}                                   | 32 ++-----------
 .../run.go}                                        | 34 +++-----------
 plugins/github/models/migrationscripts/register.go |  6 +--
 11 files changed, 64 insertions(+), 259 deletions(-)

diff --git a/plugins/github/impl/impl.go b/plugins/github/impl/impl.go
index a6290b3a..2821cc0f 100644
--- a/plugins/github/impl/impl.go
+++ b/plugins/github/impl/impl.go
@@ -22,7 +22,6 @@ import (
        "time"
 
        "github.com/apache/incubator-devlake/errors"
-       "github.com/apache/incubator-devlake/migration"
        "github.com/apache/incubator-devlake/plugins/core"
        "github.com/apache/incubator-devlake/plugins/github/api"
        "github.com/apache/incubator-devlake/plugins/github/models"
@@ -176,7 +175,7 @@ func (plugin Github) RootPkgPath() string {
        return "github.com/apache/incubator-devlake/plugins/github"
 }
 
-func (plugin Github) MigrationScripts() []migration.Script {
+func (plugin Github) MigrationScripts() []core.MigrationScript {
        return migrationscripts.All()
 }
 
diff --git a/plugins/github/models/migrationscripts/20220715_add_init_tables.go 
b/plugins/github/models/migrationscripts/20220715_add_init_tables.go
index 02420190..0964d01d 100644
--- a/plugins/github/models/migrationscripts/20220715_add_init_tables.go
+++ b/plugins/github/models/migrationscripts/20220715_add_init_tables.go
@@ -18,13 +18,12 @@ limitations under the License.
 package migrationscripts
 
 import (
-       "context"
        "github.com/apache/incubator-devlake/errors"
+       "github.com/apache/incubator-devlake/helpers/migrationhelper"
        "github.com/apache/incubator-devlake/plugins/core"
        "github.com/apache/incubator-devlake/plugins/helper"
 
        
"github.com/apache/incubator-devlake/plugins/github/models/migrationscripts/archived"
-       "gorm.io/gorm"
 )
 
 type addInitTables struct {
@@ -35,8 +34,9 @@ func (u *addInitTables) SetConfigGetter(config 
core.ConfigGetter) {
        u.config = config
 }
 
-func (u *addInitTables) Up(ctx context.Context, db *gorm.DB) errors.Error {
-       err := db.Migrator().DropTable(
+func (u *addInitTables) Up(basicRes core.BasicRes) errors.Error {
+       db := basicRes.GetDal()
+       err := db.DropTables(
                &archived.GithubRepo{},
                &archived.GithubConnection{},
                &archived.GithubCommit{},
@@ -73,32 +73,36 @@ func (u *addInitTables) Up(ctx context.Context, db 
*gorm.DB) errors.Error {
 
        // create connection
        if err != nil {
-               return errors.Convert(err)
+               return err
        }
 
-       err = db.Migrator().CreateTable(archived.GithubConnection{})
+       err = db.AutoMigrate(archived.GithubConnection{})
        if err != nil {
-               return errors.Convert(err)
+               return err
        }
-       encodeKey := u.config.GetString(core.EncodeKeyEnvStr)
+       encodeKey := basicRes.GetConfig(core.EncodeKeyEnvStr)
        connection := &archived.GithubConnection{}
-       connection.Endpoint = u.config.GetString(`GITHUB_ENDPOINT`)
-       connection.Proxy = u.config.GetString(`GITHUB_PROXY`)
-       connection.Token = u.config.GetString(`GITHUB_AUTH`)
+       connection.Endpoint = basicRes.GetConfig(`GITHUB_ENDPOINT`)
+       connection.Proxy = basicRes.GetConfig(`GITHUB_PROXY`)
+       connection.Token = basicRes.GetConfig(`GITHUB_AUTH`)
        connection.Name = `GitHub`
        if connection.Endpoint != `` && connection.Token != `` && encodeKey != 
`` {
                err = helper.UpdateEncryptFields(connection, func(plaintext 
string) (string, errors.Error) {
                        return core.Encrypt(encodeKey, plaintext)
                })
                if err != nil {
-                       return errors.Convert(err)
+                       return err
                }
                // update from .env and save to db
-               db.Create(connection)
+               err = db.Create(connection)
+               if err != nil {
+                       return err
+               }
        }
 
        // create other table with connection id
-       err = db.Migrator().AutoMigrate(
+       err = migrationhelper.AutoMigrateTables(
+               basicRes,
                &archived.GithubRepo{},
                &archived.GithubCommit{},
                &archived.GithubRepoCommit{},
@@ -120,7 +124,7 @@ func (u *addInitTables) Up(ctx context.Context, db 
*gorm.DB) errors.Error {
                &archived.GithubAccountOrg{},
                &archived.GithubAccount{},
        )
-       return errors.Convert(err)
+       return err
 }
 
 func (*addInitTables) Version() uint64 {
diff --git a/plugins/github/models/migrationscripts/20220728_add_runs_table.go 
b/plugins/github/models/migrationscripts/20220728_add_runs_table.go
index 04ee10e6..c217d548 100644
--- a/plugins/github/models/migrationscripts/20220728_add_runs_table.go
+++ b/plugins/github/models/migrationscripts/20220728_add_runs_table.go
@@ -18,56 +18,17 @@ limitations under the License.
 package migrationscripts
 
 import (
-       "context"
        "github.com/apache/incubator-devlake/errors"
-       "time"
-
-       "github.com/apache/incubator-devlake/models/migrationscripts/archived"
-       "gorm.io/gorm"
+       "github.com/apache/incubator-devlake/plugins/core"
+       
"github.com/apache/incubator-devlake/plugins/github/models/migrationscripts/archived"
 )
 
-type GithubRun20220728 struct {
-       archived.NoPKModel
-       ConnectionId     uint64     `gorm:"primaryKey"`
-       RepoId           int        `gorm:"primaryKey"`
-       ID               int64      `json:"id" 
gorm:"primaryKey;autoIncrement:false"`
-       Name             string     `json:"name" gorm:"type:varchar(255)"`
-       NodeID           string     `json:"node_id" gorm:"type:varchar(255)"`
-       HeadBranch       string     `json:"head_branch" 
gorm:"type:varchar(255)"`
-       HeadSha          string     `json:"head_sha" gorm:"type:varchar(255)"`
-       Path             string     `json:"path" gorm:"type:varchar(255)"`
-       RunNumber        int        `json:"run_number"`
-       Event            string     `json:"event" gorm:"type:varchar(255)"`
-       Status           string     `json:"status" gorm:"type:varchar(255)"`
-       Conclusion       string     `json:"conclusion" gorm:"type:varchar(255)"`
-       WorkflowID       int        `json:"workflow_id"`
-       CheckSuiteID     int64      `json:"check_suite_id"`
-       CheckSuiteNodeID string     `json:"check_suite_node_id" 
gorm:"type:varchar(255)"`
-       URL              string     `json:"url" gorm:"type:varchar(255)"`
-       HTMLURL          string     `json:"html_url" gorm:"type:varchar(255)"`
-       GithubCreatedAt  *time.Time `json:"created_at"`
-       GithubUpdatedAt  *time.Time `json:"updated_at"`
-       RunAttempt       int        `json:"run_attempt"`
-       RunStartedAt     *time.Time `json:"run_started_at"`
-       JobsURL          string     `json:"jobs_url" gorm:"type:varchar(255)"`
-       LogsURL          string     `json:"logs_url" gorm:"type:varchar(255)"`
-       CheckSuiteURL    string     `json:"check_suite_url" 
gorm:"type:varchar(255)"`
-       ArtifactsURL     string     `json:"artifacts_url" 
gorm:"type:varchar(255)"`
-       CancelURL        string     `json:"cancel_url" gorm:"type:varchar(255)"`
-       RerunURL         string     `json:"rerun_url" gorm:"type:varchar(255)"`
-       WorkflowURL      string     `json:"workflow_url" 
gorm:"type:varchar(255)"`
-       Type             string     `json:"type" gorm:"type:varchar(255)"`
-}
-
-func (GithubRun20220728) TableName() string {
-       return "_tool_github_runs"
-}
-
 type addGithubRunsTable struct{}
 
-func (u *addGithubRunsTable) Up(ctx context.Context, db *gorm.DB) errors.Error 
{
+func (u *addGithubRunsTable) Up(basicRes core.BasicRes) errors.Error {
+       db := basicRes.GetDal()
        // create table
-       err := db.Migrator().CreateTable(GithubRun20220728{})
+       err := db.AutoMigrate(&archived.GithubRun{})
        if err != nil {
                return errors.Default.Wrap(err, "create table _tool_github_runs 
error")
        }
diff --git a/plugins/github/models/migrationscripts/20220729_add_jobs_table.go 
b/plugins/github/models/migrationscripts/20220729_add_jobs_table.go
index 08163700..1c9b0246 100644
--- a/plugins/github/models/migrationscripts/20220729_add_jobs_table.go
+++ b/plugins/github/models/migrationscripts/20220729_add_jobs_table.go
@@ -18,49 +18,16 @@ limitations under the License.
 package migrationscripts
 
 import (
-       "context"
        "github.com/apache/incubator-devlake/errors"
-       "time"
-
-       "github.com/apache/incubator-devlake/models/migrationscripts/archived"
-       "gorm.io/datatypes"
-       "gorm.io/gorm"
+       "github.com/apache/incubator-devlake/plugins/core"
+       
"github.com/apache/incubator-devlake/plugins/github/models/migrationscripts/archived"
 )
 
-type GithubJob20220729 struct {
-       archived.NoPKModel
-       ConnectionId  uint64         `gorm:"primaryKey"`
-       RepoId        int            `gorm:"primaryKey"`
-       ID            int            `json:"id" 
gorm:"primaryKey;autoIncrement:false"`
-       RunID         int            `json:"run_id"`
-       RunURL        string         `json:"run_url" gorm:"type:varchar(255)"`
-       NodeID        string         `json:"node_id" gorm:"type:varchar(255)"`
-       HeadSha       string         `json:"head_sha" gorm:"type:varchar(255)"`
-       URL           string         `json:"url" gorm:"type:varchar(255)"`
-       HTMLURL       string         `json:"html_url" gorm:"type:varchar(255)"`
-       Status        string         `json:"status" gorm:"type:varchar(255)"`
-       Conclusion    string         `json:"conclusion" 
gorm:"type:varchar(255)"`
-       StartedAt     *time.Time     `json:"started_at"`
-       CompletedAt   *time.Time     `json:"completed_at"`
-       Name          string         `json:"name" gorm:"type:varchar(255)"`
-       Steps         datatypes.JSON `json:"steps"`
-       CheckRunURL   string         `json:"check_run_url" 
gorm:"type:varchar(255)"`
-       Labels        datatypes.JSON `json:"labels"`
-       RunnerID      int            `json:"runner_id"`
-       RunnerName    string         `json:"runner_name" 
gorm:"type:varchar(255)"`
-       RunnerGroupID int            `json:"runner_group_id"`
-       Type          string         `json:"type" gorm:"type:varchar(255)"`
-}
-
-func (GithubJob20220729) TableName() string {
-       return "_tool_github_jobs"
-}
-
 type addGithubJobsTable struct{}
 
-func (u *addGithubJobsTable) Up(ctx context.Context, db *gorm.DB) errors.Error 
{
+func (u *addGithubJobsTable) Up(basicRes core.BasicRes) errors.Error {
        // create table
-       err := db.Migrator().CreateTable(GithubJob20220729{})
+       err := basicRes.GetDal().AutoMigrate(&archived.GithubJob{})
        if err != nil {
                return errors.Default.Wrap(err, "create table _tool_github_jobs 
error")
        }
diff --git 
a/plugins/github/models/migrationscripts/20220802_add_pipeline_table.go 
b/plugins/github/models/migrationscripts/20220802_add_pipeline_table.go
index c04fae95..97574fde 100644
--- a/plugins/github/models/migrationscripts/20220802_add_pipeline_table.go
+++ b/plugins/github/models/migrationscripts/20220802_add_pipeline_table.go
@@ -18,37 +18,16 @@ limitations under the License.
 package migrationscripts
 
 import (
-       "context"
        "github.com/apache/incubator-devlake/errors"
-       "time"
-
-       "github.com/apache/incubator-devlake/models/migrationscripts/archived"
-       "gorm.io/gorm"
+       "github.com/apache/incubator-devlake/plugins/core"
+       
"github.com/apache/incubator-devlake/plugins/github/models/migrationscripts/archived"
 )
 
-type GithubPipeline20220803 struct {
-       archived.NoPKModel
-       ConnectionId uint64     `gorm:"primaryKey"`
-       RepoId       int        `gorm:"primaryKey"`
-       Branch       string     `json:"branch" 
gorm:"primaryKey;type:varchar(255)"`
-       Commit       string     `json:"commit" 
gorm:"primaryKey;type:varchar(255)"`
-       StartedDate  *time.Time `json:"started_time"`
-       FinishedDate *time.Time `json:"finished_time"`
-       Duration     float64    `json:"duration"`
-       Status       string     `json:"status" gorm:"type:varchar(255)"`
-       Result       string     `json:"results" gorm:"type:varchar(255)"`
-       Type         string     `json:"type" gorm:"type:varchar(255)"`
-}
-
-func (GithubPipeline20220803) TableName() string {
-       return "_tool_github_pipelines"
-}
-
 type addGithubPipelineTable struct{}
 
-func (u *addGithubPipelineTable) Up(ctx context.Context, db *gorm.DB) 
errors.Error {
+func (u *addGithubPipelineTable) Up(basicRes core.BasicRes) errors.Error {
        // create table
-       err := db.Migrator().CreateTable(GithubPipeline20220803{})
+       err := basicRes.GetDal().AutoMigrate(&archived.GithubPipeline{})
        if err != nil {
                return errors.Default.Wrap(err, "create table 
_tool_github_pipelines error")
        }
diff --git 
a/plugins/github/models/migrationscripts/20220908_delete_pipeline_table.go 
b/plugins/github/models/migrationscripts/20220908_delete_pipeline_table.go
index b821f17b..ef9fae09 100644
--- a/plugins/github/models/migrationscripts/20220908_delete_pipeline_table.go
+++ b/plugins/github/models/migrationscripts/20220908_delete_pipeline_table.go
@@ -18,23 +18,22 @@ limitations under the License.
 package migrationscripts
 
 import (
-       "context"
+       "github.com/apache/incubator-devlake/plugins/core"
 
        "github.com/apache/incubator-devlake/errors"
-       "gorm.io/gorm"
 )
 
-type GithubPipeline20220908 struct{}
+type githubPipeline20220908 struct{}
 
-func (GithubPipeline20220908) TableName() string {
+func (githubPipeline20220908) TableName() string {
        return "_tool_github_pipelines"
 }
 
 type deleteGithubPipelineTable struct{}
 
-func (u *deleteGithubPipelineTable) Up(ctx context.Context, db *gorm.DB) 
errors.Error {
+func (u *deleteGithubPipelineTable) Up(basicRes core.BasicRes) errors.Error {
        // create table
-       err := db.Migrator().DropTable(GithubPipeline20220908{})
+       err := basicRes.GetDal().DropTables(&githubPipeline20220908{})
        if err != nil {
                return errors.Default.Wrap(err, "delete table 
_tool_github_pipelines error")
        }
diff --git 
a/plugins/github/models/migrationscripts/20220919_add_headrepoId_field_in_githubPr.go
 
b/plugins/github/models/migrationscripts/20220919_add_headrepoId_field_in_githubPr.go
index 7cde1314..9acb2b99 100644
--- 
a/plugins/github/models/migrationscripts/20220919_add_headrepoId_field_in_githubPr.go
+++ 
b/plugins/github/models/migrationscripts/20220919_add_headrepoId_field_in_githubPr.go
@@ -18,58 +18,26 @@ limitations under the License.
 package migrationscripts
 
 import (
-       "context"
-       "gorm.io/gorm"
-       "gorm.io/gorm/clause"
-       "time"
-
        "github.com/apache/incubator-devlake/errors"
-       "github.com/apache/incubator-devlake/models/migrationscripts/archived"
+       "github.com/apache/incubator-devlake/plugins/core"
 )
 
-type addFieldHeadRepoId20220919 struct {
-       ConnectionId    uint64 `gorm:"primaryKey"`
-       GithubId        int    `gorm:"primaryKey"`
-       RepoId          int    `gorm:"index"`
-       HeadRepoId      int
-       Number          int    `gorm:"index"` // This number is used in GET 
requests to the API associated to reviewers / comments / etc.
-       State           string `gorm:"type:varchar(255)"`
-       Title           string
-       GithubCreatedAt time.Time
-       GithubUpdatedAt time.Time `gorm:"index"`
-       ClosedAt        *time.Time
-       // In order to get the following fields, we need to collect PRs 
individually from GitHub
-       Additions      int
-       Deletions      int
-       Comments       int
-       Commits        int
-       ReviewComments int
-       Merged         bool
-       MergedAt       *time.Time
-       Body           string
-       Type           string `gorm:"type:varchar(255)"`
-       Component      string `gorm:"type:varchar(255)"`
-       MergeCommitSha string `gorm:"type:varchar(40)"`
-       HeadRef        string `gorm:"type:varchar(255)"`
-       BaseRef        string `gorm:"type:varchar(255)"`
-       BaseCommitSha  string `gorm:"type:varchar(255)"`
-       HeadCommitSha  string `gorm:"type:varchar(255)"`
-       Url            string `gorm:"type:varchar(255)"`
-       AuthorName     string `gorm:"type:varchar(100)"`
-       AuthorId       int
-       archived.NoPKModel
+type pullRequest20220919 struct {
+       HeadRepoId int
 }
 
-func (addFieldHeadRepoId20220919) TableName() string {
+func (pullRequest20220919) TableName() string {
        return "_tool_github_pull_requests"
 }
 
 type addHeadRepoIdFieldInGithubPr struct{}
 
-func (*addHeadRepoIdFieldInGithubPr) Up(ctx context.Context, db *gorm.DB) 
errors.Error {
-       err := db.Migrator().AddColumn(addFieldHeadRepoId20220919{}, 
"head_repo_id")
-       _ = db.Exec("SELECT * FROM ? LIMIT 1", clause.Table{Name: 
addFieldHeadRepoId20220919{}.TableName()})
-       return errors.Convert(err)
+func (*addHeadRepoIdFieldInGithubPr) Up(basicRes core.BasicRes) errors.Error {
+       err := basicRes.GetDal().AutoMigrate(&pullRequest20220919{})
+       if err != nil {
+               return err
+       }
+       return nil
 }
 
 func (*addHeadRepoIdFieldInGithubPr) Version() uint64 {
diff --git a/plugins/github/models/migrationscripts/20220729_add_jobs_table.go 
b/plugins/github/models/migrationscripts/archived/job.go
similarity index 78%
copy from plugins/github/models/migrationscripts/20220729_add_jobs_table.go
copy to plugins/github/models/migrationscripts/archived/job.go
index 08163700..3c615af0 100644
--- a/plugins/github/models/migrationscripts/20220729_add_jobs_table.go
+++ b/plugins/github/models/migrationscripts/archived/job.go
@@ -15,19 +15,15 @@ See the License for the specific language governing 
permissions and
 limitations under the License.
 */
 
-package migrationscripts
+package archived
 
 import (
-       "context"
-       "github.com/apache/incubator-devlake/errors"
-       "time"
-
        "github.com/apache/incubator-devlake/models/migrationscripts/archived"
        "gorm.io/datatypes"
-       "gorm.io/gorm"
+       "time"
 )
 
-type GithubJob20220729 struct {
+type GithubJob struct {
        archived.NoPKModel
        ConnectionId  uint64         `gorm:"primaryKey"`
        RepoId        int            `gorm:"primaryKey"`
@@ -52,26 +48,6 @@ type GithubJob20220729 struct {
        Type          string         `json:"type" gorm:"type:varchar(255)"`
 }
 
-func (GithubJob20220729) TableName() string {
+func (GithubJob) TableName() string {
        return "_tool_github_jobs"
 }
-
-type addGithubJobsTable struct{}
-
-func (u *addGithubJobsTable) Up(ctx context.Context, db *gorm.DB) errors.Error 
{
-       // create table
-       err := db.Migrator().CreateTable(GithubJob20220729{})
-       if err != nil {
-               return errors.Default.Wrap(err, "create table _tool_github_jobs 
error")
-       }
-       return nil
-
-}
-
-func (*addGithubJobsTable) Version() uint64 {
-       return 20220729000001
-}
-
-func (*addGithubJobsTable) Name() string {
-       return "Github add github_jobs table"
-}
diff --git 
a/plugins/github/models/migrationscripts/20220802_add_pipeline_table.go 
b/plugins/github/models/migrationscripts/archived/pipeline.go
similarity index 68%
copy from plugins/github/models/migrationscripts/20220802_add_pipeline_table.go
copy to plugins/github/models/migrationscripts/archived/pipeline.go
index c04fae95..c15f75a2 100644
--- a/plugins/github/models/migrationscripts/20220802_add_pipeline_table.go
+++ b/plugins/github/models/migrationscripts/archived/pipeline.go
@@ -15,18 +15,14 @@ See the License for the specific language governing 
permissions and
 limitations under the License.
 */
 
-package migrationscripts
+package archived
 
 import (
-       "context"
-       "github.com/apache/incubator-devlake/errors"
-       "time"
-
        "github.com/apache/incubator-devlake/models/migrationscripts/archived"
-       "gorm.io/gorm"
+       "time"
 )
 
-type GithubPipeline20220803 struct {
+type GithubPipeline struct {
        archived.NoPKModel
        ConnectionId uint64     `gorm:"primaryKey"`
        RepoId       int        `gorm:"primaryKey"`
@@ -40,26 +36,6 @@ type GithubPipeline20220803 struct {
        Type         string     `json:"type" gorm:"type:varchar(255)"`
 }
 
-func (GithubPipeline20220803) TableName() string {
+func (GithubPipeline) TableName() string {
        return "_tool_github_pipelines"
 }
-
-type addGithubPipelineTable struct{}
-
-func (u *addGithubPipelineTable) Up(ctx context.Context, db *gorm.DB) 
errors.Error {
-       // create table
-       err := db.Migrator().CreateTable(GithubPipeline20220803{})
-       if err != nil {
-               return errors.Default.Wrap(err, "create table 
_tool_github_pipelines error")
-       }
-       return nil
-
-}
-
-func (*addGithubPipelineTable) Version() uint64 {
-       return 20220803000001
-}
-
-func (*addGithubPipelineTable) Name() string {
-       return "Github add github_pipelines table"
-}
diff --git a/plugins/github/models/migrationscripts/20220728_add_runs_table.go 
b/plugins/github/models/migrationscripts/archived/run.go
similarity index 81%
copy from plugins/github/models/migrationscripts/20220728_add_runs_table.go
copy to plugins/github/models/migrationscripts/archived/run.go
index 04ee10e6..b6146a03 100644
--- a/plugins/github/models/migrationscripts/20220728_add_runs_table.go
+++ b/plugins/github/models/migrationscripts/archived/run.go
@@ -15,19 +15,14 @@ See the License for the specific language governing 
permissions and
 limitations under the License.
 */
 
-package migrationscripts
+package archived
 
 import (
-       "context"
-       "github.com/apache/incubator-devlake/errors"
-       "time"
-
        "github.com/apache/incubator-devlake/models/migrationscripts/archived"
-       "gorm.io/gorm"
+       "time"
 )
 
-type GithubRun20220728 struct {
-       archived.NoPKModel
+type GithubRun struct {
        ConnectionId     uint64     `gorm:"primaryKey"`
        RepoId           int        `gorm:"primaryKey"`
        ID               int64      `json:"id" 
gorm:"primaryKey;autoIncrement:false"`
@@ -57,28 +52,9 @@ type GithubRun20220728 struct {
        RerunURL         string     `json:"rerun_url" gorm:"type:varchar(255)"`
        WorkflowURL      string     `json:"workflow_url" 
gorm:"type:varchar(255)"`
        Type             string     `json:"type" gorm:"type:varchar(255)"`
+       archived.NoPKModel
 }
 
-func (GithubRun20220728) TableName() string {
+func (GithubRun) TableName() string {
        return "_tool_github_runs"
 }
-
-type addGithubRunsTable struct{}
-
-func (u *addGithubRunsTable) Up(ctx context.Context, db *gorm.DB) errors.Error 
{
-       // create table
-       err := db.Migrator().CreateTable(GithubRun20220728{})
-       if err != nil {
-               return errors.Default.Wrap(err, "create table _tool_github_runs 
error")
-       }
-       return nil
-
-}
-
-func (*addGithubRunsTable) Version() uint64 {
-       return 20220728000001
-}
-
-func (*addGithubRunsTable) Name() string {
-       return "Github add github_runs table"
-}
diff --git a/plugins/github/models/migrationscripts/register.go 
b/plugins/github/models/migrationscripts/register.go
index d8d3b356..7af63c8c 100644
--- a/plugins/github/models/migrationscripts/register.go
+++ b/plugins/github/models/migrationscripts/register.go
@@ -18,12 +18,12 @@ limitations under the License.
 package migrationscripts
 
 import (
-       "github.com/apache/incubator-devlake/migration"
+       "github.com/apache/incubator-devlake/plugins/core"
 )
 
 // All return all the migration scripts
-func All() []migration.Script {
-       return []migration.Script{
+func All() []core.MigrationScript {
+       return []core.MigrationScript{
                new(addInitTables),
                new(addGithubRunsTable),
                new(addGithubJobsTable),

Reply via email to