diff options
author | Serhat Yenican <104850907+serhat-yenican-sonarsource@users.noreply.github.com> | 2024-11-29 11:22:45 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-11-29 20:03:05 +0000 |
commit | c8c28a618615c3046aa464b5f9faf1924c132ae2 (patch) | |
tree | db97ee4f050312f637e7df6b8bbce04bbcdb6c4d /server/sonar-db-migration | |
parent | 2042ab9d8282a70e56f96c408b5c939564b752a0 (diff) | |
download | sonarqube-c8c28a618615c3046aa464b5f9faf1924c132ae2.tar.gz sonarqube-c8c28a618615c3046aa464b5f9faf1924c132ae2.zip |
SGB-224 use query parameters for db migration sql queries (#12438)
Diffstat (limited to 'server/sonar-db-migration')
2 files changed, 11 insertions, 6 deletions
diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigrateAiSuggestionEnabledValuesTest.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigrateAiSuggestionEnabledValuesTest.java index 2e2f65e4cd9..ff892fe0aca 100644 --- a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigrateAiSuggestionEnabledValuesTest.java +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigrateAiSuggestionEnabledValuesTest.java @@ -44,8 +44,8 @@ class MigrateAiSuggestionEnabledValuesTest { void execute_shouldNotUpdateAnything_whenThePropertyDoesNotExists() throws SQLException { underTest.execute(); - assertThat(db.countSql(String.format("select count(1) from properties where prop_key = '%s'", AI_CODEFIX_ENABLED_PROP_KEY))).isZero(); - assertThat(db.countSql("select count(1) from projects where ai_code_fix_enabled is true")).isZero(); + assertThat(db.countSql(String.format("select count(*) from properties where prop_key = '%s'", AI_CODEFIX_ENABLED_PROP_KEY))).isZero(); + assertThat(db.countSql("select count(*) from projects where ai_code_fix_enabled = " + getBool(true))).isZero(); } @Test @@ -57,7 +57,7 @@ class MigrateAiSuggestionEnabledValuesTest { .extracting(r -> r.get("TEXT_VALUE")) .containsExactly(DISABLED); - assertThat(db.countSql("select count(1) from projects where ai_code_fix_enabled is true")).isZero(); + assertThat(db.countSql("select count(*) from projects where ai_code_fix_enabled = " + getBool(true))).isZero(); } @Test @@ -69,7 +69,8 @@ class MigrateAiSuggestionEnabledValuesTest { .extracting(r -> r.get("TEXT_VALUE")) .containsExactly(ENABLED_FOR_ALL_PROJECTS); - assertThat(db.countSql("select count(1) from projects where ai_code_fix_enabled is false")).isZero(); + assertThat(db.countSql("select count(*) from projects where ai_code_fix_enabled = " + getBool(true))).isEqualTo(2); + assertThat(db.countSql("select count(*) from projects where ai_code_fix_enabled = " + getBool(false))).isZero(); } private void insertProjects() { @@ -102,4 +103,8 @@ class MigrateAiSuggestionEnabledValuesTest { "created_at", 1L); } + private String getBool(boolean isTrue) { + var dialect = db.database().getDialect(); + return isTrue ? dialect.getTrueSqlValue() : dialect.getFalseSqlValue(); + } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/MigrateAiSuggestionEnabledValues.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/MigrateAiSuggestionEnabledValues.java index 6b0a0beedc2..043b04727fa 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/MigrateAiSuggestionEnabledValues.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/MigrateAiSuggestionEnabledValues.java @@ -36,7 +36,6 @@ public class MigrateAiSuggestionEnabledValues extends DataChange { @Override protected void execute(Context context) throws SQLException { - var isAiCodeFixEnabledOptional = Optional.ofNullable(context.prepareSelect("select text_value from properties where prop_key=?") .setString(1, AI_CODEFIX_ENABLED_PROP_KEY) .get(r -> r.getBoolean(1))); @@ -49,7 +48,8 @@ public class MigrateAiSuggestionEnabledValues extends DataChange { .execute() .commit(); if (isAiCodeFixEnabled) { - context.prepareUpsert("update projects set ai_code_fix_enabled=true") + context.prepareUpsert("update projects set ai_code_fix_enabled = ?") + .setBoolean(1, true) .execute() .commit(); } |