mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 21:49:22 +00:00
54f0293f0a
* Sync interval specifed as duration string * Changed mirror interval text * make fmt * Add MinInterval for mirror sync * Use duration internally * Changed min default to 10m * make fmt * Incorrect default * Removed defaults in MustDuration() * Add Mirror interval migration * Default values corrected * Use transaction during migration * Change http 500 to page with error message * Cleanup session.commit()
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
// Copyright 2017 Gitea. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package migrations
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/go-xorm/xorm"
|
|
)
|
|
|
|
func convertIntervalToDuration(x *xorm.Engine) (err error) {
|
|
type Repository struct {
|
|
ID int64
|
|
OwnerID int64
|
|
Name string
|
|
}
|
|
type Mirror struct {
|
|
ID int64 `xorm:"pk autoincr"`
|
|
RepoID int64 `xorm:"INDEX"`
|
|
Repo *Repository `xorm:"-"`
|
|
Interval time.Duration
|
|
EnablePrune bool `xorm:"NOT NULL DEFAULT true"`
|
|
|
|
Updated time.Time `xorm:"-"`
|
|
UpdatedUnix int64 `xorm:"INDEX"`
|
|
NextUpdate time.Time `xorm:"-"`
|
|
NextUpdateUnix int64 `xorm:"INDEX"`
|
|
|
|
address string `xorm:"-"`
|
|
}
|
|
|
|
sess := x.NewSession()
|
|
defer sess.Close()
|
|
|
|
if err := sess.Begin(); err != nil {
|
|
return err
|
|
}
|
|
|
|
var mirrors []Mirror
|
|
err = sess.Table("mirror").Select("*").Find(&mirrors)
|
|
if err != nil {
|
|
return fmt.Errorf("Query repositories: %v", err)
|
|
}
|
|
for _, mirror := range mirrors {
|
|
mirror.Interval = mirror.Interval * time.Hour
|
|
_, err := sess.Id(mirror.ID).Cols("interval").Update(mirror)
|
|
if err != nil {
|
|
return fmt.Errorf("update mirror interval failed: %v", err)
|
|
}
|
|
}
|
|
|
|
return sess.Commit()
|
|
}
|