Backend: Improve file share and sync entities #225
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
61d7d751fa
commit
ec051e5481
2 changed files with 18 additions and 20 deletions
|
@ -13,13 +13,12 @@ type FileShare struct {
|
||||||
FileID uint `gorm:"primary_key;auto_increment:false"`
|
FileID uint `gorm:"primary_key;auto_increment:false"`
|
||||||
AccountID uint `gorm:"primary_key;auto_increment:false"`
|
AccountID uint `gorm:"primary_key;auto_increment:false"`
|
||||||
RemoteName string `gorm:"primary_key;auto_increment:false;type:varbinary(256)"`
|
RemoteName string `gorm:"primary_key;auto_increment:false;type:varbinary(256)"`
|
||||||
ShareStatus string `gorm:"type:varbinary(16);"`
|
Status string `gorm:"type:varbinary(16);"`
|
||||||
ShareError string `gorm:"type:varbinary(512);"`
|
Error string `gorm:"type:varbinary(512);"`
|
||||||
RetryCount uint
|
|
||||||
File *File
|
File *File
|
||||||
Account *Account
|
Account *Account
|
||||||
RemoveAt sql.NullTime
|
SharedAt sql.NullTime
|
||||||
PushedAt sql.NullTime
|
ExpiresAt sql.NullTime
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,11 @@ import (
|
||||||
|
|
||||||
// FileSync represents a one-to-many relation between File and Account for syncing with remote services.
|
// FileSync represents a one-to-many relation between File and Account for syncing with remote services.
|
||||||
type FileSync struct {
|
type FileSync struct {
|
||||||
FileID uint `gorm:"primary_key;auto_increment:false"`
|
FileID uint `gorm:"index;"`
|
||||||
AccountID uint `gorm:"primary_key;auto_increment:false"`
|
AccountID uint `gorm:"primary_key;auto_increment:false"`
|
||||||
RemoteName string `gorm:"type:varbinary(256);"`
|
RemoteName string `gorm:"type:varbinary(256);primary_key;auto_increment:false"`
|
||||||
SyncStatus string `gorm:"type:varbinary(16);"`
|
Status string `gorm:"type:varbinary(16);"`
|
||||||
SyncError string `gorm:"type:varbinary(512);"`
|
Error string `gorm:"type:varbinary(512);"`
|
||||||
RetryCount uint
|
|
||||||
File *File
|
File *File
|
||||||
Account *Account
|
Account *Account
|
||||||
SyncedAt sql.NullTime
|
SyncedAt sql.NullTime
|
||||||
|
@ -29,10 +28,10 @@ func (FileSync) TableName() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFileSync creates a new entity.
|
// NewFileSync creates a new entity.
|
||||||
func NewFileSync(fileID, accountID uint) *FileSync {
|
func NewFileSync(accountID uint, remoteName string) *FileSync {
|
||||||
result := &FileSync{
|
result := &FileSync{
|
||||||
FileID: fileID,
|
|
||||||
AccountID: accountID,
|
AccountID: accountID,
|
||||||
|
RemoteName: remoteName,
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -43,7 +42,7 @@ func (m *FileSync) FirstOrCreate(db *gorm.DB) *FileSync {
|
||||||
mutex.Db.Lock()
|
mutex.Db.Lock()
|
||||||
defer mutex.Db.Unlock()
|
defer mutex.Db.Unlock()
|
||||||
|
|
||||||
if err := db.FirstOrCreate(m, "file_id = ? AND account_id = ?", m.FileID, m.AccountID).Error; err != nil {
|
if err := db.FirstOrCreate(m, "account_id = ? AND remote_name = ?", m.AccountID, m.RemoteName).Error; err != nil {
|
||||||
log.Errorf("file sync: %s", err)
|
log.Errorf("file sync: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue