diff --git a/repository/src/main/java/org/alfresco/util/schemacomp/SchemaDifferenceHelper.java b/repository/src/main/java/org/alfresco/util/schemacomp/SchemaDifferenceHelper.java index 9b12bcafd1..e6785f8f8c 100644 --- a/repository/src/main/java/org/alfresco/util/schemacomp/SchemaDifferenceHelper.java +++ b/repository/src/main/java/org/alfresco/util/schemacomp/SchemaDifferenceHelper.java @@ -78,19 +78,20 @@ public class SchemaDifferenceHelper public String findPatchCausingDifference(Difference difference) { - for (SchemaUpgradeScriptPatch patch: optionalUpgradePatches) + String differenceText = describe(difference); + for (SchemaUpgradeScriptPatch patch : optionalUpgradePatches) { - if (!isPatchApplied(patch)) - { - List problemPatterns = getProblemsPatterns(patch); - for (String problemPattern: problemPatterns) - { - if (describe(difference).matches(problemPattern)) - { - return patch.getId(); - } - } - } + if (!isPatchApplied(patch)) + { + List problemPatterns = getProblemsPatterns(patch); + for (String problemPattern : problemPatterns) + { + if (differenceText.matches(problemPattern)) + { + return patch.getId(); + } + } + } } return null; diff --git a/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/AlfrescoCreate-RepoTables.sql b/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/AlfrescoCreate-RepoTables.sql index f106adb6a8..76a1107baa 100644 --- a/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/AlfrescoCreate-RepoTables.sql +++ b/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/AlfrescoCreate-RepoTables.sql @@ -162,28 +162,16 @@ CREATE TABLE alf_authority_alias CONSTRAINT fk_alf_autha_ali FOREIGN KEY (alias_id) REFERENCES alf_authority (id) ) ENGINE=InnoDB; -CREATE TABLE alf_server -( - id BIGINT NOT NULL AUTO_INCREMENT, - version BIGINT NOT NULL, - ip_address VARCHAR(39) NOT NULL, - PRIMARY KEY (id), - UNIQUE KEY ip_address (ip_address) -) ENGINE=InnoDB; - CREATE TABLE alf_transaction ( id BIGINT NOT NULL AUTO_INCREMENT, version BIGINT NOT NULL, - server_id BIGINT, change_txn_id VARCHAR(56) NOT NULL, commit_time_ms BIGINT, PRIMARY KEY (id), KEY idx_alf_txn_ctms (commit_time_ms, id), KEY idx_alf_txn_ctms_sc (commit_time_ms), - key idx_alf_txn_id_ctms (id, commit_time_ms), - KEY fk_alf_txn_svr (server_id), - CONSTRAINT fk_alf_txn_svr FOREIGN KEY (server_id) REFERENCES alf_server (id) + key idx_alf_txn_id_ctms (id, commit_time_ms) ) ENGINE=InnoDB; CREATE TABLE alf_store 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 09b0fc371b..515393e8e4 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 @@ -2474,38 +2474,6 @@ - - - - bigint - false - true - - - bigint - false - false - - - varchar(39) - false - false - - - - - id - - - - - - - ip_address - - - -
@@ -2652,17 +2620,12 @@ false false - - bigint - true - false - - + varchar(56) false false - + bigint true false @@ -2673,13 +2636,6 @@ id - - - server_id - alf_server - id - - @@ -2698,11 +2654,6 @@ commit_time_ms - - - server_id - -
diff --git a/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/AlfrescoCreate-RepoTables.sql b/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/AlfrescoCreate-RepoTables.sql index b5176f5fa6..5740ad18d5 100644 --- a/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/AlfrescoCreate-RepoTables.sql +++ b/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/AlfrescoCreate-RepoTables.sql @@ -174,31 +174,18 @@ CREATE UNIQUE INDEX auth_id ON alf_authority_alias (auth_id, alias_id); CREATE INDEX fk_alf_autha_ali ON alf_authority_alias (alias_id); CREATE INDEX fk_alf_autha_aut ON alf_authority_alias (auth_id); -CREATE SEQUENCE alf_server_seq START WITH 1 INCREMENT BY 1; -CREATE TABLE alf_server -( - id INT8 NOT NULL, - version INT8 NOT NULL, - ip_address VARCHAR(39) NOT NULL, - PRIMARY KEY (id) -); -CREATE UNIQUE INDEX ip_address ON alf_server (ip_address); - CREATE SEQUENCE alf_transaction_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_transaction ( id INT8 NOT NULL, version INT8 NOT NULL, - server_id INT8, change_txn_id VARCHAR(56) NOT NULL, commit_time_ms INT8, - PRIMARY KEY (id), - CONSTRAINT fk_alf_txn_svr FOREIGN KEY (server_id) REFERENCES alf_server (id) + PRIMARY KEY (id) ); CREATE INDEX idx_alf_txn_ctms ON alf_transaction (commit_time_ms, id); CREATE INDEX idx_alf_txn_ctms_sc ON alf_transaction (commit_time_ms); CREATE INDEX idx_alf_txn_id_ctms ON alf_transaction (id, commit_time_ms); -CREATE INDEX fk_alf_txn_svr ON alf_transaction (server_id); CREATE SEQUENCE alf_store_seq START WITH 1 INCREMENT BY 1; CREATE TABLE alf_store diff --git a/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Schema-Reference-ALF.xml b/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Schema-Reference-ALF.xml index 9b549e4ec5..bd5079c166 100644 --- a/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Schema-Reference-ALF.xml +++ b/repository/src/main/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Schema-Reference-ALF.xml @@ -44,7 +44,6 @@ - @@ -2545,38 +2544,6 @@
- - - - int8 - false - false - - - int8 - false - false - - - varchar(39) - false - false - - - - - id - - - - - - - ip_address - - - -
@@ -2723,17 +2690,12 @@ false false - - int8 - true - false - - + varchar(56) false false - + int8 true false @@ -2744,19 +2706,7 @@ id - - - server_id - alf_server - id - - - - - server_id - - commit_time_ms diff --git a/repository/src/main/resources/alfresco/dbscripts/db-schema-context.xml b/repository/src/main/resources/alfresco/dbscripts/db-schema-context.xml index 9f1c79fb9d..606cfc0f1a 100644 --- a/repository/src/main/resources/alfresco/dbscripts/db-schema-context.xml +++ b/repository/src/main/resources/alfresco/dbscripts/db-schema-context.xml @@ -56,6 +56,7 @@ + diff --git a/repository/src/main/resources/alfresco/dbscripts/upgrade/7.1.0/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/remove-alf_server-table.sql b/repository/src/main/resources/alfresco/dbscripts/upgrade/7.1.0/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/remove-alf_server-table.sql new file mode 100644 index 0000000000..7c8086d884 --- /dev/null +++ b/repository/src/main/resources/alfresco/dbscripts/upgrade/7.1.0/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/remove-alf_server-table.sql @@ -0,0 +1,31 @@ +-- +-- Title: Remove alf_server table +-- Database: MySQL +-- Since: V6.3 +-- Author: David Edwards +-- Author: Alex Mukha +-- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- + +SET FOREIGN_KEY_CHECKS=0; + +DROP TABLE alf_server; + +ALTER TABLE alf_transaction + DROP FOREIGN KEY fk_alf_txn_svr, + DROP COLUMN server_id; + +SET FOREIGN_KEY_CHECKS=1; + +-- +-- Record script finish +-- +DELETE FROM alf_applied_patch WHERE id = 'patch.db-V7.1.0-remove-alf_server-table'; +INSERT INTO alf_applied_patch + (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) + VALUES + ( + 'patch.db-V7.1.0-remove-alf_server-table', 'Remove alf_server table', + 0, 15000, -1, 15001, null, 'UNKNOWN', ${TRUE}, ${TRUE}, 'alf_server table and constraints removed' + ); diff --git a/repository/src/main/resources/alfresco/dbscripts/upgrade/7.1.0/org.alfresco.repo.domain.dialect.PostgreSQLDialect/remove-alf_server-table.sql b/repository/src/main/resources/alfresco/dbscripts/upgrade/7.1.0/org.alfresco.repo.domain.dialect.PostgreSQLDialect/remove-alf_server-table.sql new file mode 100644 index 0000000000..357afd3339 --- /dev/null +++ b/repository/src/main/resources/alfresco/dbscripts/upgrade/7.1.0/org.alfresco.repo.domain.dialect.PostgreSQLDialect/remove-alf_server-table.sql @@ -0,0 +1,26 @@ +-- +-- Title: Remove alf_server table +-- Database: PostgreSQL +-- Since: V6.3 +-- Author: Bruno Bossola +-- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- + +ALTER TABLE alf_transaction + DROP CONSTRAINT IF EXISTS fk_alf_txn_svr, + DROP COLUMN IF EXISTS server_id; + +DROP TABLE IF EXISTS alf_server; + +-- +-- Record script finish +-- +DELETE FROM alf_applied_patch WHERE id = 'patch.db-V7.1.0-remove-alf_server-table'; +INSERT INTO alf_applied_patch + (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) + VALUES + ( + 'patch.db-V7.1.0-remove-alf_server-table', 'Removes alf_server table and constraints', + 0, 15000, -1, 15001, null, 'UNKNOWN', ${TRUE}, ${TRUE}, 'alf_server table and constraints removed' + ); diff --git a/repository/src/main/resources/alfresco/dbscripts/upgrade/7.1.0/remove-alf_server-table.patterns b/repository/src/main/resources/alfresco/dbscripts/upgrade/7.1.0/remove-alf_server-table.patterns new file mode 100644 index 0000000000..04e338851a --- /dev/null +++ b/repository/src/main/resources/alfresco/dbscripts/upgrade/7.1.0/remove-alf_server-table.patterns @@ -0,0 +1,7 @@ +(?i).*expected column .*alf_transaction\.change_txn_id\.order="3".* +(?i).*expected column .*alf_transaction\.commit_time_ms\.order="4".* +(?i).*unexpected column found in database with path: .*alf_transaction\.server_id +(?i).*unexpected foreign key found in database with path: .*alf_transaction\.fk_alf_txn_svr +(?i).*unexpected index found in database with path: .*alf_transaction\.fk_alf_txn_svr +(?i).*unexpected sequence found in database with path: .*alf_server_seq +(?i).*unexpected table found in database with path: .*alf_server diff --git a/repository/src/main/resources/alfresco/messages/patch-service.properties b/repository/src/main/resources/alfresco/messages/patch-service.properties index 49682fd571..ef0c0c90c0 100644 --- a/repository/src/main/resources/alfresco/messages/patch-service.properties +++ b/repository/src/main/resources/alfresco/messages/patch-service.properties @@ -402,4 +402,8 @@ patch.db-V5.2-remove-jbpm-tables-from-db.description=Removes all JBPM related ta patch.db-V6.0-change-set-indexes.description=Add additional indexes to support acl tracking. -patch.db-V6.3-add-indexes-node-transaction.description=Create additional indexes on alf_node and alf_transaction \ No newline at end of file +patch.db-V6.3-add-indexes-node-transaction.description=Create additional indexes on alf_node and alf_transaction + +patch.db-V7.1.0-remove-alf_server-table.description=Removes alf_server table and constraints + + diff --git a/repository/src/main/resources/alfresco/patch/patch-services-context.xml b/repository/src/main/resources/alfresco/patch/patch-services-context.xml index 6d78a839ca..49a5b90d25 100644 --- a/repository/src/main/resources/alfresco/patch/patch-services-context.xml +++ b/repository/src/main/resources/alfresco/patch/patch-services-context.xml @@ -1409,4 +1409,22 @@ classpath:alfresco/dbscripts/upgrade/6.3/${db.script.dialect}/add-indexes-node-transaction.sql - + + + patch.db-V7.1.0-remove-alf_server-table + patch.db-V7.1.0-remove-alf_server-table.description + 0 + 15000 + 15001 + + classpath:alfresco/dbscripts/upgrade/7.1.0/${db.script.dialect}/remove-alf_server-table.sql + + + classpath:alfresco/dbscripts/upgrade/7.1.0/remove-alf_server-table.patterns + + ${system.remove-alf_server-table-from-db.ignored} + + + + diff --git a/repository/src/main/resources/alfresco/repository.properties b/repository/src/main/resources/alfresco/repository.properties index b7f27589da..45289872f0 100644 --- a/repository/src/main/resources/alfresco/repository.properties +++ b/repository/src/main/resources/alfresco/repository.properties @@ -3,7 +3,7 @@ repository.name=Main Repository # Schema number -version.schema=15000 +version.schema=15001 # Directory configuration @@ -1239,3 +1239,6 @@ system.new-node-transaction-indexes.ignored=true # Allows the configuration of maximum limits of the temp files to be deleted or the maximum time allowed to run for the job system.tempFileCleaner.maxFilesToDelete= system.tempFileCleaner.maxTimeToRun= + +# Property to long running migration to remove alf_server in v7+ patch.db-V7.1.0-remove-alf_server-table +system.remove-alf_server-table-from-db.ignored=true diff --git a/repository/src/test/java/org/alfresco/util/schemacomp/SchemaBootstrapTest.java b/repository/src/test/java/org/alfresco/util/schemacomp/SchemaBootstrapTest.java index cb39221720..7a1fff1ea0 100644 --- a/repository/src/test/java/org/alfresco/util/schemacomp/SchemaBootstrapTest.java +++ b/repository/src/test/java/org/alfresco/util/schemacomp/SchemaBootstrapTest.java @@ -52,11 +52,9 @@ import org.alfresco.util.test.junitrules.ApplicationContextInit; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.RuleChain; -import org.junit.rules.TemporaryFolder; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; @@ -67,7 +65,7 @@ import org.w3c.dom.Node; @Category({OwnJVMTestsCategory.class}) public class SchemaBootstrapTest { - private static final String BOOTSTRAP_TEST_CONTEXT = "classpath*:alfresco/dbscripts/test-bootstrap-context.xml"; + private static final String BOOTSTRAP_TEST_CONTEXT = "classpath*:alfresco/dbscripts/bootstrap-context-test.xml"; private static final String MAIN_SCHEMA_REFERENCE_FILE = "classpath:alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Schema-Reference-ALF.xml"; private static final String TEST_SCHEMA_REFERENCE_FILE = "classpath:alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Test-Schema-Reference-ALF.xml"; private static final List TEST_SCHEMA_REFERENCE_URLS = Arrays.asList( @@ -82,9 +80,6 @@ public class SchemaBootstrapTest private SchemaBootstrap schemaBootstrap; private SchemaUpgradeScriptPatch optionalPatch; - @Rule - public TemporaryFolder testFolder = new TemporaryFolder(); - @BeforeClass public static void beforeClass() throws Exception { diff --git a/repository/src/test/java/org/alfresco/util/schemacomp/SchemaDifferenceHelperUnitTest.java b/repository/src/test/java/org/alfresco/util/schemacomp/SchemaDifferenceHelperUnitTest.java index 2592e45600..ec5fd4e2cf 100644 --- a/repository/src/test/java/org/alfresco/util/schemacomp/SchemaDifferenceHelperUnitTest.java +++ b/repository/src/test/java/org/alfresco/util/schemacomp/SchemaDifferenceHelperUnitTest.java @@ -43,6 +43,7 @@ import org.alfresco.repo.admin.patch.AppliedPatch; import org.alfresco.repo.admin.patch.PatchService; import org.alfresco.repo.admin.patch.impl.SchemaUpgradeScriptPatch; import org.alfresco.repo.domain.dialect.Dialect; +import org.alfresco.util.schemacomp.model.DbObject; import org.alfresco.util.schemacomp.model.Index; import org.alfresco.util.schemacomp.model.Schema; import org.alfresco.util.schemacomp.model.Table; @@ -125,8 +126,7 @@ public class SchemaDifferenceHelperUnitTest private Difference createDifference() { - Difference difference = new Difference(Where.IN_BOTH_BUT_DIFFERENCE, mock(DbProperty.class), mock(DbProperty.class)); - return difference; + return new Difference(Where.IN_BOTH_BUT_DIFFERENCE, new DbProperty(mock(DbObject.class)), new DbProperty(mock(DbObject.class))); } private Index createTableIndex(String tableName) diff --git a/repository/src/test/java/org/alfresco/util/schemacomp/SchemaReferenceFileTest.java b/repository/src/test/java/org/alfresco/util/schemacomp/SchemaReferenceFileTest.java index 5c620c075d..2488f8be5e 100644 --- a/repository/src/test/java/org/alfresco/util/schemacomp/SchemaReferenceFileTest.java +++ b/repository/src/test/java/org/alfresco/util/schemacomp/SchemaReferenceFileTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -25,47 +25,47 @@ */ package org.alfresco.util.schemacomp; - -import static org.junit.Assert.fail; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; import org.alfresco.repo.domain.schema.SchemaBootstrap; import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.testing.category.DBTests; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; import org.springframework.context.support.ClassPathXmlApplicationContext; /** - * Test intended for use in the continuous integration system that checks whether the - * schema reference file (for whichever database the tests are being run against) - * is in sync with the actual schema. If the test fails (and the schema comparator is - * in working order) then the most likely cause is that a new up-to-date schema reference file - * needs to be created. + * Test intended for use in the continuous integration system that checks + * whether the schema reference file (for whichever database the tests are being + * run against) is in sync with the actual schema. If the test fails (and the + * schema comparator is in working order) then the most likely cause is that a + * new up-to-date schema reference file needs to be created. *

