diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-03 15:34:42 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-09-07 08:33:31 +0200 |
commit | cf6cbbb26136ef38430fab84ac8cc38ae974a0a6 (patch) | |
tree | 4ec51a4b12543f8dd4cdb1ad9c002f267e99a89c /server/sonar-db-migration/src | |
parent | 019d17348791cccaa65c8709070d58f73e11c8db (diff) | |
download | sonarqube-cf6cbbb26136ef38430fab84ac8cc38ae974a0a6.tar.gz sonarqube-cf6cbbb26136ef38430fab84ac8cc38ae974a0a6.zip |
SONAR-9662 Create "plugins" table
Diffstat (limited to 'server/sonar-db-migration/src')
6 files changed, 153 insertions, 3 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddPluginKeyToRules.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddPluginKeyToRules.java index 4fa05dc1927..3443213e5bb 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddPluginKeyToRules.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddPluginKeyToRules.java @@ -38,7 +38,7 @@ public class AddPluginKeyToRules extends DdlChange { context.execute(new AddColumnsBuilder(getDialect(), "rules") .addColumn(newVarcharColumnDefBuilder() .setColumnName("plugin_key") - .setLimit(200) + .setLimit(CreateTablePlugins.PLUGIN_KEY_MAX_SIZE) .setIsNullable(true) .build()) .build()); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePlugins.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePlugins.java new file mode 100644 index 00000000000..9b28fa45fd7 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePlugins.java @@ -0,0 +1,81 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * 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.v66; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; +import org.sonar.server.platform.db.migration.sql.CreateTableBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder; +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class CreateTablePlugins extends DdlChange { + + static final int PLUGIN_KEY_MAX_SIZE = 200; + private static final String TABLE_NAME = "plugins"; + + public CreateTablePlugins(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + VarcharColumnDef keyColumn = newVarcharColumnDefBuilder() + .setColumnName("kee") + .setLimit(PLUGIN_KEY_MAX_SIZE) + .setIsNullable(false) + .build(); + context.execute( + new CreateTableBuilder(getDialect(), TABLE_NAME) + .addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(UUID_SIZE).setIsNullable(false).setIgnoreOracleUnit(true).build()) + .addColumn(keyColumn) + .addColumn(newVarcharColumnDefBuilder() + .setColumnName("base_plugin_key") + .setLimit(PLUGIN_KEY_MAX_SIZE) + .setIsNullable(true) + .build()) + .addColumn(newVarcharColumnDefBuilder() + .setColumnName("hash") + .setLimit(200) + .setIsNullable(false) + .build()) + .addColumn(newBigIntegerColumnDefBuilder() + .setColumnName("created_at") + .setIsNullable(false) + .build()) + .addColumn(newBigIntegerColumnDefBuilder() + .setColumnName("updated_at") + .setIsNullable(false) + .build()) + .build()); + + context.execute( + new CreateIndexBuilder(getDialect()) + .setTable(TABLE_NAME) + .setName("plugins_key") + .addColumn(keyColumn) + .setUnique(true) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java index 3ac1c79b7fa..1880ebc31d6 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java @@ -31,6 +31,7 @@ public class DbVersion66 implements DbVersion { .add(1801, "Create table CE task characteristics", CreateTableCeTaskCharacteristics.class) .add(1802, "Delete leak settings on views", DeleteLeakSettingsOnViews.class) .add(1803, "Fix empty USERS.EXTERNAL_IDENTITY and USERS.EXTERNAL_IDENTITY_PROVIDER", FixEmptyIdentityProviderInUsers.class) - .add(1804, "Add rules.plugin_key", AddPluginKeyToRules.class); + .add(1804, "Add rules.plugin_key", AddPluginKeyToRules.class) + .add(1805, "Create table plugins", CreateTablePlugins.class); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePluginsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePluginsTest.java new file mode 100644 index 00000000000..91f3f4b92f6 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePluginsTest.java @@ -0,0 +1,68 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * 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.v66; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.db.CoreDbTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CreateTablePluginsTest { + + private static final String TABLE = "plugins"; + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(CreateTablePluginsTest.class, "empty.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private CreateTablePlugins underTest = new CreateTablePlugins(db.database()); + + @Test + public void creates_table_on_empty_db() throws SQLException { + underTest.execute(); + + assertThat(db.countRowsOfTable(TABLE)).isEqualTo(0); + + db.assertColumnDefinition(TABLE, "uuid", Types.VARCHAR, 40, false); + db.assertPrimaryKey(TABLE, "pk_plugins", "uuid"); + db.assertColumnDefinition(TABLE, "kee", Types.VARCHAR, 200, false); + db.assertColumnDefinition(TABLE, "base_plugin_key", Types.VARCHAR, 200, true); + db.assertColumnDefinition(TABLE, "hash", Types.VARCHAR, 200, false); + db.assertColumnDefinition(TABLE, "created_at", Types.BIGINT, null, false); + db.assertColumnDefinition(TABLE, "updated_at", Types.BIGINT, null, false); + + db.assertUniqueIndex(TABLE, "plugins_key", "kee"); + } + + @Test + public void migration_is_not_reentrant() throws SQLException { + underTest.execute(); + + expectedException.expect(IllegalStateException.class); + + underTest.execute(); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java index 591df1a3dd4..bce2e551bc1 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java @@ -35,6 +35,6 @@ public class DbVersion66Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 5); + verifyMigrationCount(underTest, 6); } } diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTablePluginsTest/empty.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTablePluginsTest/empty.sql new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTablePluginsTest/empty.sql |