- 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
33 lines
1,001 B
Go
33 lines
1,001 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type UserFolder struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
|
|
UserID uuid.UUID `gorm:"type:uuid;not null" json:"user_id"`
|
|
Name string `gorm:"size:255;not null" json:"name"`
|
|
ParentID *uuid.UUID `gorm:"type:uuid" json:"parent_id,omitempty"`
|
|
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:"-"`
|
|
Parent *UserFolder `gorm:"foreignKey:ParentID;constraint:OnDelete:CASCADE" json:"-"`
|
|
Children []UserFolder `gorm:"foreignKey:ParentID" json:"children,omitempty"`
|
|
Files []UserFile `gorm:"foreignKey:FolderID" json:"files,omitempty"`
|
|
}
|
|
|
|
func (UserFolder) TableName() string {
|
|
return "user_folders"
|
|
}
|
|
|
|
func (m *UserFolder) BeforeCreate(tx *gorm.DB) error {
|
|
if m.ID == uuid.Nil {
|
|
m.ID = uuid.New()
|
|
}
|
|
return nil
|
|
}
|