This commit is contained in:
Vladimir V Maksimov
2026-02-10 16:08:35 +03:00
parent 1f63c5fbd4
commit 8e1f17a359
9 changed files with 877 additions and 20 deletions

64
pfs_db/models.go Normal file
View File

@@ -0,0 +1,64 @@
package pfs_db
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type DirModel struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey"`
ParentID *uuid.UUID `gorm:"type:uuid;index"`
Parent *DirModel `gorm:"foreignKey:ParentID;constraint:OnDelete:CASCADE"`
Name string
OwnerID uuid.UUID
IsPublic bool
Created time.Time
LastModified time.Time
}
func (d *DirModel) BeforeCreate(tx *gorm.DB) error {
now := time.Now()
d.Created = now
d.LastModified = now
return nil
}
func (d *DirModel) BeforeUpdate(tx *gorm.DB) error {
d.LastModified = time.Now()
return nil
}
type FileModel struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey"`
DirID *uuid.UUID `gorm:"type:uuid;index"`
Dir *DirModel `gorm:"foreignKey:DirID;constraint:OnDelete:CASCADE"`
Name string
OwnerID uuid.UUID
IsPublic bool
Created time.Time
LastModified time.Time
FileData FileDataModel `gorm:"foreignKey:FileID;references:ID;constraint:OnDelete:CASCADE"`
}
func (f *FileModel) BeforeCreate(tx *gorm.DB) error {
now := time.Now()
f.Created = now
f.LastModified = now
return nil
}
func (f *FileModel) BeforeUpdate(tx *gorm.DB) error {
f.LastModified = time.Now()
return nil
}
type FileDataModel struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey"`
FileID uuid.UUID `gorm:"type:uuid;uniqueIndex;not null"`
Data []byte
}