* Schema reference files are created using the {@link DbToXML} tool. *

- * Note: if no reference file exists then the test will pass, this is to allow piece meal - * introduction of schmea reference files. + * Note: if no reference file exists then the test will pass, this is to allow + * piece meal introduction of schmea reference files. * * @see DbToXML * @author Matt Ward */ -@Category({OwnJVMTestsCategory.class, DBTests.class}) +@Category({ OwnJVMTestsCategory.class, DBTests.class }) public class SchemaReferenceFileTest { private ClassPathXmlApplicationContext ctx; private SchemaBootstrap schemaBootstrap; - + @Before public void setUp() throws Exception { - ctx = (ClassPathXmlApplicationContext) ApplicationContextHelper.getApplicationContext(); + ctx = (ClassPathXmlApplicationContext) ApplicationContextHelper.getApplicationContext(); schemaBootstrap = (SchemaBootstrap) ctx.getBean("schemaBootstrap"); } @@ -74,12 +74,28 @@ public class SchemaReferenceFileTest { ByteArrayOutputStream buff = new ByteArrayOutputStream(); PrintWriter out = new PrintWriter(buff); - int numProblems = schemaBootstrap.validateSchema(null, out); + int maybeProblems = schemaBootstrap.validateSchema(null, out); out.flush(); - - if (numProblems > 0) + + if (maybeProblems > 0) { - fail(buff.toString()); + List errors = computeRealErrors(buff); + assertTrue("\n"+buff, errors.isEmpty()); } } + + private List computeRealErrors(ByteArrayOutputStream buff) + { + String[] lines = buff.toString().split("\\n"); + + List errors = new ArrayList<>(); + for (int i = 0; i < lines.length; i++) + { + String line = lines[i].trim(); + if (line.isEmpty()) + break; + errors.add(line); + } + return errors; + } } diff --git a/repository/src/test/resources/alfresco/dbscripts/test-bootstrap-context.xml b/repository/src/test/resources/alfresco/dbscripts/bootstrap-context-test.xml similarity index 100% rename from repository/src/test/resources/alfresco/dbscripts/test-bootstrap-context.xml rename to repository/src/test/resources/alfresco/dbscripts/bootstrap-context-test.xml diff --git a/repository/src/test/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Test-Schema-Reference-ALF.xml b/repository/src/test/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Test-Schema-Reference-ALF.xml index 927a2fc2a2..0089785445 100644 --- a/repository/src/test/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Test-Schema-Reference-ALF.xml +++ b/repository/src/test/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Test-Schema-Reference-ALF.xml @@ -44,7 +44,6 @@ - @@ -2551,38 +2550,6 @@

- - - - int8 - false - false - - - int8 - false - false - - - varchar(39) - false - false - - - - - id - - - - - - - ip_address - - - -
@@ -2729,17 +2696,12 @@ false false - - int8 - true - false - - + varchar(56) false false - + int8 true false @@ -2750,19 +2712,7 @@ id - - - server_id - alf_server - id - - - - - server_id - - commit_time_ms