frps端同步frpc2.4-LTS的全套代码库的设计逻辑
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package main
|
||||
|
||||
// ============================================================
|
||||
// db-history.go - Schema 版本声明与字段映射(frps 版)
|
||||
// ============================================================
|
||||
|
||||
type SchemaVersionDef struct {
|
||||
Version string
|
||||
TableName string
|
||||
Columns map[string]ColumnDef
|
||||
}
|
||||
|
||||
type ColumnDef struct {
|
||||
Type string
|
||||
NotNull bool
|
||||
Default string
|
||||
Primary bool
|
||||
}
|
||||
|
||||
var schemaHistory = []SchemaVersionDef{
|
||||
// v1:frps 初始版本(与 2.0-lts 兼容)
|
||||
{
|
||||
Version: "v1",
|
||||
TableName: "global_config",
|
||||
Columns: map[string]ColumnDef{
|
||||
"id": {Type: "INTEGER", Primary: true},
|
||||
"bind_port": {Type: "INTEGER", NotNull: true, Default: "9358"},
|
||||
"token": {Type: "TEXT", NotNull: true, Default: "'CHANGE_ME'"},
|
||||
"log_level": {Type: "TEXT", NotNull: true, Default: "'info'"},
|
||||
"log_max_days": {Type: "INTEGER", NotNull: true, Default: "3"},
|
||||
"tcp_mux": {Type: "INTEGER", NotNull: true, Default: "1"},
|
||||
"updated_at": {Type: "DATETIME", Default: "CURRENT_TIMESTAMP"},
|
||||
},
|
||||
},
|
||||
// v2:当前版本(与 v1 相同,保留扩展)
|
||||
{
|
||||
Version: "v2",
|
||||
TableName: "global_config",
|
||||
Columns: map[string]ColumnDef{
|
||||
"id": {Type: "INTEGER", Primary: true},
|
||||
"bind_port": {Type: "INTEGER", NotNull: true, Default: "9358"},
|
||||
"token": {Type: "TEXT", NotNull: true, Default: "'CHANGE_ME'"},
|
||||
"log_level": {Type: "TEXT", NotNull: true, Default: "'info'"},
|
||||
"log_max_days": {Type: "INTEGER", NotNull: true, Default: "3"},
|
||||
"tcp_mux": {Type: "INTEGER", NotNull: true, Default: "1"},
|
||||
"updated_at": {Type: "DATETIME", Default: "CURRENT_TIMESTAMP"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func getSchemaDef(version string) *SchemaVersionDef {
|
||||
for _, def := range schemaHistory {
|
||||
if def.Version == version {
|
||||
return &def
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getLatestSchemaDef() *SchemaVersionDef {
|
||||
if len(schemaHistory) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &schemaHistory[len(schemaHistory)-1]
|
||||
}
|
||||
|
||||
func schemaVersionsEqual(v1, v2 *SchemaVersionDef) bool {
|
||||
if v1 == nil || v2 == nil {
|
||||
return false
|
||||
}
|
||||
if v1.TableName != v2.TableName {
|
||||
return false
|
||||
}
|
||||
if len(v1.Columns) != len(v2.Columns) {
|
||||
return false
|
||||
}
|
||||
for name, col1 := range v1.Columns {
|
||||
col2, ok := v2.Columns[name]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if col1.Type != col2.Type || col1.NotNull != col2.NotNull || col1.Default != col2.Default {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user