1
0

feat(migration): migration from other services now happens in the background

This commit is contained in:
kolaente
2023-11-09 00:15:11 +01:00
parent 707bb6f89e
commit 46683a2516
10 changed files with 325 additions and 18 deletions

View File

@ -28,7 +28,8 @@ type Status struct {
ID int64 `xorm:"bigint autoincr not null unique pk" json:"id"`
UserID int64 `xorm:"bigint not null" json:"-"`
MigratorName string `xorm:"varchar(255)" json:"migrator_name"`
Created time.Time `xorm:"created not null 'created'" json:"time"`
StartedAt time.Time `xorm:"not null" json:"started_at"`
FinishedAt time.Time `xorm:"null" json:"finished_at"`
}
// TableName holds the table name for the migration status table
@ -36,19 +37,31 @@ func (s *Status) TableName() string {
return "migration_status"
}
// SetMigrationStatus sets the migration status for a user
func SetMigrationStatus(m MigratorName, u *user.User) (err error) {
// StartMigration sets the migration status for a user
func StartMigration(m MigratorName, u *user.User) (status *Status, err error) {
s := db.NewSession()
defer s.Close()
status := &Status{
status = &Status{
UserID: u.ID,
MigratorName: m.Name(),
StartedAt: time.Now(),
}
_, err = s.Insert(status)
return
}
// FinishMigration sets the finished at time and calls it a day
func FinishMigration(status *Status) (err error) {
s := db.NewSession()
defer s.Close()
status.FinishedAt = time.Now()
_, err = s.Where("id = ?", status.ID).Update(status)
return
}
// GetMigrationStatus returns the migration status for a migration and a user
func GetMigrationStatus(m MigratorName, u *user.User) (status *Status, err error) {
s := db.NewSession()