);
CREATE UNIQUE INDEX "PK_ES_QUEUE" ON "ES_QUEUE" ("UUID");
CREATE INDEX "ES_QUEUE_CREATED_AT" ON "ES_QUEUE" ("CREATED_AT");
+
+CREATE TABLE "PLUGINS" (
+ "UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
+ "KEE" VARCHAR(200) NOT NULL,
+ "BASE_PLUGIN_KEY" VARCHAR(200),
+ "HASH" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+CREATE UNIQUE INDEX "PLUGINS_KEY" ON "PLUGINS" ("KEE");
context.execute(new AddColumnsBuilder(getDialect(), "rules")
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("plugin_key")
- .setLimit(200)
+ .setLimit(CreateTablePlugins.PLUGIN_KEY_MAX_SIZE)
.setIsNullable(true)
.build())
.build());
--- /dev/null
+/*
+ * 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());
+ }
+}
.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);
}
}
--- /dev/null
+/*
+ * 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();
+ }
+
+}
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 5);
+ verifyMigrationCount(underTest, 6);
}
}