Просмотр исходного кода

SONAR-13426 add project_badge_token table

tags/9.2.0.49834
Pierre 2 лет назад
Родитель
Сommit
be652549aa

+ 9
- 0
server/sonar-db-dao/src/schema/schema-sq.ddl Просмотреть файл

@@ -623,6 +623,15 @@ CREATE UNIQUE INDEX "UNIQ_PROJECT_ALM_SETTINGS" ON "PROJECT_ALM_SETTINGS"("PROJE
CREATE INDEX "PROJECT_ALM_SETTINGS_ALM" ON "PROJECT_ALM_SETTINGS"("ALM_SETTING_UUID");
CREATE INDEX "PROJECT_ALM_SETTINGS_SLUG" ON "PROJECT_ALM_SETTINGS"("ALM_SLUG");

CREATE TABLE "PROJECT_BADGE_TOKEN"(
"UUID" VARCHAR(40) NOT NULL,
"TOKEN" VARCHAR(255) NOT NULL,
"PROJECT_UUID" VARCHAR(40) NOT NULL,
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
);
ALTER TABLE "PROJECT_BADGE_TOKEN" ADD CONSTRAINT "PK_PROJECT_BADGE_TOKEN" PRIMARY KEY("UUID");

CREATE TABLE "PROJECT_BRANCHES"(
"UUID" VARCHAR(50) NOT NULL,
"PROJECT_UUID" VARCHAR(50) NOT NULL,

+ 61
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/CreateProjectBadgeTokenTable.java Просмотреть файл

@@ -0,0 +1,61 @@
/*
* SonarQube
* Copyright (C) 2009-2021 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.v92;

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

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
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 CreateProjectBadgeTokenTable extends DdlChange {

public static final String PROJECT_BADGE_TOKEN_TABLE = "project_badge_token";

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

@Override
public void execute(Context context) throws SQLException {
if (tableExists()) {
return;
}

context.execute(new CreateTableBuilder(getDialect(), PROJECT_BADGE_TOKEN_TABLE)
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("token").setIsNullable(false).setLimit(255).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("project_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(false).build())
.build());
}

private boolean tableExists() throws SQLException {
try (var connection = getDatabase().getDataSource().getConnection()) {
return DatabaseUtils.tableExists(PROJECT_BADGE_TOKEN_TABLE, connection);
}
}

}

+ 1
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java Просмотреть файл

@@ -37,6 +37,7 @@ public class DbVersion92 implements DbVersion {
.add(6109, "Create table 'portfolio_proj_branches'", CreatePortfolioProjectBranchesTable.class)
.add(6110, "Add column 'branch_key' to table 'portfolios'", AddBranchToPortfolios.class)
.add(6111, "Change size of column 'kee' in 'components'", AlterKeeInComponentsTable.class)
.add(6112, "Create 'project_badge_token' Table", CreateProjectBadgeTokenTable.class)
;
}
}

+ 65
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/CreateProjectBadgeTokenTableTest.java Просмотреть файл

@@ -0,0 +1,65 @@
/*
* SonarQube
* Copyright (C) 2009-2021 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.v92;

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

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;

public class CreateProjectBadgeTokenTableTest {

private static final String TABLE_NAME = "project_badge_token";

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

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

@Test
public void migration_should_create_a_table_with_index() throws SQLException {
db.assertTableDoesNotExist(TABLE_NAME);

underTest.execute();

db.assertTableExists(TABLE_NAME);
db.assertPrimaryKey(TABLE_NAME, "pk_project_badge_token", "uuid");
db.assertColumnDefinition(TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false);
db.assertColumnDefinition(TABLE_NAME, "token", Types.VARCHAR, 255, false);
db.assertColumnDefinition(TABLE_NAME, "project_uuid", Types.VARCHAR, UUID_SIZE, false);
db.assertColumnDefinition(TABLE_NAME, "updated_at", Types.BIGINT, 20, false);
db.assertColumnDefinition(TABLE_NAME, "created_at", Types.BIGINT, 20, false);
}

@Test
public void migration_should_be_reentrant() throws SQLException {
db.assertTableDoesNotExist(TABLE_NAME);

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

db.assertTableExists(TABLE_NAME);
}
}

+ 1
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/CreateProjectBadgeTokenTableTest/schema.sql Просмотреть файл

@@ -0,0 +1 @@
DROP TABLE IF EXISTS project_badge_token;

Загрузка…
Отмена
Сохранить