Skip to content

Commit

Permalink
fix: 修复sqlserver数据库表名称不区分大小 TencentBlueKing#7624
Browse files Browse the repository at this point in the history
  • Loading branch information
yksitu authored and zhangzhw8 committed Oct 28, 2024
1 parent e4921fe commit c7f5fa2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions dbm-services/sqlserver/db-tools/dbactuator/pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,16 @@ func GetSysDBS() []string {
return []string{"msdb", "master", "model", "tempdb", "Monitor"}
}

// match 根据show databases 返回的实际db,匹配出dbname
// match 根据show databases 返回的实际db,匹配出dbname, 不区分大小写
//
// @receiver e
// @receiver regularDbNames
// @return matched
func DbMatch(dbs, regularDbNames []string) (matched []string, err error) {
for _, regexpStr := range regularDbNames {
re, err := regexp.Compile(regexpStr)
// 转换成不区分大小写正则
realRegexpStr := fmt.Sprintf("(?i)%s", regexpStr)
re, err := regexp.Compile(realRegexpStr)
if err != nil {
logger.Error(" regexp.Compile(%s) failed:%s", regexpStr, err.Error())
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions dbm-ui/backend/flow/utils/sqlserver/sqlserver_db_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def sqlserver_match_dbs(
db_filter = DbTableFilter(
include_db_patterns=db_patterns,
include_table_patterns=[""],
exclude_db_patterns=ignore_db_patterns,
exclude_table_patterns=[""] if ignore_db_patterns else [],
exclude_db_patterns=ignore_db_patterns if ignore_db_patterns else [""],
exclude_table_patterns=[""],
)
db_filter.inject_system_dbs([SQLSERVER_CUSTOM_SYS_DB])
db_filter_pattern = re.compile(db_filter.db_filter_regexp())
db_filter_pattern = re.compile(db_filter.db_filter_regexp(), re.IGNORECASE)

# 获取过滤后db
real_dbs = [db_name for db_name in dbs if db_filter_pattern.match(db_name)]
Expand Down Expand Up @@ -106,7 +106,7 @@ def multi_get_dbs_for_drs(cluster_ids: List[int], db_list: list, ignore_db_list:

def check_sqlserver_db_exist(cluster_id: int, check_dbs: list) -> list:
"""
根据存入的db名称,判断库名是否在集群存在
根据存入的db名称,判断库名是否在集群存在,这里判断是不区分大小写
@param cluster_id: 对应的cluster_id
@param check_dbs: 需要验证的check_dbs 列表
"""
Expand Down Expand Up @@ -134,11 +134,11 @@ def check_sqlserver_db_exist(cluster_id: int, check_dbs: list) -> list:
)
if ret[0]["error_msg"]:
raise Exception(f"[{master_instance.ip_port}] check db failed: {ret[0]['error_msg']}")
# 判断库是否存在
# 判断库是否存在, 这里判断不区分大小写
for db_name in check_dbs:
is_exists = False
for info in ret[0]["cmd_results"][0]["table_data"]:
if db_name == info["name"]:
if db_name.lower() == info["name"].lower():
is_exists = True
result.append({"name": db_name, "is_exists": is_exists})
break
Expand Down

0 comments on commit c7f5fa2

Please sign in to comment.