Adding queues and storage is now postgres only
This commit is contained in:
parent
7ec0ce5a45
commit
1c2472cc2c
11 changed files with 368 additions and 31 deletions
58
storage/storage.go.old
Normal file
58
storage/storage.go.old
Normal file
|
@ -0,0 +1,58 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gitlab.com/mstarongitlab/linstrom/storage/cache"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Storage is responsible for all database, cache and media related actions
|
||||
// and serves as the lowest layer of the cake
|
||||
type Storage struct {
|
||||
db *gorm.DB
|
||||
cache *cache.Cache
|
||||
}
|
||||
|
||||
var ErrInvalidData = errors.New("invalid data")
|
||||
|
||||
// Build a new storage using sqlite as database backend
|
||||
func NewStorageSqlite(filePath string, cache *cache.Cache) (*Storage, error) {
|
||||
db, err := gorm.Open(sqlite.Open(filePath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storageFromEmptyDb(db, cache)
|
||||
}
|
||||
|
||||
func NewStoragePostgres(dbUrl string, cache *cache.Cache) (*Storage, error) {
|
||||
db, err := gorm.Open(postgres.Open(dbUrl))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storageFromEmptyDb(db, cache)
|
||||
}
|
||||
|
||||
func storageFromEmptyDb(db *gorm.DB, cache *cache.Cache) (*Storage, error) {
|
||||
// AutoMigrate ensures the db is in a state where all the structs given here
|
||||
// have their own tables and relations setup. It also updates tables if necessary
|
||||
err := db.AutoMigrate(
|
||||
MediaMetadata{},
|
||||
Account{},
|
||||
RemoteServer{},
|
||||
Note{},
|
||||
Role{},
|
||||
PasskeySession{},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// And finally, build the actual storage struct
|
||||
return &Storage{
|
||||
db: db,
|
||||
cache: cache,
|
||||
}, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue