veza/veza-backend-api/internal/models/cloud_file_version.go

31 lines
837 B
Go

package models
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// CloudFileVersion stores a version snapshot of a user file
type CloudFileVersion struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
FileID uuid.UUID `gorm:"type:uuid;not null" json:"file_id"`
Version int `gorm:"not null" json:"version"`
StorageKey string `gorm:"type:text;not null" json:"storage_key"`
SizeBytes int64 `gorm:"not null;default:0" json:"size_bytes"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
File *UserFile `gorm:"foreignKey:FileID;constraint:OnDelete:CASCADE" json:"-"`
}
func (CloudFileVersion) TableName() string {
return "cloud_file_versions"
}
func (m *CloudFileVersion) BeforeCreate(tx *gorm.DB) error {
if m.ID == uuid.Nil {
m.ID = uuid.New()
}
return nil
}