Browse Source

SONAR-20164 add `created_at` to indexes

tags/10.2.0.77647
Pierre 9 months ago
parent
commit
040fdcf7b0
21 changed files with 697 additions and 4 deletions
  1. 3
    3
      server/sonar-db-dao/src/schema/schema-sq.ddl
  2. 62
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/CreateIndexOnColumns.java
  3. 29
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveries.java
  4. 29
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveries.java
  5. 29
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveries.java
  6. 12
    1
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
  7. 29
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveries.java
  8. 29
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveries.java
  9. 29
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveries.java
  10. 54
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesTest.java
  11. 54
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesTest.java
  12. 55
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesTest.java
  13. 57
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest.java
  14. 57
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesTest.java
  15. 58
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesTest.java
  16. 18
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesTest/schema.sql
  17. 18
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesTest/schema.sql
  18. 18
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesTest/schema.sql
  19. 19
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest/schema.sql
  20. 19
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesTest/schema.sql
  21. 19
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesTest/schema.sql

+ 3
- 3
server/sonar-db-dao/src/schema/schema-sq.ddl View File

@@ -1102,9 +1102,9 @@ CREATE TABLE "WEBHOOK_DELIVERIES"(
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
CREATE INDEX "IDX_WBHK_DLVRS_WBHK_UUID" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID" NULLS FIRST);
CREATE INDEX "WD_PROJECT_UUID" ON "WEBHOOK_DELIVERIES"("PROJECT_UUID" NULLS FIRST);
CREATE INDEX "WD_WEBHOOK_UUID_CREATED_AT" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID" NULLS FIRST, "CREATED_AT" NULLS FIRST);
CREATE INDEX "WD_PROJECT_UUID_CREATED_AT" ON "WEBHOOK_DELIVERIES"("PROJECT_UUID" NULLS FIRST, "CREATED_AT" NULLS FIRST);
CREATE INDEX "WD_CE_TASK_UUID_CREATED_AT" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST, "CREATED_AT" NULLS FIRST);

CREATE TABLE "WEBHOOKS"(
"UUID" CHARACTER VARYING(40) NOT NULL,

+ 62
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/CreateIndexOnColumns.java View File

@@ -0,0 +1,62 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.step;

import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;

public abstract class CreateIndexOnColumns extends DdlChange {

private final String table;
private final String indexPrefix;
private final String[] columnNames;
private final boolean unique;

protected CreateIndexOnColumns(Database db, String table, String indexPrefix, boolean unique, String... columnNames) {
super(db);
this.table = table;
this.indexPrefix = indexPrefix;
this.unique = unique;
this.columnNames = columnNames;
}

@Override
public void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
if (!DatabaseUtils.indexExistsIgnoreCase(table, newIndexName(), connection)) {
CreateIndexBuilder builder = new CreateIndexBuilder()
.setTable(table)
.setName(newIndexName())
.setUnique(unique);
for (String columnName : columnNames) {
builder.addColumn(columnName);
}
context.execute(builder.build());
}
}
}

public String newIndexName() {
return indexPrefix + "_" + String.join("_", columnNames);
}
}

+ 29
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveries.java View File

@@ -0,0 +1,29 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.CreateIndexOnColumns;

public class CreateIndexProjectUuidCreatedAtInWebhookDeliveries extends CreateIndexOnColumns {
protected CreateIndexProjectUuidCreatedAtInWebhookDeliveries(Database db) {
super(db, "webhook_deliveries", "wd", false, "project_uuid", "created_at");
}
}

+ 29
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveries.java View File

@@ -0,0 +1,29 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.CreateIndexOnColumns;

public class CreateIndexTaskUuidCreatedAtInWebhookDeliveries extends CreateIndexOnColumns {
protected CreateIndexTaskUuidCreatedAtInWebhookDeliveries(Database db) {
super(db, "webhook_deliveries", "wd", false, "ce_task_uuid", "created_at");
}
}

+ 29
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveries.java View File

@@ -0,0 +1,29 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.CreateIndexOnColumns;

public class CreateIndexWebhookUuidCreatedAtInWebhookDeliveries extends CreateIndexOnColumns {
protected CreateIndexWebhookUuidCreatedAtInWebhookDeliveries(Database db) {
super(db, "webhook_deliveries", "wd", false, "webhook_uuid", "created_at");
}
}

+ 12
- 1
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java View File

