2022-01-31 22:30:36 +01:00
|
|
|
package sql
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-gorp/gorp/v3"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
type migration_2_8_26 struct {
|
|
|
|
db *SqlDb
|
2022-01-31 22:30:36 +01:00
|
|
|
}
|
|
|
|
|
2024-10-05 09:09:17 +02:00
|
|
|
func (m migration_2_8_26) PostApply(tx *gorp.Transaction) error {
|
2022-02-03 08:05:13 +01:00
|
|
|
rows, err := tx.Query(m.db.PrepareQuery("SELECT id, git_url FROM project__repository"))
|
2022-01-31 22:30:36 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
repoUrls := make(map[string]string)
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var id, url string
|
|
|
|
|
|
|
|
err3 := rows.Scan(&id, &url)
|
|
|
|
if err3 != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
repoUrls[id] = url
|
|
|
|
}
|
|
|
|
|
|
|
|
err = rows.Close()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for id, url := range repoUrls {
|
|
|
|
branch := "master"
|
|
|
|
parts := strings.Split(url, "#")
|
|
|
|
if len(parts) > 1 {
|
|
|
|
url, branch = parts[0], parts[1]
|
|
|
|
}
|
2022-02-03 08:05:13 +01:00
|
|
|
q := m.db.PrepareQuery("UPDATE project__repository " +
|
2022-01-31 22:30:36 +01:00
|
|
|
"SET git_url = ?, git_branch = ? " +
|
|
|
|
"WHERE id = ?")
|
|
|
|
_, err = tx.Exec(q, url, branch, id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|