Skip to content
Snippets Groups Projects
Commit 1f3d8049 authored by Thomas Mortagne's avatar Thomas Mortagne
Browse files

XWIKI-19276: Cannot update to XWiki 13.10.2: "Index column size too large. The...

XWIKI-19276: Cannot update to XWiki 13.10.2: "Index column size too large. The maximum column size is 767 bytes"
* moved DYNAMIC raw type migration first
* also removed R130200001 migration which does the exact same thing
parent c13487e0
No related branches found
No related tags found
No related merge requests found
......@@ -138,9 +138,16 @@
-->
<!-- Difference related to the Security refactoring. Start a new <revapi.differences> entry for other
differences -->
<!-- Added generics to NumberProperty. Start a new <revapi.differences> entry for other differences -->
<revapi.differences>
<differences>
<item>
<ignore>true</ignore>
<code>java.class.removed</code>
<old>class com.xpn.xwiki.store.migration.hibernate.R130200001XWIKI18429DataMigration</old>
<justification>Migration not needed anymore</justification>
</item>
</differences>
</revapi.differences>
</analysisConfiguration>
</configuration>
</plugin>
......
......@@ -832,7 +832,7 @@
**/store/migration/hibernate/R6079XWIKI1878DataMigration.java,
**/store/migration/hibernate/R7350XWIKI2079DataMigration.java,
**/store/migration/hibernate/R40000XWIKI6990DataMigration.java,
**/store/migration/hibernate/R130200001XWIKI18429DataMigration.java,
**/store/migration/hibernate/AbstractResizeMigration.java,
**/store/XWikiAttachmentStoreInterface.java,
**/store/XWikiBatcherFactory.java,
**/store/XWikiBatcher.java,
......
......@@ -23,14 +23,13 @@
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
......@@ -50,7 +49,6 @@
import org.hibernate.mapping.Value;
import org.hibernate.query.NativeQuery;
import org.slf4j.Logger;
import org.xwiki.component.annotation.Component;
import org.xwiki.extension.version.Version;
import org.xwiki.extension.version.internal.DefaultVersion;
......@@ -64,16 +62,11 @@
import com.xpn.xwiki.store.migration.XWikiDBVersion;
/**
* This migration increase the maximum size of all the columns potentially containing a document reference to the
* maximum index supported by MySQL: 768.
* Extended by migrations which need to resize columns to the maximum index supported by MySQL: 768.
*
* @version $Id$
* @since 13.2RC1
*/
@Component
@Named("R130200001XWIKI18429")
@Singleton
public class R130200001XWIKI18429DataMigration extends AbstractHibernateDataMigration
public abstract class AbstractResizeMigration extends AbstractHibernateDataMigration
{
private static final int MAXSIZE_MIN = 720;
......@@ -238,23 +231,44 @@ public String getPreHibernateLiquibaseChangeLog() throws DataMigrationException
try (Connection connection = jdbcConnectionAccess.obtainConnection()) {
DatabaseMetaData databaseMetaData = connection.getMetaData();
// Remove combined UNIQUE KEY affecting xwikiattrecyclebin#XDA_FILENAME column since those are not
// supposed to exist anymore and it can prevent the resize on MySQL/MariaDB
java.util.Collection<PersistentClass> bindings =
this.hibernateStore.getConfigurationMetadata().getEntityBindings();
Set<String> dynamicTables = new HashSet<>();
List<PersistentClass> existingTables = new ArrayList<>(bindings.size());
if (this.hibernateStore.getDatabaseProductName() == DatabaseProduct.MYSQL) {
// Make sure all MySQL/MariaDB tables use a DYNAMIC row format (required to support key prefix
// length limit up to 3072 bytes)
for (PersistentClass entity : this.hibernateStore.getConfigurationMetadata().getEntityBindings()) {
if (exists(entity, databaseMetaData)) {
existingTables.add(entity);
setTableDYNAMIC(entity, builder, dynamicTables);
}
}
// Remove combined UNIQUE KEY affecting xwikiattrecyclebin#XDA_FILENAME column since those are not
// supposed to exist anymore and it can prevent the resize on MySQL/MariaDB
removeAttachmentRecycleFilenameMultiKey(builder);
removeRecycleFilenameMultiKey(builder);
}
// Update collumns for which the size changed
updateColumns(databaseMetaData, builder);
// Update columns for which the size changed
updateColumns(existingTables, databaseMetaData, builder, dynamicTables);
}
} catch (SQLException e) {
throw new DataMigrationException("Error while extracting metadata", e);
}
if (builder.length() > 0) {
return String.format("<changeSet author=\"xwiki\" id=\"R%s\">%s</changeSet>", getVersion().getVersion(),
builder.toString());
String script = String.format("<changeSet author=\"xwiki\" id=\"R%s\">%s</changeSet>",
getVersion().getVersion(), builder.toString());
this.logger.debug("Liquibase script: {}", script);
return script;
}
return null;
......@@ -312,28 +326,17 @@ public List<String> doInHibernate(Session session) throws HibernateException, XW
}
}
private void updateColumns(DatabaseMetaData databaseMetaData, StringBuilder builder)
throws SQLException, DataMigrationException
private void updateColumns(List<PersistentClass> existingTables, DatabaseMetaData databaseMetaData,
StringBuilder builder, Set<String> dynamicTables) throws SQLException, DataMigrationException
{
Set<String> dynamicTables = new HashSet<>();
for (PersistentClass entity : this.hibernateStore.getConfigurationMetadata().getEntityBindings()) {
// Check if the table exist
if (exists(entity, databaseMetaData)) {
if (this.hibernateStore.getDatabaseProductName() == DatabaseProduct.MYSQL) {
// Make sure all MySQL/MariaDB tables use a DYNAMIC row format (required to support key prefix
// length limit up to 3072 bytes)
setTableDYNAMIC(entity, builder, dynamicTables);
}
// Find properties to update
for (Iterator<Property> it = entity.getPropertyIterator(); it.hasNext();) {
updateProperty(it.next(), databaseMetaData, dynamicTables, builder);
}
// Check the key
updateValue(entity.getKey(), databaseMetaData, dynamicTables, builder);
for (PersistentClass entity : existingTables) {
// Find properties to update
for (Iterator<Property> it = entity.getPropertyIterator(); it.hasNext();) {
updateProperty(it.next(), databaseMetaData, dynamicTables, builder);
}
// Check the key
updateValue(entity.getKey(), databaseMetaData, dynamicTables, builder);
}
}
......@@ -356,6 +359,8 @@ private void setTableDYNAMIC(String tableName, StringBuilder builder, Set<String
builder.append(tableName);
builder.append(" ROW_FORMAT=DYNAMIC");
builder.append("</sql>");
dynamicTables.add(tableName);
}
}
......@@ -418,6 +423,7 @@ private void update(Column column, Set<String> dynamicTables, StringBuilder buil
// Make sure all MySQL/MariaDB tables use a DYNAMIC row format (required to support key prefix
// length limit up to 3072 bytes)
// Check again in case it's a special table which was missed in the previous pass
setTableDYNAMIC(tableName, builder, dynamicTables);
// Not using <modifyDataType> here because Liquibase ignores attributes likes "NOT NULL"
......
......@@ -54,7 +54,7 @@
* This migration aims at applying the fix done on https://jira.xwiki.org/browse/XWIKI-15215 (change the type of some
* column so that they fit in the maximum allowed maximum row size for the used table type) instances older than
* 11.3RC1. Without this it's difficult to migrate to utf8mb3. It's also a requirement for
* {@link R130200001XWIKI18429DataMigration}.
* {@link AbstractResizeMigration}.
* <p>
* The columns are:
* <ul>
......
......@@ -27,7 +27,7 @@
import com.xpn.xwiki.store.migration.XWikiDBVersion;
/**
* This migration increase the maximum size of the parent column to the maximum index supported by MySQL: 768.
* This migration increase the maximum size of various columns to the maximum index supported by MySQL: 768.
*
* @version $Id$
* @since 13.4.7
......@@ -37,12 +37,12 @@
@Component
@Named("R130407000XWIKI19207")
@Singleton
public class R130407000XWIKI19207DataMigration extends R130200001XWIKI18429DataMigration
public class R130407000XWIKI19207DataMigration extends AbstractResizeMigration
{
@Override
public String getDescription()
{
return "Increase the maximum size of the parent column to the maximum index supported by MySQL";
return "Increase the maximum size of the columns to the maximum index supported by MySQL";
}
@Override
......
......@@ -206,7 +206,6 @@ com.xpn.xwiki.store.migration.hibernate.R911001XWIKI14895DataMigration
com.xpn.xwiki.store.migration.hibernate.R1008010XWIKI10092DataMigration
com.xpn.xwiki.store.migration.hibernate.R1138000XWIKI16709DataMigration
com.xpn.xwiki.store.migration.hibernate.R130200000XWIKI17200DataMigration
com.xpn.xwiki.store.migration.hibernate.R130200001XWIKI18429DataMigration
com.xpn.xwiki.store.migration.hibernate.R130407000XWIKI19207DataMigration
com.xpn.xwiki.store.VoidAttachmentVersioningStore
com.xpn.xwiki.store.XWikiHibernateStore
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment