feat: 新增装机绑定功能与权限、BOM工序配置
1. 新增装机绑定实体与相关CRUD逻辑,支持工件工序物料绑定/解绑 2. 为BOM物料新增装配工序字段,支持按工序校验绑定 3. 扩展权限表,新增父权限码字段支持菜单按钮关联 4. 统一各页面帮助弹窗参数,新增角色管理帮助文档 5. 新增公共格式化工具函数,优化侧边栏菜单展开逻辑 6. 新增工位终端绑定代理接口与MES内部绑定API 7. 修复主入口数据库连接与schema初始化逻辑,新增一键迁移工具
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
// 一次性运维工具:直接加载项目配置执行 EnsureDB + EnsureSchema(建新表 + 幂等补列),
|
||||
// 绕过交互式管理员密码门禁(密码留在配置文件内,不落日志、不打印)。
|
||||
// 用法:go run ./tools/migrateonce
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"bj_power_mes/internal/config"
|
||||
"bj_power_mes/internal/db"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var c config.Config
|
||||
conf.MustLoad("etc/bj_power_mes-api.yaml", &c)
|
||||
|
||||
if err := db.EnsureDB(c.Database); err != nil {
|
||||
fmt.Println("ENSURE_DB_FAIL:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
client, sqlDB := db.MustNewDB(c.Database)
|
||||
defer client.Close()
|
||||
defer sqlDB.Close()
|
||||
|
||||
// 迁移前现状:库名 + 现有表清单
|
||||
rows, err := sqlDB.QueryContext(context.Background(),
|
||||
`SELECT current_database(), COALESCE(string_agg(tablename, ','), '(empty)') FROM pg_tables WHERE schemaname='public'`)
|
||||
if err == nil && rows.Next() {
|
||||
var dbname, tables string
|
||||
_ = rows.Scan(&dbname, &tables)
|
||||
rows.Close()
|
||||
fmt.Printf("DB=%s TABLES_BEFORE=%s\n", dbname, tables)
|
||||
}
|
||||
|
||||
if err := db.EnsureSchema(client, sqlDB); err != nil {
|
||||
fmt.Println("MIGRATE_FAIL:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// 迁移结果自检:新表存在 + 旧表新列存在
|
||||
var tableExists bool
|
||||
if err := sqlDB.QueryRowContext(context.Background(),
|
||||
`SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_schema='public' AND table_name='workpiece_bind')`,
|
||||
).Scan(&tableExists); err != nil {
|
||||
fmt.Println("VERIFY_FAIL:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var colExists bool
|
||||
if err := sqlDB.QueryRowContext(context.Background(),
|
||||
`SELECT EXISTS(SELECT 1 FROM information_schema.columns WHERE table_schema='public' AND table_name='work_order_bom' AND column_name='process_code')`,
|
||||
).Scan(&colExists); err != nil {
|
||||
fmt.Println("VERIFY_FAIL:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var bindCols int
|
||||
_ = sqlDB.QueryRowContext(context.Background(),
|
||||
`SELECT COUNT(*) FROM information_schema.columns WHERE table_schema='public' AND table_name='workpiece_bind'`,
|
||||
).Scan(&bindCols)
|
||||
|
||||
fmt.Printf("MIGRATE_OK workpiece_bind_table=%v bom_item.process_code=%v workpiece_bind_cols=%d\n",
|
||||
tableExists, colExists, bindCols)
|
||||
if !tableExists || !colExists {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user