修改SQL对比算法

This commit is contained in:
刘祥超
2020-11-16 23:30:47 +08:00
parent 1c703dd013
commit e76ba5cc6b
21 changed files with 588 additions and 1512 deletions

View File

@@ -1,7 +1,7 @@
package teaconst
const (
Version = "0.0.1"
Version = "0.0.2"
ProductName = "Edge API"
ProcessName = "edge-api"

View File

@@ -862,7 +862,7 @@ func (this *ServerDAO) createEvent() error {
return SharedSysEventDAO.CreateEvent(NewServerChangeEvent())
}
// 查询当前服务的ClusterId
// 查询当前服务的集群ID
func (this *ServerDAO) FindServerClusterId(serverId int64) (int64, error) {
return this.Query().
Pk(serverId).
@@ -870,6 +870,14 @@ func (this *ServerDAO) FindServerClusterId(serverId int64) (int64, error) {
FindInt64Col(0)
}
// 查询服务的DNS名称
func (this *ServerDAO) FindServerDNSName(serverId int64) (string, error) {
return this.Query().
Pk(serverId).
Result("dnsName").
FindStringCol("")
}
// 生成DNS Name
func (this *ServerDAO) genDNSName() (string, error) {
for {

View File

@@ -903,6 +903,52 @@ func (this *ServerService) FindAllEnabledServersDNSWithClusterId(ctx context.Con
return &pb.FindAllEnabledServersDNSWithClusterIdResponse{Servers: result}, nil
}
// 查找单个服务的DNS信息
func (this *ServerService) FindEnabledServerDNS(ctx context.Context, req *pb.FindEnabledServerDNSRequest) (*pb.FindEnabledServerDNSResponse, error) {
// 校验请求
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
if err != nil {
return nil, err
}
dnsName, err := models.SharedServerDAO.FindServerDNSName(req.ServerId)
if err != nil {
return nil, err
}
clusterId, err := models.SharedServerDAO.FindServerClusterId(req.ServerId)
if err != nil {
return nil, err
}
var pbDomain *pb.DNSDomain = nil
if clusterId > 0 {
clusterDNS, err := models.SharedNodeClusterDAO.FindClusterDNSInfo(clusterId)
if err != nil {
return nil, err
}
if clusterDNS != nil {
domainId := int64(clusterDNS.DnsDomainId)
if domainId > 0 {
domain, err := models.SharedDNSDomainDAO.FindEnabledDNSDomain(domainId)
if err != nil {
return nil, err
}
if domain != nil {
pbDomain = &pb.DNSDomain{
Id: domainId,
Name: domain.Name,
}
}
}
}
}
return &pb.FindEnabledServerDNSResponse{
DnsName: dnsName,
Domain: pbDomain,
}, nil
}
// 自动同步DNS状态
func (this *ServerService) notifyServerDNSChanged(serverId int64) error {
clusterId, err := models.SharedServerDAO.FindServerClusterId(serverId)

16
internal/setup/sql.go Normal file

File diff suppressed because one or more lines are too long

256
internal/setup/sql_dump.go Normal file
View File

@@ -0,0 +1,256 @@
package setup
import (
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/types"
"regexp"
"strings"
)
var recordsTables = []*SQLRecordsTable{
{
TableName: "edgeRegionCities",
UniqueFields: []string{"name", "provinceId"},
},
{
TableName: "edgeRegionCountries",
UniqueFields: []string{"name"},
},
{
TableName: "edgeRegionProvinces",
UniqueFields: []string{"name", "countryId"},
},
}
type SQLDump struct {
}
func NewSQLDump() *SQLDump {
return &SQLDump{}
}
// 导出数据
func (this *SQLDump) Dump(db *dbs.DB) (result *SQLDumpResult, err error) {
result = &SQLDumpResult{}
tableNames, err := db.TableNames()
if err != nil {
return result, err
}
for _, tableName := range tableNames {
// 忽略一些分表
if strings.HasPrefix(tableName, "edgeHTTPAccessLogs_") {
continue
}
table, err := db.FindFullTable(tableName)
if err != nil {
return nil, err
}
sqlTable := &SQLTable{
Name: table.Name,
Engine: table.Engine,
Charset: table.Collation,
Definition: regexp.MustCompile(" AUTO_INCREMENT=\\d+").ReplaceAllString(table.Code, ""),
}
// 字段
fields := []*SQLField{}
for _, field := range table.Fields {
fields = append(fields, &SQLField{
Name: field.Name,
Definition: field.Definition(),
})
}
sqlTable.Fields = fields
// 索引
indexes := []*SQLIndex{}
for _, index := range table.Indexes {
indexes = append(indexes, &SQLIndex{
Name: index.Name,
Definition: index.Definition(),
})
}
sqlTable.Indexes = indexes
// Records
records := []*SQLRecord{}
recordsTable := this.findRecordsTable(tableName)
if recordsTable != nil {
ones, _, err := db.FindOnes("SELECT * FROM " + tableName + " ORDER BY id ASC")
if err != nil {
return result, err
}
for _, one := range ones {
record := &SQLRecord{
Id: one.GetInt64("id"),
Values: map[string]string{},
UniqueFields: recordsTable.UniqueFields,
}
for k, v := range one {
record.Values[k] = types.String(v)
}
records = append(records, record)
}
}
sqlTable.Records = records
result.Tables = append(result.Tables, sqlTable)
}
return
}
// 应用数据
func (this *SQLDump) Apply(db *dbs.DB, newResult *SQLDumpResult) (ops []string, err error) {
currentResult, err := this.Dump(db)
if err != nil {
return nil, err
}
// 新增表格
for _, newTable := range newResult.Tables {
oldTable := currentResult.FindTable(newTable.Name)
if oldTable == nil {
ops = append(ops, "+ table "+newTable.Name)
_, err = db.Exec(newTable.Definition)
if err != nil {
return nil, err
}
} else if oldTable.Definition != newTable.Definition {
// 对比字段
// +
for _, newField := range newTable.Fields {
oldField := oldTable.FindField(newField.Name)
if oldField == nil {
ops = append(ops, "+ "+newTable.Name+" "+newField.Name)
_, err = db.Exec("ALTER TABLE " + newTable.Name + " ADD " + newField.Name + " " + newField.Definition)
if err != nil {
return nil, err
}
} else if oldField.Definition != newField.Definition {
ops = append(ops, "* "+newTable.Name+" "+newField.Name)
_, err = db.Exec("ALTER TABLE " + newTable.Name + " MODIFY " + newField.Name + " " + newField.Definition)
if err != nil {
return nil, err
}
}
}
// 对比索引
// +
for _, newIndex := range newTable.Indexes {
oldIndex := oldTable.FindIndex(newIndex.Name)
if oldIndex == nil {
ops = append(ops, "+ index "+newTable.Name+" "+newIndex.Name)
_, err = db.Exec("ALTER TABLE " + newTable.Name + " ADD " + newIndex.Definition)
if err != nil {
return nil, err
}
} else if oldIndex.Definition != newIndex.Definition {
ops = append(ops, "* index "+newTable.Name+" "+newIndex.Name)
_, err = db.Exec("ALTER TABLE " + newTable.Name + " DROP KEY " + newIndex.Name)
if err != nil {
return nil, err
}
_, err = db.Exec("ALTER TABLE " + newTable.Name + " ADD " + newIndex.Definition)
if err != nil {
return nil, err
}
}
}
// -
for _, oldIndex := range oldTable.Indexes {
newIndex := newTable.FindIndex(oldIndex.Name)
if newIndex == nil {
ops = append(ops, "- index "+oldTable.Name+" "+oldIndex.Name)
_, err = db.Exec("ALTER TABLE " + oldTable.Name + " DROP KEY " + oldIndex.Name)
if err != nil {
return nil, err
}
}
}
// 对比字段
// -
for _, oldField := range oldTable.Fields {
newField := newTable.FindField(oldField.Name)
if newField == nil {
ops = append(ops, "- field "+oldTable.Name+" "+oldField.Name)
_, err = db.Exec("ALTER TABLE " + oldTable.Name + " DROP COLUMN " + oldField.Name)
if err != nil {
return nil, err
}
}
}
}
// 对比记录
// +
for _, record := range newTable.Records {
queryArgs := []string{}
queryValues := []interface{}{}
valueStrings := []string{}
for _, field := range record.UniqueFields {
queryArgs = append(queryArgs, field+"=?")
queryValues = append(queryValues, record.Values[field])
valueStrings = append(valueStrings, record.Values[field])
}
one, err := db.FindOne("SELECT * FROM "+newTable.Name+" WHERE "+strings.Join(queryArgs, " AND "), queryValues...)
if err != nil {
return nil, err
}
if one == nil {
ops = append(ops, "+ record "+newTable.Name+" "+strings.Join(valueStrings, ", "))
params := []string{}
args := []string{}
values := []interface{}{}
for k, v := range record.Values {
if k == "id" {
continue
}
params = append(params, "`"+k+"`")
args = append(args, "?")
values = append(values, v)
}
_, err = db.Exec("INSERT INTO "+newTable.Name+" ("+strings.Join(params, ", ")+") VALUES ("+strings.Join(args, ", ")+")", values...)
if err != nil {
return nil, err
}
} else if !record.ValuesEquals(one) {
ops = append(ops, "* record "+newTable.Name+" "+strings.Join(valueStrings, ", "))
args := []string{}
values := []interface{}{}
for k, v := range record.Values {
if k == "id" {
continue
}
args = append(args, k+"=?")
values = append(values, v)
}
values = append(values, one.GetInt("id"))
_, err = db.Exec("UPDATE " + newTable.Name + " SET " + strings.Join(args, ", ") + " WHERE id=?", values...)
if err != nil {
return nil, err
}
}
}
}
// 减少表格
// 由于我们不删除任何表格,所以这里什么都不做
return
}
// 查找有记录的表
func (this *SQLDump) findRecordsTable(tableName string) *SQLRecordsTable {
for _, table := range recordsTables {
if table.TableName == tableName {
return table
}
}
return nil
}

View File

@@ -0,0 +1,14 @@
package setup
type SQLDumpResult struct {
Tables []*SQLTable `json:"tables"`
}
func (this *SQLDumpResult) FindTable(tableName string) *SQLTable {
for _, table := range this.Tables {
if table.Name == tableName {
return table
}
}
return nil
}

View File

@@ -0,0 +1,77 @@
package setup
import (
"encoding/json"
"github.com/iwind/TeaGo/dbs"
"testing"
)
func TestSQLDump_Dump(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",
})
dump := NewSQLDump()
result, err := dump.Dump(db)
if err != nil {
t.Fatal(err)
}
// Table
for _, table := range result.Tables {
_ = table
//t.Log(table.Name, table.Engine, table.Charset)
/**for _, field := range table.Fields {
t.Log("===", field.Name, ":", field.Definition)
}**/
/**for _, index := range table.Indexes {
t.Log("===", index.Name, ":", index.Definition)
}**/
/**for _, record := range table.Records {
t.Log(record.Id, record.Values)
}**/
}
data, err := json.Marshal(result)
if err != nil {
t.Fatal(err)
}
t.Log(len(data), "bytes")
}
func TestSQLDump_Apply(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",
})
dump := NewSQLDump()
result, err := dump.Dump(db)
if err != nil {
t.Fatal(err)
}
db2, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
Driver: "mysql",
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_new?charset=utf8mb4&timeout=30s",
Prefix: "edge",
})
if err != nil {
t.Fatal(err)
}
ops, err := dump.Apply(db2, result)
if err != nil {
t.Fatal(err)
}
t.Log("ok")
if len(ops) > 0 {
for _, op := range ops {
t.Log("", op)
}
}
}

