def _setIndexedCols(self): '''Decides which fields must be indexed, based on key and index information.''' #Find all columns that are indexed or unique indexed uniq = self.sqlDb.inspector.get_unique_constraints(self.tableName) idx = self.sqlDb.inspector.get_indexes(self.tableName) #Only single-field constraints will be carried over as such uniqCols = [x['column_names'] for x in uniq \ if len(x['column_names']) == 1] idxCols = [x['column_names'] for x in idx] idxCols.extend([x['column_names'] for x in uniq \ if len(x['column_names']) != 1]) #Don't forget primary key constraint if len(self.pkCols) == 1: uniqCols.append(self.pkCols.keys()) else: idxCols.append(self.pkCols.keys()) uniqColNames = listUnique(listFlatten(uniqCols)) #Remove unique constrained columns from columns to be indexed idxColNames = listSubtract(listUnique(listFlatten(idxCols)), uniqColNames) self.uniqCols = [self.cols[x] for x in uniqColNames] #Redundant fields are excluded if REMOVE_REDUNDANT_FIELDS: self.idxCols = [self.cols[x] for x in idxColNames \ if not self.cols[x].isRedundant()] else: self.idxCols = [self.cols[x] for x in idxColNames] LOG.debug("Unique constraints on table %s, columns %s" % (self.tableName, str([x.name for x in self.uniqCols]))) LOG.debug("Indexes on table %s, columns %s" % (self.tableName, str([x.name for x in self.idxCols])))
def _setIndexedCols(self): """Decides which fields must be indexed, based on key and index information.""" # Find all columns that are indexed or unique indexed uniq = self.sqlDb.inspector.get_unique_constraints(self.tableName) idx = self.sqlDb.inspector.get_indexes(self.tableName) # Only single-field constraints will be carried over as such uniqCols = [x["column_names"] for x in uniq if len(x["column_names"]) == 1] idxCols = [x["column_names"] for x in idx] idxCols.extend([x["column_names"] for x in uniq if len(x["column_names"]) != 1]) # Don't forget primary key constraint if len(self.pkCols) == 1: uniqCols.append(self.pkCols.keys()) else: idxCols.append(self.pkCols.keys()) uniqColNames = listUnique(listFlatten(uniqCols)) # Remove unique constrained columns from columns to be indexed idxColNames = listSubtract(listUnique(listFlatten(idxCols)), uniqColNames) self.uniqCols = [self.cols[x] for x in uniqColNames] # Redundant fields are excluded if REMOVE_REDUNDANT_FIELDS: self.idxCols = [self.cols[x] for x in idxColNames if not self.cols[x].isRedundant()] else: self.idxCols = [self.cols[x] for x in idxColNames] LOG.debug("Unique constraints on table %s, columns %s" % (self.tableName, str([x.name for x in self.uniqCols]))) LOG.debug("Indexes on table %s, columns %s" % (self.tableName, str([x.name for x in self.idxCols])))
def isManyToManyStrict(self): '''True if this table implements a many-to-many relationship. Definition used: - Referring two tables. - Primary key composed exclusively out of foreign keys - There are no tables referring to this table''' return len(self.refTables) == 2 and \ len(listSubtract(self.pkCols.keys(), self.fKeysCols.keys())) == 0 \ and len(self.depTables) == 0
def isManyToManyStrict(self): """True if this table implements a many-to-many relationship. Definition used: - Referring two tables. - Primary key composed exclusively out of foreign keys - There are no tables referring to this table""" return ( len(self.refTables) == 2 and len(listSubtract(self.pkCols.keys(), self.fKeysCols.keys())) == 0 and len(self.depTables) == 0 )