2023-12-27 22:59:20 +08:00
|
|
|
package persistence
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"mayfly-go/internal/db/domain/entity"
|
|
|
|
|
"mayfly-go/internal/db/domain/repository"
|
|
|
|
|
"mayfly-go/pkg/gormx"
|
|
|
|
|
"slices"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var _ repository.DbBackup = (*dbBackupRepoImpl)(nil)
|
|
|
|
|
|
|
|
|
|
type dbBackupRepoImpl struct {
|
2024-01-11 11:35:51 +08:00
|
|
|
dbJobBase[*entity.DbBackup]
|
2023-12-27 22:59:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewDbBackupRepo() repository.DbBackup {
|
|
|
|
|
return &dbBackupRepoImpl{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *dbBackupRepoImpl) GetDbNamesWithoutBackup(instanceId uint64, dbNames []string) ([]string, error) {
|
|
|
|
|
var dbNamesWithBackup []string
|
2024-01-05 08:55:34 +08:00
|
|
|
query := gormx.NewQuery(d.GetModel()).
|
2023-12-27 22:59:20 +08:00
|
|
|
Eq("db_instance_id", instanceId).
|
|
|
|
|
Eq("repeated", true)
|
|
|
|
|
if err := query.GenGdb().Pluck("db_name", &dbNamesWithBackup).Error; err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
result := make([]string, 0, len(dbNames))
|
|
|
|
|
for _, name := range dbNames {
|
|
|
|
|
if !slices.Contains(dbNamesWithBackup, name) {
|
|
|
|
|
result = append(result, name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|