diff --git a/internal/biz/app.go b/internal/biz/app.go index 893214b2..95cf63e6 100644 --- a/internal/biz/app.go +++ b/internal/biz/app.go @@ -8,11 +8,11 @@ import ( type App struct { ID uint `gorm:"primaryKey" json:"id"` - Slug string `gorm:"not null;unique" json:"slug"` - Channel string `gorm:"not null" json:"channel"` - Version string `gorm:"not null" json:"version"` - Show bool `gorm:"not null" json:"show"` - ShowOrder int `gorm:"not null" json:"show_order"` + Slug string `gorm:"not null;default:'';unique" json:"slug"` + Channel string `gorm:"not null;default:''" json:"channel"` + Version string `gorm:"not null;default:''" json:"version"` + Show bool `gorm:"not null;default:false" json:"show"` + ShowOrder int `gorm:"not null;default:0" json:"show_order"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/internal/biz/cache.go b/internal/biz/cache.go index 01a23159..9bcabc9d 100644 --- a/internal/biz/cache.go +++ b/internal/biz/cache.go @@ -11,7 +11,7 @@ const ( type Cache struct { Key CacheKey `gorm:"primaryKey" json:"key"` - Value string `gorm:"not null" json:"value"` + Value string `gorm:"not null;default:''" json:"value"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/internal/biz/cert.go b/internal/biz/cert.go index 26f0c58e..9388b1be 100644 --- a/internal/biz/cert.go +++ b/internal/biz/cert.go @@ -10,16 +10,16 @@ import ( type Cert struct { ID uint `gorm:"primaryKey" json:"id"` - AccountID uint `gorm:"not null" json:"account_id"` // 关联的 ACME 账户 ID - WebsiteID uint `gorm:"not null" json:"website_id"` // 关联的网站 ID - DNSID uint `gorm:"not null" json:"dns_id"` // 关联的 DNS ID - Type string `gorm:"not null" json:"type"` // 证书类型 (P256, P384, 2048, 3072, 4096) - Domains []string `gorm:"not null;serializer:json" json:"domains"` - AutoRenew bool `gorm:"not null" json:"auto_renew"` // 自动续签 - CertURL string `gorm:"not null" json:"cert_url"` // 证书 URL (续签时使用) - Cert string `gorm:"not null" json:"cert"` // 证书内容 - Key string `gorm:"not null" json:"key"` // 私钥内容 - Script string `gorm:"not null" json:"script"` // 部署脚本 + AccountID uint `gorm:"not null;default:0" json:"account_id"` // 关联的 ACME 账户 ID + WebsiteID uint `gorm:"not null;default:0" json:"website_id"` // 关联的网站 ID + DNSID uint `gorm:"not null;default:0" json:"dns_id"` // 关联的 DNS ID + Type string `gorm:"not null;default:''" json:"type"` // 证书类型 (P256, P384, 2048, 3072, 4096) + Domains []string `gorm:"not null;default:'[]';serializer:json" json:"domains"` + AutoRenew bool `gorm:"not null;default:false" json:"auto_renew"` // 自动续签 + CertURL string `gorm:"not null;default:''" json:"cert_url"` // 证书 URL (续签时使用) + Cert string `gorm:"not null;default:''" json:"cert"` // 证书内容 + Key string `gorm:"not null;default:''" json:"key"` // 私钥内容 + Script string `gorm:"not null;default:''" json:"script"` // 部署脚本 CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` diff --git a/internal/biz/cert_account.go b/internal/biz/cert_account.go index dedbfbed..0dc4b2db 100644 --- a/internal/biz/cert_account.go +++ b/internal/biz/cert_account.go @@ -8,12 +8,12 @@ import ( type CertAccount struct { ID uint `gorm:"primaryKey" json:"id"` - Email string `gorm:"not null" json:"email"` - CA string `gorm:"not null" json:"ca"` // CA 提供商 (letsencrypt, zerossl, sslcom, google, buypass) - Kid string `gorm:"not null" json:"kid"` - HmacEncoded string `gorm:"not null" json:"hmac_encoded"` - PrivateKey string `gorm:"not null" json:"private_key"` - KeyType string `gorm:"not null" json:"key_type"` // 密钥类型 (P256, P384, 2048, 3072, 4096) + Email string `gorm:"not null;default:''" json:"email"` + CA string `gorm:"not null;default:'letsencrypt'" json:"ca"` // CA 提供商 (letsencrypt, zerossl, sslcom, google, buypass) + Kid string `gorm:"not null;default:''" json:"kid"` + HmacEncoded string `gorm:"not null;default:''" json:"hmac_encoded"` + PrivateKey string `gorm:"not null;default:''" json:"private_key"` + KeyType string `gorm:"not null;default:'P256'" json:"key_type"` // 密钥类型 (P256, P384, 2048, 3072, 4096) CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` diff --git a/internal/biz/cert_dns.go b/internal/biz/cert_dns.go index 5d69dfe6..a18b461d 100644 --- a/internal/biz/cert_dns.go +++ b/internal/biz/cert_dns.go @@ -9,8 +9,8 @@ import ( type CertDNS struct { ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"not null" json:"name"` // 备注名称 - Type string `gorm:"not null" json:"type"` // DNS 提供商 (tencent, aliyun, cloudflare) + Name string `gorm:"not null;default:''" json:"name"` // 备注名称 + Type string `gorm:"not null;default:'aliyun'" json:"type"` // DNS 提供商 (tencent, aliyun, cloudflare) Data acme.DNSParam `gorm:"not null;serializer:json" json:"dns_param"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` diff --git a/internal/biz/cron.go b/internal/biz/cron.go index 1d36d644..de8a3a27 100644 --- a/internal/biz/cron.go +++ b/internal/biz/cron.go @@ -8,12 +8,12 @@ import ( type Cron struct { ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"not null;unique" json:"name"` - Status bool `gorm:"not null" json:"status"` - Type string `gorm:"not null" json:"type"` - Time string `gorm:"not null" json:"time"` - Shell string `gorm:"not null" json:"shell"` - Log string `gorm:"not null" json:"log"` + Name string `gorm:"not null;default:'';unique" json:"name"` + Status bool `gorm:"not null;default:false" json:"status"` + Type string `gorm:"not null;default:''" json:"type"` + Time string `gorm:"not null;default:''" json:"time"` + Shell string `gorm:"not null;default:''" json:"shell"` + Log string `gorm:"not null;default:''" json:"log"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/internal/biz/database_server.go b/internal/biz/database_server.go index caae8e22..b6aa8fab 100644 --- a/internal/biz/database_server.go +++ b/internal/biz/database_server.go @@ -19,14 +19,14 @@ const ( type DatabaseServer struct { ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"not null;unique" json:"name"` - Type DatabaseType `gorm:"not null" json:"type"` - Host string `gorm:"not null" json:"host"` - Port uint `gorm:"not null" json:"port"` - Username string `gorm:"not null" json:"username"` - Password string `gorm:"not null" json:"password"` + Name string `gorm:"not null;default:'';unique" json:"name"` + Type DatabaseType `gorm:"not null;default:''" json:"type"` + Host string `gorm:"not null;default:''" json:"host"` + Port uint `gorm:"not null;default:0" json:"port"` + Username string `gorm:"not null;default:''" json:"username"` + Password string `gorm:"not null;default:''" json:"password"` Status DatabaseServerStatus `gorm:"-:all" json:"status"` - Remark string `gorm:"not null" json:"remark"` + Remark string `gorm:"not null;default:''" json:"remark"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/internal/biz/database_user.go b/internal/biz/database_user.go index 962c63ce..84f1132f 100644 --- a/internal/biz/database_user.go +++ b/internal/biz/database_user.go @@ -19,13 +19,13 @@ const ( type DatabaseUser struct { ID uint `gorm:"primaryKey" json:"id"` - ServerID uint `gorm:"not null" json:"server_id"` - Username string `gorm:"not null" json:"username"` - Password string `gorm:"not null" json:"password"` - Host string `gorm:"not null" json:"host"` // 仅 mysql - Status DatabaseUserStatus `gorm:"-:all" json:"status"` // 仅显示 - Privileges []string `gorm:"-:all" json:"privileges"` // 仅显示 - Remark string `gorm:"not null" json:"remark"` + ServerID uint `gorm:"not null;default:0" json:"server_id"` + Username string `gorm:"not null;default:''" json:"username"` + Password string `gorm:"not null;default:''" json:"password"` + Host string `gorm:"not null;default:''" json:"host"` // 仅 mysql + Status DatabaseUserStatus `gorm:"-:all" json:"status"` // 仅显示 + Privileges []string `gorm:"-:all" json:"privileges"` // 仅显示 + Remark string `gorm:"not null;default:''" json:"remark"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` diff --git a/internal/biz/monitor.go b/internal/biz/monitor.go index 0455546c..e3072019 100644 --- a/internal/biz/monitor.go +++ b/internal/biz/monitor.go @@ -9,7 +9,7 @@ import ( type Monitor struct { ID uint `gorm:"primaryKey" json:"id"` - Info types.CurrentInfo `gorm:"not null;serializer:json" json:"info"` + Info types.CurrentInfo `gorm:"not null;default:'{}';serializer:json" json:"info"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/internal/biz/setting.go b/internal/biz/setting.go index 10f75091..87a76a85 100644 --- a/internal/biz/setting.go +++ b/internal/biz/setting.go @@ -23,8 +23,8 @@ const ( type Setting struct { ID uint `gorm:"primaryKey" json:"id"` - Key SettingKey `gorm:"not null;unique" json:"key"` - Value string `gorm:"not null" json:"value"` + Key SettingKey `gorm:"not null;default:'';unique" json:"key"` + Value string `gorm:"not null;default:''" json:"value"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/internal/biz/ssh.go b/internal/biz/ssh.go index ba107b7c..b88367a2 100644 --- a/internal/biz/ssh.go +++ b/internal/biz/ssh.go @@ -13,11 +13,11 @@ import ( type SSH struct { ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"not null" json:"name"` - Host string `gorm:"not null" json:"host"` - Port uint `gorm:"not null" json:"port"` - Config ssh.ClientConfig `gorm:"not null;serializer:json" json:"config"` - Remark string `gorm:"not null" json:"remark"` + Name string `gorm:"not null;default:''" json:"name"` + Host string `gorm:"not null;default:''" json:"host"` + Port uint `gorm:"not null;default:0" json:"port"` + Config ssh.ClientConfig `gorm:"not null;default:'{}';serializer:json" json:"config"` + Remark string `gorm:"not null;default:''" json:"remark"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/internal/biz/task.go b/internal/biz/task.go index 35a8d586..5711b6d4 100644 --- a/internal/biz/task.go +++ b/internal/biz/task.go @@ -13,10 +13,10 @@ const ( type Task struct { ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"not null;index" json:"name"` + Name string `gorm:"not null;default:'';index" json:"name"` Status TaskStatus `gorm:"not null;default:'waiting'" json:"status"` - Shell string `gorm:"not null" json:"-"` - Log string `gorm:"not null" json:"log"` + Shell string `gorm:"not null;default:''" json:"-"` + Log string `gorm:"not null;default:''" json:"log"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/internal/biz/user.go b/internal/biz/user.go index 652e81ef..0233f620 100644 --- a/internal/biz/user.go +++ b/internal/biz/user.go @@ -8,9 +8,9 @@ import ( type User struct { ID uint `gorm:"primaryKey" json:"id"` - Username string `gorm:"not null;unique" json:"username"` - Password string `gorm:"not null" json:"password"` - Email string `gorm:"not null" json:"email"` + Username string `gorm:"not null;default:'';unique" json:"username"` + Password string `gorm:"not null;default:''" json:"password"` + Email string `gorm:"not null;default:''" json:"email"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` diff --git a/internal/biz/website.go b/internal/biz/website.go index 7bd382a2..c69b089a 100644 --- a/internal/biz/website.go +++ b/internal/biz/website.go @@ -10,11 +10,11 @@ import ( type Website struct { ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"not null;unique" json:"name"` + Name string `gorm:"not null;default:'';unique" json:"name"` Status bool `gorm:"not null;default:true" json:"status"` - Path string `gorm:"not null" json:"path"` - Https bool `gorm:"not null" json:"https"` - Remark string `gorm:"not null" json:"remark"` + Path string `gorm:"not null;default:''" json:"path"` + Https bool `gorm:"not null;default:false" json:"https"` + Remark string `gorm:"not null;default:''" json:"remark"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"`