- Add MinIO S3-compatible storage to docker-compose (dev, staging, prod) - Create migrations 103-108 (waveform_url, user_folders, user_files, user_storage_quotas, gear_items.is_public, gear_images) - Add Go models: UserFile, UserFolder, StorageQuota, GearImage - Add WaveformURL to Track model, IsPublic + GearImages to GearItem model
34 lines
1 KiB
Go
34 lines
1 KiB
Go
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
|
|
}
|