This commit is contained in:
Melody Becker 2024-09-16 17:42:16 +02:00
parent 1a97c35e22
commit 704d0e8750
4 changed files with 49 additions and 1 deletions

View file

@ -1 +1,16 @@
services: name # Development compose file
services:
postgres:
image: docker.io/postgres:16.4
restart: unless-stopped
environment:
POSTGRES_PASSWORD: linstrom
POSTGRES_USER: linstrom
POSTGRES_DB: linstrom
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 1s
timeout: 5s
retries: 10
ports:
- 5432:5432

View file

@ -36,6 +36,13 @@ func main() {
log.Fatal().Err(err).Msg("Failed to start cache") log.Fatal().Err(err).Msg("Failed to start cache")
} }
// var store *storage.Storage
// if config.GlobalConfig.Storage.DbIsPostgres != nil && *config.GlobalConfig.Storage.DbIsPostgres {
// store, err = storage.NewStoragePostgres(config.GlobalConfig.Storage.DatabaseUrl, storageCache)
// } else {
// store, err = storage.NewStorageSqlite(config.GlobalConfig.Storage.DatabaseUrl, storageCache)
// }
//
store, err := storage.NewStorage(config.GlobalConfig.Storage.BuildPostgresDSN(), storageCache) store, err := storage.NewStorage(config.GlobalConfig.Storage.BuildPostgresDSN(), storageCache)
if err != nil { if err != nil {

View file

@ -2,6 +2,8 @@ package storage
import ( import (
"time" "time"
"gorm.io/gorm"
) )
// Auto-generate string names for the various constants // Auto-generate string names for the various constants
@ -34,3 +36,25 @@ type InboundJob struct {
// If from an inbox, include the owner id here // If from an inbox, include the owner id here
InboxOwner *string `gorm:"->;<-create"` InboxOwner *string `gorm:"->;<-create"`
} }
func (s *Storage) AddNewInboundJob(data []byte, source InboundJobSource, inboxOwner *string) {
newJob := InboundJob{
RawData: data,
Source: source,
InboxOwner: inboxOwner,
}
s.db.Create(&newJob)
}
// Get the specified amount of jobs, sorted by age (oldest first)
func (s *Storage) GetOldestInboundJobs(amount int) ([]InboundJob, error) {
jobs := []InboundJob{}
switch err := s.db.Order("id asc, created_at asc").Limit(amount).Find(jobs).Error; err {
case gorm.ErrRecordNotFound:
return nil, ErrEntryNotFound
case nil:
return jobs, nil
default:
return nil, err
}
}

View file

@ -45,6 +45,8 @@ func storageFromEmptyDb(db *gorm.DB, cache *cache.Cache) (*Storage, error) {
Note{}, Note{},
Role{}, Role{},
PasskeySession{}, PasskeySession{},
InboundJob{},
OutboundJob{},
) )
if err != nil { if err != nil {
return nil, err return nil, err