This commit is contained in:
GoEdgeLab
2024-07-27 14:15:25 +08:00
parent be70925770
commit 5a17ae9d79
520 changed files with 2515 additions and 762 deletions

View File

@@ -3,6 +3,10 @@ package setup
import (
"encoding/json"
"fmt"
"os"
"strconv"
"strings"
"github.com/TeaOSLab/EdgeAPI/internal/configs"
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
"github.com/TeaOSLab/EdgeAPI/internal/errors"
@@ -10,9 +14,6 @@ import (
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/cmd"
"github.com/iwind/TeaGo/types"
"os"
"strconv"
"strings"
)
type Setup struct {

View File

@@ -1,8 +1,9 @@
package setup
import (
_ "github.com/iwind/TeaGo/bootstrap"
"testing"
_ "github.com/iwind/TeaGo/bootstrap"
)
func TestSetup_Run(t *testing.T) {

View File

@@ -141,7 +141,7 @@
"name": "edgeACMETasks",
"engine": "InnoDB",
"charset": "utf8mb4_general_ci",
"definition": "CREATE TABLE `edgeACMETasks` (\n `id` bigint(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 `acmeUserId` int(11) unsigned DEFAULT '0' COMMENT 'ACME用户ID',\n `dnsDomain` varchar(255) DEFAULT NULL COMMENT 'DNS主域名',\n `dnsProviderId` bigint(11) unsigned DEFAULT '0' COMMENT 'DNS服务商',\n `domains` json DEFAULT NULL COMMENT '证书域名',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n `certId` bigint(11) unsigned DEFAULT '0' COMMENT '生成的证书ID',\n `autoRenew` tinyint(1) unsigned DEFAULT '0' COMMENT '是否自动更新',\n `authType` varchar(64) DEFAULT NULL COMMENT '认证类型',\n `authURL` varchar(1024) DEFAULT NULL COMMENT '认证URL',\n PRIMARY KEY (`id`),\n KEY `adminId` (`adminId`),\n KEY `userId` (`userId`),\n KEY `acmeUserId` (`acmeUserId`),\n KEY `certId` (`certId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='ACME任务'",
"definition": "CREATE TABLE `edgeACMETasks` (\n `id` bigint(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 `acmeUserId` int(11) unsigned DEFAULT '0' COMMENT 'ACME用户ID',\n `dnsDomain` varchar(255) DEFAULT NULL COMMENT 'DNS主域名',\n `dnsProviderId` bigint(11) unsigned DEFAULT '0' COMMENT 'DNS服务商',\n `domains` json DEFAULT NULL COMMENT '证书域名',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n `async` tinyint(1) unsigned DEFAULT '0' COMMENT 'async', \n `certId` bigint(11) unsigned DEFAULT '0' COMMENT '生成的证书ID',\n `autoRenew` tinyint(1) unsigned DEFAULT '0' COMMENT '是否自动更新',\n `status` tinyint(3) unsigned DEFAULT '0',\n `authType` varchar(64) DEFAULT NULL COMMENT '认证类型',\n `authURL` varchar(1024) DEFAULT NULL COMMENT '认证URL',\n PRIMARY KEY (`id`),\n KEY `adminId` (`adminId`),\n KEY `userId` (`userId`),\n KEY `acmeUserId` (`acmeUserId`),\n KEY `certId` (`certId`),\n KEY `async` (`async`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='ACME任务'",
"fields": [
{
"name": "id",
@@ -198,6 +198,14 @@
{
"name": "authURL",
"definition": "varchar(1024) COMMENT '认证URL'"
},
{
"name": "async",
"definition": "tinyint(1) unsigned DEFAULT '0' COMMENT 'async'"
},
{
"name": "status",
"definition": "tinyint(3) unsigned DEFAULT '0'"
}
],
"indexes": [
@@ -220,6 +228,10 @@
{
"name": "certId",
"definition": "KEY `certId` (`certId`) USING BTREE"
},
{
"name": "async",
"definition": "KEY `async` (`async`) USING BTREE"
}
],
"records": []
@@ -122093,7 +122105,7 @@
"name": "edgeNodes",
"engine": "InnoDB",
"charset": "utf8mb4_general_ci",
"definition": "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 `level` tinyint(1) unsigned DEFAULT '1' COMMENT '级别',\n `lnAddrs` json DEFAULT NULL COMMENT 'Ln级别访问地址',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `isUp` tinyint(1) unsigned DEFAULT '1' COMMENT '是否在线',\n `countUp` int(11) unsigned DEFAULT '0' COMMENT '连续在线次数',\n `countDown` int(11) unsigned DEFAULT '0' COMMENT '连续下线次数',\n `isActive` tinyint(1) unsigned DEFAULT '1' COMMENT '是否活跃',\n `inactiveNotifiedAt` bigint(11) unsigned DEFAULT '0' 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 `secondaryClusterIds` json DEFAULT NULL 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 `maxThreads` int(11) unsigned DEFAULT '0' COMMENT '最大线程数',\n `ddosProtection` json DEFAULT NULL COMMENT 'DDOS配置',\n `dnsRoutes` json DEFAULT NULL COMMENT 'DNS线路设置',\n `maxCacheDiskCapacity` json DEFAULT NULL COMMENT '硬盘缓存容量',\n `maxCacheMemoryCapacity` json DEFAULT NULL COMMENT '内存缓存容量',\n `cacheDiskDir` varchar(255) DEFAULT NULL COMMENT '主缓存目录',\n `cacheDiskSubDirs` json DEFAULT NULL COMMENT '其他缓存目录',\n `dnsResolver` json DEFAULT NULL COMMENT 'DNS解析器',\n `enableIPLists` tinyint(1) unsigned DEFAULT '1' COMMENT '启用IP名单',\n `apiNodeAddrs` json DEFAULT NULL COMMENT 'API节点地址',\n `offlineDay` varchar(8) DEFAULT NULL COMMENT '下线日期YYYYMMDD',\n `offlineIsNotified` tinyint(1) unsigned DEFAULT '0' COMMENT '下线是否已通知',\n `isBackupForCluster` tinyint(1) unsigned DEFAULT '0' COMMENT '是否为集群备用节点',\n `isBackupForGroup` tinyint(1) unsigned DEFAULT '0' COMMENT '是否为分组备用节点',\n `backupIPs` json DEFAULT NULL COMMENT '备用IP',\n `actionStatus` json DEFAULT NULL COMMENT '当前动作配置',\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='节点'",
"definition": "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 `level` tinyint(1) unsigned DEFAULT '1' COMMENT '级别',\n `lnAddrs` json DEFAULT NULL COMMENT 'Ln级别访问地址',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `isUp` tinyint(1) unsigned DEFAULT '1' COMMENT '是否在线',\n `countUp` int(11) unsigned DEFAULT '0' COMMENT '连续在线次数',\n `countDown` int(11) unsigned DEFAULT '0' COMMENT '连续下线次数',\n `isActive` tinyint(1) unsigned DEFAULT '1' COMMENT '是否活跃',\n `inactiveNotifiedAt` bigint(11) unsigned DEFAULT '0' 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 `secondaryClusterIds` json DEFAULT NULL 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 `maxThreads` int(11) unsigned DEFAULT '0' COMMENT '最大线程数',\n `ddosProtection` json DEFAULT NULL COMMENT 'DDOS配置',\n `dnsRoutes` json DEFAULT NULL COMMENT 'DNS线路设置',\n `maxCacheDiskCapacity` json DEFAULT NULL COMMENT '硬盘缓存容量',\n `maxCacheMemoryCapacity` json DEFAULT NULL COMMENT '内存缓存容量',\n `cacheDiskDir` varchar(255) DEFAULT NULL COMMENT '主缓存目录',\n `cacheDiskSubDirs` json DEFAULT NULL COMMENT '其他缓存目录',\n `dnsResolver` json DEFAULT NULL COMMENT 'DNS解析器',\n `enableIPLists` tinyint(1) unsigned DEFAULT '1' COMMENT '启用IP名单',\n `apiNodeAddrs` json DEFAULT NULL COMMENT 'API节点地址',\n `offlineDay` varchar(8) DEFAULT NULL COMMENT '下线日期YYYYMMDD',\n `offlineIsNotified` tinyint(1) unsigned DEFAULT '0' COMMENT '下线是否已通知',\n `isBackupForCluster` tinyint(1) unsigned DEFAULT '0' COMMENT '是否为集群备用节点',\n `isBackupForGroup` tinyint(1) unsigned DEFAULT '0' COMMENT '是否为分组备用节点',\n `backupIPs` json DEFAULT NULL COMMENT '备用IP',\n `actionStatus` json DEFAULT NULL COMMENT '当前动作配置',\n `bypassMobile` int(4) unsigned DEFAULT '0' COMMENT '是否过移动',\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='节点'",
"fields": [
{
"name": "id",
@@ -122274,6 +122286,10 @@
{
"name": "actionStatus",
"definition": "json COMMENT '当前动作配置'"
},
{
"name": "bypassMobile",
"definition": "int(4) unsigned DEFAULT '0' COMMENT '是否过移动'"
}
],
"indexes": [

View File

@@ -3,17 +3,18 @@ package setup
import (
"errors"
"fmt"
"github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
"io"
"regexp"
"runtime"
"sort"
"strings"
"sync"
"github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
)
var recordsTables = []*SQLRecordsTable{

View File

@@ -2,9 +2,10 @@ package setup
import (
"encoding/json"
"github.com/iwind/TeaGo/dbs"
"testing"
"time"
"github.com/iwind/TeaGo/dbs"
)
func TestSQLDump_Dump(t *testing.T) {

View File

@@ -4,6 +4,9 @@ import (
"crypto/rand"
"encoding/json"
"fmt"
"io"
"time"
"github.com/TeaOSLab/EdgeAPI/internal/configs"
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
@@ -15,8 +18,6 @@ import (
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
stringutil "github.com/iwind/TeaGo/utils/string"
"io"
"time"
)
// SQLExecutor 安装或升级SQL执行器
@@ -53,7 +54,7 @@ func (this *SQLExecutor) Run(showLog bool) error {
// prevent default configure loading
var globalConfig = dbs.GlobalConfig()
if globalConfig != nil && len(globalConfig.DBs) == 0 {
globalConfig.DBs = map[string]*dbs.DBConfig{"prod": this.dbConfig}
globalConfig.DBs = map[string]*dbs.DBConfig{Tea.Env: this.dbConfig}
}
defer func() {

View File

@@ -1,4 +1,4 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
//go:build !plus
package setup

View File

@@ -1,8 +1,9 @@
package setup
import (
"github.com/iwind/TeaGo/dbs"
"testing"
"github.com/iwind/TeaGo/dbs"
)
func TestSQLExecutor_Run(t *testing.T) {

View File

@@ -2,6 +2,9 @@ package setup
import (
"encoding/json"
"strconv"
"strings"
"github.com/TeaOSLab/EdgeAPI/internal/acme"
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
@@ -16,8 +19,6 @@ import (
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
"strconv"
"strings"
)
type upgradeVersion struct {

View File

@@ -1,4 +1,4 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
//go:build !plus
package setup
@@ -6,13 +6,14 @@ package setup
import (
"encoding/json"
"fmt"
"regexp"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/types"
timeutil "github.com/iwind/TeaGo/utils/time"
"regexp"
)
// v0.2.8.1

View File

@@ -1,11 +1,12 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
//go:build !plus
package setup
import (
"github.com/iwind/TeaGo/dbs"
"testing"
"github.com/iwind/TeaGo/dbs"
)
func TestUpgradeSQLData_v0_5_6(t *testing.T) {
@@ -28,7 +29,6 @@ func TestUpgradeSQLData_v0_5_6(t *testing.T) {
t.Log("ok")
}
func TestUpgradeSQLData_v1_3_4(t *testing.T) {
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
Driver: "mysql",
@@ -48,5 +48,3 @@ func TestUpgradeSQLData_v1_3_4(t *testing.T) {
}
t.Log("ok")
}

View File

@@ -1,8 +1,9 @@
package setup
import (
"github.com/iwind/TeaGo/dbs"
"testing"
"github.com/iwind/TeaGo/dbs"
)
func TestUpgradeSQLData(t *testing.T) {

View File

@@ -3,10 +3,11 @@
package setup
import (
"strings"
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
"github.com/iwind/TeaGo/types"
stringutil "github.com/iwind/TeaGo/utils/string"
"strings"
)
// ComposeSQLVersion 组合SQL的版本号

View File

@@ -3,9 +3,10 @@
package setup_test
import (
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/setup"
"github.com/iwind/TeaGo/assert"
"testing"
)
func TestComposeSQLVersion(t *testing.T) {