Fixed code smell to reduce cognitive complexity.
parent
290cf8271b
commit
e1168f8de0
|
@ -176,14 +176,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=acl)
|
||||
|
||||
# We will set get privileges from acl sql so we don't need
|
||||
# it from properties sql
|
||||
for row in acl['rows']:
|
||||
priv = parse_priv_from_db(row)
|
||||
if row['deftype'] in data:
|
||||
data[row['deftype']].append(priv)
|
||||
else:
|
||||
data[row['deftype']] = [priv]
|
||||
BaseTableView._set_privileges_for_properties(data, acl)
|
||||
|
||||
# We will add Auto vacuum defaults with out result for grid
|
||||
data['vacuum_table'] = copy.deepcopy(
|
||||
|
@ -214,6 +207,24 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
table_or_type = 'type'
|
||||
# Get inherited table(s) columns and add it into columns dict
|
||||
elif data['coll_inherits'] and len(data['coll_inherits']) > 0:
|
||||
is_error, errmsg = self._get_inherited_tables(scid, data,
|
||||
other_columns)
|
||||
if is_error:
|
||||
return internal_server_error(errormsg=errmsg)
|
||||
|
||||
table_or_type = 'table'
|
||||
|
||||
# We will fetch all the columns for the table using
|
||||
# columns properties.sql, so we need to set template path
|
||||
data = column_utils.get_formatted_columns(self.conn, tid,
|
||||
data, other_columns,
|
||||
table_or_type)
|
||||
|
||||
self._add_constrints_to_output(data, did, tid)
|
||||
|
||||
return data
|
||||
|
||||
def _get_inherited_tables(self, scid, data, other_columns):
|
||||
# Return all tables which can be inherited & do not show
|
||||
# system columns
|
||||
SQL = render_template("/".join([self.table_template_path,
|
||||
|
@ -223,7 +234,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
)
|
||||
status, rset = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
return True, rset
|
||||
|
||||
for row in rset['rows']:
|
||||
if row['inherits'] in data['coll_inherits']:
|
||||
|
@ -235,17 +246,23 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return True, res
|
||||
other_columns.extend(res['rows'][:])
|
||||
|
||||
table_or_type = 'table'
|
||||
return False, ''
|
||||
|
||||
# We will fetch all the columns for the table using
|
||||
# columns properties.sql, so we need to set template path
|
||||
data = column_utils.get_formatted_columns(self.conn, tid,
|
||||
data, other_columns,
|
||||
table_or_type)
|
||||
@staticmethod
|
||||
def _set_privileges_for_properties(data, acl):
|
||||
# We will set get privileges from acl sql so we don't need
|
||||
# it from properties sql
|
||||
for row in acl['rows']:
|
||||
priv = parse_priv_from_db(row)
|
||||
if row['deftype'] in data:
|
||||
data[row['deftype']].append(priv)
|
||||
else:
|
||||
data[row['deftype']] = [priv]
|
||||
|
||||
def _add_constrints_to_output(self, data, did, tid):
|
||||
# Here we will add constraint in our output
|
||||
index_constraints = {
|
||||
'p': 'primary_key', 'u': 'unique_constraint'
|
||||
|
@ -278,8 +295,6 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
for ex in exclusion_constraints:
|
||||
data.setdefault('exclude_constraint', []).append(ex)
|
||||
|
||||
return data
|
||||
|
||||
def get_table_dependents(self, tid):
|
||||
"""
|
||||
This function get the dependents and return ajax response
|
||||
|
@ -756,6 +771,15 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
else:
|
||||
return False
|
||||
elif key == 'foreign_key':
|
||||
return BaseTableView._check_foreign_key()
|
||||
|
||||
elif key == 'check_constraint':
|
||||
return BaseTableView._check_constraint(data)
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _check_foreign_key(data):
|
||||
if 'oid' not in data:
|
||||
for arg in ['columns']:
|
||||
if arg not in data or \
|
||||
|
@ -771,14 +795,13 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
|
||||
return True
|
||||
|
||||
elif key == 'check_constraint':
|
||||
@staticmethod
|
||||
def _check_constraint(data):
|
||||
for arg in ['consrc']:
|
||||
if arg not in data or data[arg] == '':
|
||||
return False
|
||||
return True
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def check_and_convert_name_to_string(data):
|
||||
"""
|
||||
|
@ -1284,6 +1307,21 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
if data['schema'] != row['schema_name']:
|
||||
partition_name = row['schema_name'] + '.' + row['name']
|
||||
|
||||
BaseTableView._partition_type_check(data, row, partitions,
|
||||
partition_name)
|
||||
|
||||
data['partitions'] = partitions
|
||||
|
||||
if not return_ajax_response:
|
||||
return data
|
||||
|
||||
return ajax_response(
|
||||
response=data,
|
||||
status=200
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _partition_type_check(data, row, partitions, partition_name):
|
||||
if data['partition_type'] == 'range':
|
||||
if row['partition_value'] == 'DEFAULT':
|
||||
is_default = True
|
||||
|
@ -1328,7 +1366,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
'FOR VALUES WITH (')[1].split(",")
|
||||
range_modulus = range_part[0].strip().strip(
|
||||
"modulus").strip()
|
||||
range_remainder = range_part[1].strip().\
|
||||
range_remainder = range_part[1].strip(). \
|
||||
strip(" remainder").strip(")").strip()
|
||||
|
||||
partitions.append({
|
||||
|
@ -1340,16 +1378,6 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
'sub_partition_scheme': row['sub_partition_scheme']
|
||||
})
|
||||
|
||||
data['partitions'] = partitions
|
||||
|
||||
if not return_ajax_response:
|
||||
return data
|
||||
|
||||
return ajax_response(
|
||||
response=data,
|
||||
status=200
|
||||
)
|
||||
|
||||
def get_partitions_sql(self, partitions, schema_diff=False):
|
||||
"""
|
||||
This function will iterate all the partitions and create SQL.
|
||||
|
@ -1412,6 +1440,14 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
+ ', REMAINDER ' +\
|
||||
remainder_str + ')'
|
||||
|
||||
partition_sql = self._check_for_partitioned_table(row, part_data,
|
||||
schema_diff)
|
||||
|
||||
sql += partition_sql
|
||||
|
||||
return sql
|
||||
|
||||
def _check_for_partitioned_table(self, row, part_data, schema_diff):
|
||||
# Check if partition is again declare as partitioned table.
|
||||
if 'is_sub_partitioned' in row and row['is_sub_partitioned']:
|
||||
part_data['partition_scheme'] = row['sub_partition_scheme'] \
|
||||
|
@ -1436,9 +1472,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
data=part_data, conn=self.conn
|
||||
)
|
||||
|
||||
sql += partition_sql
|
||||
|
||||
return sql
|
||||
return partition_sql
|
||||
|
||||
def truncate(self, gid, sid, did, scid, tid, res):
|
||||
"""
|
||||
|
@ -1574,6 +1608,11 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||
and vacuum_key in old_data:
|
||||
set_values = []
|
||||
reset_values = []
|
||||
self._iterate_vacuume_table(data, old_data, set_values,
|
||||
reset_values, vacuum_key)
|
||||
|
||||
def _iterate_vacuume_table(self, data, old_data, set_values, reset_values,
|
||||
vacuum_key):
|
||||
for data_row in data[vacuum_key]['changed']:
|
||||
for old_data_row in old_data[vacuum_key]:
|
||||
if data_row['name'] == old_data_row['name'] and \
|
||||
|
|
Loading…
Reference in New Issue