go-tell/internal/persistence/models.go

45 lines
1.4 KiB
Go
Raw Normal View History

package persistence
import "time"
type ContentModel struct {
ID uint `gorm:"primaryKey"`
Slug string `gorm:"uniqueIndex;not null"`
Title string `gorm:"not null"`
Summary string
Body string `gorm:"not null"`
Status string `gorm:"not null;default:'draft'"`
Published bool `gorm:"not null;default:false"`
2026-09-19 15:11:12 +02:00
CategoryID uint
Category CategoryModel `gorm:"foreignKey:CategoryID"`
Badges []BadgeModel `gorm:"many2many:content_badges;joinForeignKey:ContentID;joinReferences:BadgeID"`
CreatedAt, UpdatedAt time.Time
}
2026-09-19 16:45:24 +02:00
func (ContentModel) TableName() string { return "content" }
2026-09-19 15:11:12 +02:00
type CategoryModel struct {
ID uint `gorm:"primaryKey"`
Slug string `gorm:"uniqueIndex;not null"`
Name string `gorm:"not null"`
}
func (CategoryModel) TableName() string { return "categories" }
type BadgeModel struct {
ID uint `gorm:"primaryKey"`
Name string `gorm:"uniqueIndex;not null"`
}
func (BadgeModel) TableName() string { return "badges" }
type ContentHistoryModel struct {
ID uint `gorm:"primaryKey"`
2026-09-19 16:45:24 +02:00
ContentID uint `gorm:"index;not null"`
Operation string `gorm:"not null"`
CreatedAt time.Time
2026-09-19 16:45:24 +02:00
Snapshot string `gorm:"type:jsonb;not null"`
}
2026-09-19 14:48:42 +02:00
2026-09-19 16:45:24 +02:00
func (ContentHistoryModel) TableName() string { return "content_history" }