mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 14:06:36 +08:00
46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
package model
|
|
|
|
import "time"
|
|
|
|
type ConfigVersionSummary struct {
|
|
ID uint `json:"id"`
|
|
Version string `json:"version"`
|
|
Checksum string `json:"checksum"`
|
|
IsActive bool `json:"is_active"`
|
|
CreatedBy string `json:"created_by"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
type ConfigVersion struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
Version string `json:"version" gorm:"uniqueIndex;size:32;not null"`
|
|
SnapshotJSON string `json:"snapshot_json" gorm:"type:text;not null"`
|
|
MainConfig string `json:"main_config" gorm:"type:text;not null;default:''"`
|
|
RenderedConfig string `json:"rendered_config" gorm:"type:text;not null"`
|
|
SupportFilesJSON string `json:"support_files_json" gorm:"type:text;not null;default:'[]'"`
|
|
Checksum string `json:"checksum" gorm:"size:64;not null"`
|
|
IsActive bool `json:"is_active" gorm:"not null;default:false;index"`
|
|
CreatedBy string `json:"created_by" gorm:"size:64;not null"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func ListConfigVersionSummaries() (versions []*ConfigVersionSummary, err error) {
|
|
err = DB.Model(&ConfigVersion{}).
|
|
Select("id", "version", "checksum", "is_active", "created_by", "created_at").
|
|
Order("id desc").
|
|
Find(&versions).Error
|
|
return versions, err
|
|
}
|
|
|
|
func GetConfigVersionByID(id uint) (*ConfigVersion, error) {
|
|
version := &ConfigVersion{}
|
|
err := DB.First(version, id).Error
|
|
return version, err
|
|
}
|
|
|
|
func GetActiveConfigVersion() (*ConfigVersion, error) {
|
|
version := &ConfigVersion{}
|
|
err := DB.Where("is_active = ?", true).Order("id desc").First(version).Error
|
|
return version, err
|
|
}
|