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

新增oracle查询 #175

Merged
merged 6 commits into from
May 9, 2019
Merged

新增oracle查询 #175

merged 6 commits into from
May 9, 2019

Conversation

LeoQuote
Copy link
Collaborator

@LeoQuote LeoQuote commented May 7, 2019

#144
#174

@yyukai

@LeoQuote LeoQuote requested review from hhyo and kjiLupin May 7, 2019 06:34
@LeoQuote
Copy link
Collaborator Author

LeoQuote commented May 7, 2019

需要rebase一下。

@LeoQuote
Copy link
Collaborator Author

LeoQuote commented May 7, 2019

不知道 oracle 能不能把schema 和table 混起来考虑, 这样如果是两层的结构, 可以在现有的结构中混用。

我看yyukai的代码的意思是schema下面还有table,然后才是字段之类的

@hhyo
Copy link
Owner

hhyo commented May 7, 2019

oracle其实不用处理database,在oracle中只有一个database,并且能通过创建user来创建schema,只需要在get_all_databases方法中返回schemas的信息,前端查询和权限申请以及校验规则就完全不用改,可以直接复用

pgsql则可以有多个database,并且不同database下的schema可以同名,所以必须要区分database和schema

@flyingonthebed
Copy link
Contributor

不知道 oracle 能不能把schema 和table 混起来考虑, 这样如果是两层的结构, 可以在现有的结构中混用。

我看yyukai的代码的意思是schema下面还有table,然后才是字段之类的

oracle 的数据库对应 mysql 的实例,表空间对应 mysql 的 database,数据库只能有一个,表空间可以有多个。
创建了用户,就等于创建了同名的 schema,并且创建用户必须指定默认表空间。
表空间里可以有多个用户,多个用户即存在多个schema。
删除用户时,如果schema中有数据,需要drop user aaa cascade; 做级联删除。
可参考下图:

image

@LeoQuote
Copy link
Collaborator Author

LeoQuote commented May 7, 2019

我有一个实现的建议:

新创建两个方法,get_first_layer_list , get_second_layer_list(瞎取的名字, 后续可以改) , 在这两个方法中拿到两层列表:

  • Mysql database table
  • oracle schema table
  • pg schema table

现有的get_all_databases , get_all_schemes 不变, 在上面说的两个方法中再调用现有的方法即可。

这样做的原因是统一engine的各种方法, 在工单和查询层面统一调用的方法,这样对后端的代码修改会非常小。

前端可以对不同类型数据库显示不同的名字。

@hhyo
Copy link
Owner

hhyo commented May 7, 2019

pg有三级db->schema->tb,其实mssql也是类似吧

@yzypals
Copy link
Collaborator

yzypals commented May 7, 2019

我目前 做了一个比较简单的处理, 直接把 oracle的模式 对标 mysql的数据库 来处理, 目前自己测试 在线查询,已经可以用了, 上线审核我用只读账号 测试 也能走完整个流程了, 看了上面 考虑的好多~!~,我想的简单了,

@LeoQuote
Copy link
Collaborator Author

LeoQuote commented May 7, 2019

@yzypals 你的方案也是很好的,redis和sql server采用的就是这样的方案,但是实际上是schema ,后端却是db,可能会有一些误解,正在思考如何解决问题

@codecov
Copy link

codecov bot commented May 8, 2019

Codecov Report

Merging #175 into master will decrease coverage by 0.89%.
The diff coverage is 35.44%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #175     +/-   ##
=========================================
- Coverage   74.06%   73.17%   -0.9%     
=========================================
  Files          62       63      +1     
  Lines        6810     6964    +154     
=========================================
+ Hits         5044     5096     +52     
- Misses       1766     1868    +102
Impacted Files Coverage Δ
sql/engines/__init__.py 61.22% <0%> (-4%) ⬇️
sql/engines/mysql.py 89.77% <100%> (ø) ⬆️
sql/engines/tests.py 100% <100%> (ø) ⬆️
sql/models.py 94.6% <100%> (+0.02%) ⬆️
sql/engines/oracle.py 25.78% <25.78%> (ø)
sql/engines/mssql.py 75% <33.33%> (-2.58%) ⬇️

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 2324a47...35b53c7. Read the comment docs.

@LeoQuote LeoQuote added the enhancement New feature or request label May 9, 2019
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.

这些点我来调整吧

sql/admin.py Outdated
@@ -58,7 +58,8 @@ class InstanceTagRelationsAdmin(admin.ModelAdmin):
# 实例管理
@admin.register(Instance)
class InstanceAdmin(admin.ModelAdmin):
list_display = ('id', 'instance_name', 'db_type', 'type', 'host', 'port', 'user', 'create_time')
list_display = ('id', 'instance_name', 'db_type', 'type', 'host', 'port', 'user', 'password', 'service_name',
Copy link
Owner

Choose a reason for hiding this comment

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

password本来就是加密的,不建议在列表展示

@@ -154,6 +154,19 @@ def query_masking(self, db_name=None, sql='', resultset=None):
filtered_result = resultset
return filtered_result

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

Choose a reason for hiding this comment

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

mssql的上线功能?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

准备做了, 我司DBA给了我一个备份方案

@@ -19,6 +19,7 @@
class="selectpicker show-tick form-control bs-select-hidden"
data-live-search="true"
data-placeholder="请选择实例:" required>
// TODO 实例中的筛选可以在python代码中, 使用filter实现, 这种实现可能有效率问题。
Copy link
Owner

Choose a reason for hiding this comment

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

确实会有效率问题

COMMENT 'Oracle Service name'
AFTER password;

alter table query_privileges_apply add `schema_list` longtext NOT NULL after db_list;
Copy link
Owner

Choose a reason for hiding this comment

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

后面三个语句可以删除了,然后直接补充在v1.5.3_v1.5.4.sql后面

@hhyo hhyo marked this pull request as ready for review May 9, 2019 14:54
@hhyo hhyo merged commit 2755119 into master May 9, 2019
@hhyo hhyo deleted the oracle branch July 6, 2019 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants