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

数据库管理页面-添加mysql/pgsql/mongo实例选择下拉菜单-并添加pgsql/mongo创建数据库功能 #1401

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

taochao2000
Copy link

@taochao2000 taochao2000 commented Feb 25, 2022

commits:数据库管理页面-添加pgsql实例选择下拉菜单-并添加pgsql创建数据库功

  1. sql/templates/database.html 添加db_type类型选择下拉菜单,自动生成对应实例和数据库列表
  2. sql/instance_database.py 添加db_type=pgsql/mongo的数据库查询和创建
  3. sql/engine/pgsql.py 添加execute方法支持pgsql create database ddl
  4. sql/engine/mongo.py 添加execute ddl参数和打印,remark字段为mongo数据库密码

@taochao2000
Copy link
Author

taochao2000 commented Feb 25, 2022

效果图:
企业微信截图_16461268958393
企业微信截图_1646126996510
image
企业微信截图_16461269398221

@LeoQuote
Copy link
Collaborator

有冲突,解决下,另外mongo 的修改和pr无关,删掉或者另开一个pr吧

@txmzzl txmzzl force-pushed the master branch 2 times, most recently from 78c7fba to b8eabf9 Compare March 1, 2022 07:54
@codecov
Copy link

codecov bot commented Mar 1, 2022

Codecov Report

Merging #1401 (509d97b) into master (ae58fbd) will decrease coverage by 3.38%.
The diff coverage is 4.12%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1401      +/-   ##
==========================================
- Coverage   77.95%   74.56%   -3.39%     
==========================================
  Files          76       82       +6     
  Lines       11963    13275    +1312     
==========================================
+ Hits         9326     9899     +573     
- Misses       2637     3376     +739     
Impacted Files Coverage Δ
sql/instance_database.py 12.68% <0.00%> (-6.42%) ⬇️
sql/engines/pgsql.py 82.81% <9.09%> (-9.55%) ⬇️
sql/engines/mongo.py 47.77% <40.00%> (-0.51%) ⬇️
sql/utils/data_masking.py 9.09% <0.00%> (-83.64%) ⬇️
sql/engines/inception.py 16.76% <0.00%> (-69.37%) ⬇️
sql/engines/mssql.py 69.89% <0.00%> (-14.82%) ⬇️
sql/templatetags/format_tags.py 65.00% <0.00%> (-13.58%) ⬇️
sql/engines/mysql.py 80.65% <0.00%> (-11.62%) ⬇️
sql/engines/goinception.py 81.13% <0.00%> (-5.72%) ⬇️
sql/engines/redis.py 77.14% <0.00%> (-2.66%) ⬇️
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b8eabf9...509d97b. Read the comment docs.

@taochao2000
Copy link
Author

有冲突,解决下,另外mongo 的修改和pr无关,删掉或者另开一个pr吧

已经删除之前PR,重新提交commit,并添加了mongo实例过滤和数据库创建
企业微信截图_16461265549412

@taochao2000 taochao2000 changed the title 数据库管理页面-添加pgsql实例选择下拉菜单-并添加pgsql创建数据库功能 数据库管理页面-添加pgsql实例选择下拉菜单-并添加pgsql/mongo创建数据库功能 Mar 1, 2022
@taochao2000 taochao2000 changed the title 数据库管理页面-添加pgsql实例选择下拉菜单-并添加pgsql/mongo创建数据库功能 数据库管理页面-添加mysql/pgsql/mongo实例选择下拉菜单-并添加pgsql/mongo创建数据库功能 Mar 1, 2022
Copy link
Owner

@hhyo hhyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢你提交的变更,如果能够将获取数据库相关方法抽象到engine中,那就更合适了,可参考#1402

<select id="db_type1" class="form-control selectpicker" name="db_type"
title="db_type"
data-live-search="true">
<option value="" selected="selected">db_type</option>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和实例列表统一,叫实例类型吧

result['msg'] += f"\n错误: {collection_name} 文档不存在!"
sql = sql.strip()
# 以;作为语句结束
q_sql = sql.split(";")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用sqlparse.split是不是更合适?

@@ -320,13 +320,18 @@ def execute_workflow(self, workflow):
"""执行上线单,返回Review set"""
return self.execute(db_name=workflow.db_name, sql=workflow.sqlworkflowcontent.sql_content)

def execute(self, db_name=None, sql=''):
def execute(self, db_name=None, sql='', ddl=''):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有看出来ddl和非ddl的区别,可以去除ddl入参和下面的判断

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mongo.py ddl执行用的还是之前的方法,确实没有区别可以去掉,是为了打印ddl字符串加了一个判断。

@@ -299,6 +300,34 @@ def execute_workflow(self, workflow, close_conn=True):
self.close()
return execute_result

def execute(self, db_name=None, sql='', ddl='', close_conn=True):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execute方法就是用于执行有影响的语句,可以去除ddl入参和判断,统一设置autocommit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pgsql执行create database需要设置conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)自动提交,和dml操作默认放到一个block事务提交有冲突,dml保证事务一致性还是比较合理。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否是ddl直接在方法内判断比较好,可以优化一下

@@ -23,14 +23,15 @@
@permission_required('sql.menu_database', raise_exception=True)
def databases(request):
"""获取实例数据库列表"""
db_type1 = request.POST.get('db_type1')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通过instance_id获取实例对象后就可以判断db类型了,不需要外部再传入这个参数

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯看了源代码instance_id获取实例可以得到db_type,不过前端传的db_type1是为了在选择数据类型后在自动过滤该db_type1的实例列表,和返回db_type没有关系吧。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个方法是获取实例的数据库列表,看了下不需要这个

@@ -3,6 +3,15 @@
{% block content %}
<!-- 自定义操作按钮-->
<div id="toolbar" class="form-inline pull-left">
<div class="form-group">
<select id="db_type1" class="form-control selectpicker" name="db_type"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db_type

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,这个修改成db_type_f,表示数据库类型过滤

<div class="col-sm-9">
<input type="text" id="remark" class="form-control"
autocomplete="off"
placeholder="请输入备注">
placeholder="请输入备注/mongo密码">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不特意描述为密码比较好,这里就是填写描述信息的地方

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,这个可以修改回来。
mongo create database ddl是自动创建用户和密码了,为了不修改模型层,所以复用了一个字段:)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants