mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-05 00:31:54 +08:00
NSRecords增加mxPriority字段
This commit is contained in:
73
internal/db/models/nameservers/ns_record_dao.go
Normal file
73
internal/db/models/nameservers/ns_record_dao.go
Normal file
@@ -0,0 +1,73 @@
|
||||
//go:build !plus
|
||||
|
||||
package nameservers
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
const (
|
||||
NSRecordStateEnabled = 1 // 已启用
|
||||
NSRecordStateDisabled = 0 // 已禁用
|
||||
)
|
||||
|
||||
type NSRecordDAO dbs.DAO
|
||||
|
||||
func NewNSRecordDAO() *NSRecordDAO {
|
||||
return dbs.NewDAO(&NSRecordDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeNSRecords",
|
||||
Model: new(NSRecord),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*NSRecordDAO)
|
||||
}
|
||||
|
||||
var SharedNSRecordDAO *NSRecordDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedNSRecordDAO = NewNSRecordDAO()
|
||||
})
|
||||
}
|
||||
|
||||
// EnableNSRecord 启用条目
|
||||
func (this *NSRecordDAO) EnableNSRecord(tx *dbs.Tx, id uint64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Set("state", NSRecordStateEnabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// DisableNSRecord 禁用条目
|
||||
func (this *NSRecordDAO) DisableNSRecord(tx *dbs.Tx, id uint64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Set("state", NSRecordStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// FindEnabledNSRecord 查找启用中的条目
|
||||
func (this *NSRecordDAO) FindEnabledNSRecord(tx *dbs.Tx, id uint64) (*NSRecord, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
State(NSRecordStateEnabled).
|
||||
Find()
|
||||
if result == nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.(*NSRecord), err
|
||||
}
|
||||
|
||||
// FindNSRecordName 根据主键查找名称
|
||||
func (this *NSRecordDAO) FindNSRecordName(tx *dbs.Tx, id uint64) (string, error) {
|
||||
return this.Query(tx).
|
||||
Pk(id).
|
||||
Result("name").
|
||||
FindStringCol("")
|
||||
}
|
||||
6
internal/db/models/nameservers/ns_record_dao_test.go
Normal file
6
internal/db/models/nameservers/ns_record_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package nameservers_test
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
)
|
||||
@@ -11,28 +11,30 @@ type NSRecord struct {
|
||||
Name string `field:"name"` // 记录名
|
||||
Type string `field:"type"` // 类型
|
||||
Value string `field:"value"` // 值
|
||||
MxPriority uint32 `field:"mxPriority"` // MX优先级
|
||||
Ttl uint32 `field:"ttl"` // TTL(秒)
|
||||
Weight uint32 `field:"weight"` // 权重
|
||||
RouteIds dbs.JSON `field:"routeIds"` // 线路
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
Version uint64 `field:"version"` //
|
||||
Version uint64 `field:"version"` // 版本号
|
||||
State uint8 `field:"state"` // 状态
|
||||
}
|
||||
|
||||
type NSRecordOperator struct {
|
||||
Id interface{} // ID
|
||||
DomainId interface{} // 域名ID
|
||||
IsOn interface{} // 是否启用
|
||||
Description interface{} // 备注
|
||||
Name interface{} // 记录名
|
||||
Type interface{} // 类型
|
||||
Value interface{} // 值
|
||||
Ttl interface{} // TTL(秒)
|
||||
Weight interface{} // 权重
|
||||
RouteIds interface{} // 线路
|
||||
CreatedAt interface{} // 创建时间
|
||||
Version interface{} //
|
||||
State interface{} // 状态
|
||||
Id any // ID
|
||||
DomainId any // 域名ID
|
||||
IsOn any // 是否启用
|
||||
Description any // 备注
|
||||
Name any // 记录名
|
||||
Type any // 类型
|
||||
Value any // 值
|
||||
MxPriority any // MX优先级
|
||||
Ttl any // TTL(秒)
|
||||
Weight any // 权重
|
||||
RouteIds any // 线路
|
||||
CreatedAt any // 创建时间
|
||||
Version any // 版本号
|
||||
State any // 状态
|
||||
}
|
||||
|
||||
func NewNSRecordOperator() *NSRecordOperator {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -719,16 +719,3 @@ func upgradeV0_4_11(db *dbs.DB) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// v0.5.7
|
||||
func upgradeV0_5_7(db *dbs.DB) error {
|
||||
// node task versions
|
||||
{
|
||||
_, err := db.Exec("UPDATE edgeNodeTasks SET version=0 WHERE LENGTH(version)=19")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -176,3 +176,16 @@ func upgradeV0_5_6(db *dbs.DB) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// v0.5.7
|
||||
func upgradeV0_5_7(db *dbs.DB) error {
|
||||
// node task versions
|
||||
{
|
||||
_, err := db.Exec("UPDATE edgeNodeTasks SET version=0 WHERE LENGTH(version)=19")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -252,21 +252,3 @@ func TestUpgradeSQLData_v0_5_3(t *testing.T) {
|
||||
t.Log("ok")
|
||||
}
|
||||
|
||||
func TestUpgradeSQLData_v0_5_7(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
_ = db.Close()
|
||||
}()
|
||||
err = upgradeV0_5_7(db)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("ok")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user