Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pymongo4.x支持mongodb3.6低版本 #2645

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions sql/engines/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
LeoQuote marked this conversation as resolved.
Show resolved Hide resolved
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):
Expand Down
9 changes: 6 additions & 3 deletions sql/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading