u.name,
u.email,
u.active,
- u.scm_accounts,
u.salt,
u.crypted_password,
u.hash_method,
<sql id="deactivateUserUpdatedFields">
active = ${_false},
email = null,
- scm_accounts = null,
salt = null,
crypted_password = null,
last_connection_date = null,
"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,
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;
public class MigrationConfigurationModule extends Module {
@Override
// DbVersion implementations
DbVersion00.class,
DbVersion100.class,
+ DbVersion110.class,
// migration steps
MigrationStepRegistryImpl.class,
+++ /dev/null
-/*
- * 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.v100;
-
-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;
-
-public 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());
- }
- }
-}
+++ /dev/null
-/*
- * 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.v100;
-
-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.v100.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME;
-import static org.sonar.server.platform.db.migration.version.v100.CreateScmAccountsTable.TABLE_NAME;
-
-public 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());
- }
- }
-}
+++ /dev/null
-/*
- * 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.v100;
-
-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;
-
-public 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());
- }
-}
.add(10_0_014, "Drop any SCIM User provisioning, turning all users local", DropScimUserProvisioning.class)
.add(10_0_015, "Add ncloc to 'Projects' table", AddNclocToProjects.class)
.add(10_0_016, "Populate ncloc in 'Projects' table", PopulateNclocForForProjects.class)
- .add(10_0_015, "Add 'scm_accounts' table", CreateScmAccountsTable.class)
- .add(10_0_016, "Migrate scm accounts from 'users' to 'scm_accounts' table", MigrateScmAccountsFromUsersToScmAccounts.class)
- .add(10_0_017, "Add index on 'scm_accounts.scm_account'", CreateIndexForScmAccountOnScmAccountsTable.class)
- .add(10_0_018, "Add index on 'users.email'", CreateIndexForEmailOnUsersTable.class)
;
}
}
+++ /dev/null
-/*
- * 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.v100;
-
-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.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;
-
-public 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 {
- 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) {
- }
-}
--- /dev/null
+/*
+ * 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());
+ }
+ }
+}
--- /dev/null
+/*
+ * 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());
+ }
+ }
+}
--- /dev/null
+/*
+ * 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());
+ }
+}
--- /dev/null
+/*
+ * 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;
+
+// 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)
+ ;
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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) {
+ }
+}
+++ /dev/null
-/*
- * 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.v100;
-
-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.v100.CreateIndexForEmailOnUsersTable.COLUMN_NAME;
-import static org.sonar.server.platform.db.migration.version.v100.CreateIndexForEmailOnUsersTable.INDEX_NAME;
-import static org.sonar.server.platform.db.migration.version.v100.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);
- }
-}
+++ /dev/null
-/*
- * 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.v100;
-
-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.v100.CreateIndexForScmAccountOnScmAccountsTable.INDEX_NAME;
-import static org.sonar.server.platform.db.migration.version.v100.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME;
-import static org.sonar.server.platform.db.migration.version.v100.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);
- }
-}
+++ /dev/null
-/*
- * 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.v100;
-
-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.v100.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME;
-import static org.sonar.server.platform.db.migration.version.v100.CreateScmAccountsTable.SCM_ACCOUNT_SIZE;
-import static org.sonar.server.platform.db.migration.version.v100.CreateScmAccountsTable.TABLE_NAME;
-import static org.sonar.server.platform.db.migration.version.v100.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);
- }
-}
+++ /dev/null
-/*
- * 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.v100;
-
-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.v100.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.sonar.server.platform.db.migration.version.v100.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));
- }
-
-
- 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;
- }
-
-}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
+++ /dev/null
-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);
+++ /dev/null
-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");
+++ /dev/null
-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");
+++ /dev/null
-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");
--- /dev/null
+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);
--- /dev/null
+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");
--- /dev/null
+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");
--- /dev/null
+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);
--- /dev/null
+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");