]> source.dussan.org Git - sonarqube.git/commitdiff
[NO JIRA] Fix DB migration name for v10.1
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 11 Apr 2023 16:46:29 +0000 (11:46 -0500)
committersonartech <sonartech@sonarsource.com>
Wed, 12 Apr 2023 20:03:18 +0000 (20:03 +0000)
35 files changed:
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/DbVersion101.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsers.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccounts.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForEmailOnUsersTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForScmAccountOnScmAccountsTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/CreateScmAccountsTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/DbVersion110.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/DropScmAccountsInUsers.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/MigrateScmAccountsFromUsersToScmAccounts.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DbVersion101Test.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForEmailOnUsersTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForScmAccountOnScmAccountsTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/CreateScmAccountsTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/DbVersion110Test.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/DropScmAccountsInUsersTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/MigrateScmAccountsFromUsersToScmAccountsTest.java [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/CreateIndexesForScmAccountsTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/CreateIndexForEmailOnUsersTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/CreateIndexForScmAccountOnScmAccountsTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/CreateIndexesForScmAccountsTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/DropScmAccountsInUsersTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/MigrateScmAccountsFromUsersToScmAccountsTest/schema.sql [deleted file]

index 0bbcf637ee5c6ded9ff8982b27b4ba35580e00c4..dbf2cc0f7fba02ad27c1b4694e760f0f00e0a0b3 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.server.platform.db.migration.step.MigrationStepRegistryImpl;
 import org.sonar.server.platform.db.migration.step.MigrationStepsProvider;
 import org.sonar.server.platform.db.migration.version.v00.DbVersion00;
 import org.sonar.server.platform.db.migration.version.v100.DbVersion100;
-import org.sonar.server.platform.db.migration.version.v110.DbVersion110;
+import org.sonar.server.platform.db.migration.version.v101.DbVersion101;
 
 public class MigrationConfigurationModule extends Module {
   @Override
@@ -39,7 +39,7 @@ public class MigrationConfigurationModule extends Module {
       // DbVersion implementations
       DbVersion00.class,
       DbVersion100.class,
-      DbVersion110.class,
+      DbVersion101.class,
 
       // migration steps
       MigrationStepRegistryImpl.class,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTable.java
new file mode 100644 (file)
index 0000000..d305a0d
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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.v101;
+
+import com.google.common.annotations.VisibleForTesting;
+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;
+
+class CreateIndexForEmailOnUsersTable extends DdlChange {
+
+  @VisibleForTesting
+  static final String INDEX_NAME = "users_email";
+  @VisibleForTesting
+  static final String TABLE_NAME = "users";
+  @VisibleForTesting
+  static final String COLUMN_NAME = "email";
+
+  public CreateIndexForEmailOnUsersTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      createIndex(context, connection);
+    }
+  }
+
+  private static void createIndex(Context context, Connection connection) {
+    if (!DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection)) {
+      context.execute(new CreateIndexBuilder()
+        .setTable(TABLE_NAME)
+        .setName(INDEX_NAME)
+        .addColumn(COLUMN_NAME)
+        .setUnique(false)
+        .build());
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTable.java
new file mode 100644 (file)
index 0000000..d16913a
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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.v101;
+
+import com.google.common.annotations.VisibleForTesting;
+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;
+
+import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.TABLE_NAME;
+
+class CreateIndexForScmAccountOnScmAccountsTable extends DdlChange {
+
+  @VisibleForTesting
+  static final String INDEX_NAME = "scm_accounts_scm_account";
+
+  public CreateIndexForScmAccountOnScmAccountsTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      createIndex(context, connection);
+    }
+  }
+
+  private static void createIndex(Context context, Connection connection) {
+    if (!DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection)) {
+      context.execute(new CreateIndexBuilder()
+        .setTable(TABLE_NAME)
+        .setName(INDEX_NAME)
+        .addColumn(SCM_ACCOUNT_COLUMN_NAME)
+        .setUnique(false)
+        .build());
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTable.java
new file mode 100644 (file)
index 0000000..443b689
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.v101;
+
+import com.google.common.annotations.VisibleForTesting;
+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.VarcharColumnDef.USER_UUID_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+class CreateScmAccountsTable extends CreateTableChange {
+  static final String TABLE_NAME = "scm_accounts";
+  static final String USER_UUID_COLUMN_NAME = "user_uuid";
+  static final String SCM_ACCOUNT_COLUMN_NAME = "scm_account";
+
+  @VisibleForTesting
+  static final int SCM_ACCOUNT_SIZE = 255;
+
+  public CreateScmAccountsTable(Database db) {
+    super(db, TABLE_NAME);
+  }
+
+  @Override
+  public void execute(Context context, String tableName) throws SQLException {
+    context.execute(new CreateTableBuilder(getDialect(), tableName)
+      .addPkColumn(newVarcharColumnDefBuilder().setColumnName(USER_UUID_COLUMN_NAME).setIsNullable(false).setLimit(USER_UUID_SIZE).build())
+      .addPkColumn(newVarcharColumnDefBuilder().setColumnName(SCM_ACCOUNT_COLUMN_NAME).setIsNullable(false).setLimit(SCM_ACCOUNT_SIZE).build())
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/DbVersion101.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/DbVersion101.java
new file mode 100644 (file)
index 0000000..fda502b
--- /dev/null
@@ -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.v101;
+
+import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+import org.sonar.server.platform.db.migration.version.v100.AddIsMainColumnInProjectBranches;
+import org.sonar.server.platform.db.migration.version.v100.AlterIsMainColumnInProjectBranches;
+import org.sonar.server.platform.db.migration.version.v100.UpdateIsMainColumnInProjectBranches;
+
+// ignoring bad number formatting, as it's indented that we align the migration numbers to SQ versions
+@SuppressWarnings("java:S3937")
+public class DbVersion101 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:
+   * 10_0_000
+   * 10_0_001
+   * 10_0_002
+   * 10_1_000
+   * 10_1_001
+   * 10_1_002
+   * 10_2_000
+   */
+
+  @Override
+  public void addSteps(MigrationStepRegistry registry) {
+    registry
+      .add(10_1_000, "Add 'scm_accounts' table", CreateScmAccountsTable.class)
+      .add(10_1_001, "Migrate scm accounts from 'users' to 'scm_accounts' table", MigrateScmAccountsFromUsersToScmAccounts.class)
+      .add(10_1_002, "Add index on 'scm_accounts.scm_account'", CreateIndexForScmAccountOnScmAccountsTable.class)
+      .add(10_1_003, "Add index on 'users.email'", CreateIndexForEmailOnUsersTable.class)
+      .add(10_1_004, "Drop 'scm_accounts' column in 'users' table", DropScmAccountsInUsers.class)
+      .add(10_1_005, "Add column 'is_main' to 'project_branches' table", AddIsMainColumnInProjectBranches.class)
+      .add(10_1_006, "Update value of 'is_main' in 'project_branches' table", UpdateIsMainColumnInProjectBranches.class)
+      .add(10_1_007, "Alter column 'is_main' in 'project_branches' table - make it not nullable", AlterIsMainColumnInProjectBranches.class)
+    ;
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsers.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsers.java
new file mode 100644 (file)
index 0000000..6384148
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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.v101;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropColumnChange;
+
+class DropScmAccountsInUsers extends DropColumnChange {
+  static final String TABLE_NAME = "users";
+  static final String COLUMN_NAME = "scm_accounts";
+
+  public DropScmAccountsInUsers(Database db) {
+    super(db, TABLE_NAME, COLUMN_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccounts.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccounts.java
new file mode 100644 (file)
index 0000000..7d27dad
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * 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.v101;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Set;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassRowSplitter;
+import org.sonar.server.platform.db.migration.step.Select;
+
+import static java.util.Collections.emptySet;
+import static java.util.stream.Collectors.toSet;
+
+class MigrateScmAccountsFromUsersToScmAccounts extends DataChange {
+
+  @VisibleForTesting
+  static final char SCM_ACCOUNTS_SEPARATOR_CHAR = '\n';
+
+  public MigrateScmAccountsFromUsersToScmAccounts(Database db) {
+    super(db);
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    if (isScmColumnDropped()) {
+      return;
+    }
+    migrateData(context);
+  }
+
+  private boolean isScmColumnDropped() throws SQLException {
+    try (var connection = getDatabase().getDataSource().getConnection()) {
+      return !DatabaseUtils.tableColumnExists(connection, DropScmAccountsInUsers.TABLE_NAME, DropScmAccountsInUsers.COLUMN_NAME);
+    }
+  }
+
+  private static void migrateData(Context context) throws SQLException {
+    MassRowSplitter<ScmAccountRow> massRowSplitter = context.prepareMassRowSplitter();
+
+    massRowSplitter.select("select u.uuid, lower(u.scm_accounts) from users u where u.active=? and not exists (select 1 from scm_accounts sa where sa.user_uuid = u.uuid)")
+      .setBoolean(1, true);
+
+    massRowSplitter.insert("insert into scm_accounts (user_uuid, scm_account) values (?, ?)");
+
+    massRowSplitter.splitRow(MigrateScmAccountsFromUsersToScmAccounts::toScmAccountRows);
+
+    massRowSplitter.execute((scmAccountRow, insert) -> {
+      insert.setString(1, scmAccountRow.userUuid());
+      insert.setString(2, scmAccountRow.scmAccount());
+      return true;
+    });
+  }
+
+  private static Set<ScmAccountRow> toScmAccountRows(Select.Row row) {
+    try {
+      String userUuid = row.getString(1);
+      String[] scmAccounts = StringUtils.split(row.getString(2), SCM_ACCOUNTS_SEPARATOR_CHAR);
+      if (scmAccounts == null) {
+        return emptySet();
+      }
+      return Arrays.stream(scmAccounts)
+        .map(scmAccount -> new ScmAccountRow(userUuid, scmAccount))
+        .collect(toSet());
+    } catch (SQLException sqlException) {
+      throw new RuntimeException(sqlException);
+    }
+  }
+
+  @VisibleForTesting
+  record ScmAccountRow(String userUuid, String scmAccount) {
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForEmailOnUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForEmailOnUsersTable.java
deleted file mode 100644 (file)
index 34930f1..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.v110;
-
-import com.google.common.annotations.VisibleForTesting;
-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;
-
-class CreateIndexForEmailOnUsersTable extends DdlChange {
-
-  @VisibleForTesting
-  static final String INDEX_NAME = "users_email";
-  @VisibleForTesting
-  static final String TABLE_NAME = "users";
-  @VisibleForTesting
-  static final String COLUMN_NAME = "email";
-
-  public CreateIndexForEmailOnUsersTable(Database db) {
-    super(db);
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    try (Connection connection = getDatabase().getDataSource().getConnection()) {
-      createIndex(context, connection);
-    }
-  }
-
-  private static void createIndex(Context context, Connection connection) {
-    if (!DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection)) {
-      context.execute(new CreateIndexBuilder()
-        .setTable(TABLE_NAME)
-        .setName(INDEX_NAME)
-        .addColumn(COLUMN_NAME)
-        .setUnique(false)
-        .build());
-    }
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForScmAccountOnScmAccountsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForScmAccountOnScmAccountsTable.java
deleted file mode 100644 (file)
index eff8f4b..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.v110;
-
-import com.google.common.annotations.VisibleForTesting;
-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;
-
-import static org.sonar.server.platform.db.migration.version.v110.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME;
-import static org.sonar.server.platform.db.migration.version.v110.CreateScmAccountsTable.TABLE_NAME;
-
-class CreateIndexForScmAccountOnScmAccountsTable extends DdlChange {
-
-  @VisibleForTesting
-  static final String INDEX_NAME = "scm_accounts_scm_account";
-
-  public CreateIndexForScmAccountOnScmAccountsTable(Database db) {
-    super(db);
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    try (Connection connection = getDatabase().getDataSource().getConnection()) {
-      createIndex(context, connection);
-    }
-  }
-
-  private static void createIndex(Context context, Connection connection) {
-    if (!DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection)) {
-      context.execute(new CreateIndexBuilder()
-        .setTable(TABLE_NAME)
-        .setName(INDEX_NAME)
-        .addColumn(SCM_ACCOUNT_COLUMN_NAME)
-        .setUnique(false)
-        .build());
-    }
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/CreateScmAccountsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/CreateScmAccountsTable.java
deleted file mode 100644 (file)
index 8ce71c7..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.v110;
-
-import com.google.common.annotations.VisibleForTesting;
-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.VarcharColumnDef.USER_UUID_SIZE;
-import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
-
-class CreateScmAccountsTable extends CreateTableChange {
-  static final String TABLE_NAME = "scm_accounts";
-  static final String USER_UUID_COLUMN_NAME = "user_uuid";
-  static final String SCM_ACCOUNT_COLUMN_NAME = "scm_account";
-
-  @VisibleForTesting
-  static final int SCM_ACCOUNT_SIZE = 255;
-
-  public CreateScmAccountsTable(Database db) {
-    super(db, TABLE_NAME);
-  }
-
-  @Override
-  public void execute(Context context, String tableName) throws SQLException {
-    context.execute(new CreateTableBuilder(getDialect(), tableName)
-      .addPkColumn(newVarcharColumnDefBuilder().setColumnName(USER_UUID_COLUMN_NAME).setIsNullable(false).setLimit(USER_UUID_SIZE).build())
-      .addPkColumn(newVarcharColumnDefBuilder().setColumnName(SCM_ACCOUNT_COLUMN_NAME).setIsNullable(false).setLimit(SCM_ACCOUNT_SIZE).build())
-      .build());
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/DbVersion110.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/DbVersion110.java
deleted file mode 100644 (file)
index ac7a16b..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.v110;
-
-import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
-import org.sonar.server.platform.db.migration.version.DbVersion;
-import org.sonar.server.platform.db.migration.version.v100.AddIsMainColumnInProjectBranches;
-import org.sonar.server.platform.db.migration.version.v100.AlterIsMainColumnInProjectBranches;
-import org.sonar.server.platform.db.migration.version.v100.UpdateIsMainColumnInProjectBranches;
-
-// ignoring bad number formatting, as it's indented that we align the migration numbers to SQ versions
-@SuppressWarnings("java:S3937")
-public class DbVersion110 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:
-   * 10_0_000
-   * 10_0_001
-   * 10_0_002
-   * 10_1_000
-   * 10_1_001
-   * 10_1_002
-   * 10_2_000
-   */
-
-  @Override
-  public void addSteps(MigrationStepRegistry registry) {
-    registry
-      .add(10_1_000, "Add 'scm_accounts' table", CreateScmAccountsTable.class)
-      .add(10_1_001, "Migrate scm accounts from 'users' to 'scm_accounts' table", MigrateScmAccountsFromUsersToScmAccounts.class)
-      .add(10_1_002, "Add index on 'scm_accounts.scm_account'", CreateIndexForScmAccountOnScmAccountsTable.class)
-      .add(10_1_003, "Add index on 'users.email'", CreateIndexForEmailOnUsersTable.class)
-      .add(10_1_004, "Drop 'scm_accounts' column in 'users' table", DropScmAccountsInUsers.class)
-      .add(10_1_005, "Add column 'is_main' to 'project_branches' table", AddIsMainColumnInProjectBranches.class)
-      .add(10_1_006, "Update value of 'is_main' in 'project_branches' table", UpdateIsMainColumnInProjectBranches.class)
-      .add(10_1_007, "Alter column 'is_main' in 'project_branches' table - make it not nullable", AlterIsMainColumnInProjectBranches.class)
-    ;
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/DropScmAccountsInUsers.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/DropScmAccountsInUsers.java
deleted file mode 100644 (file)
index ecbdbd0..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.v110;
-
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.step.DropColumnChange;
-
-class DropScmAccountsInUsers extends DropColumnChange {
-  static final String TABLE_NAME = "users";
-  static final String COLUMN_NAME = "scm_accounts";
-
-  public DropScmAccountsInUsers(Database db) {
-    super(db, TABLE_NAME, COLUMN_NAME);
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/MigrateScmAccountsFromUsersToScmAccounts.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v110/MigrateScmAccountsFromUsersToScmAccounts.java
deleted file mode 100644 (file)
index 1a96820..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.v110;
-
-import com.google.common.annotations.VisibleForTesting;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Set;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
-import org.sonar.server.platform.db.migration.step.DataChange;
-import org.sonar.server.platform.db.migration.step.MassRowSplitter;
-import org.sonar.server.platform.db.migration.step.Select;
-
-import static java.util.Collections.emptySet;
-import static java.util.stream.Collectors.toSet;
-
-class MigrateScmAccountsFromUsersToScmAccounts extends DataChange {
-
-  @VisibleForTesting
-  static final char SCM_ACCOUNTS_SEPARATOR_CHAR = '\n';
-
-  public MigrateScmAccountsFromUsersToScmAccounts(Database db) {
-    super(db);
-  }
-
-  @Override
-  protected void execute(Context context) throws SQLException {
-    if (isScmColumnDropped()) {
-      return;
-    }
-    migrateData(context);
-  }
-
-  private boolean isScmColumnDropped() throws SQLException {
-    try (var connection = getDatabase().getDataSource().getConnection()) {
-      return !DatabaseUtils.tableColumnExists(connection, DropScmAccountsInUsers.TABLE_NAME, DropScmAccountsInUsers.COLUMN_NAME);
-    }
-  }
-
-  private static void migrateData(Context context) throws SQLException {
-    MassRowSplitter<ScmAccountRow> massRowSplitter = context.prepareMassRowSplitter();
-
-    massRowSplitter.select("select u.uuid, lower(u.scm_accounts) from users u where u.active=? and not exists (select 1 from scm_accounts sa where sa.user_uuid = u.uuid)")
-      .setBoolean(1, true);
-
-    massRowSplitter.insert("insert into scm_accounts (user_uuid, scm_account) values (?, ?)");
-
-    massRowSplitter.splitRow(MigrateScmAccountsFromUsersToScmAccounts::toScmAccountRows);
-
-    massRowSplitter.execute((scmAccountRow, insert) -> {
-      insert.setString(1, scmAccountRow.userUuid());
-      insert.setString(2, scmAccountRow.scmAccount());
-      return true;
-    });
-  }
-
-  private static Set<ScmAccountRow> toScmAccountRows(Select.Row row) {
-    try {
-      String userUuid = row.getString(1);
-      String[] scmAccounts = StringUtils.split(row.getString(2), SCM_ACCOUNTS_SEPARATOR_CHAR);
-      if (scmAccounts == null) {
-        return emptySet();
-      }
-      return Arrays.stream(scmAccounts)
-        .map(scmAccount -> new ScmAccountRow(userUuid, scmAccount))
-        .collect(toSet());
-    } catch (SQLException sqlException) {
-      throw new RuntimeException(sqlException);
-    }
-  }
-
-  @VisibleForTesting
-  record ScmAccountRow(String userUuid, String scmAccount) {
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableTest.java
new file mode 100644 (file)
index 0000000..012def5
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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.v101;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForEmailOnUsersTable.COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForEmailOnUsersTable.INDEX_NAME;
+import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForEmailOnUsersTable.TABLE_NAME;
+
+public class CreateIndexForEmailOnUsersTableTest {
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexForEmailOnUsersTableTest.class, "schema.sql");
+
+  private final CreateIndexForEmailOnUsersTable createIndexForEmailOnUsersTable = new CreateIndexForEmailOnUsersTable(db.database());
+
+  @Test
+  public void migration_should_create_index() throws SQLException {
+    db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
+
+    createIndexForEmailOnUsersTable.execute();
+
+    db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
+  }
+
+  @Test
+  public void migration_should_be_reentrant() throws SQLException {
+    createIndexForEmailOnUsersTable.execute();
+    createIndexForEmailOnUsersTable.execute();
+
+    db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableTest.java
new file mode 100644 (file)
index 0000000..8a4662b
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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.v101;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForScmAccountOnScmAccountsTable.INDEX_NAME;
+import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.TABLE_NAME;
+
+public class CreateIndexForScmAccountOnScmAccountsTableTest {
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexForScmAccountOnScmAccountsTableTest.class, "schema.sql");
+
+  private final CreateIndexForScmAccountOnScmAccountsTable createIndexForScmAccountOnScmAccountsTable = new CreateIndexForScmAccountOnScmAccountsTable(db.database());
+
+  @Test
+  public void migration_should_create_index() throws SQLException {
+    db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
+
+    createIndexForScmAccountOnScmAccountsTable.execute();
+
+    db.assertIndex(TABLE_NAME, INDEX_NAME, SCM_ACCOUNT_COLUMN_NAME);
+  }
+
+  @Test
+  public void migration_should_be_reentrant() throws SQLException {
+    createIndexForScmAccountOnScmAccountsTable.execute();
+    createIndexForScmAccountOnScmAccountsTable.execute();
+
+    db.assertIndex(TABLE_NAME, INDEX_NAME, SCM_ACCOUNT_COLUMN_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTableTest.java
new file mode 100644 (file)
index 0000000..4a31114
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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.v101;
+
+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.USER_UUID_SIZE;
+import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNT_SIZE;
+import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.TABLE_NAME;
+import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.USER_UUID_COLUMN_NAME;
+
+public class CreateScmAccountsTableTest {
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createEmpty();
+
+  private final DdlChange createScmAccountsTable = new CreateScmAccountsTable(db.database());
+
+  @Test
+  public void migration_should_create_a_table() throws SQLException {
+    db.assertTableDoesNotExist(TABLE_NAME);
+
+    createScmAccountsTable.execute();
+
+    db.assertTableExists(TABLE_NAME);
+    db.assertColumnDefinition(TABLE_NAME, USER_UUID_COLUMN_NAME, Types.VARCHAR, USER_UUID_SIZE, false);
+    db.assertColumnDefinition(TABLE_NAME, SCM_ACCOUNT_COLUMN_NAME, Types.VARCHAR, SCM_ACCOUNT_SIZE, false);
+    db.assertPrimaryKey(TABLE_NAME, "pk_scm_accounts", USER_UUID_COLUMN_NAME, SCM_ACCOUNT_COLUMN_NAME);
+  }
+
+  @Test
+  public void migration_should_be_reentrant() throws SQLException {
+    db.assertTableDoesNotExist(TABLE_NAME);
+
+    createScmAccountsTable.execute();
+    // re-entrant
+    createScmAccountsTable.execute();
+
+    db.assertTableExists(TABLE_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DbVersion101Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DbVersion101Test.java
new file mode 100644 (file)
index 0000000..e0d5cc4
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.v101;
+
+import org.junit.Test;
+
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationNotEmpty;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+public class DbVersion101Test {
+  private final DbVersion101 underTest = new DbVersion101();
+
+  @Test
+  public void migrationNumber_starts_at_10_1_000() {
+    verifyMinimumMigrationNumber(underTest, 10_1_000);
+  }
+
+  @Test
+  public void verify_migration_is_not_empty() {
+    verifyMigrationNotEmpty(underTest);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersTest.java
new file mode 100644 (file)
index 0000000..7770afb
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.v101;
+
+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.version.v101.DropScmAccountsInUsers.COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v101.DropScmAccountsInUsers.TABLE_NAME;
+
+public class DropScmAccountsInUsersTest {
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(DropScmAccountsInUsersTest.class, "schema.sql");
+  private final DdlChange dropScmAccountsInUsers = new DropScmAccountsInUsers(db.database());
+
+  @Test
+  public void drops_column() throws SQLException {
+    db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 4000, true);
+    dropScmAccountsInUsers.execute();
+    db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 4000, true);
+    dropScmAccountsInUsers.execute();
+    dropScmAccountsInUsers.execute();
+    db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsTest.java
new file mode 100644 (file)
index 0000000..93763ce
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * 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.v101;
+
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.version.v101.MigrateScmAccountsFromUsersToScmAccounts.ScmAccountRow;
+
+import static java.lang.String.format;
+import static java.util.stream.Collectors.toSet;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatNoException;
+import static org.sonar.server.platform.db.migration.version.v101.MigrateScmAccountsFromUsersToScmAccounts.SCM_ACCOUNTS_SEPARATOR_CHAR;
+
+public class MigrateScmAccountsFromUsersToScmAccountsTest {
+
+  private static final UuidFactory UUID_FACTORY = UuidFactoryFast.getInstance();
+  private static final String SCM_ACCOUNT1 = "scmaccount";
+  private static final String SCM_ACCOUNT2 = "scmaccount2";
+  private static final String SCM_ACCOUNT_CAMELCASE = "scmAccount3";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(MigrateScmAccountsFromUsersToScmAccountsTest.class, "schema.sql");
+
+  private final DataChange migrateScmAccountsFromUsersToScmAccounts = new MigrateScmAccountsFromUsersToScmAccounts(db.database());
+
+  @Test
+  public void execute_whenUserHasNullScmAccounts_doNotInsertInScmAccounts() throws SQLException {
+    insertUserAndGetUuid(null);
+
+    migrateScmAccountsFromUsersToScmAccounts.execute();
+
+    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
+    assertThat(scmAccounts).isEmpty();
+  }
+
+  @Test
+  public void execute_whenUserHasEmptyScmAccounts_doNotInsertInScmAccounts() throws SQLException {
+    insertUserAndGetUuid("");
+
+    migrateScmAccountsFromUsersToScmAccounts.execute();
+
+    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
+    assertThat(scmAccounts).isEmpty();
+  }
+
+  @Test
+  public void execute_whenUserHasEmptyScmAccountsWithOneSeparator_doNotInsertInScmAccounts() throws SQLException {
+    insertUserAndGetUuid(String.valueOf(SCM_ACCOUNTS_SEPARATOR_CHAR));
+
+    migrateScmAccountsFromUsersToScmAccounts.execute();
+
+    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
+    assertThat(scmAccounts).isEmpty();
+  }
+
+  @Test
+  public void execute_whenUserHasEmptyScmAccountsWithTwoSeparators_doNotInsertInScmAccounts() throws SQLException {
+    insertUserAndGetUuid(SCM_ACCOUNTS_SEPARATOR_CHAR + String.valueOf(SCM_ACCOUNTS_SEPARATOR_CHAR));
+
+    migrateScmAccountsFromUsersToScmAccounts.execute();
+
+    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
+    assertThat(scmAccounts).isEmpty();
+  }
+
+  @Test
+  public void execute_whenUserHasOneScmAccountWithoutSeparator_insertsInScmAccounts() throws SQLException {
+    String userUuid = insertUserAndGetUuid(SCM_ACCOUNT1);
+
+    migrateScmAccountsFromUsersToScmAccounts.execute();
+
+    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
+    assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1));
+  }
+
+  @Test
+  public void execute_whenUserHasOneScmAccountWithSeparators_insertsInScmAccounts() throws SQLException {
+    String userUuid = insertUserAndGetUuid(format("%s%s%s", SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT1, SCM_ACCOUNTS_SEPARATOR_CHAR));
+
+    migrateScmAccountsFromUsersToScmAccounts.execute();
+
+    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
+    assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1));
+  }
+
+  @Test
+  public void execute_whenUserHasOneScmAccountWithMixedCase_insertsInScmAccountsInLowerCase() throws SQLException {
+    String userUuid = insertUserAndGetUuid(format("%s%s%s", SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT_CAMELCASE, SCM_ACCOUNTS_SEPARATOR_CHAR));
+
+    migrateScmAccountsFromUsersToScmAccounts.execute();
+
+    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
+    assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT_CAMELCASE.toLowerCase(Locale.ENGLISH)));
+  }
+
+  @Test
+  public void execute_whenUserHasTwoScmAccount_insertsInScmAccounts() throws SQLException {
+    String userUuid = insertUserAndGetUuid(format("%s%s%s%s%s",
+      SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT1, SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT2, SCM_ACCOUNTS_SEPARATOR_CHAR));
+
+    migrateScmAccountsFromUsersToScmAccounts.execute();
+
+    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
+    assertThat(scmAccounts).containsExactlyInAnyOrder(
+      new ScmAccountRow(userUuid, SCM_ACCOUNT1),
+      new ScmAccountRow(userUuid, SCM_ACCOUNT2)
+    );
+  }
+
+  @Test
+  public void migration_should_be_reentrant() throws SQLException {
+    String userUuid = insertUserAndGetUuid(SCM_ACCOUNT1);
+
+    migrateScmAccountsFromUsersToScmAccounts.execute();
+    migrateScmAccountsFromUsersToScmAccounts.execute();
+
+    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
+    assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1));
+  }
+
+  @Test
+  public void migration_should_be_reentrant_if_scm_account_column_dropped() {
+    db.executeDdl("alter table users drop column scm_accounts");
+
+    assertThatNoException().isThrownBy(migrateScmAccountsFromUsersToScmAccounts::execute);
+  }
+
+
+  private Set<ScmAccountRow> findAllScmAccounts() {
+    Set<ScmAccountRow> scmAccounts = db.select("select user_uuid USERUUID, scm_account SCMACCOUNT from scm_accounts")
+      .stream()
+      .map(row -> new ScmAccountRow((String) row.get("USERUUID"), (String) row.get("SCMACCOUNT")))
+      .collect(toSet());
+    return scmAccounts;
+  }
+
+  private String insertUserAndGetUuid(@Nullable String scmAccounts) {
+
+    Map<String, Object> map = new HashMap<>();
+    String uuid = UUID_FACTORY.create();
+    String login = "login_" + uuid;
+    map.put("UUID", uuid);
+    map.put("LOGIN", login);
+    map.put("HASH_METHOD", "tagada");
+    map.put("EXTERNAL_LOGIN", login);
+    map.put("EXTERNAL_IDENTITY_PROVIDER", "sonarqube");
+    map.put("EXTERNAL_ID", login);
+    map.put("CREATED_AT", System.currentTimeMillis());
+    map.put("RESET_PASSWORD", false);
+    map.put("USER_LOCAL", true);
+    map.put("SCM_ACCOUNTS", scmAccounts);
+    db.executeInsert("users", map);
+    return uuid;
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForEmailOnUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForEmailOnUsersTableTest.java
deleted file mode 100644 (file)
index 2e2287e..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.v110;
-
-import java.sql.SQLException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.db.CoreDbTester;
-
-import static org.sonar.server.platform.db.migration.version.v110.CreateIndexForEmailOnUsersTable.COLUMN_NAME;
-import static org.sonar.server.platform.db.migration.version.v110.CreateIndexForEmailOnUsersTable.INDEX_NAME;
-import static org.sonar.server.platform.db.migration.version.v110.CreateIndexForEmailOnUsersTable.TABLE_NAME;
-
-public class CreateIndexForEmailOnUsersTableTest {
-  @Rule
-  public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexForEmailOnUsersTableTest.class, "schema.sql");
-
-  private final CreateIndexForEmailOnUsersTable createIndexForEmailOnUsersTable = new CreateIndexForEmailOnUsersTable(db.database());
-
-  @Test
-  public void migration_should_create_index() throws SQLException {
-    db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
-
-    createIndexForEmailOnUsersTable.execute();
-
-    db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
-  }
-
-  @Test
-  public void migration_should_be_reentrant() throws SQLException {
-    createIndexForEmailOnUsersTable.execute();
-    createIndexForEmailOnUsersTable.execute();
-
-    db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForScmAccountOnScmAccountsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/CreateIndexForScmAccountOnScmAccountsTableTest.java
deleted file mode 100644 (file)
index 8ccc06c..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.v110;
-
-import java.sql.SQLException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.db.CoreDbTester;
-
-import static org.sonar.server.platform.db.migration.version.v110.CreateIndexForScmAccountOnScmAccountsTable.INDEX_NAME;
-import static org.sonar.server.platform.db.migration.version.v110.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME;
-import static org.sonar.server.platform.db.migration.version.v110.CreateScmAccountsTable.TABLE_NAME;
-
-public class CreateIndexForScmAccountOnScmAccountsTableTest {
-  @Rule
-  public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexForScmAccountOnScmAccountsTableTest.class, "schema.sql");
-
-  private final CreateIndexForScmAccountOnScmAccountsTable createIndexForScmAccountOnScmAccountsTable = new CreateIndexForScmAccountOnScmAccountsTable(db.database());
-
-  @Test
-  public void migration_should_create_index() throws SQLException {
-    db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
-
-    createIndexForScmAccountOnScmAccountsTable.execute();
-
-    db.assertIndex(TABLE_NAME, INDEX_NAME, SCM_ACCOUNT_COLUMN_NAME);
-  }
-
-  @Test
-  public void migration_should_be_reentrant() throws SQLException {
-    createIndexForScmAccountOnScmAccountsTable.execute();
-    createIndexForScmAccountOnScmAccountsTable.execute();
-
-    db.assertIndex(TABLE_NAME, INDEX_NAME, SCM_ACCOUNT_COLUMN_NAME);
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/CreateScmAccountsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/CreateScmAccountsTableTest.java
deleted file mode 100644 (file)
index 815d0e5..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.v110;
-
-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 org.sonar.server.platform.db.migration.version.v110.CreateScmAccountsTable;
-
-import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.USER_UUID_SIZE;
-import static org.sonar.server.platform.db.migration.version.v110.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME;
-import static org.sonar.server.platform.db.migration.version.v110.CreateScmAccountsTable.SCM_ACCOUNT_SIZE;
-import static org.sonar.server.platform.db.migration.version.v110.CreateScmAccountsTable.TABLE_NAME;
-import static org.sonar.server.platform.db.migration.version.v110.CreateScmAccountsTable.USER_UUID_COLUMN_NAME;
-
-public class CreateScmAccountsTableTest {
-  @Rule
-  public final CoreDbTester db = CoreDbTester.createEmpty();
-
-  private final DdlChange createScmAccountsTable = new CreateScmAccountsTable(db.database());
-
-  @Test
-  public void migration_should_create_a_table() throws SQLException {
-    db.assertTableDoesNotExist(TABLE_NAME);
-
-    createScmAccountsTable.execute();
-
-    db.assertTableExists(TABLE_NAME);
-    db.assertColumnDefinition(TABLE_NAME, USER_UUID_COLUMN_NAME, Types.VARCHAR, USER_UUID_SIZE, false);
-    db.assertColumnDefinition(TABLE_NAME, SCM_ACCOUNT_COLUMN_NAME, Types.VARCHAR, SCM_ACCOUNT_SIZE, false);
-    db.assertPrimaryKey(TABLE_NAME, "pk_scm_accounts", USER_UUID_COLUMN_NAME, SCM_ACCOUNT_COLUMN_NAME);
-  }
-
-  @Test
-  public void migration_should_be_reentrant() throws SQLException {
-    db.assertTableDoesNotExist(TABLE_NAME);
-
-    createScmAccountsTable.execute();
-    // re-entrant
-    createScmAccountsTable.execute();
-
-    db.assertTableExists(TABLE_NAME);
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/DbVersion110Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/DbVersion110Test.java
deleted file mode 100644 (file)
index 6cff42c..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.v110;
-
-import org.junit.Test;
-
-import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationNotEmpty;
-import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
-
-public class DbVersion110Test {
-  private final DbVersion110 underTest = new DbVersion110();
-
-  @Test
-  public void migrationNumber_starts_at_10_1_000() {
-    verifyMinimumMigrationNumber(underTest, 10_1_000);
-  }
-
-  @Test
-  public void verify_migration_is_not_empty() {
-    verifyMigrationNotEmpty(underTest);
-  }
-
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/DropScmAccountsInUsersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/DropScmAccountsInUsersTest.java
deleted file mode 100644 (file)
index db354f3..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.v110;
-
-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.version.v110.DropScmAccountsInUsers.COLUMN_NAME;
-import static org.sonar.server.platform.db.migration.version.v110.DropScmAccountsInUsers.TABLE_NAME;
-
-public class DropScmAccountsInUsersTest {
-
-  @Rule
-  public final CoreDbTester db = CoreDbTester.createForSchema(DropScmAccountsInUsersTest.class, "schema.sql");
-  private final DdlChange dropScmAccountsInUsers = new DropScmAccountsInUsers(db.database());
-
-  @Test
-  public void drops_column() throws SQLException {
-    db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 4000, true);
-    dropScmAccountsInUsers.execute();
-    db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
-  }
-
-  @Test
-  public void migration_is_reentrant() throws SQLException {
-    db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 4000, true);
-    dropScmAccountsInUsers.execute();
-    dropScmAccountsInUsers.execute();
-    db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/MigrateScmAccountsFromUsersToScmAccountsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v110/MigrateScmAccountsFromUsersToScmAccountsTest.java
deleted file mode 100644 (file)
index c5be86e..0000000
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * 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.v110;
-
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import javax.annotation.Nullable;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.core.util.UuidFactoryFast;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DataChange;
-import org.sonar.server.platform.db.migration.version.v110.MigrateScmAccountsFromUsersToScmAccounts.ScmAccountRow;
-
-import static java.lang.String.format;
-import static java.util.stream.Collectors.toSet;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatNoException;
-import static org.sonar.server.platform.db.migration.version.v110.MigrateScmAccountsFromUsersToScmAccounts.SCM_ACCOUNTS_SEPARATOR_CHAR;
-
-public class MigrateScmAccountsFromUsersToScmAccountsTest {
-
-  private static final UuidFactory UUID_FACTORY = UuidFactoryFast.getInstance();
-  private static final String SCM_ACCOUNT1 = "scmaccount";
-  private static final String SCM_ACCOUNT2 = "scmaccount2";
-  private static final String SCM_ACCOUNT_CAMELCASE = "scmAccount3";
-
-  @Rule
-  public final CoreDbTester db = CoreDbTester.createForSchema(MigrateScmAccountsFromUsersToScmAccountsTest.class, "schema.sql");
-
-  private final DataChange migrateScmAccountsFromUsersToScmAccounts = new MigrateScmAccountsFromUsersToScmAccounts(db.database());
-
-  @Test
-  public void execute_whenUserHasNullScmAccounts_doNotInsertInScmAccounts() throws SQLException {
-    insertUserAndGetUuid(null);
-
-    migrateScmAccountsFromUsersToScmAccounts.execute();
-
-    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
-    assertThat(scmAccounts).isEmpty();
-  }
-
-  @Test
-  public void execute_whenUserHasEmptyScmAccounts_doNotInsertInScmAccounts() throws SQLException {
-    insertUserAndGetUuid("");
-
-    migrateScmAccountsFromUsersToScmAccounts.execute();
-
-    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
-    assertThat(scmAccounts).isEmpty();
-  }
-
-  @Test
-  public void execute_whenUserHasEmptyScmAccountsWithOneSeparator_doNotInsertInScmAccounts() throws SQLException {
-    insertUserAndGetUuid(String.valueOf(SCM_ACCOUNTS_SEPARATOR_CHAR));
-
-    migrateScmAccountsFromUsersToScmAccounts.execute();
-
-    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
-    assertThat(scmAccounts).isEmpty();
-  }
-
-  @Test
-  public void execute_whenUserHasEmptyScmAccountsWithTwoSeparators_doNotInsertInScmAccounts() throws SQLException {
-    insertUserAndGetUuid(SCM_ACCOUNTS_SEPARATOR_CHAR + String.valueOf(SCM_ACCOUNTS_SEPARATOR_CHAR));
-
-    migrateScmAccountsFromUsersToScmAccounts.execute();
-
-    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
-    assertThat(scmAccounts).isEmpty();
-  }
-
-  @Test
-  public void execute_whenUserHasOneScmAccountWithoutSeparator_insertsInScmAccounts() throws SQLException {
-    String userUuid = insertUserAndGetUuid(SCM_ACCOUNT1);
-
-    migrateScmAccountsFromUsersToScmAccounts.execute();
-
-    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
-    assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1));
-  }
-
-  @Test
-  public void execute_whenUserHasOneScmAccountWithSeparators_insertsInScmAccounts() throws SQLException {
-    String userUuid = insertUserAndGetUuid(format("%s%s%s", SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT1, SCM_ACCOUNTS_SEPARATOR_CHAR));
-
-    migrateScmAccountsFromUsersToScmAccounts.execute();
-
-    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
-    assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1));
-  }
-
-  @Test
-  public void execute_whenUserHasOneScmAccountWithMixedCase_insertsInScmAccountsInLowerCase() throws SQLException {
-    String userUuid = insertUserAndGetUuid(format("%s%s%s", SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT_CAMELCASE, SCM_ACCOUNTS_SEPARATOR_CHAR));
-
-    migrateScmAccountsFromUsersToScmAccounts.execute();
-
-    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
-    assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT_CAMELCASE.toLowerCase(Locale.ENGLISH)));
-  }
-
-  @Test
-  public void execute_whenUserHasTwoScmAccount_insertsInScmAccounts() throws SQLException {
-    String userUuid = insertUserAndGetUuid(format("%s%s%s%s%s",
-      SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT1, SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT2, SCM_ACCOUNTS_SEPARATOR_CHAR));
-
-    migrateScmAccountsFromUsersToScmAccounts.execute();
-
-    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
-    assertThat(scmAccounts).containsExactlyInAnyOrder(
-      new ScmAccountRow(userUuid, SCM_ACCOUNT1),
-      new ScmAccountRow(userUuid, SCM_ACCOUNT2)
-    );
-  }
-
-  @Test
-  public void migration_should_be_reentrant() throws SQLException {
-    String userUuid = insertUserAndGetUuid(SCM_ACCOUNT1);
-
-    migrateScmAccountsFromUsersToScmAccounts.execute();
-    migrateScmAccountsFromUsersToScmAccounts.execute();
-
-    Set<ScmAccountRow> scmAccounts = findAllScmAccounts();
-    assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1));
-  }
-
-  @Test
-  public void migration_should_be_reentrant_if_scm_account_column_dropped() {
-    db.executeDdl("alter table users drop column scm_accounts");
-
-    assertThatNoException().isThrownBy(migrateScmAccountsFromUsersToScmAccounts::execute);
-  }
-
-
-  private Set<ScmAccountRow> findAllScmAccounts() {
-    Set<ScmAccountRow> scmAccounts = db.select("select user_uuid USERUUID, scm_account SCMACCOUNT from scm_accounts")
-      .stream()
-      .map(row -> new ScmAccountRow((String) row.get("USERUUID"), (String) row.get("SCMACCOUNT")))
-      .collect(toSet());
-    return scmAccounts;
-  }
-
-  private String insertUserAndGetUuid(@Nullable String scmAccounts) {
-
-    Map<String, Object> map = new HashMap<>();
-    String uuid = UUID_FACTORY.create();
-    String login = "login_" + uuid;
-    map.put("UUID", uuid);
-    map.put("LOGIN", login);
-    map.put("HASH_METHOD", "tagada");
-    map.put("EXTERNAL_LOGIN", login);
-    map.put("EXTERNAL_IDENTITY_PROVIDER", "sonarqube");
-    map.put("EXTERNAL_ID", login);
-    map.put("CREATED_AT", System.currentTimeMillis());
-    map.put("RESET_PASSWORD", false);
-    map.put("USER_LOCAL", true);
-    map.put("SCM_ACCOUNTS", scmAccounts);
-    db.executeInsert("users", map);
-    return uuid;
-  }
-
-}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableTest/schema.sql
new file mode 100644 (file)
index 0000000..f2af204
--- /dev/null
@@ -0,0 +1,27 @@
+CREATE TABLE "USERS"(
+    "UUID" CHARACTER VARYING(255) NOT NULL,
+    "LOGIN" CHARACTER VARYING(255) NOT NULL,
+    "NAME" CHARACTER VARYING(200),
+    "EMAIL" CHARACTER VARYING(100),
+    "CRYPTED_PASSWORD" CHARACTER VARYING(100),
+    "SALT" CHARACTER VARYING(40),
+    "HASH_METHOD" CHARACTER VARYING(10),
+    "ACTIVE" BOOLEAN DEFAULT TRUE,
+    "SCM_ACCOUNTS" CHARACTER VARYING(4000),
+    "EXTERNAL_LOGIN" CHARACTER VARYING(255) NOT NULL,
+    "EXTERNAL_IDENTITY_PROVIDER" CHARACTER VARYING(100) NOT NULL,
+    "EXTERNAL_ID" CHARACTER VARYING(255) NOT NULL,
+    "USER_LOCAL" BOOLEAN NOT NULL,
+    "HOMEPAGE_TYPE" CHARACTER VARYING(40),
+    "HOMEPAGE_PARAMETER" CHARACTER VARYING(40),
+    "LAST_CONNECTION_DATE" BIGINT,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "RESET_PASSWORD" BOOLEAN NOT NULL,
+    "LAST_SONARLINT_CONNECTION" BIGINT
+);
+ALTER TABLE "USERS" ADD CONSTRAINT "PK_USERS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS"("LOGIN" NULLS FIRST);
+CREATE INDEX "USERS_UPDATED_AT" ON "USERS"("UPDATED_AT" NULLS FIRST);
+CREATE UNIQUE INDEX "UNIQ_EXTERNAL_ID" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_ID" NULLS FIRST);
+CREATE UNIQUE INDEX "UNIQ_EXTERNAL_LOGIN" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_LOGIN" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableTest/schema.sql
new file mode 100644 (file)
index 0000000..7a113bb
--- /dev/null
@@ -0,0 +1,5 @@
+CREATE TABLE "SCM_ACCOUNTS"(
+    "USER_UUID" CHARACTER VARYING(255) NOT NULL,
+    "SCM_ACCOUNT" CHARACTER VARYING(255) NOT NULL
+);
+ALTER TABLE "SCM_ACCOUNTS" ADD CONSTRAINT "PK_SCM_ACCOUNTS" PRIMARY KEY("USER_UUID", "SCM_ACCOUNT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/CreateIndexesForScmAccountsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/CreateIndexesForScmAccountsTest/schema.sql
new file mode 100644 (file)
index 0000000..7a113bb
--- /dev/null
@@ -0,0 +1,5 @@
+CREATE TABLE "SCM_ACCOUNTS"(
+    "USER_UUID" CHARACTER VARYING(255) NOT NULL,
+    "SCM_ACCOUNT" CHARACTER VARYING(255) NOT NULL
+);
+ALTER TABLE "SCM_ACCOUNTS" ADD CONSTRAINT "PK_SCM_ACCOUNTS" PRIMARY KEY("USER_UUID", "SCM_ACCOUNT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersTest/schema.sql
new file mode 100644 (file)
index 0000000..f2af204
--- /dev/null
@@ -0,0 +1,27 @@
+CREATE TABLE "USERS"(
+    "UUID" CHARACTER VARYING(255) NOT NULL,
+    "LOGIN" CHARACTER VARYING(255) NOT NULL,
+    "NAME" CHARACTER VARYING(200),
+    "EMAIL" CHARACTER VARYING(100),
+    "CRYPTED_PASSWORD" CHARACTER VARYING(100),
+    "SALT" CHARACTER VARYING(40),
+    "HASH_METHOD" CHARACTER VARYING(10),
+    "ACTIVE" BOOLEAN DEFAULT TRUE,
+    "SCM_ACCOUNTS" CHARACTER VARYING(4000),
+    "EXTERNAL_LOGIN" CHARACTER VARYING(255) NOT NULL,
+    "EXTERNAL_IDENTITY_PROVIDER" CHARACTER VARYING(100) NOT NULL,
+    "EXTERNAL_ID" CHARACTER VARYING(255) NOT NULL,
+    "USER_LOCAL" BOOLEAN NOT NULL,
+    "HOMEPAGE_TYPE" CHARACTER VARYING(40),
+    "HOMEPAGE_PARAMETER" CHARACTER VARYING(40),
+    "LAST_CONNECTION_DATE" BIGINT,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "RESET_PASSWORD" BOOLEAN NOT NULL,
+    "LAST_SONARLINT_CONNECTION" BIGINT
+);
+ALTER TABLE "USERS" ADD CONSTRAINT "PK_USERS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS"("LOGIN" NULLS FIRST);
+CREATE INDEX "USERS_UPDATED_AT" ON "USERS"("UPDATED_AT" NULLS FIRST);
+CREATE UNIQUE INDEX "UNIQ_EXTERNAL_ID" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_ID" NULLS FIRST);
+CREATE UNIQUE INDEX "UNIQ_EXTERNAL_LOGIN" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_LOGIN" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsTest/schema.sql
new file mode 100644 (file)
index 0000000..2f34178
--- /dev/null
@@ -0,0 +1,33 @@
+CREATE TABLE "USERS"(
+    "UUID" CHARACTER VARYING(255) NOT NULL,
+    "LOGIN" CHARACTER VARYING(255) NOT NULL,
+    "NAME" CHARACTER VARYING(200),
+    "EMAIL" CHARACTER VARYING(100),
+    "CRYPTED_PASSWORD" CHARACTER VARYING(100),
+    "SALT" CHARACTER VARYING(40),
+    "HASH_METHOD" CHARACTER VARYING(10),
+    "ACTIVE" BOOLEAN DEFAULT TRUE,
+    "SCM_ACCOUNTS" CHARACTER VARYING(4000),
+    "EXTERNAL_LOGIN" CHARACTER VARYING(255) NOT NULL,
+    "EXTERNAL_IDENTITY_PROVIDER" CHARACTER VARYING(100) NOT NULL,
+    "EXTERNAL_ID" CHARACTER VARYING(255) NOT NULL,
+    "USER_LOCAL" BOOLEAN NOT NULL,
+    "HOMEPAGE_TYPE" CHARACTER VARYING(40),
+    "HOMEPAGE_PARAMETER" CHARACTER VARYING(40),
+    "LAST_CONNECTION_DATE" BIGINT,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "RESET_PASSWORD" BOOLEAN NOT NULL,
+    "LAST_SONARLINT_CONNECTION" BIGINT
+);
+ALTER TABLE "USERS" ADD CONSTRAINT "PK_USERS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS"("LOGIN" NULLS FIRST);
+CREATE INDEX "USERS_UPDATED_AT" ON "USERS"("UPDATED_AT" NULLS FIRST);
+CREATE UNIQUE INDEX "UNIQ_EXTERNAL_ID" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_ID" NULLS FIRST);
+CREATE UNIQUE INDEX "UNIQ_EXTERNAL_LOGIN" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_LOGIN" NULLS FIRST);
+
+CREATE TABLE "SCM_ACCOUNTS"(
+    "USER_UUID" CHARACTER VARYING(255) NOT NULL,
+    "SCM_ACCOUNT" CHARACTER VARYING(255) NOT NULL
+);
+ALTER TABLE "SCM_ACCOUNTS" ADD CONSTRAINT "PK_SCM_ACCOUNTS" PRIMARY KEY("USER_UUID", "SCM_ACCOUNT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/CreateIndexForEmailOnUsersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/CreateIndexForEmailOnUsersTableTest/schema.sql
deleted file mode 100644 (file)
index f2af204..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-CREATE TABLE "USERS"(
-    "UUID" CHARACTER VARYING(255) NOT NULL,
-    "LOGIN" CHARACTER VARYING(255) NOT NULL,
-    "NAME" CHARACTER VARYING(200),
-    "EMAIL" CHARACTER VARYING(100),
-    "CRYPTED_PASSWORD" CHARACTER VARYING(100),
-    "SALT" CHARACTER VARYING(40),
-    "HASH_METHOD" CHARACTER VARYING(10),
-    "ACTIVE" BOOLEAN DEFAULT TRUE,
-    "SCM_ACCOUNTS" CHARACTER VARYING(4000),
-    "EXTERNAL_LOGIN" CHARACTER VARYING(255) NOT NULL,
-    "EXTERNAL_IDENTITY_PROVIDER" CHARACTER VARYING(100) NOT NULL,
-    "EXTERNAL_ID" CHARACTER VARYING(255) NOT NULL,
-    "USER_LOCAL" BOOLEAN NOT NULL,
-    "HOMEPAGE_TYPE" CHARACTER VARYING(40),
-    "HOMEPAGE_PARAMETER" CHARACTER VARYING(40),
-    "LAST_CONNECTION_DATE" BIGINT,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "RESET_PASSWORD" BOOLEAN NOT NULL,
-    "LAST_SONARLINT_CONNECTION" BIGINT
-);
-ALTER TABLE "USERS" ADD CONSTRAINT "PK_USERS" PRIMARY KEY("UUID");
-CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS"("LOGIN" NULLS FIRST);
-CREATE INDEX "USERS_UPDATED_AT" ON "USERS"("UPDATED_AT" NULLS FIRST);
-CREATE UNIQUE INDEX "UNIQ_EXTERNAL_ID" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_ID" NULLS FIRST);
-CREATE UNIQUE INDEX "UNIQ_EXTERNAL_LOGIN" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_LOGIN" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/CreateIndexForScmAccountOnScmAccountsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/CreateIndexForScmAccountOnScmAccountsTableTest/schema.sql
deleted file mode 100644 (file)
index 7a113bb..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-CREATE TABLE "SCM_ACCOUNTS"(
-    "USER_UUID" CHARACTER VARYING(255) NOT NULL,
-    "SCM_ACCOUNT" CHARACTER VARYING(255) NOT NULL
-);
-ALTER TABLE "SCM_ACCOUNTS" ADD CONSTRAINT "PK_SCM_ACCOUNTS" PRIMARY KEY("USER_UUID", "SCM_ACCOUNT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/CreateIndexesForScmAccountsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/CreateIndexesForScmAccountsTest/schema.sql
deleted file mode 100644 (file)
index 7a113bb..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-CREATE TABLE "SCM_ACCOUNTS"(
-    "USER_UUID" CHARACTER VARYING(255) NOT NULL,
-    "SCM_ACCOUNT" CHARACTER VARYING(255) NOT NULL
-);
-ALTER TABLE "SCM_ACCOUNTS" ADD CONSTRAINT "PK_SCM_ACCOUNTS" PRIMARY KEY("USER_UUID", "SCM_ACCOUNT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/DropScmAccountsInUsersTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/DropScmAccountsInUsersTest/schema.sql
deleted file mode 100644 (file)
index f2af204..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-CREATE TABLE "USERS"(
-    "UUID" CHARACTER VARYING(255) NOT NULL,
-    "LOGIN" CHARACTER VARYING(255) NOT NULL,
-    "NAME" CHARACTER VARYING(200),
-    "EMAIL" CHARACTER VARYING(100),
-    "CRYPTED_PASSWORD" CHARACTER VARYING(100),
-    "SALT" CHARACTER VARYING(40),
-    "HASH_METHOD" CHARACTER VARYING(10),
-    "ACTIVE" BOOLEAN DEFAULT TRUE,
-    "SCM_ACCOUNTS" CHARACTER VARYING(4000),
-    "EXTERNAL_LOGIN" CHARACTER VARYING(255) NOT NULL,
-    "EXTERNAL_IDENTITY_PROVIDER" CHARACTER VARYING(100) NOT NULL,
-    "EXTERNAL_ID" CHARACTER VARYING(255) NOT NULL,
-    "USER_LOCAL" BOOLEAN NOT NULL,
-    "HOMEPAGE_TYPE" CHARACTER VARYING(40),
-    "HOMEPAGE_PARAMETER" CHARACTER VARYING(40),
-    "LAST_CONNECTION_DATE" BIGINT,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "RESET_PASSWORD" BOOLEAN NOT NULL,
-    "LAST_SONARLINT_CONNECTION" BIGINT
-);
-ALTER TABLE "USERS" ADD CONSTRAINT "PK_USERS" PRIMARY KEY("UUID");
-CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS"("LOGIN" NULLS FIRST);
-CREATE INDEX "USERS_UPDATED_AT" ON "USERS"("UPDATED_AT" NULLS FIRST);
-CREATE UNIQUE INDEX "UNIQ_EXTERNAL_ID" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_ID" NULLS FIRST);
-CREATE UNIQUE INDEX "UNIQ_EXTERNAL_LOGIN" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_LOGIN" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/MigrateScmAccountsFromUsersToScmAccountsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v110/MigrateScmAccountsFromUsersToScmAccountsTest/schema.sql
deleted file mode 100644 (file)
index 2f34178..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-CREATE TABLE "USERS"(
-    "UUID" CHARACTER VARYING(255) NOT NULL,
-    "LOGIN" CHARACTER VARYING(255) NOT NULL,
-    "NAME" CHARACTER VARYING(200),
-    "EMAIL" CHARACTER VARYING(100),
-    "CRYPTED_PASSWORD" CHARACTER VARYING(100),
-    "SALT" CHARACTER VARYING(40),
-    "HASH_METHOD" CHARACTER VARYING(10),
-    "ACTIVE" BOOLEAN DEFAULT TRUE,
-    "SCM_ACCOUNTS" CHARACTER VARYING(4000),
-    "EXTERNAL_LOGIN" CHARACTER VARYING(255) NOT NULL,
-    "EXTERNAL_IDENTITY_PROVIDER" CHARACTER VARYING(100) NOT NULL,
-    "EXTERNAL_ID" CHARACTER VARYING(255) NOT NULL,
-    "USER_LOCAL" BOOLEAN NOT NULL,
-    "HOMEPAGE_TYPE" CHARACTER VARYING(40),
-    "HOMEPAGE_PARAMETER" CHARACTER VARYING(40),
-    "LAST_CONNECTION_DATE" BIGINT,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "RESET_PASSWORD" BOOLEAN NOT NULL,
-    "LAST_SONARLINT_CONNECTION" BIGINT
-);
-ALTER TABLE "USERS" ADD CONSTRAINT "PK_USERS" PRIMARY KEY("UUID");
-CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS"("LOGIN" NULLS FIRST);
-CREATE INDEX "USERS_UPDATED_AT" ON "USERS"("UPDATED_AT" NULLS FIRST);
-CREATE UNIQUE INDEX "UNIQ_EXTERNAL_ID" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_ID" NULLS FIRST);
-CREATE UNIQUE INDEX "UNIQ_EXTERNAL_LOGIN" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER" NULLS FIRST, "EXTERNAL_LOGIN" NULLS FIRST);
-
-CREATE TABLE "SCM_ACCOUNTS"(
-    "USER_UUID" CHARACTER VARYING(255) NOT NULL,
-    "SCM_ACCOUNT" CHARACTER VARYING(255) NOT NULL
-);
-ALTER TABLE "SCM_ACCOUNTS" ADD CONSTRAINT "PK_SCM_ACCOUNTS" PRIMARY KEY("USER_UUID", "SCM_ACCOUNT");