Sfoglia il codice sorgente

SONAR-16374 Create 'push_events' table

tags/9.6.0.59041
Jacek 1 anno fa
parent
commit
aa16d0446c

+ 9
- 0
server/sonar-db-dao/src/schema/schema-sq.ddl Vedi File

@@ -740,6 +740,15 @@ CREATE TABLE "PROPERTIES"(
ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("UUID");
CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY" NULLS FIRST);

CREATE TABLE "PUSH_EVENTS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
"PAYLOAD" BINARY LARGE OBJECT NOT NULL,
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "PUSH_EVENTS" ADD CONSTRAINT "PK_PUSH_EVENTS" PRIMARY KEY("UUID");
CREATE INDEX "IDX_PUSH_EVEN_CREA_UUID_PROJ" ON "PUSH_EVENTS"("CREATED_AT" NULLS FIRST, "UUID" NULLS FIRST, "PROJECT_UUID" NULLS FIRST);

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

+ 57
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v96/CreateIndexForPushEvents.java Vedi File

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

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;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class CreateIndexForPushEvents extends DdlChange {

private static final String TABLE_NAME = "push_events";
private static final String INDEX_NAME = "idx_push_even_crea_uuid_proj";

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

@Override
public void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
createIndexOnOrderByConditions(context, connection);
}
}

private static void createIndexOnOrderByConditions(Context context, Connection connection) {
if (!DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection)) {
context.execute(new CreateIndexBuilder()
.setTable(TABLE_NAME)
.setName(INDEX_NAME)
.addColumn("created_at")
.addColumn("uuid")
.addColumn("project_uuid")
.build());
}
}

}

+ 49
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v96/CreatePushEventsTable.java Vedi File

@@ -0,0 +1,49 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.v96;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.step.CreateTableChange;

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.BlobColumnDef.newBlobColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class CreatePushEventsTable extends CreateTableChange {

public static final String PUSH_EVENTS_TABLE_NAME = "push_events";

public CreatePushEventsTable(Database db) {
super(db, PUSH_EVENTS_TABLE_NAME);
}

@Override
public void execute(Context context, String tableName) throws SQLException {
context.execute(new CreateTableBuilder(getDialect(), tableName)
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("project_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("payload").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.build());
}
}

+ 2
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v96/DbVersion96.java Vedi File

@@ -38,6 +38,8 @@ public class DbVersion96 implements DbVersion {
.add(6507, "Overwrite plugin file hash to force reloading rules", ForceReloadingOfAllPlugins.class)
.add(6508, "Migrate 'sonarlint_ad_seen' from users to properties", MigrateSonarlintAdSeenFromUsersToProperties.class)
.add(6509, "Drop column sonarlint_ad_seen in 'users'", DropSonarlintAdSeenColumnInUsersTable.class)
.add(6510, "Create table 'push_events'", CreatePushEventsTable.class)
.add(6511, "Create index 'idx_push_even_crea_uuid_proj' on 'push_events'", CreateIndexForPushEvents.class)
;
}
}

+ 52
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v96/CreateIndexForPushEventsTest.java Vedi File

@@ -0,0 +1,52 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.v96;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;

public class CreateIndexForPushEventsTest {

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

private final CreateIndexForPushEvents underTest = new CreateIndexForPushEvents(db.database());

@Test
public void should_create_index() throws SQLException {
db.assertIndexDoesNotExist("push_events", "idx_push_even_crea_uuid_proj");
underTest.execute();
db.assertIndex("push_events", "idx_push_even_crea_uuid_proj", "created_at", "uuid", "project_uuid");
}

@Test
public void migration_should_be_reentrant() throws SQLException {
db.assertIndexDoesNotExist("push_events", "idx_push_even_crea_uuid_proj");

underTest.execute();
// re-entrant
underTest.execute();

db.assertIndex("push_events", "idx_push_even_crea_uuid_proj", "created_at", "uuid", "project_uuid");
}

}

+ 49
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v96/CreatePushEventsTableTest.java Vedi File

@@ -0,0 +1,49 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.v96;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;

public class CreatePushEventsTableTest {
@Rule
public final CoreDbTester db = CoreDbTester.createEmpty();

private final CreatePushEventsTable underTest = new CreatePushEventsTable(db.database());

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

db.assertTableExists("push_events");
}

@Test
public void migration_is_reentrant() throws SQLException {
underTest.execute();
// re-entrant
underTest.execute();

db.assertTableExists("push_events");
}

}

+ 7
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v96/CreateIndexForPushEventsTest/schema.sql Vedi File

@@ -0,0 +1,7 @@
CREATE TABLE "PUSH_EVENTS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
"PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "PUSH_EVENTS" ADD CONSTRAINT "PK_PUSH_EVENTS" PRIMARY KEY("UUID");

Loading…
Annulla
Salva