Handle repos with unknown PDS
This commit is contained in:
parent
fa8b67bcc9
commit
b2003530ba
4 changed files with 29 additions and 2 deletions
12
pds/pds.go
12
pds/pds.go
|
@ -1,6 +1,8 @@
|
|||
package pds
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
@ -8,6 +10,8 @@ import (
|
|||
"github.com/uabluerail/indexer/models"
|
||||
)
|
||||
|
||||
const Unknown models.ID = 0
|
||||
|
||||
type PDS struct {
|
||||
ID models.ID `gorm:"primarykey"`
|
||||
CreatedAt time.Time
|
||||
|
@ -22,3 +26,11 @@ type PDS struct {
|
|||
func AutoMigrate(db *gorm.DB) error {
|
||||
return db.AutoMigrate(&PDS{})
|
||||
}
|
||||
|
||||
func EnsureExists(ctx context.Context, db *gorm.DB, host string) (*PDS, error) {
|
||||
remote := PDS{Host: host}
|
||||
if err := db.Model(&remote).Where(&PDS{Host: host}).FirstOrCreate(&remote).Error; err != nil {
|
||||
return nil, fmt.Errorf("failed to get PDS record from DB for %q: %w", remote.Host, err)
|
||||
}
|
||||
return &remote, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue