diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2019-07-19 17:12:33 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-08-09 20:21:24 +0200 |
commit | e8985121ed131098be84a1a28bc2584052c4d911 (patch) | |
tree | ac5bfac1809dbd987ce993f183bdcc8729df6fdc /server/sonar-db-migration | |
parent | a787e0d957e3bf706e8d28934300468ac2a7ee14 (diff) | |
download | sonarqube-e8985121ed131098be84a1a28bc2584052c4d911.tar.gz sonarqube-e8985121ed131098be84a1a28bc2584052c4d911.zip |
SONAR-8520 init H2 with Java code as with all other DBs
schema-h2.ddl file is replaced by autogenerated file schema-sq.ddl (and moved to module sonar-db-dao)
files rows-h2.sql and schema_migrations-h2.ddl are dropped
command "./gradlew :server:sonar-db-dao:dumpSchema" can be used to update schema-sq.ddl
but this is optional as build will always ensure file is up-to-date with java changes and fail the build if it is not (required for CI builds)
Diffstat (limited to 'server/sonar-db-migration')
13 files changed, 38 insertions, 31 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java index fc1127987c3..b199571a48c 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java @@ -24,7 +24,7 @@ import org.sonar.server.platform.db.migration.history.MigrationHistoryImpl; import org.sonar.server.platform.db.migration.history.MigrationHistoryMeddler; import org.sonar.server.platform.db.migration.step.MigrationStepRegistryImpl; import org.sonar.server.platform.db.migration.step.MigrationStepsProvider; -import org.sonar.server.platform.db.migration.version.v79.DbVersion79; +import org.sonar.server.platform.db.migration.version.v00.DbVersion00; import org.sonar.server.platform.db.migration.version.v80.DbVersion80; public class MigrationConfigurationModule extends Module { @@ -32,7 +32,7 @@ public class MigrationConfigurationModule extends Module { protected void configureModule() { add( // DbVersion implementations - DbVersion79.class, + DbVersion00.class, DbVersion80.class, // migration steps diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/engine/MigrationContainerPopulatorImpl.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/engine/MigrationContainerPopulatorImpl.java index 432ce8664a1..2c89a904094 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/engine/MigrationContainerPopulatorImpl.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/engine/MigrationContainerPopulatorImpl.java @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.Set; import org.sonar.server.platform.db.migration.step.MigrationStep; import org.sonar.server.platform.db.migration.step.MigrationSteps; +import org.sonar.server.platform.db.migration.step.MigrationStepsExecutor; import org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl; import org.sonar.server.platform.db.migration.version.DbVersion; @@ -38,14 +39,20 @@ import org.sonar.server.platform.db.migration.version.DbVersion; */ public class MigrationContainerPopulatorImpl implements MigrationContainerPopulator { private final DbVersion[] dbVersions; + private final Class<? extends MigrationStepsExecutor> executorType; public MigrationContainerPopulatorImpl(DbVersion... dbVersions) { + this(MigrationStepsExecutorImpl.class, dbVersions); + } + + protected MigrationContainerPopulatorImpl(Class<? extends MigrationStepsExecutor> executorType, DbVersion... dbVersions) { this.dbVersions = dbVersions; + this.executorType = executorType; } @Override public void populateContainer(MigrationContainer container) { - container.add(MigrationStepsExecutorImpl.class); + container.add(executorType); populateFromDbVersion(container); populateFromMigrationSteps(container); } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DdlChange.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DdlChange.java index c4620a40d80..e84746ec219 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DdlChange.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DdlChange.java @@ -41,7 +41,7 @@ public abstract class DdlChange implements MigrationStep { @Override public final void execute() throws SQLException { try (Connection writeConnection = createDdlConnection()) { - Context context = new Context(writeConnection); + Context context = new ContextImpl(writeConnection); execute(context); } } @@ -62,22 +62,31 @@ public abstract class DdlChange implements MigrationStep { return db.getDialect(); } - public static class Context { + public interface Context { + void execute(String sql); + + void execute(String... sqls); + + void execute(List<String> sqls); + } + + private static class ContextImpl implements Context { private static final int ERROR_HANDLING_THRESHOLD = 10; // the tricky regexp is required to match "NULL" but not "NOT NULL" private final Pattern nullPattern = Pattern.compile("\\h?(?<!NOT )NULL"); private final Pattern notNullPattern = Pattern.compile("\\h?NOT NULL"); private final Connection writeConnection; - public Context(Connection writeConnection) { + private ContextImpl(Connection writeConnection) { this.writeConnection = writeConnection; } - public void execute(String sql) throws SQLException { + @Override + public void execute(String sql) { execute(sql, sql, 0); } - public void execute(String original, String sql, int errorCount) throws SQLException { + private void execute(String original, String sql, int errorCount) { try (Statement stmt = writeConnection.createStatement()) { stmt.execute(sql); writeConnection.commit(); @@ -108,11 +117,13 @@ public abstract class DdlChange implements MigrationStep { } } - public void execute(String... sqls) throws SQLException { + @Override + public void execute(String... sqls) { execute(asList(sqls)); } - public void execute(List<String> sqls) throws SQLException { + @Override + public void execute(List<String> sqls) { for (String sql : sqls) { execute(sql); } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v79/CreateInitialSchema.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchema.java index b6e36d57228..a999c797d2e 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v79/CreateInitialSchema.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchema.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.platform.db.migration.version.v79; +package org.sonar.server.platform.db.migration.version.v00; import java.sql.SQLException; import org.sonar.db.Database; diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v79/DbVersion79.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/DbVersion00.java index 741aa24b9d5..fc1b14b473b 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v79/DbVersion79.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/DbVersion00.java @@ -17,12 +17,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.platform.db.migration.version.v79; +package org.sonar.server.platform.db.migration.version.v00; import org.sonar.server.platform.db.migration.step.MigrationStepRegistry; import org.sonar.server.platform.db.migration.version.DbVersion; -public class DbVersion79 implements DbVersion { +public class DbVersion00 implements DbVersion { @Override public void addSteps(MigrationStepRegistry registry) { registry diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v79/PopulateInitialSchema.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchema.java index 4d18e3bfa84..66c3ff3af84 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v79/PopulateInitialSchema.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchema.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.platform.db.migration.version.v79; +package org.sonar.server.platform.db.migration.version.v00; import java.sql.SQLException; import java.util.Arrays; diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v79/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/package-info.java index 1bcbde154dd..539483a3ef5 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v79/package-info.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/package-info.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @ParametersAreNonnullByDefault -package org.sonar.server.platform.db.migration.version.v79; +package org.sonar.server.platform.db.migration.version.v00; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java index dcf576234aa..f7f1788d7e0 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java @@ -22,14 +22,11 @@ package org.sonar.server.platform.db.migration.charset; import java.sql.Connection; import java.util.List; import java.util.Map; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.sonar.db.CoreDbTester; -import org.sonar.db.dialect.H2; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assume.assumeTrue; public class SqlExecutorTest { @@ -43,14 +40,6 @@ public class SqlExecutorTest { @Rule public CoreDbTester dbTester = CoreDbTester.createForSchema(SqlExecutorTest.class, "users_table.sql"); - @Before - public void disableIfNotH2() { - // TODO dbTester.selectFirst() returns keys with different case - // depending on target db (lower-case for MySQL but upper-case for H2). - // It has to be fixed in order to reactive this test for all dbs. - assumeTrue(dbTester.database().getDialect().getId().equals(H2.ID)); - } - @Test public void executeSelect_executes_PreparedStatement() throws Exception { dbTester.executeInsert(USERS_DB_TABLE, LOGIN_DB_COLUMN, "login1", NAME_DB_COLUMN, "name one", IS_ROOT_DB_COLUMN, false); diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v79/CreateInitialSchemaTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaTest.java index af0b1b77415..1f4e830047b 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v79/CreateInitialSchemaTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaTest.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.platform.db.migration.version.v79; +package org.sonar.server.platform.db.migration.version.v00; import java.sql.Connection; import java.sql.ResultSet; diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v79/DbVersion79Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/DbVersion00Test.java index 51fa25d635b..15ccec939f6 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v79/DbVersion79Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/DbVersion00Test.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.platform.db.migration.version.v79; +package org.sonar.server.platform.db.migration.version.v00; import org.junit.Test; @@ -25,8 +25,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount; import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber; -public class DbVersion79Test { - private DbVersion79 underTest = new DbVersion79(); +public class DbVersion00Test { + private DbVersion00 underTest = new DbVersion00(); @Test public void verify_no_support_component() { diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v79/PopulateInitialSchemaTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java index 7817f522149..166d955374a 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v79/PopulateInitialSchemaTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.platform.db.migration.version.v79; +package org.sonar.server.platform.db.migration.version.v00; import java.sql.SQLException; import java.util.Date; diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v79/CreateInitialSchemaTest/empty.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaTest/empty.sql index e69de29bb2d..e69de29bb2d 100644 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v79/CreateInitialSchemaTest/empty.sql +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaTest/empty.sql diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v79/PopulateInitialSchemaTest/v79.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest/v79.sql index 26147e6f907..26147e6f907 100644 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v79/PopulateInitialSchemaTest/v79.sql +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest/v79.sql |