Example #1
0
    def query(self, request):
        cdata = self.cleaned_data
        envi_id = cdata.get('envi_id')
        is_master = 1

        # 判断是否为只读环境,查找parent_id最小的,即认为为只读环境(一般为生产环境的从库)
        parent_id_min = SqlOrdersEnvironment.objects.all().aggregate(
            Min('parent_id'))['parent_id__min']
        if int(envi_id) == SqlOrdersEnvironment.objects.get(
                parent_id=parent_id_min).envi_id:
            is_master = 0

        query = f"select b.id, b.host, b.port, b.schema from sqlaudit_schemas_grant a " \
                f"join sqlaudit_mysql_schemas b on a.schema_id = b.schema_join join sqlaudit_user_accounts c  " \
                f"on c.uid = a.user_id where c.uid={request.user.uid} " \
                f"and b.envi_id={envi_id} and b.is_master={is_master}"

        context = []
        for row in MysqlSchemas.objects.raw(query):
            data = GetTableInfo(row.host, row.port,
                                row.schema).get_online_tables()
            show_schema = '_'.join((row.comment, row.schema))
            context.append({
                'id':
                '___'.join((row.host, str(row.port), row.schema)),
                'text':
                show_schema,
                'children':
                data
            })
        return context
Example #2
0
 def query(self):
     cdata = self.cleaned_data
     host, port, schema = cdata.get('schema').split('___')
     if len(schema.split('.')) == 2:
         data = GetTableInfo(host, port, schema).get_stru_info()
         context = {'status': 0, 'data': data}
     else:
         context = {'status': 2, 'msg': ''}
     return context
Example #3
0
    def query(self):
        cdata = self.cleaned_data
        schema = cdata['schema']
        host, port, schema = schema.split(',')

        status, msg = check_db_conn_status(host, port)
        if status:
            table_list = GetTableInfo(host, port, schema).get_column_info()
            context = {'status': 0, 'msg': '', 'data': table_list}
        else:
            context = {'status': 2, 'msg': f'无法连接到数据库,请联系管理员,\n主机: {host}\n端口: {port}'}
        return context
Example #4
0
    def query(self, request):
        cdata = self.cleaned_data
        envi_id = cdata.get('envi_id')

        query = f"select b.id, b.host, b.port, b.schema from sqlaudit_schemas_grant a " \
                f"join sqlaudit_mysql_schemas b on a.schema_id = b.schema_join join sqlaudit_user_accounts c  " \
                f"on c.uid = a.user_id where c.uid={request.user.uid} " \
                f"and b.envi_id={envi_id} and b.is_type in (0, 2)"

        context = []
        for row in MysqlSchemas.objects.raw(query):
            data = GetTableInfo(row.host, row.port,
                                row.schema).get_online_tables()
            show_schema = '_'.join((row.comment, row.schema))
            context.append({
                'id':
                '___'.join((row.host, str(row.port), row.schema)),
                'text':
                show_schema,
                'children':
                data
            })
        return context