@@ -28,9 +28,9 @@ import org.junit.Test; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; | |||
import org.sonar.server.computation.task.projectanalysis.component.Component; | |||
import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; | |||
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; | |||
import org.sonar.server.computation.task.projectanalysis.event.Event; | |||
import org.sonar.server.computation.task.projectanalysis.event.EventRepository; | |||
import org.sonar.server.computation.task.step.ComputationStep; | |||
@@ -74,20 +74,21 @@ public class PersistEventsStepTest extends BaseStepTest { | |||
private Date someDate = new Date(150000000L); | |||
EventRepository eventRepository = mock(EventRepository.class); | |||
PersistEventsStep step; | |||
private EventRepository eventRepository = mock(EventRepository.class); | |||
private PersistEventsStep underTest; | |||
@Before | |||
public void setup() { | |||
when(system2.now()).thenReturn(1225630680000L); | |||
analysisMetadataHolder.setAnalysisDate(someDate.getTime()).setUuid(ANALYSIS_UUID); | |||
step = new PersistEventsStep(dbTester.getDbClient(), system2, treeRootHolder, analysisMetadataHolder, eventRepository); | |||
underTest = new PersistEventsStep(dbTester.getDbClient(), system2, treeRootHolder, analysisMetadataHolder, eventRepository); | |||
when(eventRepository.getEvents(any(Component.class))).thenReturn(Collections.<Event>emptyList()); | |||
} | |||
@Override | |||
protected ComputationStep step() { | |||
return step; | |||
return underTest; | |||
} | |||
@Test | |||
@@ -96,9 +97,9 @@ public class PersistEventsStepTest extends BaseStepTest { | |||
treeRootHolder.setRoot(ROOT); | |||
step.execute(); | |||
underTest.execute(); | |||
dbTester.assertDbUnit(getClass(), "nothing_to_do_when_no_events_in_report.xml", "events"); | |||
dbTester.assertDbUnit(getClass(), "nothing_to_do_when_no_events_in_report.xml", new String[] {"uuid"}, "events"); | |||
} | |||
@Test | |||
@@ -110,9 +111,9 @@ public class PersistEventsStepTest extends BaseStepTest { | |||
when(eventRepository.getEvents(ROOT)).thenReturn(ImmutableList.of(Event.createAlert("Red (was Orange)", null, "Open issues > 0"))); | |||
treeRootHolder.setRoot(ROOT); | |||
step.execute(); | |||
underTest.execute(); | |||
dbTester.assertDbUnit(getClass(), "persist_report_events_with_component_children-result.xml", "events"); | |||
dbTester.assertDbUnit(getClass(), "persist_report_events_with_component_children-result.xml", new String[] {"uuid"}, "events"); | |||
} | |||
@Test | |||
@@ -137,9 +138,9 @@ public class PersistEventsStepTest extends BaseStepTest { | |||
.build(); | |||
treeRootHolder.setRoot(project); | |||
step.execute(); | |||
underTest.execute(); | |||
dbTester.assertDbUnit(getClass(), "add_version_event-result.xml", "events"); | |||
dbTester.assertDbUnit(getClass(), "add_version_event-result.xml", new String[] {"uuid"}, "events"); | |||
} | |||
@Test | |||
@@ -164,9 +165,9 @@ public class PersistEventsStepTest extends BaseStepTest { | |||
.build(); | |||
treeRootHolder.setRoot(project); | |||
step.execute(); | |||
underTest.execute(); | |||
dbTester.assertDbUnit(getClass(), "keep_one_event_by_version-result.xml", "events"); | |||
dbTester.assertDbUnit(getClass(), "keep_one_event_by_version-result.xml", new String[] {"uuid"}, "events"); | |||
} | |||
} |
@@ -1,9 +1,9 @@ | |||
<dataset> | |||
<events id="1" name="Red (was Orange)" category="Alert" description="Open issues > 0" | |||
<events id="1" uuid="E1" name="Red (was Orange)" category="Alert" description="Open issues > 0" | |||
event_data="[null]" | |||
event_date="150000000" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" /> | |||
<events id="2" name="Changes in 'Default' (Java)" category="Profile" description="[null]" | |||
<events id="2" uuid="E2" name="Changes in 'Default' (Java)" category="Profile" description="[null]" | |||
event_data="from=2014-10-12T08:36:25+0000;key=java-default;to=2014-10-12T10:36:25+0000" | |||
event_date="150000000" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" /> | |||
@@ -1,6 +1,7 @@ | |||
<dataset> | |||
<events id="1" | |||
uuid="E1" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="1.0" |
@@ -1,6 +1,7 @@ | |||
<dataset> | |||
<events id="1" | |||
uuid="E1" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="1.3-SNAPSHOT" | |||
@@ -10,6 +11,7 @@ | |||
event_date="120000000" | |||
created_at="120000000"/> | |||
<events id="2" | |||
uuid="E2" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="1.4" | |||
@@ -23,6 +25,7 @@ | |||
<!--component_uuid="ABCD" analysis_uuid="uuid_1" created_at="140000000" />--> | |||
<events id="4" | |||
uuid="E4" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="1.5-SNAPSHOT" |
@@ -1,6 +1,7 @@ | |||
<dataset> | |||
<events id="1" | |||
uuid="E1" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="1.3-SNAPSHOT" | |||
@@ -10,6 +11,7 @@ | |||
event_date="120000000" | |||
created_at="120000000"/> | |||
<events id="2" | |||
uuid="E2" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="1.4" | |||
@@ -19,6 +21,7 @@ | |||
event_date="130000000" | |||
created_at="130000000"/> | |||
<events id="3" | |||
uuid="E3" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="1.5-SNAPSHOT" |
@@ -1,6 +1,7 @@ | |||
<dataset> | |||
<events id="1" | |||
uuid="E1" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="1.0" | |||
@@ -10,6 +11,7 @@ | |||
event_date="1413407091086" | |||
created_at="1225630680000"/> | |||
<events id="2" | |||
uuid="E2" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="Red (was Orange)" | |||
@@ -19,6 +21,7 @@ | |||
event_date="1413407091086" | |||
created_at="1225630680000"/> | |||
<events id="3" | |||
uuid="E3" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="Changes in 'Default' (Java)" | |||
@@ -29,6 +32,7 @@ | |||
created_at="1225630680000"/> | |||
<events id="4" | |||
uuid="E4" | |||
analysis_uuid="uuid_1" | |||
component_uuid="BCDE" | |||
name="1.0" |
@@ -1,6 +1,7 @@ | |||
<dataset> | |||
<events id="1" | |||
uuid="E1" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="Red (was Orange)" |
@@ -0,0 +1,29 @@ | |||
# | |||
# SonarQube, open source software quality management tool. | |||
# Copyright (C) 2008-2016 SonarSource | |||
# mailto:contact AT sonarsource DOT com | |||
# | |||
# SonarQube 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. | |||
# | |||
# SonarQube 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. | |||
# | |||
# | |||
# SonarQube 6.3 | |||
# | |||
class AddUuidToEvents < ActiveRecord::Migration | |||
def self.up | |||
execute_java_migration('org.sonar.db.version.v63.AddUuidToEvents') | |||
end | |||
end |
@@ -29,6 +29,7 @@ public class EventDto { | |||
public static final String CATEGORY_PROFILE = "Profile"; | |||
private Long id; | |||
private String uuid; | |||
private String analysisUuid; | |||
private String componentUuid; | |||
private String name; | |||
@@ -47,6 +48,15 @@ public class EventDto { | |||
return this; | |||
} | |||
public String getUuid() { | |||
return uuid; | |||
} | |||
public EventDto setUuid(String uuid) { | |||
this.uuid = uuid; | |||
return this; | |||
} | |||
public String getAnalysisUuid() { | |||
return analysisUuid; | |||
} |
@@ -30,7 +30,7 @@ import org.sonar.db.MyBatis; | |||
public class DatabaseVersion { | |||
public static final int LAST_VERSION = 1_423; | |||
public static final int LAST_VERSION = 1_500; | |||
/** | |||
* The minimum supported version which can be upgraded. Lower |
@@ -182,6 +182,7 @@ import org.sonar.db.version.v62.PopulateOrganizationUuidOfGroups; | |||
import org.sonar.db.version.v62.PopulateOrganizationUuidOfPermissionTemplates; | |||
import org.sonar.db.version.v62.PopulateOrganizationUuidOfUserRoles; | |||
import org.sonar.db.version.v62.UpdateQualityGateConditionsOnCoverage; | |||
import org.sonar.db.version.v63.AddUuidToEvents; | |||
public class MigrationStepModule extends Module { | |||
@Override | |||
@@ -384,6 +385,9 @@ public class MigrationStepModule extends Module { | |||
DropRelatedDashboardTables.class, | |||
DropMeasureFiltersTables.class, | |||
DropIssueFiltersTables.class, | |||
CreateTableWebhookDeliveries.class); | |||
CreateTableWebhookDeliveries.class, | |||
// 6.3 | |||
AddUuidToEvents.class); | |||
} | |||
} |
@@ -0,0 +1,46 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2016 SonarSource SA | |||
* mailto:contact 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.db.version.v63; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.db.version.AddColumnsBuilder; | |||
import org.sonar.db.version.DdlChange; | |||
import org.sonar.db.version.VarcharColumnDef; | |||
import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; | |||
public class AddUuidToEvents extends DdlChange { | |||
public AddUuidToEvents(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
VarcharColumnDef column = newVarcharColumnDefBuilder() | |||
.setColumnName("uuid") | |||
.setIsNullable(true) | |||
.setLimit(40) | |||
.build(); | |||
context.execute(new AddColumnsBuilder(getDialect(), "events").addColumn(column).build()); | |||
} | |||
} |
@@ -0,0 +1,56 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2016 SonarSource SA | |||
* mailto:contact 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.db.version.v63; | |||
import java.sql.SQLException; | |||
import org.sonar.core.util.UuidFactory; | |||
import org.sonar.db.Database; | |||
import org.sonar.db.version.BaseDataChange; | |||
import org.sonar.db.version.MassUpdate; | |||
import org.sonar.db.version.Select; | |||
import org.sonar.db.version.SqlStatement; | |||
public class PopulateUuidColumnOnEvents extends BaseDataChange { | |||
private final UuidFactory uuidFactory; | |||
public PopulateUuidColumnOnEvents(Database db, UuidFactory uuidFactory) { | |||
super(db); | |||
this.uuidFactory = uuidFactory; | |||
} | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
MassUpdate massUpdate = context.prepareMassUpdate(); | |||
massUpdate.select("SELECT e.id from events e where e.uuid is null"); | |||
massUpdate.update("UPDATE events SET uuid=? WHERE id=?"); | |||
massUpdate.rowPluralName("events"); | |||
massUpdate.execute(this::handle); | |||
} | |||
private boolean handle(Select.Row row, SqlStatement update) throws SQLException { | |||
long id = row.getLong(1); | |||
update.setString(1, uuidFactory.create()); | |||
update.setLong(2, id); | |||
return true; | |||
} | |||
} |
@@ -0,0 +1,25 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2016 SonarSource SA | |||
* mailto:contact 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. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.db.version.v63; | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -4,6 +4,7 @@ | |||
<sql id="eventColumns"> | |||
e.id, | |||
e.uuid, | |||
e.analysis_uuid as "analysisUuid", | |||
e.component_uuid as "componentUuid", | |||
e.name, | |||
@@ -24,8 +25,17 @@ | |||
</select> | |||
<insert id="insert" parameterType="Event" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> | |||
INSERT INTO events (analysis_uuid, component_uuid, name, category, description, event_data, event_date, created_at) | |||
VALUES (#{analysisUuid}, #{componentUuid}, #{name}, #{category}, #{description}, #{data}, #{date}, #{createdAt}) | |||
INSERT INTO events (uuid, analysis_uuid, component_uuid, name, category, description, event_data, event_date, created_at) | |||
VALUES ( | |||
#{uuid, jdbcType=VARCHAR}, | |||
#{analysisUuid, jdbcType=VARCHAR}, | |||
#{componentUuid, jdbcType=VARCHAR}, | |||
#{name, jdbcType=VARCHAR}, | |||
#{category, jdbcType=VARCHAR}, | |||
#{description, jdbcType=VARCHAR}, | |||
#{data, jdbcType=VARCHAR}, | |||
#{date, jdbcType=BIGINT}, | |||
#{createdAt, jdbcType=BIGINT}) | |||
</insert> | |||
<delete id="delete"> |
@@ -513,6 +513,8 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1421'); | |||
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1422'); | |||
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1423'); | |||
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1500'); | |||
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, IS_ROOT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', true, '1418215735482', '1418215735482'); | |||
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; | |||
@@ -157,6 +157,7 @@ CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES" ("PLUGIN_NAME", "PLUGIN_RULE_KEY | |||
CREATE TABLE "EVENTS" ( | |||
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), | |||
"UUID" VARCHAR(40), | |||
"NAME" VARCHAR(400), | |||
"ANALYSIS_UUID" VARCHAR(50) NOT NULL, | |||
"COMPONENT_UUID" VARCHAR(50), | |||
@@ -169,7 +170,6 @@ CREATE TABLE "EVENTS" ( | |||
CREATE INDEX "EVENTS_ANALYSIS" ON "EVENTS" ("ANALYSIS_UUID"); | |||
CREATE INDEX "EVENTS_COMPONENT_UUID" ON "EVENTS" ("COMPONENT_UUID"); | |||
CREATE TABLE "QUALITY_GATES" ( | |||
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), | |||
"NAME" VARCHAR(100) NOT NULL, |
@@ -22,6 +22,7 @@ package org.sonar.db.event; | |||
import java.util.List; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbTester; | |||
@@ -29,23 +30,26 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
public class EventDaoTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
EventDao dao = dbTester.getDbClient().eventDao(); | |||
EventDao underTest = dbTester.getDbClient().eventDao(); | |||
@Test | |||
public void select_by_component_uuid() { | |||
dbTester.prepareDbUnit(getClass(), "shared.xml"); | |||
List<EventDto> dtos = dao.selectByComponentUuid(dbTester.getSession(), "ABCD"); | |||
List<EventDto> dtos = underTest.selectByComponentUuid(dbTester.getSession(), "ABCD"); | |||
assertThat(dtos).hasSize(3); | |||
dtos = dao.selectByComponentUuid(dbTester.getSession(), "BCDE"); | |||
dtos = underTest.selectByComponentUuid(dbTester.getSession(), "BCDE"); | |||
assertThat(dtos).hasSize(1); | |||
EventDto dto = dtos.get(0); | |||
assertThat(dto.getId()).isEqualTo(4L); | |||
assertThat(dto.getUuid()).isEqualTo("E4"); | |||
assertThat(dto.getAnalysisUuid()).isEqualTo("uuid_1"); | |||
assertThat(dto.getComponentUuid()).isEqualTo("BCDE"); | |||
assertThat(dto.getName()).isEqualTo("1.0"); | |||
@@ -60,7 +64,7 @@ public class EventDaoTest { | |||
public void return_different_categories() { | |||
dbTester.prepareDbUnit(getClass(), "shared.xml"); | |||
List<EventDto> dtos = dao.selectByComponentUuid(dbTester.getSession(), "ABCD"); | |||
List<EventDto> dtos = underTest.selectByComponentUuid(dbTester.getSession(), "ABCD"); | |||
assertThat(dtos).extracting("category").containsOnly(EventDto.CATEGORY_ALERT, EventDto.CATEGORY_PROFILE, EventDto.CATEGORY_VERSION); | |||
} | |||
@@ -68,7 +72,8 @@ public class EventDaoTest { | |||
public void insert() { | |||
dbTester.prepareDbUnit(getClass(), "empty.xml"); | |||
dao.insert(dbTester.getSession(), new EventDto() | |||
underTest.insert(dbTester.getSession(), new EventDto() | |||
.setUuid("E1") | |||
.setAnalysisUuid("uuid_1") | |||
.setComponentUuid("ABCD") | |||
.setName("1.0") | |||
@@ -86,7 +91,7 @@ public class EventDaoTest { | |||
public void delete() { | |||
dbTester.prepareDbUnit(getClass(), "delete.xml"); | |||
dao.delete(dbTester.getSession(), 1L); | |||
underTest.delete(dbTester.getSession(), 1L); | |||
dbTester.getSession().commit(); | |||
assertThat(dbTester.countRowsOfTable("events")).isEqualTo(0); |
@@ -29,6 +29,6 @@ public class MigrationStepModuleTest { | |||
public void verify_count_of_added_MigrationStep_types() { | |||
ComponentContainer container = new ComponentContainer(); | |||
new MigrationStepModule().configure(container); | |||
assertThat(container.size()).isEqualTo(164); | |||
assertThat(container.size()).isEqualTo(165); | |||
} | |||
} |
@@ -0,0 +1,58 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2016 SonarSource SA | |||
* mailto:contact 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.db.version.v63; | |||
import java.sql.SQLException; | |||
import java.sql.Types; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbTester; | |||
public class AddUuidToEventsTest { | |||
@Rule | |||
public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, AddUuidToEventsTest.class, "previous-events.sql"); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private AddUuidToEvents underTest = new AddUuidToEvents(dbTester.database()); | |||
@Test | |||
public void creates_table_on_empty_db() throws SQLException { | |||
underTest.execute(); | |||
dbTester.assertColumnDefinition("events", "uuid", Types.VARCHAR, 40, true); | |||
} | |||
@Test | |||
public void migration_is_not_reentrant() throws SQLException { | |||
underTest.execute(); | |||
expectedException.expect(IllegalStateException.class); | |||
underTest.execute(); | |||
} | |||
} |
@@ -1,6 +1,7 @@ | |||
<dataset> | |||
<events id="1" | |||
uuid="E1" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="1.0" |
@@ -1,6 +1,7 @@ | |||
<dataset> | |||
<events id="1" | |||
uuid="E1" | |||
analysis_uuid="uuid_1" | |||
component_uuid="ABCD" | |||
name="1.0" |
@@ -1,6 +1,7 @@ | |||
<dataset> | |||
<events id="1" | |||
uuid="E1" | |||
name="1.0" | |||
category="Version" | |||
description="Version 1.0" | |||
@@ -10,6 +11,7 @@ | |||
analysis_uuid="uuid_1" | |||
created_at="1225630680000"/> | |||
<events id="2" | |||
uuid="E2" | |||
name="Red (was Orange)" | |||
category="Alert" | |||
description="Critical issues variation > 0 since previous version (1.0 - 2015 Feb 09), Open issues > 0" | |||
@@ -19,6 +21,7 @@ | |||
analysis_uuid="uuid_1" | |||
created_at="1225630680000"/> | |||
<events id="3" | |||
uuid="E3" | |||
name="Changes in 'Default' (Java)" | |||
category="Profile" | |||
description="Version 1.0" | |||
@@ -28,6 +31,7 @@ | |||
analysis_uuid="uuid_1" | |||
created_at="1225630680000"/> | |||
<events id="4" | |||
uuid="E4" | |||
name="1.0" | |||
category="Version" | |||
description="Version 1.0" |
@@ -57,6 +57,7 @@ Note that measures, events and reviews are not deleted. | |||
measure_data="[null]"/> | |||
<events id="1" | |||
uuid="E1" | |||
analysis_uuid="u1" | |||
component_uuid="1" | |||
category="VERSION" | |||
@@ -116,6 +117,7 @@ Note that measures, events and reviews are not deleted. | |||
measure_data="[null]"/> | |||
<events id="2" | |||
uuid="E2" | |||
analysis_uuid="u2" | |||
component_uuid="2" | |||
category="VERSION" |
@@ -44,6 +44,7 @@ | |||
measure_data="[null]"/> | |||
<events id="1" | |||
uuid="E1" | |||
analysis_uuid="u1" | |||
component_uuid="1" | |||
category="VERSION" | |||
@@ -108,6 +109,7 @@ | |||
measure_data="[null]"/> | |||
<events id="2" | |||
uuid="E2" | |||
analysis_uuid="u2" | |||
component_uuid="2" | |||
category="VERSION" |
@@ -0,0 +1,11 @@ | |||
CREATE TABLE "EVENTS" ( | |||
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), | |||
"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) | |||
); |