package models import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) type UserFile struct { ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"` UserID uuid.UUID `gorm:"type:uuid;not null" json:"user_id"` FolderID *uuid.UUID `gorm:"type:uuid" json:"folder_id,omitempty"` Filename string `gorm:"size:255;not null" json:"filename"` S3Key string `gorm:"size:500;not null" json:"s3_key"` SizeBytes int64 `gorm:"not null;default:0" json:"size_bytes"` MimeType string `gorm:"size:100;not null;default:'application/octet-stream'" json:"mime_type"` CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"` User User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"-"` Folder *UserFolder `gorm:"foreignKey:FolderID;constraint:OnDelete:SET NULL" json:"-"` } func (UserFile) TableName() string { return "user_files" } func (m *UserFile) BeforeCreate(tx *gorm.DB) error { if m.ID == uuid.Nil { m.ID = uuid.New() } return nil }