@@ -25,6 +25,7 @@ import org.sonar.server.platform.db.migration.version.DbVersion;
// ignoring bad number formatting, as it's indented that we align the migration numbers to SQ versions
@SuppressWarnings("java:S3937")
public class DbVersion102 implements DbVersion {

/**
* We use the start of the 10.X cycle as an opportunity to align migration numbers with the SQ version number.
* Please follow this pattern:
@@ -85,6 +86,8 @@ public class DbVersion102 implements DbVersion {
.add(10_2_032, "Increase size of 'ce_queue.main_is_last_key' from 55 to 80 characters", IncreaseMainIsLastKeyInCeActivity.class)
.add(10_2_033, "Add column 'clean_code_attribute' in 'rules' table", AddCleanCodeAttributeInRules.class)
.add(10_2_034, "Populate 'clean_code_attribute' column in 'rules' table", PopulateCleanCodeAttributeColumnInRules.class)
//TODO SONAR-20073
//.add(10_2_035, "Make 'clean_code_attribute' column not nullable in 'rules' table", MakeCleanCodeAttributeColumnNotNullableInRules.class);

.add(10_2_036, "Create 'rules_default_impacts' table", CreateRulesDefaultImpactsTable.class)
.add(10_2_037, "Create unique constraint index on 'rules_default_impacts' table", CreateUniqueConstraintOnRulesDefaultImpacts.class)
@@ -98,6 +101,14 @@ public class DbVersion102 implements DbVersion {
.add(10_2_044, "Update column 'value' and populate column 'previous_non_compliant_value' in 'new_code_periods' table",
UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriods.class)
.add(10_2_045, "Alter 'project_uuid' in 'user_dismissed_messages' - make it nullable", MakeProjectUuidNullableInUserDismissedMessages.class)
.add(10_2_046, "Create index 'project_branches_project_uuid' in 'project_branches' table", CreateIndexProjectUuidInProjectBranches.class);
.add(10_2_046, "Create index 'project_branches_project_uuid' in 'project_branches' table", CreateIndexProjectUuidInProjectBranches.class)

.add(10_2_047, "Drop index 'idx_wbhk_dlvrs_wbhk_uuid' in 'webhook_deliveries'", DropIndexWebhookUuidInWebhookDeliveries.class)
.add(10_2_048, "Create index 'wb_webhook_uuid_created_at' in 'webhook_deliveries'", CreateIndexWebhookUuidCreatedAtInWebhookDeliveries.class)
.add(10_2_049, "Drop index 'wd_project_uuid' in 'webhook_deliveries'", DropIndexProjectUuidInWebhookDeliveries.class)
.add(10_2_050, "Create index 'wd_project_uuid_created_at' in 'webhook_deliveries'", CreateIndexProjectUuidCreatedAtInWebhookDeliveries.class)
.add(10_2_051, "Drop index 'ce_task_uuid' in 'webhook_deliveries'", DropIndexTaskUuidInWebhookDeliveries.class)
.add(10_2_052, "Create index 'wd_task_uuid_created_at' in 'webhook_deliveries'", CreateIndexTaskUuidCreatedAtInWebhookDeliveries.class)
;
}
}

+ 29
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveries.java View File

@@ -0,0 +1,29 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;

public class DropIndexProjectUuidInWebhookDeliveries extends DropIndexChange {
public DropIndexProjectUuidInWebhookDeliveries(Database db) {
super(db, "wd_project_uuid", "webhook_deliveries");
}
}

+ 29
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveries.java View File

@@ -0,0 +1,29 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;

public class DropIndexTaskUuidInWebhookDeliveries extends DropIndexChange {
public DropIndexTaskUuidInWebhookDeliveries(Database db) {
super(db, "ce_task_uuid", "webhook_deliveries");
}
}

+ 29
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveries.java View File

@@ -0,0 +1,29 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;

public class DropIndexWebhookUuidInWebhookDeliveries extends DropIndexChange {
public DropIndexWebhookUuidInWebhookDeliveries(Database db) {
super(db, "idx_wbhk_dlvrs_wbhk_uuid", "webhook_deliveries");
}
}

+ 54
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesTest.java View File

@@ -0,0 +1,54 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class CreateIndexProjectUuidCreatedAtInWebhookDeliveriesTest {

public static final String TABLE_NAME = "webhook_deliveries";
public static final String INDEX_NAME = "wd_project_uuid_created_at";

@Rule
public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexProjectUuidCreatedAtInWebhookDeliveriesTest.class, "schema.sql");

private final DdlChange createIndex = new CreateIndexProjectUuidCreatedAtInWebhookDeliveries(db.database());

@Test
public void migration_should_create_index() throws SQLException {
db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);

createIndex.execute();

db.assertIndex(TABLE_NAME, INDEX_NAME, "project_uuid", "created_at");
}

@Test
public void migration_should_be_reentrant() throws SQLException {
createIndex.execute();
createIndex.execute();

db.assertIndex(TABLE_NAME, INDEX_NAME, "project_uuid", "created_at");
}
}

+ 54
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesTest.java View File

@@ -0,0 +1,54 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class CreateIndexTaskUuidCreatedAtInWebhookDeliveriesTest {

public static final String TABLE_NAME = "webhook_deliveries";
public static final String INDEX_NAME = "wd_ce_task_uuid_created_at";

@Rule
public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexTaskUuidCreatedAtInWebhookDeliveriesTest.class, "schema.sql");

private final DdlChange createIndex = new CreateIndexTaskUuidCreatedAtInWebhookDeliveries(db.database());

@Test
public void migration_should_create_index() throws SQLException {
db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);

createIndex.execute();

db.assertIndex(TABLE_NAME, INDEX_NAME, "ce_task_uuid", "created_at");
}

@Test
public void migration_should_be_reentrant() throws SQLException {
createIndex.execute();
createIndex.execute();

db.assertIndex(TABLE_NAME, INDEX_NAME, "ce_task_uuid", "created_at");
}
}

+ 55
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesTest.java View File

@@ -0,0 +1,55 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesTest {

public static final String TABLE_NAME = "webhook_deliveries";
public static final String INDEX_NAME = "wd_webhook_uuid_created_at";

@Rule
public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesTest.class, "schema.sql");

private final DdlChange createIndex = new CreateIndexWebhookUuidCreatedAtInWebhookDeliveries(db.database());

@Test
public void migration_should_create_index() throws SQLException {
db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);

createIndex.execute();

db.assertIndex(TABLE_NAME, INDEX_NAME, "webhook_uuid", "created_at");
}

@Test
public void migration_should_be_reentrant() throws SQLException {
createIndex.execute();
createIndex.execute();

db.assertIndex(TABLE_NAME, INDEX_NAME, "webhook_uuid", "created_at");
}

}

+ 57
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest.java View File

@@ -0,0 +1,57 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndexProjectUuidInWebhookDeliveriesTest {

private static final String TABLE_NAME = "webhook_deliveries";
private static final String COLUMN_NAME = "project_uuid";
private static final String INDEX_NAME = "wd_project_uuid";

@Rule
public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexProjectUuidInWebhookDeliveriesTest.class, "schema.sql");

private final DdlChange underTest = new DropIndexProjectUuidInWebhookDeliveries(db.database());

@Test
public void index_is_dropped() throws SQLException {
db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);

underTest.execute();

db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
}

@Test
public void migration_is_reentrant() throws SQLException {
db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);

underTest.execute();
underTest.execute();

db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
}
}

+ 57
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesTest.java View File

@@ -0,0 +1,57 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndexTaskUuidInWebhookDeliveriesTest {

private static final String TABLE_NAME = "webhook_deliveries";
private static final String COLUMN_NAME = "ce_task_uuid";
private static final String INDEX_NAME = "ce_task_uuid";

@Rule
public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexTaskUuidInWebhookDeliveriesTest.class, "schema.sql");

private final DdlChange underTest = new DropIndexTaskUuidInWebhookDeliveries(db.database());

@Test
public void index_is_dropped() throws SQLException {
db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);

underTest.execute();

db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
}

@Test
public void migration_is_reentrant() throws SQLException {
db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);

underTest.execute();
underTest.execute();

db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
}
}

+ 58
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesTest.java View File

@@ -0,0 +1,58 @@
/*
* SonarQube
* Copyright (C) 2009-2023 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.v102;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndexWebhookUuidInWebhookDeliveriesTest {

private static final String TABLE_NAME = "webhook_deliveries";
private static final String COLUMN_NAME = "webhook_uuid";
private static final String INDEX_NAME = "idx_wbhk_dlvrs_wbhk_uuid";

@Rule
public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexWebhookUuidInWebhookDeliveriesTest.class, "schema.sql");

private final DdlChange underTest = new DropIndexWebhookUuidInWebhookDeliveries(db.database());

@Test
public void index_is_dropped() throws SQLException {
db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);

underTest.execute();

db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
}

@Test
public void migration_is_reentrant() throws SQLException {
db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);

underTest.execute();
underTest.execute();

db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
}

}

+ 18
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesTest/schema.sql View File

@@ -0,0 +1,18 @@
CREATE TABLE "WEBHOOK_DELIVERIES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
"PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
"CE_TASK_UUID" CHARACTER VARYING(40),
"ANALYSIS_UUID" CHARACTER VARYING(40),
"NAME" CHARACTER VARYING(100) NOT NULL,
"URL" CHARACTER VARYING(2000) NOT NULL,
"SUCCESS" BOOLEAN NOT NULL,
"HTTP_STATUS" INTEGER,
"DURATION_MS" BIGINT NOT NULL,
"PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
"ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
CREATE INDEX "WD_WEBHOOK_UUID_CREATED_AT" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID", "CREATED_AT" NULLS FIRST);

+ 18
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesTest/schema.sql View File

@@ -0,0 +1,18 @@
CREATE TABLE "WEBHOOK_DELIVERIES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
"PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
"CE_TASK_UUID" CHARACTER VARYING(40),
"ANALYSIS_UUID" CHARACTER VARYING(40),
"NAME" CHARACTER VARYING(100) NOT NULL,
"URL" CHARACTER VARYING(2000) NOT NULL,
"SUCCESS" BOOLEAN NOT NULL,
"HTTP_STATUS" INTEGER,
"DURATION_MS" BIGINT NOT NULL,
"PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
"ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
CREATE INDEX "WD_WEBHOOK_UUID_CREATED_AT" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID", "CREATED_AT" NULLS FIRST);
CREATE INDEX "WD_PROJECT_UUID_CREATED_AT" ON "WEBHOOK_DELIVERIES"("PROJECT_UUID", "CREATED_AT" NULLS FIRST);

+ 18
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesTest/schema.sql View File

@@ -0,0 +1,18 @@
CREATE TABLE "WEBHOOK_DELIVERIES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
"PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
"CE_TASK_UUID" CHARACTER VARYING(40),
"ANALYSIS_UUID" CHARACTER VARYING(40),
"NAME" CHARACTER VARYING(100) NOT NULL,
"URL" CHARACTER VARYING(2000) NOT NULL,
"SUCCESS" BOOLEAN NOT NULL,
"HTTP_STATUS" INTEGER,
"DURATION_MS" BIGINT NOT NULL,
"PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
"ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
CREATE INDEX "PROJECT_UUID" ON "WEBHOOK_DELIVERIES"("PROJECT_UUID" NULLS FIRST);

+ 19
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest/schema.sql View File

@@ -0,0 +1,19 @@
CREATE TABLE "WEBHOOK_DELIVERIES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
"PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
"CE_TASK_UUID" CHARACTER VARYING(40),
"ANALYSIS_UUID" CHARACTER VARYING(40),
"NAME" CHARACTER VARYING(100) NOT NULL,
"URL" CHARACTER VARYING(2000) NOT NULL,
"SUCCESS" BOOLEAN NOT NULL,
"HTTP_STATUS" INTEGER,
"DURATION_MS" BIGINT NOT NULL,
"PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
"ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
CREATE INDEX "WD_PROJECT_UUID" ON "WEBHOOK_DELIVERIES"("PROJECT_UUID" NULLS FIRST);
CREATE INDEX "WD_WEBHOOK_UUID_CREATED_AT" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID", "CREATED_AT" NULLS FIRST);

+ 19
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesTest/schema.sql View File

@@ -0,0 +1,19 @@
CREATE TABLE "WEBHOOK_DELIVERIES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
"PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
"CE_TASK_UUID" CHARACTER VARYING(40),
"ANALYSIS_UUID" CHARACTER VARYING(40),
"NAME" CHARACTER VARYING(100) NOT NULL,
"URL" CHARACTER VARYING(2000) NOT NULL,
"SUCCESS" BOOLEAN NOT NULL,
"HTTP_STATUS" INTEGER,
"DURATION_MS" BIGINT NOT NULL,
"PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
"ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
CREATE INDEX "WD_WEBHOOK_UUID_CREATED_AT" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID", "CREATED_AT" NULLS FIRST);
CREATE INDEX "WD_PROJECT_UUID_CREATED_AT" ON "WEBHOOK_DELIVERIES"("PROJECT_UUID", "CREATED_AT" NULLS FIRST);

+ 19
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesTest/schema.sql View File

@@ -0,0 +1,19 @@
CREATE TABLE "WEBHOOK_DELIVERIES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
"PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
"CE_TASK_UUID" CHARACTER VARYING(40),
"ANALYSIS_UUID" CHARACTER VARYING(40),
"NAME" CHARACTER VARYING(100) NOT NULL,
"URL" CHARACTER VARYING(2000) NOT NULL,
"SUCCESS" BOOLEAN NOT NULL,
"HTTP_STATUS" INTEGER,
"DURATION_MS" BIGINT NOT NULL,
"PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
"ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
CREATE INDEX "IDX_WBHK_DLVRS_WBHK_UUID" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID" NULLS FIRST);
CREATE INDEX "PROJECT_UUID" ON "WEBHOOK_DELIVERIES"("PROJECT_UUID" NULLS FIRST);

Loading…
Cancel
Save