From d60cd5ed1c65c32b3517222767e07f4512e57206 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Fri, 5 Mar 2021 11:37:47 +0000 Subject: [PATCH] ACS-1180 ACS 7 Stacks: MySQL 8 (#336) --- .travis.yml | 13 ++++---- .../alfresco/util/schemacomp/ExportDb.java | 31 ++++++++++++++----- .../Schema-Reference-ACT.xml | 2 +- .../Schema-Reference-ALF.xml | 8 ++--- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index eb73189929..49402870a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -142,13 +142,12 @@ jobs: - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.16.1 script: travis_wait 20 mvn -B test -pl repository -Dtest=AllDBTestsTestSuite -Ddb.driver=com.mysql.jdbc.Driver -Ddb.name=alfresco -Ddb.url=jdbc:mysql://localhost:3307/alfresco -Ddb.username=alfresco -Ddb.password=alfresco -# One failing test to do with the schema reference files. ACS-1180 -# - name: "Repository - MySQL 8 tests" -# if: commit_message !~ /\[skip db\]/ -# before_script: -# - docker run -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mysql:8 --transaction-isolation='READ-COMMITTED' -# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.16.1 -# script: travis_wait 20 mvn -B test -pl repository -Dtest=AllDBTestsTestSuite -Ddb.driver=com.mysql.jdbc.Driver -Ddb.name=alfresco -Ddb.url=jdbc:mysql://localhost:3307/alfresco -Ddb.username=alfresco -Ddb.password=alfresco + - name: "Repository - MySQL 8 tests" + if: commit_message !~ /\[skip db\]/ + before_script: + - docker run -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mysql:8 --transaction-isolation='READ-COMMITTED' + - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.16.1 + script: travis_wait 20 mvn -B test -pl repository -Dtest=AllDBTestsTestSuite -Ddb.driver=com.mysql.jdbc.Driver -Ddb.name=alfresco -Ddb.url=jdbc:mysql://localhost:3307/alfresco -Ddb.username=alfresco -Ddb.password=alfresco - name: "Repository - PostgreSQL 10.9 tests" if: commit_message !~ /\[skip db\]/ diff --git a/repository/src/main/java/org/alfresco/util/schemacomp/ExportDb.java b/repository/src/main/java/org/alfresco/util/schemacomp/ExportDb.java index 54ee08076f..d4f355482f 100644 --- a/repository/src/main/java/org/alfresco/util/schemacomp/ExportDb.java +++ b/repository/src/main/java/org/alfresco/util/schemacomp/ExportDb.java @@ -32,8 +32,12 @@ import java.sql.DatabaseMetaData; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.stream.Collectors; import javax.sql.DataSource; @@ -41,10 +45,10 @@ import org.alfresco.repo.domain.dialect.Dialect; import org.alfresco.repo.domain.dialect.TypeNames; import org.alfresco.service.descriptor.Descriptor; import org.alfresco.service.descriptor.DescriptorService; +import org.alfresco.util.DBScriptUtil; import org.alfresco.util.DatabaseMetaDataHelper; import org.alfresco.util.DialectUtil; import org.alfresco.util.PropertyCheck; -import org.alfresco.util.DBScriptUtil; import org.alfresco.util.schemacomp.model.Column; import org.alfresco.util.schemacomp.model.ForeignKey; import org.alfresco.util.schemacomp.model.Index; @@ -257,6 +261,7 @@ public class ExportDb tableTypes = new String[] { "TABLE", "VIEW", "SEQUENCE" }; } + // No tables are returned when using MySQL8 - maybe this issue can be solved if we update the MySQL JDBC driver that we use (the new driver class is `com.mysql.cj.jdbc.Driver'). final ResultSet tables = dbmd.getTables(null, schemaName, prefixFilter, tableTypes); processTables(dbmd, tables); @@ -331,10 +336,11 @@ public class ExportDb columns.close(); - // Primary key + // Primary key - beware that getPrimaryKeys gets primary keys ordered by their column name final ResultSet primarykeycols = dbmd.getPrimaryKeys(null, tables.getString("TABLE_SCHEM"), tableName); - + PrimaryKey pk = null; + Map keySeqsAndColumnNames = new LinkedHashMap<>(); while (primarykeycols.next()) { @@ -343,12 +349,23 @@ public class ExportDb String pkName = primarykeycols.getString("PK_NAME"); pk = new PrimaryKey(pkName); } - String columnName = primarykeycols.getString("COLUMN_NAME"); - pk.getColumnNames().add(columnName); - + + // We should add columns ordered by the KEY_SEQ rather than by the column name + // Populating map with key sequences and column names for a proper sorting later. int columnOrder = primarykeycols.getInt("KEY_SEQ"); - pk.getColumnOrders().add(columnOrder); + String columnName = primarykeycols.getString("COLUMN_NAME"); + keySeqsAndColumnNames.put(columnOrder, columnName); } + + List keyseqSortedColumnNames = new LinkedList<>(); + List keySeqSortedColumnOrders = keySeqsAndColumnNames.keySet().stream().sorted().collect(Collectors.toList()); + for (int keySeq: keySeqSortedColumnOrders) + { + keyseqSortedColumnNames.add(keySeqsAndColumnNames.get(keySeq)); + } + pk.setColumnOrders(keySeqSortedColumnOrders); + pk.setColumnNames(keyseqSortedColumnNames); + primarykeycols.close(); // If this table has a primary key, add it. diff --git a/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/Schema-Reference-ACT.xml b/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/Schema-Reference-ACT.xml index 7c0f1c40e9..24fe2943a8 100644 --- a/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/Schema-Reference-ACT.xml +++ b/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/Schema-Reference-ACT.xml @@ -898,8 +898,8 @@ - GROUP_ID_ USER_ID_ + GROUP_ID_ diff --git a/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/Schema-Reference-ALF.xml b/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/Schema-Reference-ALF.xml index 7d6c902e4d..600f35900b 100644 --- a/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/Schema-Reference-ALF.xml +++ b/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/Schema-Reference-ALF.xml @@ -1885,10 +1885,10 @@ - list_index - locale_id node_id qname_id + list_index + locale_id @@ -2174,9 +2174,9 @@ + root_prop_id contained_in prop_index - root_prop_id @@ -2543,8 +2543,8 @@ - node_id user_node_id + node_id