Quellcode durchsuchen

SONAR-19789 Add initial_perm_sync column to the projects table

tags/10.2.0.77647
Antoine Vigneau vor 10 Monaten
Ursprung
Commit
403184b1e3

+ 2
- 1
server/sonar-db-dao/src/schema/schema-sq.ddl Datei anzeigen

@@ -729,7 +729,8 @@ CREATE TABLE "PROJECTS"(
"TAGS" CHARACTER VARYING(500),
"CREATED_AT" BIGINT,
"UPDATED_AT" BIGINT NOT NULL,
"NCLOC" BIGINT
"NCLOC" BIGINT,
"INITIAL_PERM_SYNC" CHARACTER VARYING(40) DEFAULT 'NOT_APPLICABLE'
);
ALTER TABLE "PROJECTS" ADD CONSTRAINT "PK_NEW_PROJECTS" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "UNIQ_PROJECTS_KEE" ON "PROJECTS"("KEE" NULLS FIRST);

+ 54
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjects.java Datei anzeigen

@@ -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.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.ColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class AddInitialPermSyncColumnInProjects extends DdlChange {
private static final String TABLE_NAME = "projects";
private static final String COLUMN_NAME = "initial_perm_sync";
private static final int COLUMN_SIZE = 40;

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

@Override
public void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
if (!DatabaseUtils.tableColumnExists(connection, TABLE_NAME, COLUMN_NAME)) {
ColumnDef columnDef = VarcharColumnDef.newVarcharColumnDefBuilder()
.setColumnName(COLUMN_NAME)
.setLimit(COLUMN_SIZE)
.setIsNullable(true)
.setDefaultValue("NOT_APPLICABLE")
.build();
context.execute(new AddColumnsBuilder(getDialect(), TABLE_NAME).addColumn(columnDef).build());
}
}
}
}

+ 3
- 1
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java Datei anzeigen

@@ -85,6 +85,8 @@ public class DbVersion102 implements DbVersion {
.add(10_2_030, "Create table 'anticipated_transitions'", CreateAnticipatedTransitionsTable.class)

.add(10_2_031, "Increase size of 'ce_queue.is_last_key' from 55 to 80 characters", IncreaseIsLastKeyInCeActivity.class)
.add(10_2_032, "Increase size of 'ce_queue.main_is_last_key' from 55 to 80 characters", IncreaseMainIsLastKeyInCeActivity.class);
.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 'initial_perm_sync' column in 'projects' table", AddInitialPermSyncColumnInProjects.class);
}
}

+ 54
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjectsTest.java Datei anzeigen

@@ -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 java.sql.Types;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;

public class AddInitialPermSyncColumnInProjectsTest {

private static final String TABLE_NAME = "projects";
private static final String COLUMN_NAME = "initial_perm_sync";
private static final int COLUMN_SIZE = 40;

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

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

@Test
public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException {
db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
underTest.execute();
db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, COLUMN_SIZE, true);
}

@Test
public void execute_whenExecutedTwice_shouldNotFail() throws SQLException {
db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
underTest.execute();
underTest.execute();
db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, COLUMN_SIZE, true);
}

}

+ 15
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjectsTest/schema.sql Datei anzeigen

@@ -0,0 +1,15 @@
CREATE TABLE "PROJECTS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"KEE" CHARACTER VARYING(400) NOT NULL,
"QUALIFIER" CHARACTER VARYING(10) NOT NULL,
"NAME" CHARACTER VARYING(2000),
"DESCRIPTION" CHARACTER VARYING(2000),
"PRIVATE" BOOLEAN NOT NULL,
"TAGS" CHARACTER VARYING(500),
"CREATED_AT" BIGINT,
"UPDATED_AT" BIGINT NOT NULL,
"NCLOC" BIGINT
);
ALTER TABLE "PROJECTS" ADD CONSTRAINT "PK_NEW_PROJECTS" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "UNIQ_PROJECTS_KEE" ON "PROJECTS"("KEE" NULLS FIRST);
CREATE INDEX "IDX_QUALIFIER" ON "PROJECTS"("QUALIFIER" NULLS FIRST);

Laden…
Abbrechen
Speichern