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 }