View File

@@ -3,21 +3,20 @@ package setup
import (
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
"github.com/TeaOSLab/EdgeAPI/internal/errors"
"github.com/TeaOSLab/EdgeAPI/internal/setup/sqls"
_ "github.com/go-sql-driver/mysql"
"github.com/go-yaml/yaml"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
stringutil "github.com/iwind/TeaGo/utils/string"
"io/ioutil"
"sort"
"strings"
"time"
)
var LatestSQLResult = &SQLDumpResult{}
// 安装或升级SQL执行器
type SQLExecutor struct {
dbConfig *dbs.DBConfig
@@ -49,113 +48,12 @@ func (this *SQLExecutor) Run() error {
return err
}
tableNames, err := db.TableNames()
sqlDump := NewSQLDump()
_, err = sqlDump.Apply(db, LatestSQLResult)
if err != nil {
return err
}
// 检查已有数据
if lists.ContainsString(tableNames, "edgeVersions") {
stmt, err := db.Prepare("SELECT version FROM " + db.TablePrefix() + "Versions")
if err != nil {
return err
}
defer func() {
_ = stmt.Close()
}()
rows, err := stmt.Query()
if err != nil {
return err
}
defer func() {
_ = rows.Close()
}()
// 对比版本
oldVersion := ""
if rows.Next() {
err = rows.Scan(&oldVersion)
if err != nil {
return errors.New("query version failed: " + err.Error())
}
}
if oldVersion == teaconst.Version {
err = this.checkData(db)
if err != nil {
return err
}
return nil
}
oldVersion = strings.Replace(oldVersion, "_", ".", -1)
upgradeVersions := []string{}
sqlMap := map[string]string{} // version => sql
for _, m := range sqls.SQLVersions {
version, _ := m["version"]
if version == "full" {
continue
}
version = strings.Replace(version, "_", ".", -1)
if len(oldVersion) == 0 || stringutil.VersionCompare(version, oldVersion) > 0 {
upgradeVersions = append(upgradeVersions, version)
sql, _ := m["sql"]
sqlMap[version] = sql
}
}
// 如果没有可以升级的版本,直接返回
if len(upgradeVersions) == 0 {
err = this.checkData(db)
if err != nil {
return err
}
return nil
}
sort.Slice(upgradeVersions, func(i, j int) bool {
return stringutil.VersionCompare(upgradeVersions[i], upgradeVersions[j]) < 0
})
// 执行升级的SQL
for _, version := range upgradeVersions {
sql := sqlMap[version]
_, err = db.Exec(sql)
if err != nil {
if !this.canIgnoreError(err) {
return errors.New("exec upgrade sql for version '" + version + "' failed: " + err.Error())
}
}
err = this.updateVersion(db, version)
if err != nil {
return err
}
}
// 检查数据
err = this.checkData(db)
if err != nil {
return err
}
return nil
}
// 全新安装
fullSQL, found := this.findFullSQL()
if !found {
return errors.New("not found full setup sql")
}
// 执行SQL
_, err = db.Exec(fullSQL)
if err != nil {
return errors.New("create tables failed: " + err.Error())
}
// 检查数据
err = this.checkData(db)
if err != nil {
@@ -165,18 +63,6 @@ func (this *SQLExecutor) Run() error {
return nil
}
// 查找完整的SQL
func (this *SQLExecutor) findFullSQL() (sql string, found bool) {
for _, m := range sqls.SQLVersions {
code, _ := m["version"]
if code == "full" {
sql, found = m["sql"]
return
}
}
return
}
// 检查数据
func (this *SQLExecutor) checkData(db *dbs.DB) error {
// 检查管理员

View File

@@ -0,0 +1,6 @@
package setup
type SQLField struct {
Name string `json:"name"`
Definition string `json:"definition"`
}

View File

@@ -0,0 +1,6 @@
package setup
type SQLIndex struct {
Name string `json:"name"`
Definition string `json:"definition"`
}

View File

@@ -0,0 +1,25 @@
package setup
import (
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
)
type SQLRecord struct {
Id int64 `json:"id"`
Values map[string]string `json:"values"`
UniqueFields []string `json:"uniqueFields"`
}
func (this *SQLRecord) ValuesEquals(values maps.Map) bool {
for k, v := range values {
if k == "id" {
continue
}
vString := types.String(v)
if this.Values[k] != vString {
return false
}
}
return true
}

View File

@@ -0,0 +1,6 @@
package setup
type SQLRecordsTable struct {
TableName string
UniqueFields []string
}

View File

@@ -0,0 +1,38 @@
package setup
type SQLTable struct {
Name string `json:"name"`
Engine string `json:"engine"`
Charset string `json:"charset"`
Definition string `json:"definition"`
Fields []*SQLField `json:"fields"`
Indexes []*SQLIndex `json:"indexes"`
Records []*SQLRecord `json:"records"`
}
func (this *SQLTable) FindField(fieldName string) *SQLField {
for _, field := range this.Fields {
if field.Name == fieldName {
return field
}
}
return nil
}
func (this *SQLTable) FindIndex(indexName string) *SQLIndex {
for _, index := range this.Indexes {
if index.Name == indexName {
return index
}
}
return nil
}
func (this *SQLTable) FindRecord(id int64) *SQLRecord {
for _, record := range this.Records {
if record.Id == id {
return record
}
}
return nil
}

View File

@@ -1,642 +0,0 @@
// generated
package sqls
var SQL_full = "CREATE TABLE `edgeAPINodes` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `clusterId` int(11) unsigned DEFAULT '0' COMMENT '专用集群ID',\n" +
" `uniqueId` varchar(32) DEFAULT NULL COMMENT '唯一ID',\n" +
" `secret` varchar(32) DEFAULT NULL COMMENT '密钥',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `description` varchar(1024) DEFAULT NULL COMMENT '描述',\n" +
" `http` json DEFAULT NULL COMMENT '监听的HTTP配置',\n" +
" `https` json DEFAULT NULL COMMENT '监听的HTTPS配置',\n" +
" `accessAddrs` json DEFAULT NULL COMMENT '外部访问地址',\n" +
" `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `weight` int(11) unsigned DEFAULT '0' COMMENT '权重',\n" +
" `status` json DEFAULT NULL COMMENT '运行状态',\n" +
" PRIMARY KEY (`id`),\n" +
" UNIQUE KEY `uniqueId` (`uniqueId`) USING BTREE\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='API节点';\n" +
"CREATE TABLE `edgeAPITokens` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `nodeId` varchar(32) DEFAULT NULL COMMENT '节点ID',\n" +
" `secret` varchar(255) DEFAULT NULL COMMENT '节点密钥',\n" +
" `role` varchar(64) DEFAULT NULL COMMENT '节点角色',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`),\n" +
" KEY `nodeId` (`nodeId`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='API令牌管理';\n" +
"CREATE TABLE `edgeAdmins` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `username` varchar(64) DEFAULT NULL COMMENT '用户名',\n" +
" `password` varchar(32) DEFAULT NULL COMMENT '密码',\n" +
" `fullname` varchar(64) DEFAULT NULL COMMENT '全名',\n" +
" `isSuper` tinyint(1) unsigned DEFAULT '0' COMMENT '是否为超级管理员',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `updatedAt` bigint(11) unsigned DEFAULT '0' COMMENT '修改时间',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管理员';\n" +
"CREATE TABLE `edgeDBNodes` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `role` varchar(255) DEFAULT NULL COMMENT '数据库角色',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `description` varchar(1024) DEFAULT NULL COMMENT '描述',\n" +
" `host` varchar(255) DEFAULT NULL COMMENT '主机',\n" +
" `port` int(11) unsigned DEFAULT '0' COMMENT '端口',\n" +
" `database` varchar(255) DEFAULT NULL COMMENT '数据库名称',\n" +
" `username` varchar(255) DEFAULT NULL COMMENT '用户名',\n" +
" `password` varchar(255) DEFAULT NULL COMMENT '密码',\n" +
" `charset` varchar(255) DEFAULT NULL COMMENT '通讯字符集',\n" +
" `connTimeout` int(11) unsigned DEFAULT '0' COMMENT '连接超时时间(秒)',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `weight` int(11) unsigned DEFAULT '0' COMMENT '权重',\n" +
" `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='数据库节点';\n" +
"CREATE TABLE `edgeFileChunks` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `fileId` int(11) unsigned DEFAULT '0' COMMENT '文件ID',\n" +
" `data` longblob COMMENT '分块内容',\n" +
" PRIMARY KEY (`id`),\n" +
" KEY `fileId` (`fileId`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文件片段';\n" +
"CREATE TABLE `edgeFiles` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `description` varchar(255) DEFAULT NULL COMMENT '文件描述',\n" +
" `filename` varchar(255) DEFAULT NULL COMMENT '文件名',\n" +
" `size` int(11) unsigned DEFAULT '0' COMMENT '文件尺寸',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n" +
" `type` varchar(64) DEFAULT '' COMMENT '类型',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`),\n" +
" KEY `type` (`type`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文件管理';\n" +
"CREATE TABLE `edgeHTTPAccessLogPolicies` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `templateId` int(11) unsigned DEFAULT '0' COMMENT '模版ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `type` varchar(255) DEFAULT NULL COMMENT '存储类型',\n" +
" `options` json DEFAULT NULL COMMENT '存储选项',\n" +
" `conds` json DEFAULT NULL COMMENT '请求条件',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='访问日志策略';\n" +
"CREATE TABLE `edgeHTTPAccessLogs` (\n" +
" `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `serverId` int(11) unsigned DEFAULT '0' COMMENT '服务ID',\n" +
" `nodeId` int(11) unsigned DEFAULT '0' COMMENT '节点ID',\n" +
" `status` int(3) unsigned DEFAULT '0' COMMENT '状态码',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `content` json DEFAULT NULL COMMENT '日志内容',\n" +
" `requestId` varchar(128) DEFAULT NULL COMMENT '请求ID',\n" +
" PRIMARY KEY (`id`),\n" +
" KEY `serverId` (`serverId`),\n" +
" KEY `nodeId` (`nodeId`),\n" +
" KEY `serverId_status` (`serverId`,`status`),\n" +
" KEY `requestId` (`requestId`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n" +
"CREATE TABLE `edgeHTTPAccessLogs_20201010` (\n" +
" `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `serverId` int(11) unsigned DEFAULT '0' COMMENT '服务ID',\n" +
" `nodeId` int(11) unsigned DEFAULT '0' COMMENT '节点ID',\n" +
" `status` int(3) unsigned DEFAULT '0' COMMENT '状态码',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `content` json DEFAULT NULL COMMENT '日志内容',\n" +
" `day` varchar(8) DEFAULT NULL COMMENT '日期Ymd',\n" +
" PRIMARY KEY (`id`),\n" +
" KEY `serverId` (`serverId`),\n" +
" KEY `nodeId` (`nodeId`),\n" +
" KEY `serverId_status` (`serverId`,`status`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n" +
"CREATE TABLE `edgeHTTPCachePolicies` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `templateId` int(11) unsigned DEFAULT '0' COMMENT '模版ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `capacity` json DEFAULT NULL COMMENT '容量数据',\n" +
" `maxKeys` bigint(20) unsigned DEFAULT '0' COMMENT '最多Key值',\n" +
" `maxSize` json DEFAULT NULL COMMENT '最大缓存内容尺寸',\n" +
" `type` varchar(255) DEFAULT NULL COMMENT '存储类型',\n" +
" `options` json DEFAULT NULL COMMENT '存储选项',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `description` varchar(1024) DEFAULT NULL COMMENT '描述',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='HTTP缓存策略';\n" +
"CREATE TABLE `edgeHTTPFirewallPolicies` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `templateId` int(11) unsigned DEFAULT '0' COMMENT '模版ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `description` varchar(1024) DEFAULT NULL COMMENT '描述',\n" +
" `inbound` json DEFAULT NULL COMMENT '入站规则',\n" +
" `outbound` json DEFAULT NULL COMMENT '出站规则',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='HTTP防火墙';\n" +
"CREATE TABLE `edgeHTTPFirewallRuleGroups` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `description` varchar(1024) DEFAULT NULL COMMENT '描述',\n" +
" `code` varchar(255) DEFAULT NULL COMMENT '代号',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `sets` json DEFAULT NULL COMMENT '规则集列表',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='防火墙规则分组';\n" +
"CREATE TABLE `edgeHTTPFirewallRuleSets` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `code` varchar(255) DEFAULT NULL COMMENT '代号',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `description` varchar(1024) DEFAULT NULL COMMENT '描述',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `rules` json DEFAULT NULL COMMENT '规则列表',\n" +
" `connector` varchar(64) DEFAULT NULL COMMENT '规则之间的关系',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `action` varchar(255) DEFAULT NULL COMMENT '执行的动作',\n" +
" `actionOptions` json DEFAULT NULL COMMENT '动作的选项',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='防火墙规则集';\n" +
"CREATE TABLE `edgeHTTPFirewallRules` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `description` varchar(1024) DEFAULT NULL COMMENT '说明',\n" +
" `param` varchar(1024) DEFAULT NULL COMMENT '参数',\n" +
" `operator` varchar(255) DEFAULT NULL COMMENT '操作符',\n" +
" `value` varchar(1024) DEFAULT NULL COMMENT '对比值',\n" +
" `isCaseInsensitive` tinyint(1) unsigned DEFAULT '1' COMMENT '是否大小写不敏感',\n" +
" `checkpointOptions` json DEFAULT NULL COMMENT '检查点参数',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='防火墙规则';\n" +
"CREATE TABLE `edgeHTTPGzips` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `level` int(11) unsigned DEFAULT '0' COMMENT '压缩级别',\n" +
" `minLength` json DEFAULT NULL COMMENT '可压缩最小值',\n" +
" `maxLength` json DEFAULT NULL COMMENT '可压缩最大值',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `conds` json DEFAULT NULL COMMENT '条件',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Gzip配置';\n" +
"CREATE TABLE `edgeHTTPHeaderPolicies` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `isOn` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '是否启用',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `addHeaders` json DEFAULT NULL COMMENT '添加的Header',\n" +
" `addTrailers` json DEFAULT NULL COMMENT '添加的Trailers',\n" +
" `setHeaders` json DEFAULT NULL COMMENT '设置Header',\n" +
" `replaceHeaders` json DEFAULT NULL COMMENT '替换Header内容',\n" +
" `expires` json DEFAULT NULL COMMENT 'Expires单独设置',\n" +
" `deleteHeaders` json DEFAULT NULL COMMENT '删除的Headers',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Header定义';\n" +
"CREATE TABLE `edgeHTTPHeaders` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `templateId` int(11) unsigned DEFAULT '0' COMMENT '模版ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `value` varchar(1024) DEFAULT NULL COMMENT '值',\n" +
" `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n" +
" `status` json DEFAULT NULL COMMENT '状态码设置',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='HTTP Header';\n" +
"CREATE TABLE `edgeHTTPLocations` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `templateId` int(11) unsigned DEFAULT '0' COMMENT '模版ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `parentId` int(11) unsigned DEFAULT '0' COMMENT '父级ID',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `pattern` varchar(1024) DEFAULT NULL COMMENT '匹配规则',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `description` varchar(1024) DEFAULT NULL COMMENT '描述',\n" +
" `webId` int(11) unsigned DEFAULT '0' COMMENT 'Web配置ID',\n" +
" `reverseProxy` json DEFAULT NULL COMMENT '反向代理',\n" +
" `urlPrefix` varchar(1024) DEFAULT NULL COMMENT 'URL前缀',\n" +
" `isBreak` tinyint(1) unsigned DEFAULT '0' COMMENT '是否终止匹配',\n" +
" `conds` json DEFAULT NULL COMMENT '匹配条件',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='路径规则配置';\n" +
"CREATE TABLE `edgeHTTPPages` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '0' COMMENT '是否启用',\n" +
" `statusList` json DEFAULT NULL COMMENT '状态列表',\n" +
" `url` varchar(1024) DEFAULT NULL COMMENT '页面URL',\n" +
" `newStatus` int(3) DEFAULT NULL COMMENT '新状态码',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='特殊页面';\n" +
"CREATE TABLE `edgeHTTPRewriteRules` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `templateId` int(11) unsigned DEFAULT '0' COMMENT '模版ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `pattern` varchar(1024) DEFAULT NULL COMMENT '匹配规则',\n" +
" `replace` varchar(1024) DEFAULT NULL COMMENT '跳转后的地址',\n" +
" `mode` varchar(255) DEFAULT NULL COMMENT '替换模式',\n" +
" `redirectStatus` int(3) unsigned DEFAULT '0' COMMENT '跳转的状态码',\n" +
" `proxyHost` varchar(255) DEFAULT NULL COMMENT '代理的主机名',\n" +
" `isBreak` tinyint(1) unsigned DEFAULT '1' COMMENT '是否终止解析',\n" +
" `withQuery` tinyint(1) unsigned DEFAULT '1' COMMENT '是否保留URI参数',\n" +
" `conds` json DEFAULT NULL COMMENT '匹配条件',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='重写规则';\n" +
"CREATE TABLE `edgeHTTPWebs` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `templateId` int(11) unsigned DEFAULT '0' COMMENT '模版ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `root` json DEFAULT NULL COMMENT '根目录',\n" +
" `charset` json DEFAULT NULL COMMENT '字符集',\n" +
" `shutdown` json DEFAULT NULL COMMENT '临时关闭页面配置',\n" +
" `pages` json DEFAULT NULL COMMENT '特殊页面',\n" +
" `redirectToHttps` json DEFAULT NULL COMMENT '跳转到HTTPS设置',\n" +
" `indexes` json DEFAULT NULL COMMENT '首页文件列表',\n" +
" `maxRequestBodySize` json DEFAULT NULL COMMENT '最大允许的请求内容尺寸',\n" +
" `requestHeader` json DEFAULT NULL COMMENT '请求Header配置',\n" +
" `responseHeader` json DEFAULT NULL COMMENT '响应Header配置',\n" +
" `accessLog` json DEFAULT NULL COMMENT '访问日志配置',\n" +
" `stat` json DEFAULT NULL COMMENT '统计配置',\n" +
" `gzip` json DEFAULT NULL COMMENT 'Gzip配置',\n" +
" `cache` json DEFAULT NULL COMMENT '缓存配置',\n" +
" `firewall` json DEFAULT NULL COMMENT '防火墙设置',\n" +
" `locations` json DEFAULT NULL COMMENT '路径规则配置',\n" +
" `websocket` json DEFAULT NULL COMMENT 'Websocket设置',\n" +
" `rewriteRules` json DEFAULT NULL COMMENT '重写规则配置',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='HTTP Web';\n" +
"CREATE TABLE `edgeHTTPWebsockets` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `handshakeTimeout` json DEFAULT NULL COMMENT '握手超时时间',\n" +
" `allowAllOrigins` tinyint(1) unsigned DEFAULT '1' COMMENT '是否支持所有源',\n" +
" `allowedOrigins` json DEFAULT NULL COMMENT '支持的源域名列表',\n" +
" `requestSameOrigin` tinyint(1) unsigned DEFAULT '1' COMMENT '是否请求一样的Origin',\n" +
" `requestOrigin` varchar(255) DEFAULT NULL COMMENT '请求Origin',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Websocket设置';\n" +
"CREATE TABLE `edgeLogs` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `level` varchar(32) DEFAULT NULL COMMENT '级别',\n" +
" `description` varchar(255) DEFAULT NULL COMMENT '描述',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `action` varchar(255) DEFAULT NULL COMMENT '动作',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `providerId` int(11) unsigned DEFAULT '0' COMMENT '供应商ID',\n" +
" `ip` varchar(32) DEFAULT NULL COMMENT 'IP地址',\n" +
" `type` varchar(255) DEFAULT 'admin' COMMENT '类型admin, user',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='操作日志';\n" +
"CREATE TABLE `edgeNodeClusters` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `useAllAPINodes` tinyint(1) unsigned DEFAULT '1' COMMENT '是否使用所有API节点',\n" +
" `apiNodes` json DEFAULT NULL COMMENT '使用的API节点',\n" +
" `installDir` varchar(512) DEFAULT NULL COMMENT '安装目录',\n" +
" `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `grantId` int(11) unsigned DEFAULT '0' COMMENT '默认认证方式',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点集群';\n" +
"CREATE TABLE `edgeNodeGrants` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `method` varchar(64) DEFAULT NULL COMMENT '登录方式',\n" +
" `username` varchar(255) DEFAULT NULL COMMENT '用户名',\n" +
" `password` varchar(255) DEFAULT NULL COMMENT '密码',\n" +
" `su` tinyint(1) unsigned DEFAULT '1' COMMENT '是否需要su',\n" +
" `privateKey` varchar(4096) DEFAULT NULL COMMENT '密钥',\n" +
" `description` varchar(255) DEFAULT NULL COMMENT '备注',\n" +
" `nodeId` int(11) unsigned DEFAULT '0' COMMENT '专有节点',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点授权';\n" +
"CREATE TABLE `edgeNodeGroups` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点分组';\n" +
"CREATE TABLE `edgeNodeIPAddresses` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `nodeId` int(11) unsigned DEFAULT '0' COMMENT '节点ID',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `ip` varchar(128) DEFAULT NULL COMMENT 'IP地址',\n" +
" `description` varchar(255) DEFAULT NULL COMMENT '描述',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n" +
" PRIMARY KEY (`id`),\n" +
" KEY `nodeId` (`nodeId`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点IP地址';\n" +
"CREATE TABLE `edgeNodeLogins` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `nodeId` int(11) unsigned DEFAULT '0' COMMENT '节点ID',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `type` varchar(255) DEFAULT NULL COMMENT '类型ssh,agent',\n" +
" `params` json DEFAULT NULL COMMENT '配置参数',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`),\n" +
" KEY `nodeId` (`nodeId`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点登录信息';\n" +
"CREATE TABLE `edgeNodeLogs` (\n" +
" `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `role` varchar(64) DEFAULT NULL COMMENT '节点角色',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `tag` varchar(255) DEFAULT NULL COMMENT '标签',\n" +
" `description` varchar(1024) DEFAULT NULL COMMENT '描述',\n" +
" `level` varchar(32) DEFAULT NULL COMMENT '级别',\n" +
" `nodeId` int(11) unsigned DEFAULT '0' COMMENT '节点ID',\n" +
" `day` varchar(8) DEFAULT NULL COMMENT '日期',\n" +
" PRIMARY KEY (`id`),\n" +
" KEY `level` (`level`),\n" +
" KEY `day` (`day`),\n" +
" KEY `role_nodeId` (`role`,`nodeId`) USING BTREE\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点日志';\n" +
"CREATE TABLE `edgeNodeRegions` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点区域';\n" +
"CREATE TABLE `edgeNodes` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `uniqueId` varchar(32) DEFAULT NULL COMMENT '节点ID',\n" +
" `secret` varchar(32) DEFAULT NULL COMMENT '密钥',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '节点名',\n" +
" `code` varchar(255) DEFAULT NULL COMMENT '代号',\n" +
" `clusterId` int(11) unsigned DEFAULT '0' COMMENT '集群ID',\n" +
" `regionId` int(11) unsigned DEFAULT '0' COMMENT '区域ID',\n" +
" `groupId` int(11) unsigned DEFAULT '0' COMMENT '分组ID',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `status` json DEFAULT NULL COMMENT '最新的状态',\n" +
" `version` int(11) unsigned DEFAULT '0' COMMENT '当前版本号',\n" +
" `latestVersion` int(11) unsigned DEFAULT '0' COMMENT '最后版本号',\n" +
" `installDir` varchar(512) DEFAULT NULL COMMENT '安装目录',\n" +
" `isInstalled` tinyint(1) unsigned DEFAULT '0' COMMENT '是否已安装',\n" +
" `installStatus` json DEFAULT NULL COMMENT '安装状态',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `connectedAPINodes` json DEFAULT NULL COMMENT '当前连接的API节点',\n" +
" `maxCPU` int(4) unsigned DEFAULT '0' COMMENT '可以使用的最多CPU',\n" +
" PRIMARY KEY (`id`),\n" +
" KEY `uniqueId` (`uniqueId`),\n" +
" KEY `clusterId` (`clusterId`),\n" +
" KEY `groupId` (`groupId`),\n" +
" KEY `regionId` (`regionId`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点';\n" +
"CREATE TABLE `edgeOrigins` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `version` int(11) unsigned DEFAULT '0' COMMENT '版本',\n" +
" `addr` json DEFAULT NULL COMMENT '地址',\n" +
" `description` varchar(512) DEFAULT NULL COMMENT '描述',\n" +
" `code` varchar(255) DEFAULT NULL COMMENT '代号',\n" +
" `weight` int(11) unsigned DEFAULT '0' COMMENT '权重',\n" +
" `connTimeout` json DEFAULT NULL COMMENT '连接超时',\n" +
" `readTimeout` json DEFAULT NULL COMMENT '读超时',\n" +
" `idleTimeout` json DEFAULT NULL COMMENT '空闲连接超时',\n" +
" `maxFails` int(11) unsigned DEFAULT '0' COMMENT '最多失败次数',\n" +
" `maxConns` int(11) unsigned DEFAULT '0' COMMENT '最大并发连接数',\n" +
" `maxIdleConns` int(11) unsigned DEFAULT '0' COMMENT '最多空闲连接数',\n" +
" `httpRequestURI` varchar(1024) DEFAULT NULL COMMENT '转发后的请求URI',\n" +
" `httpRequestHeader` json DEFAULT NULL COMMENT '请求Header配置',\n" +
" `httpResponseHeader` json DEFAULT NULL COMMENT '响应Header配置',\n" +
" `host` varchar(255) DEFAULT NULL COMMENT '自定义主机名',\n" +
" `healthCheck` json DEFAULT NULL COMMENT '健康检查设置',\n" +
" `cert` json DEFAULT NULL COMMENT '证书设置',\n" +
" `ftp` json DEFAULT NULL COMMENT 'FTP相关设置',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='源站';\n" +
"CREATE TABLE `edgeProviders` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `username` varchar(64) DEFAULT NULL COMMENT '用户名',\n" +
" `password` varchar(32) DEFAULT NULL COMMENT '密码',\n" +
" `fullname` varchar(64) DEFAULT NULL COMMENT '真实姓名',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `updatedAt` bigint(11) unsigned DEFAULT '0' COMMENT '修改时间',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='供应商';\n" +
"CREATE TABLE `edgeReverseProxies` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `templateId` int(11) unsigned DEFAULT '0' COMMENT '模版ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `scheduling` json DEFAULT NULL COMMENT '调度算法',\n" +
" `primaryOrigins` json DEFAULT NULL COMMENT '主要源站',\n" +
" `backupOrigins` json DEFAULT NULL COMMENT '备用源站',\n" +
" `stripPrefix` varchar(255) DEFAULT NULL COMMENT '去除URL前缀',\n" +
" `requestHost` varchar(255) DEFAULT NULL COMMENT '请求Host',\n" +
" `requestURI` varchar(1024) DEFAULT NULL COMMENT '请求URI',\n" +
" `autoFlush` tinyint(1) unsigned DEFAULT '0' COMMENT '是否自动刷新缓冲区',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='反向代理配置';\n" +
"CREATE TABLE `edgeSSLCertGroups` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '分组名',\n" +
" `order` int(11) unsigned DEFAULT '0' COMMENT '分组排序',\n" +
" `state` tinyint(1) unsigned DEFAULT '0' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='证书分组';\n" +
"CREATE TABLE `edgeSSLCerts` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `updatedAt` bigint(11) unsigned DEFAULT '0' COMMENT '修改时间',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '证书名',\n" +
" `description` varchar(1024) DEFAULT NULL COMMENT '描述',\n" +
" `certData` blob COMMENT '证书内容',\n" +
" `keyData` blob COMMENT '密钥内容',\n" +
" `serverName` varchar(255) DEFAULT NULL COMMENT '证书使用的主机名',\n" +
" `isCA` tinyint(1) unsigned DEFAULT '0' COMMENT '是否为CA证书',\n" +
" `groupIds` json DEFAULT NULL COMMENT '证书分组',\n" +
" `timeBeginAt` bigint(11) unsigned DEFAULT '0' COMMENT '开始时间',\n" +
" `timeEndAt` bigint(11) unsigned DEFAULT '0' COMMENT '结束时间',\n" +
" `dnsNames` json DEFAULT NULL COMMENT 'DNS名称列表',\n" +
" `commonNames` json DEFAULT NULL COMMENT '发行单位列表',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='SSL证书';\n" +
"CREATE TABLE `edgeSSLPolicies` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `certs` json DEFAULT NULL COMMENT '证书列表',\n" +
" `clientCACerts` json DEFAULT NULL COMMENT '客户端证书',\n" +
" `clientAuthType` int(11) unsigned DEFAULT '0' COMMENT '客户端认证类型',\n" +
" `minVersion` varchar(32) DEFAULT NULL COMMENT '支持的SSL最小版本',\n" +
" `cipherSuitesIsOn` tinyint(1) unsigned DEFAULT '0' COMMENT '是否自定义加密算法套件',\n" +
" `cipherSuites` json DEFAULT NULL COMMENT '加密算法套件',\n" +
" `hsts` json DEFAULT NULL COMMENT 'HSTS设置',\n" +
" `http2Enabled` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用HTTP/2',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='SSL配置策略';\n" +
"CREATE TABLE `edgeServerGroups` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='服务分组';\n" +
"CREATE TABLE `edgeServers` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n" +
" `type` varchar(64) DEFAULT NULL COMMENT '服务类型',\n" +
" `name` varchar(255) DEFAULT NULL COMMENT '名称',\n" +
" `description` varchar(512) DEFAULT NULL COMMENT '描述',\n" +
" `serverNames` json DEFAULT NULL COMMENT '域名列表',\n" +
" `http` json DEFAULT NULL COMMENT 'HTTP配置',\n" +
" `https` json DEFAULT NULL COMMENT 'HTTPS配置',\n" +
" `tcp` json DEFAULT NULL COMMENT 'TCP配置',\n" +
" `tls` json DEFAULT NULL COMMENT 'TLS配置',\n" +
" `unix` json DEFAULT NULL COMMENT 'Unix配置',\n" +
" `udp` json DEFAULT NULL COMMENT 'UDP配置',\n" +
" `webId` int(11) unsigned DEFAULT '0' COMMENT 'WEB配置',\n" +
" `reverseProxy` json DEFAULT NULL COMMENT '反向代理配置',\n" +
" `groupIds` json DEFAULT NULL COMMENT '分组ID列表',\n" +
" `config` json DEFAULT NULL COMMENT '服务配置,自动生成',\n" +
" `configMd5` varchar(32) DEFAULT NULL COMMENT 'Md5',\n" +
" `clusterId` int(11) unsigned DEFAULT '0' COMMENT '集群ID',\n" +
" `includeNodes` json DEFAULT NULL COMMENT '部署条件',\n" +
" `excludeNodes` json DEFAULT NULL COMMENT '节点排除条件',\n" +
" `version` int(11) unsigned DEFAULT '0' COMMENT '版本号',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`),\n" +
" KEY `userId` (`userId`),\n" +
" KEY `adminId` (`adminId`),\n" +
" KEY `isUpdating_state` (`state`) USING BTREE\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='服务';\n" +
"CREATE TABLE `edgeSysEvents` (\n" +
" `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `type` varchar(255) DEFAULT NULL COMMENT '类型',\n" +
" `params` json DEFAULT NULL COMMENT '参数',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统事件';\n" +
"CREATE TABLE `edgeSysLockers` (\n" +
" `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `key` varchar(255) DEFAULT NULL COMMENT '键值',\n" +
" `version` bigint(20) unsigned DEFAULT '0' COMMENT '版本号',\n" +
" `timeoutAt` bigint(11) unsigned DEFAULT '0' COMMENT '超时时间',\n" +
" PRIMARY KEY (`id`),\n" +
" UNIQUE KEY `key` (`key`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='并发锁';\n" +
"CREATE TABLE `edgeSysSettings` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `code` varchar(255) DEFAULT NULL COMMENT '代号',\n" +
" `value` json DEFAULT NULL COMMENT '配置值',\n" +
" PRIMARY KEY (`id`),\n" +
" UNIQUE KEY `code` (`code`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统配置';\n" +
"CREATE TABLE `edgeTCPFirewallPolicies` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `adminId` int(11) DEFAULT NULL COMMENT '管理员ID',\n" +
" `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n" +
" `templateId` int(11) unsigned DEFAULT '0' COMMENT '模版ID',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='TCP防火墙';\n" +
"CREATE TABLE `edgeUsers` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `username` varchar(64) DEFAULT NULL COMMENT '用户名',\n" +
" `password` varchar(32) DEFAULT NULL COMMENT '密码',\n" +
" `fullname` varchar(64) DEFAULT NULL COMMENT '真实姓名',\n" +
" `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n" +
" `updatedAt` bigint(11) unsigned DEFAULT '0' COMMENT '修改时间',\n" +
" `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户';\n" +
"CREATE TABLE `edgeVersions` (\n" +
" `id` bigint(16) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n" +
" `version` varchar(64) DEFAULT NULL,\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='数据库结构版本';\n" +
"\n"

View File

@@ -1,6 +0,0 @@
// generated
package sqls
var SQLVersions = []map[string]string{
{"version": "full", "sql": SQL_full},
}