diff --git a/sql/engines/mongo.py b/sql/engines/mongo.py index b1ededea1b..29285ba1fd 100644 --- a/sql/engines/mongo.py +++ b/sql/engines/mongo.py @@ -13,6 +13,7 @@ from dateutil.parser import parse from bson.objectid import ObjectId from bson.int64 import Int64 +from urllib.parse import quote_plus from . import EngineBase from .models import ResultSet, ReviewSet, ReviewResult @@ -795,15 +796,13 @@ def execute_check(self, db_name=None, sql=""): def get_connection(self, db_name=None): self.db_name = db_name or self.instance.db_name or "admin" auth_db = self.instance.db_name or "admin" - self.conn = pymongo.MongoClient( - self.host, - self.port, - authSource=auth_db, - connect=True, - connectTimeoutMS=10000, - ) if self.user and self.password: - self.conn[self.db_name].authenticate(self.user, self.password, auth_db) + user = quote_plus(self.user) + password = quote_plus(self.password) + uri = f"mongodb://{user}:{password}@{self.host}:{self.port}/{self.db_name}?authSource={auth_db}" + else: + uri = f"mongodb://{self.host}:{self.port}/{self.db_name}" + self.conn = pymongo.MongoClient(uri, connect=True, connectTimeoutMS=10000) return self.conn def close(self): diff --git a/sql/instance.py b/sql/instance.py index 54486be745..42890466eb 100644 --- a/sql/instance.py +++ b/sql/instance.py @@ -233,9 +233,12 @@ def schemasync(request): # 提交给SchemaSync获取对比结果 schema_sync = SchemaSync() + tag = int(time.time()) + timestamp = time.time() + formatted_time = time.strftime("%Y%m%d%H%M", time.localtime(timestamp)) # 准备参数 tag = int(time.time()) - output_directory = os.path.join(settings.BASE_DIR, "downloads/schemasync/") + output_directory = os.path.join(settings.BASE_DIR, "downloads/schemasync/",formatted_time) os.makedirs(output_directory, exist_ok=True) args = { "sync-auto-inc": sync_auto_inc, @@ -264,13 +267,13 @@ def schemasync(request): # 非全部数据库对比可以读取对比结果并在前端展示 if db_name != "*": date = time.strftime("%Y%m%d", time.localtime()) - patch_sql_file = "%s%s_%s.%s.patch.sql" % ( + patch_sql_file = "%s/%s_%s.%s.patch.sql" % ( output_directory, target_db_name, tag, date, ) - revert_sql_file = "%s%s_%s.%s.revert.sql" % ( + revert_sql_file = "%s/%s_%s.%s.revert.sql" % ( output_directory, target_db_name, tag,