qdy преди 1 месец
родител
ревизия
2876310a5f
променени са 4 файла, в които са добавени 26 реда и са изтрити 4 реда
  1. 0
    3
      internal/tables/dim_ business.go
  2. 0
    0
      internal/tables/dim_table.go
  3. 1
    1
      internal/tables/dim_table_field.go
  4. 25
    0
      main.go

internal/model/dim_ business.go → internal/tables/dim_ business.go Целия файл

@@ -24,9 +24,6 @@ func init() {
24 24
 
25 25
 		// 常用查询索引
26 26
 		tb.AddIndex("idx_project_table_field", "project_id", "table_name", "field_name")
27
-		tb.AddIndex("idx_standard_name", "standard_cn_name")
28
-		tb.AddIndex("idx_category", "category")
29
-		tb.AddIndex("idx_created_at", "created_at")
30 27
 
31 28
 		r.RegisterTable(tb.Build())
32 29
 	})

internal/model/dim_table.go → internal/tables/dim_table.go Целия файл


internal/model/dim_table_field.go → internal/tables/dim_table_field.go Целия файл

@@ -14,7 +14,7 @@ func init() {
14 14
 			String("table_name", 64).NotNull().Comment("表名").End().
15 15
 			String("field_name", 64).NotNull().Comment("字段名称(英文)").End().
16 16
 			String("field_name_cn", 128).NotNull().Comment("字段中文名称").End().
17
-			Text("description").Comment("字段描述").End().
17
+			String("description", 128).Comment("字段描述").End().
18 18
 			String("field_type", 64).NotNull().Comment("字段类型(如:varchar, int, datetime等)").End().
19 19
 			Int("field_length").Comment("字段长度/精度").End().
20 20
 			Bool("is_primary_key").Default("0").NotNull().Comment("是否为主键(0:否, 1:是)").End().

+ 25
- 0
main.go Целия файл

@@ -19,7 +19,10 @@ import (
19 19
 	"git.x2erp.com/qdy/go-base/webx/router"
20 20
 
21 21
 	"git.x2erp.com/qdy/go-db/factory/database"
22
+	"git.x2erp.com/qdy/go-db/sqldef"
22 23
 	mcpsdk "github.com/modelcontextprotocol/go-sdk/mcp"
24
+
25
+	_ "git.x2erp.com/qdy/go-svc-mcp/internal/tables" // 导入表定义包,触发 init() 函数
23 26
 )
24 27
 
25 28
 var (
@@ -45,6 +48,8 @@ func main() {
45 48
 	// 3. 创建数据库工厂
46 49
 	dbFactory := container.Create(ctr, database.CreateDBFactory)
47 50
 	dbFactory.TestConnection()
51
+	// 创建表
52
+	creteTabel(dbFactory)
48 53
 
49 54
 	// 创建mongodb
50 55
 	//mongoDBFactory := container.Create(ctr, mongodb.CreateFactory)
@@ -117,3 +122,23 @@ func createMcpService(cfg config.IConfig, dbFactory *database.DBFactory) *mcp.Se
117 122
 
118 123
 	return mcpServer
119 124
 }
125
+
126
+func creteTabel(factory *database.DBFactory) {
127
+
128
+	// 获取数据库连接和类型
129
+	db := factory.GetDB()
130
+	dbType := factory.GetDBType()
131
+
132
+	// 创建表同步器
133
+	syncer, err := sqldef.NewTableSyncer(db, dbType)
134
+	if err != nil {
135
+		log.Printf("创建 - 建立器失败: %v", err)
136
+	}
137
+
138
+	// 创建表
139
+	if err := syncer.CreateTables(); err != nil {
140
+		log.Printf("建表失败: %v", err)
141
+	}
142
+
143
+	log.Println("数据库表建立完成!")
144
+}

Loading…
Отказ
Запис