Sync
This commit is contained in:
parent
94197780e1
commit
2977f09245
32 changed files with 763 additions and 936 deletions
|
@ -1,8 +1,6 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
|
@ -35,34 +33,16 @@ func storageFromEmptyDb(db *gorm.DB) (*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
|
||||
db.AutoMigrate(
|
||||
placeholderMediaFile,
|
||||
placeholderUser(),
|
||||
placeholderNote,
|
||||
placeholderServer,
|
||||
MediaFile{},
|
||||
Account{},
|
||||
RemoteServer{},
|
||||
Note{},
|
||||
Role{},
|
||||
PasskeySession{},
|
||||
)
|
||||
// Afterwards add the placeholder entries for each table.
|
||||
// FirstOrCreate either creates a new entry or retrieves the first matching one
|
||||
// We only care about the creation if there is none yet, so no need to carry the result over
|
||||
if res := db.FirstOrCreate(placeholderMediaFile); res.Error != nil {
|
||||
return nil, fmt.Errorf("failed to add placeholder media file: %w", res.Error)
|
||||
}
|
||||
if res := db.FirstOrCreate(placeholderUser()); res.Error != nil {
|
||||
return nil, fmt.Errorf("failed to add placeholder media file: %w", res.Error)
|
||||
}
|
||||
if res := db.FirstOrCreate(placeholderNote); res.Error != nil {
|
||||
return nil, fmt.Errorf("failed to add placeholder media file: %w", res.Error)
|
||||
}
|
||||
if res := db.FirstOrCreate(placeholderServer); res.Error != nil {
|
||||
return nil, fmt.Errorf("failed to add placeholder media file: %w", res.Error)
|
||||
}
|
||||
|
||||
// And finally, build the actual storage struct
|
||||
return &Storage{
|
||||
db: db,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TODO: Placeholder. Update to proper implementation later. Including signature
|
||||
func (s *Storage) FindLocalAccount(handle string) (string, error) {
|
||||
return handle, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue