def migrateTableIndexToMySQL(self, state, source_index, targetTable): sourceTable = source_index.owner if len(sourceTable.columns) == 0 or len(targetTable.columns) == 0: state.addMigrationLogEntry(2, source_index, None, 'The migration of table %s indices was attempted but either the source or the target table has no columns attribute' % sourceTable.name) return None target_index = grt.classes.db_mysql_Index() log = state.addMigrationLogEntry(0, source_index, target_index, "") target_index.owner = targetTable target_index.name = self.migrateIdentifier(source_index.name, log, dots_allowed=True) target_index.oldName = source_index.name target_index.isPrimary = source_index.isPrimary target_index.deferability = source_index.deferability target_index.unique = source_index.unique target_index.indexType = source_index.indexType target_index.comment = source_index.comment for source_index_column in source_index.columns: referenced_index_col = find_object_with_old_name(targetTable.columns, source_index_column.referencedColumn.name) if not referenced_index_col: state.addMigrationLogEntry(2, source_index, target_index, 'The column "%s" is part of source table "%s" index "%s" but there is no such column in the target table' % (source_index_column.name, sourceTable.name, source_index.name) ) #return None ##XXXXX target_index_column = grt.classes.db_mysql_IndexColumn() target_index_column.owner = target_index target_index_column.referencedColumn = referenced_index_col target_index_column.name = source_index_column.name target_index_column.columnLength = source_index_column.columnLength # if this is a text/string column, make sure that the key length is inside limit if referenced_index_col.simpleType and referenced_index_col.simpleType.group.name in ('string', 'text', 'blob'): prefix_length_limit = min(referenced_index_col.length, MYSQL_MAX_INDEX_KEY_LENGTH_INNODB_UTF8) if referenced_index_col.length > 0 else MYSQL_MAX_INDEX_KEY_LENGTH_INNODB_UTF8 if target_index_column.columnLength > 0: target_index_column.columnLength = min(prefix_length_limit, target_index_column.columnLength) elif target_index_column.columnLength == 0: # if there's no index key length limit and the length of the column is bigger than allowed, then limit it if referenced_index_col.length > 0 and prefix_length_limit < referenced_index_col.length: target_index_column.columnLength = prefix_length_limit # if the column type is blob/text, then we always need a key length limit elif referenced_index_col.simpleType.group.name in ('text', 'blob'): target_index_column.columnLength = prefix_length_limit else: target_index_column.columnLength = min(prefix_length_limit, referenced_index_col.length) if target_index_column.columnLength != source_index_column.columnLength: state.addMigrationLogEntry(1, source_index, target_index, 'Truncated key column length for column %s from %s to %s' % (source_index_column.name, source_index_column.columnLength, target_index_column.columnLength)) target_index_column.descend = source_index_column.descend target_index_column.comment = source_index_column.comment target_index.columns.append(target_index_column) return target_index
def migrateTablePrimaryKeyToMySQL(self, state, sourceTable, targetTable): if sourceTable.primaryKey: # we're searching for an index here, not a PK, so search it by name targetTable.primaryKey = find_object_with_old_name( targetTable.indices, sourceTable.primaryKey.name) return 0
def migrateTablePrimaryKeyToMySQL(self, state, sourceTable, targetTable): if sourceTable.primaryKey: # we're searching for an index here, not a PK, so search it by name targetTable.primaryKey = find_object_with_old_name(targetTable.indices, sourceTable.primaryKey.name) return 0