Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-8931 extend size of LOADED_TEMPLATES.TEMPLATE_TYPE
- Loading branch information
Showing
19 changed files
with
679 additions
and
34 deletions.
There are no files selected for viewing
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
.../java/org/sonar/server/platform/db/migration/version/v64/AddIndexLoadedTemplatesType.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
/* | |||
* 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.CreateIndexBuilder; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
|
|||
public class AddIndexLoadedTemplatesType extends DdlChange { | |||
public AddIndexLoadedTemplatesType(Database db) { | |||
super(db); | |||
} | |||
|
|||
@Override | |||
public void execute(Context context) throws SQLException { | |||
context.execute( | |||
new CreateIndexBuilder(getDialect()) | |||
.setTable("loaded_templates") | |||
.setName("ix_loaded_templates_type") | |||
.addColumn(VarcharColumnDef.newVarcharColumnDefBuilder() | |||
.setColumnName("template_type") | |||
.setIsNullable(false) | |||
.setLimit(64) | |||
.build()) | |||
.build()); | |||
} | |||
} |
37 changes: 37 additions & 0 deletions
37
...n/java/org/sonar/server/platform/db/migration/version/v64/CleanLoadedTemplateOrphans.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,37 @@ | |||
/* | |||
* 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; | |||
|
|||
public class CleanLoadedTemplateOrphans extends DataChange { | |||
public CleanLoadedTemplateOrphans(Database db) { | |||
super(db); | |||
} | |||
|
|||
@Override | |||
protected void execute(Context context) throws SQLException { | |||
context.prepareUpsert("delete from loaded_templates where template_type is null") | |||
.execute() | |||
.commit(); | |||
} | |||
} |
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
44 changes: 44 additions & 0 deletions
44
...va/org/sonar/server/platform/db/migration/version/v64/ExtendLoadedTemplateTypeColumn.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
/* | |||
* 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.step.DdlChange; | |||
|
|||
public class ExtendLoadedTemplateTypeColumn extends DdlChange { | |||
public ExtendLoadedTemplateTypeColumn(Database db) { | |||
super(db); | |||
} | |||
|
|||
@Override | |||
public void execute(Context context) throws SQLException { | |||
context.execute( | |||
new AlterColumnsBuilder(getDialect(), "loaded_templates") | |||
.updateColumn(VarcharColumnDef.newVarcharColumnDefBuilder() | |||
.setColumnName("template_type") | |||
.setIsNullable(false) | |||
.setLimit(64) | |||
.build()) | |||
.build()); | |||
} | |||
} |
69 changes: 69 additions & 0 deletions
69
...sonar/server/platform/db/migration/version/v64/UpgradeQualityTemplateLoadedTemplates.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,69 @@ | |||
/* | |||
* 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.security.MessageDigest; | |||
import java.sql.SQLException; | |||
import org.apache.commons.codec.digest.DigestUtils; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.step.DataChange; | |||
import org.sonar.server.platform.db.migration.step.MassUpdate; | |||
import org.sonar.server.platform.db.migration.version.v63.DefaultOrganizationUuid; | |||
|
|||
import static java.lang.String.format; | |||
import static java.nio.charset.StandardCharsets.UTF_8; | |||
import static org.apache.commons.codec.binary.Hex.encodeHexString; | |||
|
|||
public class UpgradeQualityTemplateLoadedTemplates extends DataChange { | |||
private static final String QUALITY_PROFILE_TYPE = "QUALITY_PROFILE"; | |||
|
|||
private final DefaultOrganizationUuid defaultOrganizationUuid; | |||
|
|||
public UpgradeQualityTemplateLoadedTemplates(Database db, DefaultOrganizationUuid defaultOrganizationUuid) { | |||
super(db); | |||
this.defaultOrganizationUuid = defaultOrganizationUuid; | |||
} | |||
|
|||
@Override | |||
protected void execute(Context context) throws SQLException { | |||
String defaultOrganizationUuid = this.defaultOrganizationUuid.getAndCheck(context); | |||
|
|||
MassUpdate massUpdate = context.prepareMassUpdate(); | |||
massUpdate | |||
.select("select id,kee from loaded_templates where template_type=?") | |||
.setString(1, QUALITY_PROFILE_TYPE); | |||
massUpdate.rowPluralName("loaded templates for quality profiles"); | |||
massUpdate.update("update loaded_templates set template_type=?,kee=? where id=?"); | |||
MessageDigest md5Digest = DigestUtils.getMd5Digest(); | |||
massUpdate.execute((row, update) -> { | |||
int id = row.getInt(1); | |||
String key = row.getString(2); | |||
|
|||
update.setString(1, computeLoadedTemplateType(key, md5Digest)); | |||
update.setString(2, defaultOrganizationUuid); | |||
update.setInt(3, id); | |||
return true; | |||
}); | |||
} | |||
|
|||
private static String computeLoadedTemplateType(String currentKey, MessageDigest messageDigest) { | |||
return format("%s.%s", QUALITY_PROFILE_TYPE, encodeHexString(messageDigest.digest(currentKey.getBytes(UTF_8)))); | |||
} | |||
} |
54 changes: 54 additions & 0 deletions
54
...a/org/sonar/server/platform/db/migration/version/v64/AddIndexLoadedTemplatesTypeTest.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,54 @@ | |||
/* | |||
* 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.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.db.CoreDbTester; | |||
|
|||
public class AddIndexLoadedTemplatesTypeTest { | |||
private static final String TABLE_LOADED_TEMPLATES = "loaded_templates"; | |||
|
|||
@Rule | |||
public CoreDbTester db = CoreDbTester.createForSchema(AddIndexLoadedTemplatesTypeTest.class, "loaded_templates_without_index.sql"); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
|
|||
private AddIndexLoadedTemplatesType underTest = new AddIndexLoadedTemplatesType(db.database()); | |||
|
|||
@Test | |||
public void execute_adds_index_ix_loaded_templates_type() throws SQLException { | |||
underTest.execute(); | |||
|
|||
db.assertIndex(TABLE_LOADED_TEMPLATES, "ix_loaded_templates_type", "template_type"); | |||
} | |||
|
|||
@Test | |||
public void execute_is_not_reentrant() throws SQLException { | |||
underTest.execute(); | |||
|
|||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Fail to execute"); | |||
|
|||
underTest.execute(); | |||
} | |||
} |
66 changes: 66 additions & 0 deletions
66
...va/org/sonar/server/platform/db/migration/version/v64/CleanLoadedTemplateOrphansTest.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,66 @@ | |||
/* | |||
* 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 javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.db.CoreDbTester; | |||
|
|||
import static org.assertj.core.api.Assertions.assertThat; | |||
|
|||
public class CleanLoadedTemplateOrphansTest { | |||
|
|||
private static final String TABLE_LOADED_TEMPLATES = "loaded_templates"; | |||
|
|||
@Rule | |||
public CoreDbTester db = CoreDbTester.createForSchema(CleanLoadedTemplateOrphansTest.class, "loaded-templates.sql"); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
|
|||
private CleanLoadedTemplateOrphans underTest = new CleanLoadedTemplateOrphans(db.database()); | |||
|
|||
@Test | |||
public void execute_has_no_effect_on_empty_table() throws SQLException { | |||
underTest.execute(); | |||
} | |||
|
|||
@Test | |||
public void execute_deletes_rows_with_null_in_template_type_column() throws SQLException { | |||
insertLoadedTemplate(null, "value1"); | |||
insertLoadedTemplate("", "value2"); | |||
insertLoadedTemplate("non_empty", "value3"); | |||
|
|||
underTest.execute(); | |||
|
|||
assertThat(db.select("select kee as \"value\" from loaded_templates")) | |||
.extracting(s -> s.get("value")) | |||
.containsOnly("value2", "value3"); | |||
} | |||
|
|||
private void insertLoadedTemplate(@Nullable String type, String key) { | |||
db.executeInsert( | |||
TABLE_LOADED_TEMPLATES, | |||
"TEMPLATE_TYPE", type, | |||
"KEE", key); | |||
} | |||
} |
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
Oops, something went wrong.