]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19789 Add initial_perm_sync column to the projects table
authorAntoine Vigneau <antoine.vigneau@sonarsource.com>
Wed, 2 Aug 2023 18:35:33 +0000 (20:35 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 4 Aug 2023 20:04:15 +0000 (20:04 +0000)
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjects.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjectsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjectsTest/schema.sql [new file with mode: 0644]

index cdc4eb7f5c1045d723677eaf3c7dfb2fd4404cb2..476c29fae2ea872dd42870e7fda687b305070bcc 100644 (file)
@@ -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);
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjects.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjects.java
new file mode 100644 (file)
index 0000000..b4fcb08
--- /dev/null
@@ -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());
+      }
+    }
+  }
+}
index a9b3582ef4213dbe2c367158d17eb55c1bc37047..0ed9ba34f145393602b65e247eb25d9ed11e649b 100644 (file)
@@ -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);
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjectsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjectsTest.java
new file mode 100644 (file)
index 0000000..72457a2
--- /dev/null
@@ -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);
+  }
+
+}
\ No newline at end of file
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjectsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/AddInitialPermSyncColumnInProjectsTest/schema.sql
new file mode 100644 (file)
index 0000000..977fc34
--- /dev/null
@@ -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);