Skip to content

Commit

Permalink
SONAR-7842 add error columns to CE_ACTIVITY
Browse files Browse the repository at this point in the history
  • Loading branch information
sns-seb committed Aug 18, 2016
1 parent ec5626d commit 8d0aafd
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# SonarQube, open source software quality management tool.
# Copyright (C) 2008-2014 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.1
#
class AddErrorColumnsToCeActivity < ActiveRecord::Migration

def self.up
execute_java_migration('org.sonar.db.version.v61.AddErrorColumnsToCeActivity')
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class DatabaseVersion {

public static final int LAST_VERSION = 1_306;
public static final int LAST_VERSION = 1_307;

/**
* The minimum supported version which can be upgraded. Lower
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
import org.sonar.db.version.v60.PopulateUuidPathColumnOnProjects;
import org.sonar.db.version.v60.RemoveUsersPasswordWhenNotLocal;
import org.sonar.db.version.v61.AddBUuidPathToProjects;
import org.sonar.db.version.v61.AddErrorColumnsToCeActivity;
import org.sonar.db.version.v61.DeleteProjectDashboards;
import org.sonar.db.version.v61.DeleteReportsFromCeQueue;
import org.sonar.db.version.v61.DropIsGlobalFromDashboards;
Expand Down Expand Up @@ -316,6 +317,7 @@ protected void configureModule() {
DropIsGlobalFromDashboards.class,
DeleteReportsFromCeQueue.class,
ShrinkModuleUuidPathOfProjects.class,
AddBUuidPathToProjects.class);
AddBUuidPathToProjects.class,
AddErrorColumnsToCeActivity.class);
}
}
Original file line number Diff line number Diff line change
@@ -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.v61;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.version.AddColumnsBuilder;
import org.sonar.db.version.DdlChange;

import static org.sonar.db.version.ClobColumnDef.newClobColumnDefBuilder;
import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddErrorColumnsToCeActivity extends DdlChange {

private static final String TABLE_CE_ACTIVITY = "ce_activity";

public AddErrorColumnsToCeActivity(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_CE_ACTIVITY)
.addColumn(newVarcharColumnDefBuilder().setColumnName("error_message").setLimit(1000).setIsNullable(true).build())
.addColumn(newClobColumnDefBuilder().setColumnName("error_stacktrace").setIsNullable(true).build())
.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1303');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1304');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1305');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1306');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1307');

INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482');
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,9 @@ CREATE TABLE "CE_ACTIVITY" (
"EXECUTED_AT" BIGINT NULL,
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL,
"EXECUTION_TIME_MS" BIGINT NULL
"EXECUTION_TIME_MS" BIGINT NULL,
"ERROR_MESSAGE" VARCHAR(1000),
"ERROR_STACKTRACE" CLOB(2147483647)
);

CREATE TABLE "CE_TASK_INPUT" (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(131);
assertThat(container.size()).isEqualTo(132);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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.v61;

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;

import static java.lang.String.valueOf;

public class AddErrorColumnsToCeActivityTest {

private static final String TABLE = "CE_ACTIVITY";

@Rule
public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddErrorColumnsToCeActivityTest.class, "old_ce_activity.sql");
@Rule
public ExpectedException expectedException = ExpectedException.none();

private AddErrorColumnsToCeActivity underTest = new AddErrorColumnsToCeActivity(db.database());

@Test
public void migration_adds_column_to_empty_table() throws SQLException {
underTest.execute();

verifyAddedColumns();
}

@Test
public void migration_adds_columns_to_populated_table() throws SQLException {
for (int i = 0; i < 9; i++) {
db.executeInsert(
TABLE,
"uuid", valueOf(i),
"task_type", "PROJECT",
"component_uuid", valueOf(i + 20),
"analysis_uuid", valueOf(i + 30),
"status", "ok",
"is_last", "true",
"is_last_key", "aa",
"submitted_at", valueOf(84654),
"created_at", valueOf(9512),
"updated_at", valueOf(45120));
}
db.commit();

underTest.execute();

verifyAddedColumns();
}

@Test
public void migration_is_not_reentrant() throws SQLException {
underTest.execute();

expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Fail to execute ");
underTest.execute();
}

private void verifyAddedColumns() {
db.assertColumnDefinition(TABLE, "error_message", Types.VARCHAR, 1000, true);
db.assertColumnDefinition(TABLE, "error_stacktrace", Types.CLOB, null, true);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
);

0 comments on commit 8d0aafd

Please sign in to comment.