diff --git a/xwiki-platform-core/pom.xml b/xwiki-platform-core/pom.xml index ea049842968602d30430668affec085568949658..c2e68a04f857914a8f0d1a95af0494ac67e576a2 100644 --- a/xwiki-platform-core/pom.xml +++ b/xwiki-platform-core/pom.xml @@ -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> diff --git a/xwiki-platform-core/xwiki-platform-oldcore/pom.xml b/xwiki-platform-core/xwiki-platform-oldcore/pom.xml index 102908d36891cf84f08d2968608c97007b338a20..e771d6ca29ea2f75183a8700f8a314bb212c15d7 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/pom.xml +++ b/xwiki-platform-core/xwiki-platform-oldcore/pom.xml @@ -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, diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130200001XWIKI18429DataMigration.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/AbstractResizeMigration.java similarity index 88% rename from xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130200001XWIKI18429DataMigration.java rename to xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/AbstractResizeMigration.java index 7a856e768f20477d7e4114b550ce64898954a494..d86bb3fe04d47358853454440f5ce688f4c54198 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130200001XWIKI18429DataMigration.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/AbstractResizeMigration.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" diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130200000XWIKI17200DataMigration.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130200000XWIKI17200DataMigration.java index e3873042836d57d6dc52e250f0a82da4e9d6cb98..6a7e341a90833c912190d000bf19fc2222e5f77d 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130200000XWIKI17200DataMigration.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130200000XWIKI17200DataMigration.java @@ -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> diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130407000XWIKI19207DataMigration.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130407000XWIKI19207DataMigration.java index 369af7bf942be53a17f6c4e8beb600e7ac15bee2..c3245f86ddcb1ced3a32b2beed52b6cd6846d006 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130407000XWIKI19207DataMigration.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130407000XWIKI19207DataMigration.java @@ -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 diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt index cf1a7f3750d834ee3900c1ed2b63fecf5560d1ed..4898ddefc67cddbd27d9d2c137008b8bc3de03cd 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt @@ -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