-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-7842 add error columns to CE_ACTIVITY
- Loading branch information
Showing
9 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1307_add_error_columns_to_ce_activity.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
sonar-db/src/main/java/org/sonar/db/version/v61/AddErrorColumnsToCeActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
sonar-db/src/test/java/org/sonar/db/version/v61/AddErrorColumnsToCeActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...st/resources/org/sonar/db/version/v61/AddErrorColumnsToCeActivityTest/old_ce_activity.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); |