"UUID" VARCHAR(50) NOT NULL,
"UUID_PATH" VARCHAR(1500) NOT NULL,
"ROOT_UUID" VARCHAR(50) NOT NULL,
- "PROJECT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
"MODULE_UUID" VARCHAR(50),
"MODULE_UUID_PATH" VARCHAR(1500),
"NAME" VARCHAR(2000),
b_path="[null]"
b_qualifier="[null]"
/>
- ²
+
<!-- **************** First sub project **************** -->
<projects organization_uuid="org1"
name="Struts UI"
uuid="E"
uuid_path="A.E."
- project_uuid="[null]"
+ project_uuid="A"
module_uuid="[null]"
module_uuid_path=".E."
scope="PRJ"
root_uuid="E"
uuid="F"
uuid_path="A.E.F."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
root_uuid="E"
uuid="G"
uuid_path="A.E.F.G."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
name="Foo Struts Core"
uuid="H"
uuid_path="H."
- project_uuid="[null]"
+ project_uuid="A"
module_uuid="[null]"
module_uuid_path=".H."
scope="PRJ"
name="Struts UI"
uuid="E"
uuid_path="A.E."
- project_uuid="[null]"
+ project_uuid="A"
module_uuid="[null]"
module_uuid_path=".E."
scope="PRJ"
root_uuid="E"
uuid="F"
uuid_path="A.E.F."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
root_uuid="E"
uuid="G"
uuid_path="A.E.F.G."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
name="Foo Struts Core"
uuid="H"
uuid_path="H."
- project_uuid="[null]"
+ project_uuid="A"
module_uuid="[null]"
module_uuid_path=".H."
scope="PRJ"
name="Struts UI"
uuid="E"
uuid_path="A.E."
- project_uuid="[null]"
+ project_uuid="A"
module_uuid="[null]"
module_uuid_path=".E."
scope="PRJ"
root_uuid="E"
uuid="F"
uuid_path="A.E.F."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
root_uuid="E"
uuid="G"
uuid_path="A.E.F.G."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
name="Foo Struts Core"
uuid="H"
uuid_path="H."
- project_uuid="[null]"
+ project_uuid="A"
module_uuid="[null]"
module_uuid_path=".H."
scope="PRJ"
name="Struts UI"
uuid="E"
uuid_path="A.E."
- project_uuid="[null]"
+ project_uuid="A"
module_uuid="[null]"
module_uuid_path=".E."
scope="PRJ"
root_uuid="E"
uuid="F"
uuid_path="A.E.F."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
root_uuid="E"
uuid="G"
uuid_path="A.E.F.G."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
name="Struts UI"
uuid="E"
uuid_path="A.E."
- project_uuid="[null]"
+ project_uuid="A"
module_uuid="[null]"
module_uuid_path=".E."
scope="PRJ"
root_uuid="E"
uuid="F"
uuid_path="A.E.F."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
root_uuid="E"
uuid="G"
uuid_path="A.E.F.G."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
name="Struts UI"
uuid="E"
uuid_path="A.E."
- project_uuid="[null]"
+ project_uuid="A"
module_uuid="[null]"
module_uuid_path=".E."
scope="PRJ"
root_uuid="E"
uuid="F"
uuid_path="A.E.F."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
root_uuid="E"
uuid="G"
uuid_path="A.E.F.G."
- project_uuid="[null]"
+ project_uuid="E"
module_uuid="[null]"
module_uuid_path=".E."
description="[null]"
name="Foo Struts Core"
uuid="H"
uuid_path="H."
- project_uuid="[null]"
+ project_uuid="A"
module_uuid="[null]"
module_uuid_path=".H."
scope="PRJ"
kee="project"
name="project"
root_uuid="ABCD"
+ project_uuid="ABCD"
uuid="ABCD"
uuid_path="NOT_USED"
description="[null]"
uuid="uuid_1"
uuid_path="NOT_USED"
root_uuid="uuid_root"
+ project_uuid="uuid_root"
kee="foo"
enabled="1"
scope="FIL"
uuid="uuid_1"
uuid_path="NOT_USED"
root_uuid="uuid_root_1"
+ project_uuid="uuid_root_1"
kee="bar-old"
enabled="[true]"
scope="FIL"
uuid="uuid_2"
uuid_path="NOT_USED"
root_uuid="uuid_root_2"
+ project_uuid="uuid_root_2"
kee="bar-last"
enabled="[true]"
scope="FIL"
uuid="uuid_3"
uuid_path="NOT_USED"
root_uuid="uuid_root_3"
+ project_uuid="uuid_root_3"
kee="foo-old"
enabled="[true]"
scope="FIL"
uuid="uuid_4"
uuid_path="NOT_USED"
root_uuid="uuid_root_4"
+ project_uuid="uuid_root_4"
kee="foo-last"
enabled="[true]"
scope="FIL"
uuid="uuid_5"
uuid_path="NOT_USED"
root_uuid="uuid_root_5"
+ project_uuid="uuid_root_5"
kee="foo"
enabled="[true]"
scope="FIL"
uuid="uuid_6"
uuid_path="NOT_USED"
root_uuid="uuid_root_1"
+ project_uuid="uuid_root_1"
kee="baz"
enabled="[true]"
scope="FIL"
id="301"
kee="pj-w-snapshot:package"
root_uuid="EDFG"
+ project_uuid="EDFG"
uuid="ABCD"
uuid_path="NOT_USED"
module_uuid="EDFG"/>
id="302"
kee="pj-w-snapshot:file"
root_uuid="EDFG"
+ project_uuid="EDFG"
uuid="BCDE"
uuid_path="NOT_USED"
module_uuid="EDFG"/>
id="303"
kee="pj-w-snapshot:other"
root_uuid="EDFG"
+ project_uuid="EDFG"
uuid="CDEF"
uuid_path="NOT_USED"
module_uuid="EDFG"/>
uuid="EDFG"
uuid_path="NOT_USED"
root_uuid="EDFG"
+ project_uuid="EDFG"
module_uuid="[null]"/>
<projects organization_uuid="org1"
id="400"
id="301"
kee="pj-w-snapshot:package"
root_uuid="DEFG"
+ project_uuid="DEFG"
uuid="ABCD"
uuid_path="NOT_USED"
module_uuid="DEFG"/>
id="302"
kee="pj-w-snapshot:file"
root_uuid="DEFG"
+ project_uuid="DEFG"
uuid="BCDE"
uuid_path="NOT_USED"
module_uuid="DEFG"/>
id="303"
kee="pj-w-snapshot:other"
root_uuid="DEFG"
+ project_uuid="DEFG"
uuid="CDEF"
uuid_path="NOT_USED"
module_uuid="DEFG"/>
uuid="DEFG"
uuid_path="NOT_USED"
root_uuid="DEFG"
+ project_uuid="DEFG"
module_uuid="[null]"/>
<projects organization_uuid="org1"
id="400"
uuid="EFGH"
uuid_path="NOT_USED"
root_uuid="EFGH"
+ project_uuid="EFGH"
module_uuid="[null]"/>
</dataset>
uuid="DEFG"
uuid_path="NOT_USED"
root_uuid="DEFG"
+ project_uuid="DEFG"
module_uuid="[null]"
enabled="[true]"/>
<projects organization_uuid="org1"
uuid="EFGH"
uuid_path="NOT_USED"
root_uuid="EFGH"
+ project_uuid="EFGH"
module_uuid="[null]"
enabled="[true]"/>
uuid="DEFG"
uuid_path="NOT_USED"
root_uuid="DEFG"
+ project_uuid="DEFG"
module_uuid="[null]"
enabled="[true]"/>
<projects organization_uuid="org1"
uuid="EFGH"
uuid_path="NOT_USED"
root_uuid="EFGH"
+ project_uuid="EFGH"
module_uuid="[null]"
enabled="[true]"/>
uuid="DEFG"
uuid_path="NOT_USED"
root_uuid="DEFG"
+ project_uuid="DEFG"
module_uuid="[null]"
enabled="[true]"/>
<projects organization_uuid="org1"
uuid="EFGH"
uuid_path="NOT_USED"
root_uuid="EFGH"
+ project_uuid="EFGH"
module_uuid="[null]"
enabled="[true]"/>
uuid="DEFG"
uuid_path="NOT_USED"
root_uuid="DEFG"
+ project_uuid="DEFG"
module_uuid="[null]"/>
<projects organization_uuid="org1"
id="400"
uuid="EFGH"
uuid_path="NOT_USED"
root_uuid="EFGH"
+ project_uuid="EFGH"
module_uuid="[null]"/>
</dataset>
uuid="DEFG"
uuid_path="NOT_USED"
root_uuid="DEFG"
+ project_uuid="DEFG"
module_uuid="[null]"/>
<projects organization_uuid="org1"
id="400"
uuid="EFGH"
uuid_path="NOT_USED"
root_uuid="EFGH"
+ project_uuid="EFGH"
module_uuid="[null]"/>
</dataset>
uuid="DEFG"
uuid_path="NOT_USED"
root_uuid="DEFG"
+ project_uuid="DEFG"
module_uuid="[null]"/>
<projects organization_uuid="org1"
id="400"
uuid="EFGH"
uuid_path="NOT_USED"
root_uuid="EFGH"
+ project_uuid="EFGH"
module_uuid="[null]"/>
</dataset>
uuid="ABCD"
uuid_path="NOT_USED"
root_uuid="ABCD"
+ project_uuid="ABCD"
module_uuid="[null]"
kee="pj-w-snapshot"
scope="PRJ"
uuid="BCDE"
uuid_path="NOT_USED"
root_uuid="BCDE"
+ project_uuid="BCDE"
module_uuid="[null]"
kee="pj-w-snapshot1"
scope="PRJ"
uuid="CDEF"
uuid_path="NOT_USED"
root_uuid="CDEF"
+ project_uuid="CDEF"
module_uuid="[null]"
kee="pj-w-snapshot2"
scope="PRJ"
uuid="DEFG"
uuid_path="NOT_USED"
root_uuid="DEFG"
+ project_uuid="DEFG"
module_uuid="[null]"
kee="pj-w-snapshot3"
scope="PRJ"
uuid="ABCD"
uuid_path="NOT_USED"
root_uuid="ABCD"
+ project_uuid="ABCD"
module_uuid="[null]"
kee="pj-w-snapshot"
scope="PRJ"
uuid="BCDE"
uuid_path="NOT_USED"
root_uuid="BCDE"
+ project_uuid="BCDE"
module_uuid="[null]"
kee="pj-w-snapshot1"
scope="PRJ"
uuid="CDEF"
uuid_path="NOT_USED"
root_uuid="CDEF"
+ project_uuid="CDEF"
module_uuid="[null]"
kee="pj-w-snapshot2"
scope="PRJ"
uuid="DEFG"
uuid_path="NOT_USED"
root_uuid="DEFG"
+ project_uuid="DEFG"
module_uuid="[null]"
kee="pj-w-snapshot3"
scope="PRJ"
uuid="ABCD"
uuid_path="NOT_USED"
root_uuid="ABCD"
+ project_uuid="ABCD"
module_uuid="[null]"
kee="pj-w-snapshot"
scope="PRJ"
uuid="BCDE"
uuid_path="NOT_USED"
root_uuid="BCDE"
+ project_uuid="BCDE"
module_uuid="[null]"
kee="pj-w-snapshot1"
scope="PRJ"
uuid="CDEF"
uuid_path="NOT_USED"
root_uuid="CDEF"
+ project_uuid="CDEF"
module_uuid="[null]"
kee="pj-w-snapshot2"
scope="PRJ"
uuid="DEFG"
uuid_path="NOT_USED"
root_uuid="DEFG"
+ project_uuid="DEFG"
module_uuid="[null]"
kee="pj-w-snapshot3"
scope="PRJ"
uuid="DEFG"
uuid_path="NOT_USED"
root_uuid="DEFG"
+ project_uuid="DEFG"
module_uuid="[null]"/>
<projects organization_uuid="org1"
id="400"
uuid="EFGH"
uuid_path="NOT_USED"
root_uuid="EFGH"
+ project_uuid="EFGH"
module_uuid="[null]"/>
</dataset>
uuid_path="NOT_USED"
enabled="[true]"
root_uuid="uuid_1"
+ project_uuid="uuid_1"
long_name="[null]"
scope="PRJ"
qualifier="TRK"
uuid_path="NOT_USED"
enabled="[true]"
root_uuid="1"
+ project_uuid="1"
created_at="[null]"
long_name="[null]"
scope="PRJ"
uuid_path="NOT_USED"
enabled="[true]"
root_uuid="P1"
+ project_uuid="P1"
created_at="[null]"
long_name="[null]"
scope="PRJ"
uuid="A"
uuid_path="NOT_USED"
root_uuid="A"
+ project_uuid="A"
kee="project-one"
name="Project One"
qualifier="TRK"
uuid="B"
uuid_path="NOT_USED"
root_uuid="B"
+ project_uuid="B"
kee="project-two"
name="Project Two"
qualifier="TRK"
uuid="C"
uuid_path="NOT_USED"
root_uuid="C"
+ project_uuid="C"
kee="project-three"
name="Project Three"
qualifier="TRK"
uuid="D"
uuid_path="NOT_USED"
root_uuid="D"
+ project_uuid="D"
kee="project-four"
name="Project Four"
qualifier="TRK"
uuid="E"
uuid_path="NOT_USED"
root_uuid="E"
+ project_uuid="E"
kee="project-five"
name="Project Five"
qualifier="TRK"
uuid="F"
uuid_path="NOT_USED"
root_uuid="F"
+ project_uuid="F"
kee="view-six"
name="View Six"
qualifier="VW"
uuid="G"
uuid_path="NOT_USED"
root_uuid="G"
+ project_uuid="G"
kee="file-one"
name="File One"
qualifier="TRK"
uuid="A"
uuid_path="NOT_USED"
root_uuid="A"
+ project_uuid="A"
kee="org.codehaus.sonar:sonar"
name="SonarQube"
enabled="[true]"
uuid="B"
uuid_path="NOT_USED"
root_uuid="B"
+ project_uuid="B"
kee="org.codehaus.sonar-plugins.java:java"
name="SonarQube Java"
enabled="[true]"
uuid="C"
uuid_path="NOT_USED"
root_uuid="C"
+ project_uuid="C"
kee="disabled:project"
name="Disabled Project"
enabled="[false]"
.add(1615, "Create table RULES_METADATA", CreateRulesMetadata.class)
.add(1616, "Populate table RULES_METADATA", PopulateRulesMetadata.class)
.add(1617, "Drop metadata columns from RULES", DropMetadataColumnsFromRules.class)
-
// ensure the index is made unique even on existing 6.4-SNAPSHOT instances (such as next or the developer machines)
.add(1618, "Make index on ORGANIZATIONS.KEE unique", org.sonar.server.platform.db.migration.version.v63.MakeIndexOnOrganizationsKeeUnique.class)
.add(1619, "Restore 'sonar-users' group", RestoreSonarUsersGroups.class)
.add(1628, "Add columns CE_QUEUE.WORKER_UUID and EXECUTION_COUNT", AddCeQueueWorkerUuidAndExecutionCount.class)
.add(1629, "Make CE_QUEUE.EXECUTION_COUNT not nullable", MakeCeQueueExecutionCountNotNullable.class)
.add(1630, "Add columns CE_ACTIVITY.WORKER_UUID and EXECUTION_COUNT", AddCeActivityWorkerUuidAndExecutionCount.class)
- .add(1631, "Make columns CE_ACTIVITY.EXECUTION_COUNT not nullable", MakeCeActivityExecutionCountNotNullable.class);
+ .add(1631, "Make columns CE_ACTIVITY.EXECUTION_COUNT not nullable", MakeCeActivityExecutionCountNotNullable.class)
+ .add(1632, "Make PROJECTS.PROJECT_UUID not nullable", MakeProjectUuidNotNullable.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.v64;
+
+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.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeProjectUuidNotNullable extends DdlChange {
+
+ private static final String TABLE_PROJECTS = "projects";
+ private static final String INDEX_PROJECTS_PROJECT_UUID = "projects_project_uuid";
+
+ public MakeProjectUuidNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder()
+ .setColumnName("project_uuid")
+ .setLimit(50)
+ .setIsNullable(false)
+ .build();
+
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable(TABLE_PROJECTS)
+ .setName(INDEX_PROJECTS_PROJECT_UUID)
+ .build());
+
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE_PROJECTS)
+ .updateColumn(projectUuidCol)
+ .build());
+
+ context.execute(new CreateIndexBuilder(getDialect())
+ .setTable(TABLE_PROJECTS)
+ .setName(INDEX_PROJECTS_PROJECT_UUID)
+ .setUnique(false).addColumn(projectUuidCol)
+ .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.v64;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PurgeComponentsWithoutProjectUuid extends DataChange {
+ public PurgeComponentsWithoutProjectUuid(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select("select id,uuid from projects where project_uuid is null");
+ massUpdate.rowPluralName("rows in projects without project_uuid");
+ massUpdate.update("delete from duplications_index where analysis_uuid in (select uuid from snapshots where component_uuid=?)");
+ massUpdate.update("delete from project_measures where component_uuid=?");
+ massUpdate.update("delete from ce_activity where component_uuid=?");
+ massUpdate.update("delete from events where component_uuid=?");
+ massUpdate.update("delete from events where analysis_uuid in (select uuid from snapshots where component_uuid=?)");
+ massUpdate.update("delete from project_links where component_uuid=?");
+ massUpdate.update("delete from snapshots where component_uuid=?");
+ massUpdate.update("delete from issues where component_uuid=? or project_uuid=?");
+ massUpdate.update("delete from file_sources where file_uuid=? or project_uuid=?");
+ massUpdate.update("delete from group_roles where resource_id=?");
+ massUpdate.update("delete from user_roles where resource_id=?");
+ massUpdate.update("delete from properties where resource_id=?");
+ massUpdate.update("delete from projects where uuid=?");
+ massUpdate.execute((row, update, updateIndex) -> {
+ long componentId = row.getLong(1);
+ String componentUuid = row.getString(2);
+ switch (updateIndex) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ update.setString(1, componentUuid);
+ return true;
+ case 7:
+ case 8:
+ update.setString(1, componentUuid);
+ update.setString(2, componentUuid);
+ return true;
+ case 9:
+ case 10:
+ case 11:
+ update.setLong(1, componentId);
+ return true;
+ case 12:
+ update.setString(1, componentUuid);
+ return true;
+ default:
+ throw new IllegalArgumentException("Unsupported update index " + updateIndex);
+ }
+ });
+ }
+}
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 32);
+ verifyMigrationCount(underTest, 33);
}
}
-
--- /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.v64;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+public class MakeProjectUuidNotNullableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeProjectUuidNotNullableTest.class, "projects_with_nullable_project_uuid.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private MakeProjectUuidNotNullable underTest = new MakeProjectUuidNotNullable(db.database());
+
+ @Test
+ public void execute_makes_column_project_uuid_not_nullable_on_empty_table() throws SQLException {
+ db.assertColumnDefinition("projects", "project_uuid", Types.VARCHAR, 50, true);
+
+ underTest.execute();
+
+ db.assertColumnDefinition("projects", "project_uuid", Types.VARCHAR, 50, false);
+ }
+
+ @Test
+ public void execute_makes_column_project_uuid_not_nullable_on_table_without_null_project_uuid() throws SQLException {
+ db.assertColumnDefinition("projects", "project_uuid", Types.VARCHAR, 50, true);
+ insertComponent("u1", "u1");
+ insertComponent("u2", "u1");
+
+ underTest.execute();
+
+ db.assertColumnDefinition("projects", "project_uuid", Types.VARCHAR, 50, false);
+ }
+
+ @Test
+ public void execute_fails_on_table_with_null_project_uuid() throws SQLException {
+ db.assertColumnDefinition("projects", "project_uuid", Types.VARCHAR, 50, true);
+ insertComponent("u1", "u1");
+ insertComponent("u2", "u1");
+ insertComponent("u3", null);
+
+ expectedException.expect(IllegalStateException.class);
+
+ underTest.execute();
+ }
+
+ private void insertComponent(String uuid, @Nullable String projectUuid) {
+ db.executeInsert(
+ "PROJECTS",
+ "ORGANIZATION_UUID", "org_" + uuid,
+ "UUID", uuid,
+ "UUID_PATH", "path_" + uuid,
+ "ROOT_UUID", "root_" + uuid,
+ "PROJECT_UUID", projectUuid);
+ }
+}
--- /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.v64;
+
+import java.sql.SQLException;
+import java.util.Random;
+import java.util.stream.Stream;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.stream.MoreCollectors;
+import org.sonar.db.CoreDbTester;
+
+import static java.lang.String.valueOf;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PurgeComponentsWithoutProjectUuidTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PurgeComponentsWithoutProjectUuidTest.class, "projects_and_children_tables.sql");
+
+ private Random random = new Random();
+
+ private PurgeComponentsWithoutProjectUuid underTest = new PurgeComponentsWithoutProjectUuid(db.database());
+
+ @Test
+ public void execute_has_no_effect_when_every_tables_are_empty() throws SQLException {
+ underTest.execute();
+ }
+
+ @Test
+ public void execute_deletes_rows_from_PROJECTS_where_project_uuid_is_null() throws SQLException {
+ insertComponent("u1", "u1");
+ insertComponent("u2", "u1");
+ insertComponent("u3", null);
+
+ underTest.execute();
+
+ assertThat(db.select("select uuid from projects").stream()
+ .flatMap(map -> map.entrySet().stream())
+ .map(entry -> (String) entry.getValue())
+ .collect(MoreCollectors.toList()))
+ .containsOnly("u1", "u2");
+ }
+
+ @Test
+ public void executes_deletes_from_child_table_DUPLICATIONS_INDEX() throws SQLException {
+ insertComponent("u1", "foo");
+ insertComponent("u2", null);
+ Stream.of("u1", "u2").forEach(componentUuid -> {
+ String snapshotUuid = "s" + componentUuid;
+ insertSnapshot(snapshotUuid, componentUuid);
+ insertDuplicationsIndex(snapshotUuid, componentUuid);
+ insertDuplicationsIndex(snapshotUuid, "other_component" + random.nextInt(30));
+ });
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(1) from duplications_index where analysis_uuid = '" + "su1" + "'")).isEqualTo(2);
+ assertThat(db.countSql("select count(1) from duplications_index where analysis_uuid = '" + "su2" + "'")).isEqualTo(0);
+ }
+
+ @Test
+ public void execute_deletes_from_child_table_PROJECT_MEASURES() throws SQLException {
+ insertComponent("u1", "foo");
+ insertComponent("u2", null);
+ Stream.of("u1", "u2").forEach(componentUuid -> {
+ String snapshotUuid1 = "s1" + componentUuid;
+ insertSnapshot(snapshotUuid1, componentUuid);
+ insertProjectMeasure(snapshotUuid1, componentUuid);
+ String snapshotUuid2 = "s2" + componentUuid;
+ insertSnapshot(snapshotUuid2, "other_component" + random.nextInt(30));
+ insertProjectMeasure(snapshotUuid2, componentUuid);
+ });
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(1) from project_measures where component_uuid = '" + "u1" + "'")).isEqualTo(2);
+ assertThat(db.countSql("select count(1) from project_measures where component_uuid = '" + "u2" + "'")).isEqualTo(0);
+ }
+
+ @Test
+ public void execute_deletes_from_child_table_CE_ACTIVITY() throws SQLException {
+ insertComponent("u1", "foo");
+ insertComponent("u2", null);
+ Stream.of("u1", "u2").forEach(componentUuid -> {
+ insertCeActivity("ce1" + componentUuid, componentUuid);
+ });
+ insertCeActivity("ce2", null);
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(1) from ce_activity where component_uuid = '" + "u1" + "'")).isEqualTo(1);
+ assertThat(db.countSql("select count(1) from ce_activity where component_uuid = '" + "u2" + "'")).isEqualTo(0);
+ assertThat(db.countSql("select count(1) from ce_activity where component_uuid is null")).isEqualTo(1);
+ }
+
+ @Test
+ public void execute_deletes_from_child_table_EVENTS() throws SQLException {
+ insertComponent("u1", "foo");
+ insertComponent("u2", null);
+ String snapshotOfOtherComponent = "bar";
+ insertSnapshot(snapshotOfOtherComponent, "foo");
+ Stream.of("u1", "u2").forEach(componentUuid -> {
+ String snapshot1 = "s1" + componentUuid;
+ insertSnapshot(snapshot1, componentUuid);
+ insertEvent("e1" + componentUuid, snapshot1, null);
+ insertEvent("e2" + componentUuid, snapshot1, componentUuid);
+ insertEvent("e3" + componentUuid, snapshotOfOtherComponent, componentUuid);
+ });
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(1) from events where component_uuid = '" + "u1" + "'")).isEqualTo(2);
+ assertThat(db.countSql("select count(1) from events where analysis_uuid = '" + "s1u1" + "'")).isEqualTo(2);
+ assertThat(db.countSql("select count(1) from events where component_uuid = '" + "u2" + "'")).isEqualTo(0);
+ assertThat(db.countSql("select count(1) from events where analysis_uuid = '" + "s1u2" + "'")).isEqualTo(0);
+ assertThat(db.countSql("select count(1) from events where analysis_uuid = '" + snapshotOfOtherComponent + "'")).isEqualTo(1);
+ }
+
+ @Test
+ public void execute_deletes_from_child_table_PROJECT_LINKS() throws SQLException {
+ insertComponent("u1", "foo");
+ insertComponent("u2", null);
+ Stream.of("u1", "u2").forEach(componentUuid -> {
+ insertProjectLink(componentUuid);
+ });
+ insertProjectLink(null);
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(1) from project_links where component_uuid = '" + "u1" + "'")).isEqualTo(1);
+ assertThat(db.countSql("select count(1) from project_links where component_uuid = '" + "u2" + "'")).isEqualTo(0);
+ assertThat(db.countSql("select count(1) from project_links where component_uuid is null")).isEqualTo(1);
+ }
+
+ @Test
+ public void execute_deletes_from_child_table_SNAPSHOTS() throws SQLException {
+ insertComponent("u1", "foo");
+ insertComponent("u2", null);
+ Stream.of("u1", "u2").forEach(componentUuid -> {
+ insertSnapshot("s1" + componentUuid, componentUuid);
+ });
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(1) from snapshots where component_uuid = '" + "u1" + "'")).isEqualTo(1);
+ assertThat(db.countSql("select count(1) from snapshots where component_uuid = '" + "u2" + "'")).isEqualTo(0);
+ }
+
+ @Test
+ public void execute_deletes_from_child_table_ISSUES() throws SQLException {
+ insertComponent("u1", "foo");
+ insertComponent("u2", null);
+ Stream.of("u1", "u2").forEach(componentUuid -> {
+ insertIssue("s1" + componentUuid, componentUuid);
+ });
+ insertIssue("s2", null);
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(1) from issues where component_uuid = '" + "u1" + "'")).isEqualTo(1);
+ assertThat(db.countSql("select count(1) from issues where component_uuid = '" + "u2" + "'")).isEqualTo(0);
+ assertThat(db.countSql("select count(1) from issues where component_uuid is null")).isEqualTo(1);
+ }
+
+ @Test
+ public void execute_deletes_from_child_table_FILE_SOURCES() throws SQLException {
+ insertComponent("u1", "foo");
+ insertComponent("u2", null);
+ Stream.of("u1", "u2").forEach(componentUuid -> {
+ insertFileSource(componentUuid, "foo");
+ insertFileSource("bar", componentUuid);
+ insertFileSource(componentUuid, componentUuid);
+ });
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(1) from file_sources where project_uuid = '" + "u1" + "' or file_uuid = '" + "u1" + "'")).isEqualTo(3);
+ assertThat(db.countSql("select count(1) from file_sources where project_uuid = '" + "u2" + "' or file_uuid = '" + "u2" + "'")).isEqualTo(0);
+ }
+
+ @Test
+ public void execute_deletes_from_child_table_GROUP_ROLES() throws SQLException {
+ long project1 = insertComponent("u1", "foo");
+ long project2 = insertComponent("u2", null);
+ Stream.of(project1, project2).forEach(componentId -> {
+ insertGroupRole(componentId);
+ });
+ insertGroupRole(null);
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(1) from group_roles where RESOURCE_ID = " + project1)).isEqualTo(1);
+ assertThat(db.countSql("select count(1) from group_roles where RESOURCE_ID = " + project2)).isEqualTo(0);
+ assertThat(db.countSql("select count(1) from group_roles where RESOURCE_ID is null")).isEqualTo(1);
+ }
+
+ @Test
+ public void execute_deletes_from_child_table_USER_ROLES() throws SQLException {
+ long project1 = insertComponent("u1", "foo");
+ long project2 = insertComponent("u2", null);
+ Stream.of(project1, project2).forEach(componentId -> {
+ insertUserRole(componentId);
+ });
+ insertUserRole(null);
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(1) from user_roles where resource_id = " + project1)).isEqualTo(1);
+ assertThat(db.countSql("select count(1) from user_roles where resource_id = " + project2)).isEqualTo(0);
+ assertThat(db.countSql("select count(1) from user_roles where resource_id is null")).isEqualTo(1);
+ }
+
+ @Test
+ public void execute_deletes_from_child_table_PROPERTIES() throws SQLException {
+ long project1 = insertComponent("u1", "foo");
+ long project2 = insertComponent("u2", null);
+ Stream.of(project1, project2).forEach(componentId -> {
+ insertProperties(componentId);
+ });
+ insertProperties(null);
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(1) from properties where resource_id = " + project1)).isEqualTo(1);
+ assertThat(db.countSql("select count(1) from properties where resource_id = " + project2)).isEqualTo(0);
+ assertThat(db.countSql("select count(1) from properties where resource_id is null")).isEqualTo(1);
+ }
+
+ private long insertComponent(String uuid, @Nullable String projectUuid) {
+ db.executeInsert(
+ "PROJECTS",
+ "ORGANIZATION_UUID", "org_" + uuid,
+ "UUID", uuid,
+ "UUID_PATH", "path_" + uuid,
+ "ROOT_UUID", "root_" + uuid,
+ "PROJECT_UUID", projectUuid);
+ return (long) db.selectFirst("select id as \"ID\" from projects where uuid='" + uuid + "'").get("ID");
+ }
+
+ private void insertSnapshot(String uuid, String componentUuid) {
+ db.executeInsert(
+ "SNAPSHOTS",
+ "UUID", uuid,
+ "COMPONENT_UUID", componentUuid,
+ "STATUS", random.nextBoolean() ? "U" : "P",
+ "ISLAST", valueOf(random.nextBoolean()));
+ }
+
+ private void insertDuplicationsIndex(String snapshotUuid, String componentUuid) {
+ db.executeInsert(
+ "DUPLICATIONS_INDEX",
+ "ANALYSIS_UUID", snapshotUuid,
+ "COMPONENT_UUID", componentUuid,
+ "HASH", "hash_" + random.nextInt(100),
+ "INDEX_IN_FILE", valueOf(random.nextInt(50)),
+ "START_LINE", valueOf(random.nextInt(50)),
+ "END_LINE", valueOf(random.nextInt(50)));
+ }
+
+ private void insertProjectMeasure(String snapshotUuid, String componentUuid) {
+ db.executeInsert(
+ "PROJECT_MEASURES",
+ "METRIC_ID", valueOf(random.nextInt(50)),
+ "COMPONENT_UUID", componentUuid,
+ "ANALYSIS_UUID", snapshotUuid);
+ }
+
+ private void insertCeActivity(String uuid, @Nullable String componentUuid) {
+ db.executeInsert(
+ "CE_ACTIVITY",
+ "UUID", uuid,
+ "TASK_TYPE", "type_" + random.nextInt(10),
+ "STATUS", "status" + random.nextInt(10),
+ "COMPONENT_UUID", componentUuid,
+ "IS_LAST", valueOf(random.nextBoolean()),
+ "IS_LAST_KEY", "isLastKey" + random.nextInt(20),
+ "SUBMITTED_AT", valueOf(random.nextInt(555)),
+ "CREATED_AT", valueOf(random.nextInt(555)),
+ "UPDATED_AT", valueOf(random.nextInt(555)));
+ }
+
+ private void insertEvent(String uuid, String analysisUuid, @Nullable String componentUuid) {
+ db.executeInsert(
+ "EVENTS",
+ "UUID", uuid,
+ "ANALYSIS_UUID", analysisUuid,
+ "COMPONENT_UUID", componentUuid,
+ "EVENT_DATE", random.nextInt(),
+ "CREATED_AT", random.nextInt());
+ }
+
+ private void insertProjectLink(@Nullable String componentUuid) {
+ db.executeInsert(
+ "PROJECT_LINKS",
+ "COMPONENT_UUID", componentUuid,
+ "HREF", "href_" + random.nextInt());
+ }
+
+ private void insertIssue(String s, @Nullable String componentUuid) {
+ db.executeInsert(
+ "ISSUES",
+ "KEE", s,
+ "COMPONENT_UUID", componentUuid,
+ "MANUAL_SEVERITY", valueOf(random.nextBoolean()));
+ }
+
+ private void insertFileSource(String projectUuid, String fileUuid) {
+ db.executeInsert(
+ "FILE_SOURCES",
+ "PROJECT_UUID", projectUuid,
+ "FILE_UUID", fileUuid,
+ "CREATED_AT", valueOf(random.nextInt(555)),
+ "UPDATED_AT", valueOf(random.nextInt(555)));
+ }
+
+ private void insertGroupRole(@Nullable Long componentId) {
+ db.executeInsert(
+ "GROUP_ROLES",
+ "ORGANIZATION_UUID", "org_" + random.nextInt(20),
+ "GROUP_ID", random.nextBoolean() ? null : random.nextInt(),
+ "RESOURCE_ID", componentId == null ? null : valueOf(componentId),
+ "ROLE", "role_" + random.nextInt(10));
+ }
+
+ private void insertUserRole(@Nullable Long componentId) {
+ db.executeInsert(
+ "USER_ROLES",
+ "ORGANIZATION_UUID", "org_" + random.nextInt(20),
+ "USER_ID", random.nextBoolean() ? null : random.nextInt(),
+ "RESOURCE_ID", componentId == null ? null : valueOf(componentId),
+ "ROLE", "role_" + random.nextInt(10));
+ }
+
+ private void insertProperties(@Nullable Long componentId) {
+ db.executeInsert(
+ "PROPERTIES",
+ "PROP_KEY", "prop_" + random.nextInt(15),
+ "RESOURCE_ID", componentId == null ? null : valueOf(componentId),
+ "IS_EMPTY", valueOf(random.nextBoolean()));
+ }
+}
--- /dev/null
+CREATE TABLE "PROJECTS" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(400),
+ "UUID" VARCHAR(50) NOT NULL,
+ "UUID_PATH" VARCHAR(1500) NOT NULL,
+ "ROOT_UUID" VARCHAR(50) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50),
+ "MODULE_UUID" VARCHAR(50),
+ "MODULE_UUID_PATH" VARCHAR(1500),
+ "NAME" VARCHAR(2000),
+ "DESCRIPTION" VARCHAR(2000),
+ "TAGS" VARCHAR(500),
+ "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "DEPRECATED_KEE" VARCHAR(400),
+ "PATH" VARCHAR(2000),
+ "LANGUAGE" VARCHAR(20),
+ "COPY_COMPONENT_UUID" VARCHAR(50),
+ "LONG_NAME" VARCHAR(2000),
+ "DEVELOPER_UUID" VARCHAR(50),
+ "CREATED_AT" TIMESTAMP,
+ "AUTHORIZATION_UPDATED_AT" BIGINT,
+ "B_CHANGED" BOOLEAN,
+ "B_COPY_COMPONENT_UUID" VARCHAR(50),
+ "B_DESCRIPTION" VARCHAR(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_UUID_PATH" VARCHAR(1500),
+ "B_LANGUAGE" VARCHAR(20),
+ "B_LONG_NAME" VARCHAR(500),
+ "B_MODULE_UUID" VARCHAR(50),
+ "B_MODULE_UUID_PATH" VARCHAR(1500),
+ "B_NAME" VARCHAR(500),
+ "B_PATH" VARCHAR(2000),
+ "B_QUALIFIER" VARCHAR(10)
+);
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "PROJECTS" ("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "PROJECTS" ("KEE");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "PROJECTS" ("ROOT_UUID");
+CREATE UNIQUE INDEX "PROJECTS_UUID" ON "PROJECTS" ("UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "PROJECTS" ("PROJECT_UUID");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "PROJECTS" ("MODULE_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "PROJECTS" ("QUALIFIER");
--- /dev/null
+CREATE TABLE "PROJECTS" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(400),
+ "UUID" VARCHAR(50) NOT NULL,
+ "UUID_PATH" VARCHAR(1500) NOT NULL,
+ "ROOT_UUID" VARCHAR(50) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50),
+ "MODULE_UUID" VARCHAR(50),
+ "MODULE_UUID_PATH" VARCHAR(1500),
+ "NAME" VARCHAR(2000),
+ "DESCRIPTION" VARCHAR(2000),
+ "TAGS" VARCHAR(500),
+ "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "DEPRECATED_KEE" VARCHAR(400),
+ "PATH" VARCHAR(2000),
+ "LANGUAGE" VARCHAR(20),
+ "COPY_COMPONENT_UUID" VARCHAR(50),
+ "LONG_NAME" VARCHAR(2000),
+ "DEVELOPER_UUID" VARCHAR(50),
+ "CREATED_AT" TIMESTAMP,
+ "AUTHORIZATION_UPDATED_AT" BIGINT,
+ "B_CHANGED" BOOLEAN,
+ "B_COPY_COMPONENT_UUID" VARCHAR(50),
+ "B_DESCRIPTION" VARCHAR(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_UUID_PATH" VARCHAR(1500),
+ "B_LANGUAGE" VARCHAR(20),
+ "B_LONG_NAME" VARCHAR(500),
+ "B_MODULE_UUID" VARCHAR(50),
+ "B_MODULE_UUID_PATH" VARCHAR(1500),
+ "B_NAME" VARCHAR(500),
+ "B_PATH" VARCHAR(2000),
+ "B_QUALIFIER" VARCHAR(10)
+);
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "PROJECTS" ("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "PROJECTS" ("KEE");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "PROJECTS" ("ROOT_UUID");
+CREATE UNIQUE INDEX "PROJECTS_UUID" ON "PROJECTS" ("UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "PROJECTS" ("PROJECT_UUID");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "PROJECTS" ("MODULE_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "PROJECTS" ("QUALIFIER");
+
+CREATE TABLE "DUPLICATIONS_INDEX" (
+ "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "HASH" VARCHAR(50) NOT NULL,
+ "INDEX_IN_FILE" INTEGER NOT NULL,
+ "START_LINE" INTEGER NOT NULL,
+ "END_LINE" INTEGER NOT NULL
+);
+CREATE INDEX "DUPLICATIONS_INDEX_HASH" ON "DUPLICATIONS_INDEX" ("HASH");
+CREATE INDEX "DUPLICATION_ANALYSIS_COMPONENT" ON "DUPLICATIONS_INDEX" ("ANALYSIS_UUID", "COMPONENT_UUID");
+
+CREATE TABLE "PROJECT_MEASURES" (
+ "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "VALUE" DOUBLE,
+ "METRIC_ID" INTEGER NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "ALERT_STATUS" VARCHAR(5),
+ "ALERT_TEXT" VARCHAR(4000),
+ "DESCRIPTION" VARCHAR(4000),
+ "PERSON_ID" INTEGER,
+ "VARIATION_VALUE_1" DOUBLE,
+ "VARIATION_VALUE_2" DOUBLE,
+ "VARIATION_VALUE_3" DOUBLE,
+ "VARIATION_VALUE_4" DOUBLE,
+ "VARIATION_VALUE_5" DOUBLE,
+ "MEASURE_DATA" BINARY
+);
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES" ("COMPONENT_UUID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES" ("ANALYSIS_UUID", "METRIC_ID");
+CREATE INDEX "MEASURES_PERSON" ON "PROJECT_MEASURES" ("PERSON_ID");
+
+CREATE TABLE "CE_ACTIVITY" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "TASK_TYPE" VARCHAR(15) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(40) NULL,
+ "ANALYSIS_UUID" VARCHAR(50) NULL,
+ "STATUS" VARCHAR(15) NOT NULL,
+ "IS_LAST" BOOLEAN NOT NULL,
+ "IS_LAST_KEY" VARCHAR(55) NOT NULL,
+ "SUBMITTER_LOGIN" VARCHAR(255) NULL,
+ "SUBMITTED_AT" BIGINT NOT NULL,
+ "STARTED_AT" BIGINT NULL,
+ "EXECUTED_AT" BIGINT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "EXECUTION_TIME_MS" BIGINT NULL,
+ "ERROR_MESSAGE" VARCHAR(1000),
+ "ERROR_STACKTRACE" CLOB(2147483647)
+);
+CREATE UNIQUE INDEX "CE_ACTIVITY_UUID" ON "CE_ACTIVITY" ("UUID");
+CREATE INDEX "CE_ACTIVITY_COMPONENT_UUID" ON "CE_ACTIVITY" ("COMPONENT_UUID");
+CREATE INDEX "CE_ACTIVITY_ISLASTKEY" ON "CE_ACTIVITY" ("IS_LAST_KEY");
+CREATE INDEX "CE_ACTIVITY_ISLAST_STATUS" ON "CE_ACTIVITY" ("IS_LAST", "STATUS");
+
+CREATE TABLE "EVENTS" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "NAME" VARCHAR(400),
+ "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50),
+ "CATEGORY" VARCHAR(50),
+ "EVENT_DATE" BIGINT NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "EVENT_DATA" VARCHAR(4000)
+);
+CREATE INDEX "EVENTS_ANALYSIS" ON "EVENTS" ("ANALYSIS_UUID");
+CREATE INDEX "EVENTS_COMPONENT_UUID" ON "EVENTS" ("COMPONENT_UUID");
+CREATE UNIQUE INDEX "EVENTS_UUID" ON "EVENTS" ("UUID");
+
+CREATE TABLE "PROJECT_LINKS" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "COMPONENT_UUID" VARCHAR(50),
+ "LINK_TYPE" VARCHAR(20),
+ "NAME" VARCHAR(128),
+ "HREF" VARCHAR(2048) NOT NULL
+);
+
+CREATE TABLE "SNAPSHOTS" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "UUID" VARCHAR(50) NOT NULL,
+ "CREATED_AT" BIGINT,
+ "BUILD_DATE" BIGINT,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "STATUS" VARCHAR(4) NOT NULL DEFAULT 'U',
+ "PURGE_STATUS" INTEGER,
+ "ISLAST" BOOLEAN NOT NULL DEFAULT FALSE,
+ "VERSION" VARCHAR(500),
+ "PERIOD1_MODE" VARCHAR(100),
+ "PERIOD1_PARAM" VARCHAR(100),
+ "PERIOD1_DATE" BIGINT,
+ "PERIOD2_MODE" VARCHAR(100),
+ "PERIOD2_PARAM" VARCHAR(100),
+ "PERIOD2_DATE" BIGINT,
+ "PERIOD3_MODE" VARCHAR(100),
+ "PERIOD3_PARAM" VARCHAR(100),
+ "PERIOD3_DATE" BIGINT,
+ "PERIOD4_MODE" VARCHAR(100),
+ "PERIOD4_PARAM" VARCHAR(100),
+ "PERIOD4_DATE" BIGINT,
+ "PERIOD5_MODE" VARCHAR(100),
+ "PERIOD5_PARAM" VARCHAR(100),
+ "PERIOD5_DATE" BIGINT
+);
+CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS" ("COMPONENT_UUID");
+CREATE UNIQUE INDEX "ANALYSES_UUID" ON "SNAPSHOTS" ("UUID");
+
+CREATE TABLE "ISSUES" (
+ "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "KEE" VARCHAR(50) UNIQUE NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50),
+ "RULE_ID" INTEGER,
+ "SEVERITY" VARCHAR(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" VARCHAR(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE,
+ "EFFORT" INTEGER,
+ "STATUS" VARCHAR(20),
+ "RESOLUTION" VARCHAR(20),
+ "CHECKSUM" VARCHAR(1000),
+ "REPORTER" VARCHAR(255),
+ "ASSIGNEE" VARCHAR(255),
+ "AUTHOR_LOGIN" VARCHAR(255),
+ "ACTION_PLAN_KEY" VARCHAR(50) NULL,
+ "ISSUE_ATTRIBUTES" VARCHAR(4000),
+ "TAGS" VARCHAR(4000),
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "LOCATIONS" BLOB,
+ "ISSUE_TYPE" TINYINT
+);
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES" ("KEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES" ("COMPONENT_UUID");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES" ("PROJECT_UUID");
+CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES" ("RULE_ID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES" ("RESOLUTION");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES" ("ASSIGNEE");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES" ("ISSUE_CREATION_DATE");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES" ("UPDATED_AT");
+
+CREATE TABLE "FILE_SOURCES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "FILE_UUID" VARCHAR(50) NOT NULL,
+ "LINE_HASHES" CLOB(2147483647),
+ "BINARY_DATA" BLOB,
+ "DATA_TYPE" VARCHAR(20),
+ "DATA_HASH" VARCHAR(50),
+ "SRC_HASH" VARCHAR(50),
+ "REVISION" VARCHAR(100),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+CREATE INDEX "FILE_SOURCES_PROJECT_UUID" ON "FILE_SOURCES" ("PROJECT_UUID");
+CREATE UNIQUE INDEX "FILE_SOURCES_UUID_TYPE" ON "FILE_SOURCES" ("FILE_UUID", "DATA_TYPE");
+CREATE INDEX "FILE_SOURCES_UPDATED_AT" ON "FILE_SOURCES" ("UPDATED_AT");
+
+CREATE TABLE "GROUP_ROLES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "GROUP_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES" ("RESOURCE_ID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES" ("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
+
+CREATE TABLE "USER_ROLES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "USER_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES" ("RESOURCE_ID");
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES" ("USER_ID");
+
+CREATE TABLE "PROPERTIES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "PROP_KEY" VARCHAR(512) NOT NULL,
+ "RESOURCE_ID" INTEGER,
+ "USER_ID" INTEGER,
+ "IS_EMPTY" BOOLEAN NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "CLOB_VALUE" CLOB(2147483647),
+ "CREATED_AT" BIGINT
+);
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES" ("PROP_KEY");
.setUuid(uuid)
.setUuidPath(uuid + ".")
.setRootUuid(uuid)
+ .setProjectUuid(uuid)
.setScope(scope)
.setQualifier(qualifier)
.setKey(key));
.setKey(key)
.setUuid(uuid)
.setUuidPath(uuid + ".")
- .setRootUuid(uuid);
+ .setRootUuid(uuid)
+ .setProjectUuid(uuid);
dbClient.componentDao().insert(dbTester.getSession(), componentDto);
return componentDto;
}
.setUuid(projectUuid)
.setKey(projectKey)
.setUuidPath("")
- .setRootUuid(""));
+ .setRootUuid("")
+ .setProjectUuid(""));
}
private ComponentDto insertProject() {
uuid_path="NOT_USED"
id="1"
root_uuid="ABCD"
+ project_uuid="ABCD"
kee="ROOT_KEY"/>
</dataset>
uuid="ABCD"
uuid_path="NOT_USED"
root_uuid="ABCD"
+ project_uuid="ABCD"
id="1"
kee="ROOT_KEY"
name="project"/>
kee="ROOT_KEY"
uuid="ABCD"
uuid_path="NOT_USED"
- root_uuid="ABCD"/>
+ root_uuid="ABCD"
+ project_uuid="ABCD"/>
<!-- 2008-11-11 -->
<!-- Version 0.9 -->
uuid="ABCD"
uuid_path="NOT_USED"
root_uuid="ABCD"
+ project_uuid="ABCD"
id="1"
kee="ROOT_KEY"
name="project"/>
name="project"
uuid="ABCD"
uuid_path="NOT_USED"
- root_uuid="ABCD"/>
+ root_uuid="ABCD"
+ project_uuid="ABCD"/>
<!-- 2008-11-11 -->
<!-- Version 0.9 -->
uuid="ABCD"
uuid_path="NOT_USED"
root_uuid="ABCD"
+ project_uuid="ABCD"
id="10"
scope="PRJ"
qualifier="TRK"
uuid="BCDE"
uuid_path="NOT_USED"
root_uuid="ABCD"
+ project_uuid="ABCD"
id="100"
scope="FIL"
qualifier="CLA"
uuid_path="NOT_USED"
id="1"
kee="struts"
- root_uuid="ABCD"/>
+ root_uuid="ABCD"
+ project_uuid="ABCD"/>
<projects organization_uuid="org1"
uuid="BCDE"
uuid_path="NOT_USED"
id="2"
kee="struts:Action.java"
- root_uuid="ABCD"/>
+ root_uuid="ABCD"
+ project_uuid="ABCD"/>
<snapshots id="1"
uuid="u1"
uuid="ABCD"
uuid_path="NOT_USED"
root_uuid="ABCD"
+ project_uuid="ABCD"
id="10"
scope="PRJ"
qualifier="TRK"
uuid="BCDE"
uuid_path="NOT_USED"
root_uuid="ABCD"
+ project_uuid="ABCD"
id="100"
scope="FIL"
qualifier="CLA"
uuid="ABCD"
uuid_path="NOT_USED"
root_uuid="ABCD"
+ project_uuid="ABCD"
id="10"
scope="PRJ"
qualifier="TRK"
uuid="BCDE"
uuid_path="NOT_USED"
root_uuid="ABCD"
+ project_uuid="ABCD"
id="100"
scope="FIL"
qualifier="CLA"
uuid="THE_PROJECT"
uuid_path="NOT_USED"
root_uuid="THE_PROJECT"
+ project_uuid="THE_PROJECT"
module_uuid="[null]"
module_uuid_path="."
path="[null]"
uuid="THE_FILE"
uuid_path="NOT_USED"
root_uuid="THE_PROJECT"
+ project_uuid="THE_PROJECT"
module_uuid="THE_PROJECT"
module_uuid_path=".THE_PROJECT."
path="src/main/java/TheFile.java"
uuid="THE_PROJECT_1"
uuid_path="NOT_USED"
root_uuid="THE_PROJECT_1"
+ project_uuid="THE_PROJECT_1"
module_uuid="[null]"
module_uuid_path="."
path="[null]"
uuid="THE_FILE_1"
uuid_path="NOT_USED"
root_uuid="THE_PROJECT_1"
+ project_uuid="THE_PROJECT_1"
module_uuid="THE_PROJECT_1"
module_uuid_path=".THE_PROJECT_1."
path="src/main/java/TheFile.java"
uuid="PROJECT"
uuid_path="NOT_USED"
root_uuid="MODULE"
+ project_uuid="MODULE"
path="[null]"
module_uuid_path=".PROJECT."
id="10"
uuid="MODULE"
uuid_path="NOT_USED"
root_uuid="PROJECT"
+ project_uuid="PROJECT"
path="struts-core"
module_uuid_path=".PROJECT.MODULE."
id="11"
uuid="FILE"
uuid_path="NOT_USED"
root_uuid="MODULE"
+ project_uuid="MODULE"
path="src/main/java/Action.java"
module_uuid_path=".PROJECT.MODULE."
id="100"
uuid="ROOT_FILE"
uuid_path="NOT_USED"
root_uuid="MODULE"
+ project_uuid="MODULE"
path="pom.xml"
module_uuid_path=".PROJECT.MODULE."
id="101"
uuid="PROJECT"
uuid_path="NOT_USED"
root_uuid="MODULE"
+ project_uuid="MODULE"
path="[null]"
module_uuid_path=".PROJECT."
id="10"
uuid="MODULE"
uuid_path="NOT_USED"
root_uuid="PROJECT"
+ project_uuid="PROJECT"
path="struts-core"
module_uuid_path=".PROJECT.MODULE."
id="11"
uuid="FILE"
uuid_path="NOT_USED"
root_uuid="MODULE"
+ project_uuid="MODULE"
path="src/main/java/Action.java"
module_uuid_path=".PROJECT.MODULE."
id="100"
uuid="ROOT_FILE"
uuid_path="NOT_USED"
root_uuid="MODULE"
+ project_uuid="MODULE"
path="pom.xml"
module_uuid_path=".PROJECT.MODULE."
id="101"
uuid="THE_PROJECT_1"
uuid_path="NOT_USED"
root_uuid="THE_PROJECT_1"
+ project_uuid="THE_PROJECT_1"
module_uuid="[null]"
module_uuid_path="."
path="[null]"
uuid="THE_FILE_1"
uuid_path="NOT_USED"
root_uuid="THE_PROJECT_1"
+ project_uuid="THE_PROJECT_1"
module_uuid="THE_PROJECT_1"
module_uuid_path=".THE_PROJECT_1."
path="src/main/java/TheFile.java"
uuid="THE_PROJECT_2"
uuid_path="NOT_USED"
root_uuid="THE_PROJECT_2"
+ project_uuid="THE_PROJECT_2"
module_uuid="[null]"
module_uuid_path="."
path="[null]"
uuid="THE_FILE_2"
uuid_path="NOT_USED"
root_uuid="THE_PROJECT_2"
+ project_uuid="THE_PROJECT_2"
module_uuid="THE_PROJECT_2"
module_uuid_path=".THE_PROJECT_2."
path="src/main/java/TheFile.java"
uuid="PROJECT1"
uuid_path="NOT_USED"
root_uuid="PROJECT1"
+ project_uuid="PROJECT1"
path="[null]"
module_uuid_path=".PROJECT1."
id="10"
uuid="MODULE1"
uuid_path="NOT_USED"
root_uuid="PROJECT1"
+ project_uuid="PROJECT1"
path="[null]"
module_uuid_path=".PROJECT1.MODULE1."
id="50"
uuid="DIR1"
uuid_path="NOT_USED"
root_uuid="MODULE1"
+ project_uuid="MODULE1"
path="src/main/java"
module_uuid_path=".PROJECT1.MODULE1."
id="70"
uuid="FILE1"
uuid_path="NOT_USED"
root_uuid="MODULE1"
+ project_uuid="MODULE1"
path="src/main/java/Action.java"
module_uuid_path=".PROJECT1."
id="100"
uuid="PROJECT1"
uuid_path="NOT_USED"
root_uuid="PROJECT1"
+ project_uuid="PROJECT1"
path="[null]"
module_uuid_path=".PROJECT1."
id="10"
uuid="MODULE1"
uuid_path="NOT_USED"
root_uuid="PROJECT1"
+ project_uuid="PROJECT1"
path="[null]"
module_uuid_path=".PROJECT1.MODULE1."
id="50"
uuid="DIR1"
uuid_path="NOT_USED"
root_uuid="MODULE1"
+ project_uuid="MODULE1"
path="src/main/java"
module_uuid_path=".PROJECT1.MODULE1."
id="70"
uuid="FILE1"
uuid_path="NOT_USED"
root_uuid="MODULE1"
+ project_uuid="MODULE1"
path="src/main/java/Action.java"
module_uuid_path=".PROJECT1."
id="100"