You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.5 KiB
63 lines
2.5 KiB
package console
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
"yunyan/lego/sys/postgres"
|
|
)
|
|
|
|
// AppProduct 应用/产品:SaaS 里的一个应用名(如 Voitrans / Lumi / EchoMeet)。
|
|
// 存 console 主库(postgres.GetSys())。一个 AppProduct 下挂多条区域部署(app_registry,按应用名 app_name 关联):
|
|
// - 现有部署(existing):直接把已部署的应用区域加进来(填 base_url/service_dsn)。
|
|
// - 待部署(pending):选一个部署目标环境(app_environment),记录关联、状态 pending,DSN 部署后回填。
|
|
type AppProduct struct {
|
|
Id uint32 `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
|
|
Name string `gorm:"column:name;size:64;uniqueIndex" json:"name"` // 应用名,如 Voitrans(账号作用域 Account.Apps 按名绑定)
|
|
ImageName string `gorm:"column:image_name;size:128" json:"image_name"` // 该应用默认镜像名(部署时用,可空,被环境/部署行覆盖)
|
|
Remark string `gorm:"column:remark;size:255" json:"remark"`
|
|
Enabled bool `gorm:"column:enabled" json:"enabled"`
|
|
Createtime int64 `gorm:"column:createtime" json:"createtime"`
|
|
Updatetime int64 `gorm:"column:updatetime" json:"updatetime"`
|
|
}
|
|
|
|
func (AppProduct) TableName() string { return comm.TableAppProduct }
|
|
|
|
// ---- 应用/产品表 CRUD(console 主库 postgres)----
|
|
|
|
// listProducts 返回全部应用(按 id 升序)。
|
|
func (this *modelComp) listProducts() (models []*AppProduct, err error) {
|
|
models = make([]*AppProduct, 0)
|
|
err = postgres.Find(comm.TableAppProduct, &models, "")
|
|
return
|
|
}
|
|
|
|
// getProduct 按 id 取应用。
|
|
func (this *modelComp) getProduct(id uint32) (model *AppProduct, err error) {
|
|
model = &AppProduct{}
|
|
err = postgres.FindOne(comm.TableAppProduct, model, "id=?", id)
|
|
return
|
|
}
|
|
|
|
// getProductByName 按名称取应用(新增时判重)。
|
|
func (this *modelComp) getProductByName(name string) (model *AppProduct, err error) {
|
|
model = &AppProduct{}
|
|
err = postgres.FindOne(comm.TableAppProduct, model, "name=?", name)
|
|
return
|
|
}
|
|
|
|
// addProduct 新增应用(Insert 后 model.Id 被回填)。
|
|
func (this *modelComp) addProduct(model *AppProduct) (err error) {
|
|
err = postgres.Insert(comm.TableAppProduct, model)
|
|
return
|
|
}
|
|
|
|
// saveProduct 更新应用。
|
|
func (this *modelComp) saveProduct(model *AppProduct) (err error) {
|
|
err = postgres.Save(comm.TableAppProduct, model)
|
|
return
|
|
}
|
|
|
|
// delProduct 删除应用。
|
|
func (this *modelComp) delProduct(id uint32) (err error) {
|
|
err = postgres.Delete(comm.TableAppProduct, "id=?", id)
|
|
return
|
|
}
|
|
|