Skip to content

Commit

Permalink
only run for mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
Josip Stojak authored and Josip Stojak committed Jun 3, 2024
1 parent 27ccff9 commit 75a2789
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,31 @@ package migrationscripts
import (
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/errors"
"net/url"
)

type addPullRequestIdIndexToPullRequestCommits struct{}

func (u *addPullRequestIdIndexToPullRequestCommits) Up(basicRes context.BasicRes) errors.Error {
db := basicRes.GetDal()
err := db.Exec("ALTER TABLE pull_request_commits DROP PRIMARY KEY;")
if err != nil {
return err
func (*addPullRequestIdIndexToPullRequestCommits) Up(basicRes context.BasicRes) errors.Error {
dbUrl := basicRes.GetConfig("DB_URL")
if dbUrl == "" {
return errors.BadInput.New("DB_URL is required")
}
err = db.Exec("ALTER TABLE pull_request_commits ADD PRIMARY KEY (pull_request_id, commit_sha);")
if err != nil {
return err
u, err1 := url.Parse(dbUrl)
if err1 != nil {
return errors.Convert(err1)
}
if u.Scheme == "mysql" {
db := basicRes.GetDal()
err := db.Exec("ALTER TABLE pull_request_commits DROP PRIMARY KEY;")
if err != nil {
return err
}
err = db.Exec("ALTER TABLE pull_request_commits ADD PRIMARY KEY (pull_request_id, commit_sha);")
if err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit 75a2789

Please sign in to comment.