repo stringlengths 1 191 ⌀ | file stringlengths 23 351 | code stringlengths 0 5.32M | file_length int64 0 5.32M | avg_line_length float64 0 2.9k | max_line_length int64 0 288k | extension_type stringclasses 1 value |
|---|---|---|---|---|---|---|
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/package-info.java | /*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.server.platform.db.migration.sql;
import javax.annotation.ParametersAreNonnullByDefault;
| 983 | 38.36 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/BaseSqlStatement.java | /*
* 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.step;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Date;
import javax.annotation.Nullable;
import org.sonar.db.DatabaseUtils;
class BaseSqlStatement<CHILD extends SqlStatement> implements SqlStatement<CHILD> {
protected PreparedStatement pstmt;
protected BaseSqlStatement(PreparedStatement pstmt) {
this.pstmt = pstmt;
}
@Override
public void close() {
DatabaseUtils.closeQuietly(pstmt);
pstmt = null;
}
@Override
@SuppressWarnings("unchecked")
public CHILD setString(int columnIndex, @Nullable String value) throws SQLException {
pstmt.setString(columnIndex, value);
return (CHILD) this;
}
@Override
@SuppressWarnings("unchecked")
public CHILD setInt(int columnIndex, @Nullable Integer value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.INTEGER);
} else {
pstmt.setInt(columnIndex, value);
}
return (CHILD) this;
}
@Override
@SuppressWarnings("unchecked")
public CHILD setLong(int columnIndex, @Nullable Long value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.BIGINT);
} else {
pstmt.setLong(columnIndex, value);
}
return (CHILD) this;
}
@Override
@SuppressWarnings("unchecked")
public CHILD setBoolean(int columnIndex, @Nullable Boolean value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.BOOLEAN);
} else {
pstmt.setBoolean(columnIndex, value);
}
return (CHILD) this;
}
@Override
@SuppressWarnings("unchecked")
public CHILD setBytes(int columnIndex, @Nullable byte[] value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.BINARY);
} else {
pstmt.setBytes(columnIndex, value);
}
return (CHILD) this;
}
@Override
@SuppressWarnings("unchecked")
public CHILD setDouble(int columnIndex, @Nullable Double value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.DOUBLE);
} else {
pstmt.setDouble(columnIndex, value);
}
return (CHILD) this;
}
@Override
@SuppressWarnings("unchecked")
public CHILD setDate(int columnIndex, @Nullable Date value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.TIMESTAMP);
} else {
pstmt.setTimestamp(columnIndex, new Timestamp(value.getTime()));
}
return (CHILD) this;
}
}
| 3,422 | 28.508621 | 89 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/CreateIndexOnColumn.java | /*
* 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.step;
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;
public abstract class CreateIndexOnColumn extends DdlChange {
private final String table;
private final String columnName;
private final boolean unique;
protected CreateIndexOnColumn(Database db, String table, String columnName, boolean unique) {
super(db);
this.table = table;
this.columnName = columnName;
this.unique = unique;
}
@Override
public void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
if (!DatabaseUtils.indexExistsIgnoreCase(table, newIndexName(), connection)) {
context.execute(new CreateIndexBuilder()
.setTable(table)
.setName(newIndexName())
.addColumn(columnName)
.setUnique(unique)
.build());
}
}
}
public String newIndexName() {
return table + "_" + columnName;
}
}
| 1,981 | 32.59322 | 95 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/CreateTableChange.java | /*
* 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.step;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
public abstract class CreateTableChange extends DdlChange {
protected final String tableName;
protected CreateTableChange(Database db, String tableName) {
super(db);
this.tableName = tableName;
}
@Override
public final void execute(Context context) throws SQLException {
if (!tableExists()) {
execute(context, tableName);
}
}
public abstract void execute(Context context, String tableName) throws SQLException;
private boolean tableExists() throws SQLException {
try (var connection = getDatabase().getDataSource().getConnection()) {
return DatabaseUtils.tableExists(tableName, connection);
}
}
}
| 1,648 | 32.653061 | 86 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DataChange.java | /*
* 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.step;
import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.dialect.Dialect;
public abstract class DataChange implements MigrationStep {
private final Database db;
public DataChange(Database db) {
this.db = db;
}
protected final Dialect getDialect() {
return db.getDialect();
}
@Override
public final void execute() throws SQLException {
try (Connection readConnection = createReadUncommittedConnection();
Connection writeConnection = createDdlConnection()) {
Context context = new Context(db, readConnection, writeConnection);
execute(context);
}
}
protected abstract void execute(Context context) throws SQLException;
protected Connection createReadUncommittedConnection() throws SQLException {
Connection connection = db.getDataSource().getConnection();
connection.setAutoCommit(false);
if (connection.getMetaData().supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED)) {
connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
}
return connection;
}
private Connection createDdlConnection() throws SQLException {
Connection res = db.getDataSource().getConnection();
res.setAutoCommit(false);
return res;
}
protected Database getDatabase() {
return db;
}
public static class Context {
private final Database db;
private final Connection readConnection;
private final Connection writeConnection;
public Context(Database db, Connection readConnection, Connection writeConnection) {
this.db = db;
this.readConnection = readConnection;
this.writeConnection = writeConnection;
}
public Select prepareSelect(String sql) throws SQLException {
return SelectImpl.create(db, readConnection, sql);
}
public Upsert prepareUpsert(String sql) throws SQLException {
return UpsertImpl.create(writeConnection, sql);
}
public MassUpdate prepareMassUpdate() {
return new MassUpdate(db, readConnection, writeConnection);
}
public <T> MassRowSplitter<T> prepareMassRowSplitter() {
return new MassRowSplitter<>(db, readConnection, writeConnection);
}
}
}
| 3,143 | 31.412371 | 110 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DdlChange.java | /*
* 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.step;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.regex.Pattern;
import org.sonar.db.Database;
import org.sonar.db.dialect.Dialect;
import static java.lang.String.format;
import static java.util.Arrays.asList;
public abstract class DdlChange implements MigrationStep {
private final Database db;
public DdlChange(Database db) {
this.db = db;
}
@Override
public final void execute() throws SQLException {
try (Connection writeConnection = createDdlConnection()) {
Context context = new ContextImpl(writeConnection);
execute(context);
}
}
private Connection createDdlConnection() throws SQLException {
Connection writeConnection = db.getDataSource().getConnection();
writeConnection.setAutoCommit(false);
return writeConnection;
}
public abstract void execute(Context context) throws SQLException;
protected Database getDatabase() {
return db;
}
protected Dialect getDialect() {
return db.getDialect();
}
public interface Context {
void execute(String sql);
void execute(String... sqls);
void execute(List<String> sqls);
}
private static class ContextImpl implements Context {
private static final int ERROR_HANDLING_THRESHOLD = 10;
// the tricky regexp is required to match "NULL" but not "NOT NULL"
private final Pattern nullPattern = Pattern.compile("\\h?(?<!NOT )NULL");
private final Pattern notNullPattern = Pattern.compile("\\h?NOT NULL");
private final Connection writeConnection;
private ContextImpl(Connection writeConnection) {
this.writeConnection = writeConnection;
}
@Override
public void execute(String sql) {
execute(sql, sql, 0);
}
private void execute(String original, String sql, int errorCount) {
try (Statement stmt = writeConnection.createStatement()) {
stmt.execute(sql);
writeConnection.commit();
} catch (SQLException e) {
if (errorCount < ERROR_HANDLING_THRESHOLD) {
String message = e.getMessage();
if (message.contains("ORA-01451")) {
String newSql = nullPattern.matcher(sql).replaceFirst("");
execute(original, newSql, errorCount + 1);
return;
} else if (message.contains("ORA-01442")) {
String newSql = notNullPattern.matcher(sql).replaceFirst("");
execute(original, newSql, errorCount + 1);
return;
}
}
throw new IllegalStateException(messageForIseOf(original, sql, errorCount), e);
} catch (Exception e) {
throw new IllegalStateException(messageForIseOf(original, sql, errorCount), e);
}
}
private static String messageForIseOf(String original, String sql, int errorCount) {
if (!original.equals(sql) || errorCount > 0) {
return format("Fail to execute %s %n (caught %s error, original was %s)", sql, errorCount, original);
} else {
return format("Fail to execute %s", sql);
}
}
@Override
public void execute(String... sqls) {
execute(asList(sqls));
}
@Override
public void execute(List<String> sqls) {
for (String sql : sqls) {
execute(sql);
}
}
}
}
| 4,198 | 30.571429 | 109 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropColumnChange.java | /*
* 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.step;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.dialect.MsSql;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
import org.sonar.server.platform.db.migration.sql.DropMsSQLDefaultConstraintsBuilder;
public abstract class DropColumnChange extends DdlChange {
private final String tableName;
private final String columnName;
protected DropColumnChange(Database db, String tableName, String columnName) {
super(db);
this.tableName = tableName;
this.columnName = columnName;
}
@Override
public void execute(Context context) throws SQLException {
if (!checkIfUseManagedColumnExists()) {
return;
}
if (MsSql.ID.equals(getDatabase().getDialect().getId())) {
context.execute(new DropMsSQLDefaultConstraintsBuilder(getDatabase()).setTable(tableName).setColumns(columnName).build());
}
context.execute(new DropColumnsBuilder(getDatabase().getDialect(), tableName, columnName).build());
}
public boolean checkIfUseManagedColumnExists() throws SQLException {
try (var connection = getDatabase().getDataSource().getConnection()) {
if (DatabaseUtils.tableColumnExists(connection, tableName, columnName)) {
return true;
}
}
return false;
}
}
| 2,212 | 34.693548 | 128 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropIndexChange.java | /*
* 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.step;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Optional;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.dialect.Dialect;
import org.sonar.db.dialect.H2;
import org.sonar.db.dialect.MsSql;
import org.sonar.db.dialect.Oracle;
import org.sonar.db.dialect.PostgreSql;
import org.sonar.server.platform.db.migration.def.Validations;
public abstract class DropIndexChange extends DdlChange {
private final String indexName;
private final String tableName;
public DropIndexChange(Database db, String indexName, String tableName) {
super(db);
Validations.validateIndexName(indexName);
Validations.validateTableName(tableName);
this.indexName = indexName;
this.tableName = tableName;
}
@Override
public void execute(Context context) throws SQLException {
findExistingIndexName()
.map(index -> createDropIndexSqlStatement(getDialect(), index))
.ifPresent(context::execute);
}
private Optional<String> findExistingIndexName() throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
return DatabaseUtils.findExistingIndex(connection, tableName, indexName);
}
}
private String createDropIndexSqlStatement(Dialect dialect, String actualIndexName) {
return switch (dialect.getId()) {
case MsSql.ID -> "DROP INDEX " + actualIndexName + " ON " + tableName;
case Oracle.ID -> "DROP INDEX " + actualIndexName;
case H2.ID, PostgreSql.ID -> "DROP INDEX IF EXISTS " + actualIndexName;
default -> throw new IllegalStateException("Unsupported dialect for drop of index: " + dialect);
};
}
}
| 2,582 | 36.985294 | 102 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPlugins.java | /*
* 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.step;
import com.google.common.annotations.VisibleForTesting;
import java.sql.SQLException;
import org.sonar.db.Database;
public class ForceReloadingOfAllPlugins extends DataChange {
@VisibleForTesting
static final String OVERWRITE_HASH = "cccccccccccccccccccccccccccccccc";
public ForceReloadingOfAllPlugins(Database db) {
super(db);
}
@Override protected void execute(Context context) throws SQLException {
Upsert upsert = context.prepareUpsert("update plugins set file_hash = ? ");
upsert.setString(1, OVERWRITE_HASH);
upsert.execute();
upsert.commit();
}
}
| 1,487 | 35.292683 | 79 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/InternalMigrationStepRegistry.java | /*
* 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.step;
public interface InternalMigrationStepRegistry extends MigrationStepRegistry {
/**
* @throws IllegalStateException if the registry is empty
*/
MigrationSteps build();
}
| 1,076 | 37.464286 | 78 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MassRowSplitter.java | /*
* 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.step;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import org.sonar.core.util.ProgressLogger;
import org.sonar.db.Database;
import static com.google.common.base.Preconditions.checkState;
public class MassRowSplitter<T> {
private final Database db;
private final Connection readConnection;
private final Connection writeConnection;
private final AtomicLong counter = new AtomicLong(0L);
private final ProgressLogger progress = ProgressLogger.create(getClass(), counter);
private Select select;
private UpsertImpl insert;
private Function<Select.Row, Set<T>> rowSplitterFunction;
public MassRowSplitter(Database db, Connection readConnection, Connection writeConnection) {
this.db = db;
this.readConnection = readConnection;
this.writeConnection = writeConnection;
}
public Select select(String sql) throws SQLException {
this.select = SelectImpl.create(db, readConnection, sql);
return this.select;
}
public Upsert insert(String sql) throws SQLException {
this.insert = UpsertImpl.create(writeConnection, sql);
return this.insert;
}
public void splitRow(Function<Select.Row, Set<T>> rowSplitterFunction) {
this.rowSplitterFunction = rowSplitterFunction;
}
public void execute(SqlStatementPreparer<T> sqlStatementPreparer) throws SQLException {
checkState(select != null && insert != null, "SELECT or UPDATE request not defined");
checkState(rowSplitterFunction != null, "rowSplitterFunction not defined");
progress.start();
try {
select.scroll(row -> processSingleRow(sqlStatementPreparer, row, rowSplitterFunction));
closeStatements();
progress.log();
} finally {
progress.stop();
}
}
private void processSingleRow(SqlStatementPreparer<T> sqlStatementPreparer, Select.Row row,
Function<Select.Row, Set<T>> rowNormalizer) throws SQLException {
Set<T> data = rowNormalizer.apply(row);
for (T datum : data) {
if (sqlStatementPreparer.handle(datum, insert)) {
insert.addBatch();
}
}
counter.getAndIncrement();
}
private void closeStatements() throws SQLException {
if (insert.getBatchCount() > 0L) {
insert.execute().commit();
}
insert.close();
select.close();
}
@FunctionalInterface
public interface SqlStatementPreparer<T> {
/**
* Convert some column values of a given row.
*
* @return true if the row must be updated, else false. If false, then the update parameter must not be touched.
*/
boolean handle(T insertData, Upsert update) throws SQLException;
}
}
| 3,600 | 32.654206 | 116 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MassUpdate.java | /*
* 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.step;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import org.sonar.core.util.ProgressLogger;
import org.sonar.db.Database;
import static com.google.common.base.Preconditions.checkState;
public class MassUpdate {
@FunctionalInterface
public interface Handler {
/**
* Convert some column values of a given row.
*
* @return true if the row must be updated, else false. If false, then the update parameter must not be touched.
*/
boolean handle(Select.Row row, SqlStatement update) throws SQLException;
}
@FunctionalInterface
public interface MultiHandler {
/**
* Convert some column values of a given row.
*
* @param updateIndex 0-based
* @return true if the row must be updated, else false. If false, then the update parameter must not be touched.
*/
boolean handle(Select.Row row, SqlStatement update, int updateIndex) throws SQLException;
}
private final Database db;
private final Connection readConnection;
private final Connection writeConnection;
private final AtomicLong counter = new AtomicLong(0L);
private final ProgressLogger progress = ProgressLogger.create(getClass(), counter);
private Select select;
private List<UpsertImpl> updates = new ArrayList<>(1);
public MassUpdate(Database db, Connection readConnection, Connection writeConnection) {
this.db = db;
this.readConnection = readConnection;
this.writeConnection = writeConnection;
}
public SqlStatement select(String sql) throws SQLException {
this.select = SelectImpl.create(db, readConnection, sql);
return this.select;
}
public Upsert update(String sql) throws SQLException {
UpsertImpl upsert = UpsertImpl.create(writeConnection, sql);
this.updates.add(upsert);
return upsert;
}
public MassUpdate rowPluralName(String s) {
this.progress.setPluralLabel(s);
return this;
}
public void execute(Handler handler) throws SQLException {
checkState(select != null && !updates.isEmpty(), "SELECT or UPDATE requests are not defined");
checkState(updates.size() == 1, "There should be only one update when using a " + Handler.class.getName());
progress.start();
try {
UpsertImpl update = updates.iterator().next();
select.scroll(row -> callSingleHandler(handler, update, row));
closeStatements();
// log the total number of processed rows
progress.log();
} finally {
progress.stop();
}
}
public void execute(MultiHandler handler) throws SQLException {
checkState(select != null && !updates.isEmpty(), "SELECT or UPDATE(s) requests are not defined");
progress.start();
try {
select.scroll(row -> callMultiHandler(handler, updates, row));
closeStatements();
// log the total number of processed rows
progress.log();
} finally {
progress.stop();
}
}
private void callSingleHandler(Handler handler, Upsert update, Select.Row row) throws SQLException {
if (handler.handle(row, update)) {
update.addBatch();
}
counter.getAndIncrement();
}
private void callMultiHandler(MultiHandler handler, List<UpsertImpl> updates, Select.Row row) throws SQLException {
int i = 0;
for (UpsertImpl update : updates) {
if (handler.handle(row, update, i)) {
update.addBatch();
}
i++;
}
counter.getAndIncrement();
}
private void closeStatements() throws SQLException {
for (UpsertImpl update : updates) {
if (update.getBatchCount() > 0L) {
update.execute().commit();
}
update.close();
}
select.close();
}
}
| 4,636 | 30.544218 | 117 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationNumber.java | /*
* 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.step;
import static com.google.common.base.Preconditions.checkArgument;
public final class MigrationNumber {
private MigrationNumber() {
// prevents instantiation
}
public static void validate(long migrationNumber) {
checkArgument(migrationNumber >= 0, "Migration number must be >= 0");
}
}
| 1,201 | 34.352941 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStep.java | /*
* 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.step;
import java.sql.SQLException;
public interface MigrationStep {
void execute() throws SQLException;
}
| 1,002 | 34.821429 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepExecutionException.java | /*
* 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.step;
import static java.util.Objects.requireNonNull;
public class MigrationStepExecutionException extends RuntimeException {
private final transient RegisteredMigrationStep failingStep;
public MigrationStepExecutionException(RegisteredMigrationStep failingStep, Throwable cause) {
super(createMessage(failingStep), requireNonNull(cause, "cause can't be null"));
this.failingStep = failingStep;
}
private static String createMessage(RegisteredMigrationStep failingStep) {
check(failingStep);
return String.format("Execution of migration step %s failed", failingStep);
}
private static RegisteredMigrationStep check(RegisteredMigrationStep failingStep) {
return requireNonNull(failingStep, "RegisteredMigrationStep can't be null");
}
public RegisteredMigrationStep getFailingStep() {
return failingStep;
}
}
| 1,745 | 37.8 | 96 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepRegistry.java | /*
* 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.step;
public interface MigrationStepRegistry {
/**
*
* @throws IllegalArgumentException if migrationNumber is < 0.
* @throws IllegalStateException if a db migration is already registered for the specified migrationNumber
*/
<T extends MigrationStep> MigrationStepRegistry add(long migrationNumber, String description, Class<T> stepClass);
}
| 1,248 | 40.633333 | 116 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepRegistryImpl.java | /*
* 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.step;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import static org.sonar.server.platform.db.migration.step.MigrationNumber.validate;
public class MigrationStepRegistryImpl implements InternalMigrationStepRegistry {
private final Map<Long, RegisteredMigrationStep> migrations = new HashMap<>();
@Override
public <T extends MigrationStep> MigrationStepRegistry add(long migrationNumber, String description, Class<T> stepClass) {
validate(migrationNumber);
requireNonNull(description, "description can't be null");
checkArgument(!description.isEmpty(), "description can't be empty");
requireNonNull(stepClass, "MigrationStep class can't be null");
checkState(!migrations.containsKey(migrationNumber), "A migration is already registered for migration number '%s'", migrationNumber);
this.migrations.put(migrationNumber, new RegisteredMigrationStep(migrationNumber, description, stepClass));
return this;
}
@Override
public MigrationSteps build() {
checkState(!migrations.isEmpty(), "Registry is empty");
return new MigrationStepsImpl(toOrderedList(this.migrations));
}
private static List<RegisteredMigrationStep> toOrderedList(Map<Long, RegisteredMigrationStep> migrations) {
return migrations.entrySet().stream()
.sorted(Comparator.comparingLong(Map.Entry::getKey))
.map(Map.Entry::getValue)
.toList();
}
}
| 2,512 | 40.883333 | 137 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationSteps.java | /*
* 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.step;
import java.util.List;
public interface MigrationSteps {
/**
* @return the migration number of the last migration step.
*/
long getMaxMigrationNumber();
/**
* Reads all migration steps in order of increasing migration number.
*/
List<RegisteredMigrationStep> readAll();
/**
* Reads migration steps, in order of increasing migration number, from the specified migration number <strong>included</strong>.
*/
List<RegisteredMigrationStep> readFrom(long migrationNumber);
}
| 1,400 | 34.025 | 131 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutor.java | /*
* 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.step;
import java.util.List;
/**
* Responsible for:
* <ul>
* <li>looping over all the {@link MigrationStep} to execute</li>
* <li>put INFO log between each {@link MigrationStep} for user information</li>
* <li>handle errors during the execution of {@link MigrationStep}</li>
* <li>update the content of table {@code SCHEMA_MIGRATION}</li>
* </ul>
*/
public interface MigrationStepsExecutor {
/**
* @throws MigrationStepExecutionException at the first failing migration step execution
*/
void execute(List<RegisteredMigrationStep> steps);
}
| 1,458 | 36.410256 | 90 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImpl.java | /*
* 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.step;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.core.platform.Container;
import org.sonar.core.util.logs.Profiler;
import org.sonar.server.platform.db.migration.history.MigrationHistory;
import static com.google.common.base.Preconditions.checkState;
public class MigrationStepsExecutorImpl implements MigrationStepsExecutor {
private static final Logger LOGGER = LoggerFactory.getLogger("DbMigrations");
private static final String GLOBAL_START_MESSAGE = "Executing DB migrations...";
private static final String GLOBAL_END_MESSAGE = "Executed DB migrations: {}";
private static final String STEP_START_PATTERN = "{}...";
private static final String STEP_STOP_PATTERN = "{}: {}";
private final Container migrationContainer;
private final MigrationHistory migrationHistory;
public MigrationStepsExecutorImpl(Container migrationContainer, MigrationHistory migrationHistory) {
this.migrationContainer = migrationContainer;
this.migrationHistory = migrationHistory;
}
@Override
public void execute(List<RegisteredMigrationStep> steps) {
Profiler globalProfiler = Profiler.create(LOGGER);
globalProfiler.startInfo(GLOBAL_START_MESSAGE);
boolean allStepsExecuted = false;
try {
steps.forEach(this::execute);
allStepsExecuted = true;
} finally {
if (allStepsExecuted) {
globalProfiler.stopInfo(GLOBAL_END_MESSAGE, "success");
} else {
globalProfiler.stopError(GLOBAL_END_MESSAGE, "failure");
}
}
}
private void execute(RegisteredMigrationStep step) {
MigrationStep migrationStep = migrationContainer.getComponentByType(step.getStepClass());
checkState(migrationStep != null, "Can not find instance of " + step.getStepClass());
execute(step, migrationStep);
}
private void execute(RegisteredMigrationStep step, MigrationStep migrationStep) {
Profiler stepProfiler = Profiler.create(LOGGER);
stepProfiler.startInfo(STEP_START_PATTERN, step);
boolean done = false;
try {
migrationStep.execute();
migrationHistory.done(step);
done = true;
} catch (Exception e) {
throw new MigrationStepExecutionException(step, e);
} finally {
if (done) {
stepProfiler.stopInfo(STEP_STOP_PATTERN, step, "success");
} else {
stepProfiler.stopError(STEP_STOP_PATTERN, step, "failure");
}
}
}
}
| 3,326 | 36.382022 | 102 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsImpl.java | /*
* 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.step;
import java.util.Collections;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.copyOf;
import static java.util.Objects.requireNonNull;
import static org.sonar.server.platform.db.migration.step.MigrationNumber.validate;
class MigrationStepsImpl implements MigrationSteps {
private final List<RegisteredMigrationStep> steps;
MigrationStepsImpl(List<RegisteredMigrationStep> steps) {
requireNonNull(steps, "steps can't be null");
checkArgument(!steps.isEmpty(), "steps can't be empty");
this.steps = copyOf(steps);
}
@Override
public long getMaxMigrationNumber() {
return steps.get(steps.size() -1).getMigrationNumber();
}
@Override
public List<RegisteredMigrationStep> readAll() {
return steps;
}
@Override
public List<RegisteredMigrationStep> readFrom(long migrationNumber) {
validate(migrationNumber);
int startingIndex = lookupIndexOfClosestTo(migrationNumber);
if (startingIndex < 0) {
return Collections.emptyList();
}
return steps.subList(startingIndex, steps.size());
}
private int lookupIndexOfClosestTo(long startingPoint) {
int index = 0;
for (RegisteredMigrationStep step : steps) {
if (step.getMigrationNumber() >= startingPoint) {
return index;
}
index++;
}
return -1;
}
}
| 2,298 | 31.842857 | 83 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsProvider.java | /*
* 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.step;
import java.util.Arrays;
import org.sonar.server.platform.db.migration.version.DbVersion;
import org.springframework.context.annotation.Bean;
/**
* This class is responsible for providing the {@link MigrationSteps} to be injected in classes that need it and
* ensures that there's only one such instance.
*/
public class MigrationStepsProvider {
@Bean("MigrationSteps")
public MigrationSteps provide(InternalMigrationStepRegistry migrationStepRegistry, DbVersion... dbVersions) {
Arrays.stream(dbVersions).forEach(dbVersion -> dbVersion.addSteps(migrationStepRegistry));
return migrationStepRegistry.build();
}
}
| 1,528 | 40.324324 | 112 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RegisteredMigrationStep.java | /*
* 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.step;
import static java.util.Objects.requireNonNull;
public final class RegisteredMigrationStep {
private final long migrationNumber;
private final String description;
private final Class<? extends MigrationStep> stepClass;
public RegisteredMigrationStep(long migrationNumber, String description, Class<? extends MigrationStep> migration) {
this.migrationNumber = migrationNumber;
this.description = requireNonNull(description, "description can't be null");
this.stepClass = requireNonNull(migration, "MigrationStep class can't be null");
}
public long getMigrationNumber() {
return migrationNumber;
}
public String getDescription() {
return description;
}
public Class<? extends MigrationStep> getStepClass() {
return stepClass;
}
@Override
public String toString() {
return "#" + migrationNumber + " '" + description + "'";
}
}
| 1,784 | 33.326923 | 118 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RenameVarcharColumnChange.java | /*
* 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.step;
import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.ColumnMetadata;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.ColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.RenameColumnsBuilder;
public abstract class RenameVarcharColumnChange extends DdlChange {
protected final String table;
protected final String oldColumn;
protected final String newColumn;
protected RenameVarcharColumnChange(Database db, String table, String oldColumn, String newColumn) {
super(db);
this.table = table;
this.oldColumn = oldColumn;
this.newColumn = newColumn;
}
@Override
public void execute(Context context) throws SQLException {
try (Connection c = getDatabase().getDataSource().getConnection()) {
ColumnMetadata oldColumnMetadata = DatabaseUtils.getColumnMetadata(c, table, oldColumn);
if (!DatabaseUtils.tableColumnExists(c, table, newColumn) && oldColumnMetadata != null) {
ColumnDef newColumnDef = new VarcharColumnDef.Builder()
.setColumnName(newColumn)
.setIsNullable(oldColumnMetadata.nullable())
.setLimit(oldColumnMetadata.limit())
.build();
context.execute(new RenameColumnsBuilder(getDialect(), table).renameColumn(oldColumn, newColumnDef).build());
}
}
}
}
| 2,341 | 38.033333 | 117 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/Select.java | /*
* 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.step;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import javax.annotation.CheckForNull;
public interface Select extends SqlStatement<Select> {
class Row {
private final ResultSet rs;
Row(ResultSet rs) {
this.rs = rs;
}
@CheckForNull
public Long getNullableLong(int columnIndex) throws SQLException {
long l = rs.getLong(columnIndex);
return rs.wasNull() ? null : l;
}
public long getLong(int columnIndex) throws SQLException {
return rs.getLong(columnIndex);
}
@CheckForNull
public Double getNullableDouble(int columnIndex) throws SQLException {
double d = rs.getDouble(columnIndex);
return rs.wasNull() ? null : d;
}
public double getDouble(int columnIndex) throws SQLException {
return rs.getDouble(columnIndex);
}
@CheckForNull
public Integer getNullableInt(int columnIndex) throws SQLException {
int i = rs.getInt(columnIndex);
return rs.wasNull() ? null : i;
}
public int getInt(int columnIndex) throws SQLException {
return rs.getInt(columnIndex);
}
@CheckForNull
public Boolean getNullableBoolean(int columnIndex) throws SQLException {
boolean b = rs.getBoolean(columnIndex);
return rs.wasNull() ? null : b;
}
public boolean getBoolean(int columnIndex) throws SQLException {
return rs.getBoolean(columnIndex);
}
@CheckForNull
public String getNullableString(int columnIndex) throws SQLException {
String s = rs.getString(columnIndex);
return rs.wasNull() ? null : s;
}
public String getString(int columnIndex) throws SQLException {
return rs.getString(columnIndex);
}
@CheckForNull
public Date getNullableDate(int columnIndex) throws SQLException {
Timestamp t = rs.getTimestamp(columnIndex);
return rs.wasNull() ? null : t;
}
public Date getDate(int columnIndex) throws SQLException {
return rs.getTimestamp(columnIndex);
}
@CheckForNull
public byte[] getNullableBytes(int columnIndex) throws SQLException {
byte[] b = rs.getBytes(columnIndex);
return rs.wasNull() ? null : b;
}
public byte[] getBytes(int columnIndex) throws SQLException {
return rs.getBytes(columnIndex);
}
@Override
public String toString() {
try {
ResultSetMetaData rsMetaData = rs.getMetaData();
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= rsMetaData.getColumnCount(); i++) {
if (i > 1) {
sb.append(",");
}
sb.append(rsMetaData.getColumnLabel(i).toLowerCase());
sb.append("=");
sb.append(rs.getObject(i));
}
return sb.toString();
} catch (Exception e) {
return "Unavailable: " + e.getMessage();
}
}
}
@FunctionalInterface
interface RowReader<T> {
T read(Row row) throws SQLException;
}
class LongReader implements RowReader<Long> {
private LongReader() {
}
@Override
public Long read(Row row) throws SQLException {
return row.getNullableLong(1);
}
}
RowReader<Long> LONG_READER = new LongReader();
class StringReader implements RowReader<String> {
@Override
public String read(Row row) throws SQLException {
return row.getNullableString(1);
}
}
@FunctionalInterface
interface RowHandler {
void handle(Row row) throws SQLException;
}
<T> List<T> list(RowReader<T> reader) throws SQLException;
@CheckForNull
<T> T get(RowReader<T> reader) throws SQLException;
void scroll(RowHandler handler) throws SQLException;
}
| 4,659 | 27.242424 | 76 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/SelectImpl.java | /*
* 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.step;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
public class SelectImpl extends BaseSqlStatement<Select> implements Select {
private SelectImpl(PreparedStatement pstmt) {
super(pstmt);
}
@Override
public <T> List<T> list(Select.RowReader<T> reader) throws SQLException {
ResultSet rs = pstmt.executeQuery();
Select.Row row = new Select.Row(rs);
try {
List<T> rows = new ArrayList<>();
while (rs.next()) {
rows.add(reader.read(row));
}
return rows;
} catch (Exception e) {
throw newExceptionWithRowDetails(row, e);
} finally {
DatabaseUtils.closeQuietly(rs);
close();
}
}
@Override
public <T> T get(Select.RowReader<T> reader) throws SQLException {
ResultSet rs = pstmt.executeQuery();
Select.Row row = new Select.Row(rs);
try {
if (rs.next()) {
return reader.read(row);
}
return null;
} catch (Exception e) {
throw newExceptionWithRowDetails(row, e);
} finally {
DatabaseUtils.closeQuietly(rs);
close();
}
}
@Override
public void scroll(Select.RowHandler handler) throws SQLException {
ResultSet rs = pstmt.executeQuery();
Select.Row row = new Select.Row(rs);
try {
while (rs.next()) {
handler.handle(row);
}
} catch (Exception e) {
throw newExceptionWithRowDetails(row, e);
} finally {
DatabaseUtils.closeQuietly(rs);
close();
}
}
private static IllegalStateException newExceptionWithRowDetails(Select.Row row, Exception e) {
return new IllegalStateException("Error during processing of row: [" + row + "]", e);
}
public static SelectImpl create(Database db, Connection connection, String sql) throws SQLException {
// TODO use DbClient#newScrollingSelectStatement()
PreparedStatement pstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
pstmt.setFetchSize(db.getDialect().getScrollDefaultFetchSize());
return new SelectImpl(pstmt);
}
}
| 3,134 | 30.666667 | 120 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/SqlStatement.java | /*
* 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.step;
import java.sql.SQLException;
import java.util.Date;
import javax.annotation.Nullable;
public interface SqlStatement<CHILD extends SqlStatement> extends AutoCloseable {
CHILD setBoolean(int columnIndex, @Nullable Boolean value) throws SQLException;
CHILD setBytes(int columnIndex, @Nullable byte[] value) throws SQLException;
CHILD setDate(int columnIndex, @Nullable Date value) throws SQLException;
CHILD setDouble(int columnIndex, @Nullable Double value) throws SQLException;
CHILD setInt(int columnIndex, @Nullable Integer value) throws SQLException;
CHILD setLong(int columnIndex, @Nullable Long value) throws SQLException;
CHILD setString(int columnIndex, @Nullable String value) throws SQLException;
@Override
void close();
}
| 1,655 | 36.636364 | 81 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/Upsert.java | /*
* 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.step;
import java.sql.SQLException;
/**
* INSERT, UPDATE or DELETE
*/
public interface Upsert extends SqlStatement<Upsert> {
/**
* Prepare for next statement.
* @return {@code true} if the buffer of batched requests has been sent and transaction
* has been committed, else {@code false}.
*/
boolean addBatch() throws SQLException;
Upsert execute() throws SQLException;
Upsert commit() throws SQLException;
/**
* Number of requests required before sending group of batched
* requests and before committing. Default value is {@link UpsertImpl#MAX_BATCH_SIZE}
*/
Upsert setBatchSize(int i);
}
| 1,520 | 32.8 | 89 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/UpsertImpl.java | /*
* 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.step;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import static com.google.common.base.Preconditions.checkArgument;
public class UpsertImpl extends BaseSqlStatement<Upsert> implements Upsert {
private static final int MAX_BATCH_SIZE = 250;
private int maxBatchSize = MAX_BATCH_SIZE;
private long batchCount = 0L;
private UpsertImpl(PreparedStatement pstmt) {
super(pstmt);
}
@Override
public Upsert setBatchSize(int i) {
checkArgument(i >= 0, "size must be positive. Got %s", i);
this.maxBatchSize = i;
return this;
}
public int getMaxBatchSize() {
return maxBatchSize;
}
@Override
public boolean addBatch() throws SQLException {
pstmt.addBatch();
pstmt.clearParameters();
batchCount++;
if (batchCount % maxBatchSize == 0L) {
pstmt.executeBatch();
pstmt.getConnection().commit();
return true;
}
return false;
}
@Override
public Upsert execute() throws SQLException {
if (batchCount == 0L) {
pstmt.execute();
} else {
pstmt.executeBatch();
}
return this;
}
public long getBatchCount() {
return batchCount;
}
@Override
public Upsert commit() throws SQLException {
pstmt.getConnection().commit();
return this;
}
public static UpsertImpl create(Connection connection, String sql) throws SQLException {
return new UpsertImpl(connection.prepareStatement(sql));
}
}
| 2,363 | 26.172414 | 90 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/package-info.java | /*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.server.platform.db.migration.step;
import javax.annotation.ParametersAreNonnullByDefault;
| 984 | 38.4 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DatabaseVersion.java | /*
* 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;
import java.util.Optional;
import org.sonar.server.platform.db.migration.history.MigrationHistory;
import org.sonar.server.platform.db.migration.step.MigrationSteps;
public class DatabaseVersion {
/**
* The minimum supported version which can be upgraded. Lower
* versions must be previously upgraded to LTS version.
* Note that the value can't be less than current LTS version.
*/
public static final long MIN_UPGRADE_VERSION = 6_802;
private final MigrationSteps migrationSteps;
private final MigrationHistory migrationHistory;
public DatabaseVersion(MigrationSteps migrationSteps, MigrationHistory migrationHistory) {
this.migrationSteps = migrationSteps;
this.migrationHistory = migrationHistory;
}
public Status getStatus() {
return getStatus(migrationHistory.getLastMigrationNumber(), migrationSteps.getMaxMigrationNumber());
}
/**
* Convenience method to retrieve the value of {@link MigrationHistory#getLastMigrationNumber()}.
*/
public Optional<Long> getVersion() {
return migrationHistory.getLastMigrationNumber();
}
private static Status getStatus(Optional<Long> currentVersion, long lastVersion) {
if (!currentVersion.isPresent()) {
return Status.FRESH_INSTALL;
}
Long aLong = currentVersion.get();
if (aLong == lastVersion) {
return Status.UP_TO_DATE;
}
if (aLong > lastVersion) {
return Status.REQUIRES_DOWNGRADE;
}
return Status.REQUIRES_UPGRADE;
}
public enum Status {
UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
}
}
| 2,479 | 33.444444 | 104 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DbVersion.java | /*
* 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;
import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
public interface DbVersion {
void addSteps(MigrationStepRegistry registry);
}
| 1,055 | 38.111111 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/package-info.java | /*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.server.platform.db.migration.version;
import javax.annotation.ParametersAreNonnullByDefault;
| 987 | 38.52 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchema.java | /*
* 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.v00;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef;
import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
import org.sonar.server.platform.db.migration.def.ColumnDef;
import org.sonar.server.platform.db.migration.def.IntegerColumnDef;
import org.sonar.server.platform.db.migration.def.TimestampColumnDef;
import org.sonar.server.platform.db.migration.def.TinyIntColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
import static java.util.Arrays.stream;
import static java.util.stream.Stream.concat;
import static java.util.stream.Stream.of;
import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.BlobColumnDef.newBlobColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.DecimalColumnDef.newDecimalColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.TimestampColumnDef.newTimestampColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.TinyIntColumnDef.newTinyIntColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.DESCRIPTION_SECTION_KEY_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.MAX_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.USER_UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
public class CreateInitialSchema extends DdlChange {
/**
* Initially, UUID columns were created with size 50 when only 40 is needed. {@link VarcharColumnDef#UUID_SIZE}
* should be used instead of this constant whenever reducing the column size is possible.
*/
private static final int OLD_UUID_VARCHAR_SIZE = 50;
// keep column name constants in alphabetic order
private static final String ANALYSIS_UUID_COL_NAME = "analysis_uuid";
private static final String COMPONENT_UUID_COL_NAME = "component_uuid";
private static final String CREATED_AT_COL_NAME = "created_at";
private static final String DESCRIPTION_COL_NAME = "description";
private static final String GROUP_UUID_COL_NAME = "group_uuid";
private static final String LANGUAGE_COL_NAME = "language";
private static final String METRIC_UUID_COL_NAME = "metric_uuid";
private static final String PROJECT_UUID_COL_NAME = "project_uuid";
private static final String BRANCH_UUID_COL_NAME = "branch_uuid";
public static final String RULE_UUID_COL_NAME = "rule_uuid";
private static final String STATUS_COL_NAME = "status";
private static final String TASK_UUID_COL_NAME = "task_uuid";
private static final String TEMPLATE_UUID_COL_NAME = "template_uuid";
private static final String TEXT_VALUE_COL_NAME = "text_value";
private static final String UPDATED_AT_COL_NAME = "updated_at";
private static final String USER_UUID_COL_NAME = "user_uuid";
private static final String VALUE_COL_NAME = "value";
private static final String PRIVATE_COL_NAME = "private";
private static final String QPROFILE_UUID_COL_NAME = "qprofile_uuid";
private static final String EXPIRATION_DATE_COL_NAME = "expiration_date";
public static final String QUALITY_GATE_UUID_COL_NAME = "quality_gate_uuid";
public static final String CLOB_VALUE_COL_NAME = "clob_value";
public static final String IS_EMPTY_COL_NAME = "is_empty";
private static final String UNIQUE_INDEX_SUFFIX = "_unique";
// usual technical columns
private static final VarcharColumnDef UUID_COL = newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
private static final BigIntegerColumnDef TECHNICAL_CREATED_AT_COL = newBigIntegerColumnDefBuilder().setColumnName(CREATED_AT_COL_NAME).setIsNullable(false).build();
private static final BigIntegerColumnDef NULLABLE_TECHNICAL_CREATED_AT_COL = newBigIntegerColumnDefBuilder().setColumnName(CREATED_AT_COL_NAME).setIsNullable(true).build();
private static final BigIntegerColumnDef TECHNICAL_UPDATED_AT_COL = newBigIntegerColumnDefBuilder().setColumnName(UPDATED_AT_COL_NAME).setIsNullable(false).build();
private static final BigIntegerColumnDef NULLABLE_TECHNICAL_UPDATED_AT_COL = newBigIntegerColumnDefBuilder().setColumnName(UPDATED_AT_COL_NAME).setIsNullable(true).build();
private static final TimestampColumnDef DEPRECATED_TECHNICAL_CREATED_AT_COL = newTimestampColumnDefBuilder().setColumnName(CREATED_AT_COL_NAME).setIsNullable(true).build();
private static final TimestampColumnDef DEPRECATED_TECHNICAL_UPDATED_AT_COL = newTimestampColumnDefBuilder().setColumnName(UPDATED_AT_COL_NAME).setIsNullable(true).build();
public CreateInitialSchema(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
createActiveRuleParameters(context);
createActiveRules(context);
createAlmPats(context);
createAlmSettings(context);
createProjectAlmSettings(context);
createAnalysisProperties(context);
createAppBranchProjectBranch(context);
createAppProjects(context);
createAudits(context);
createCeActivity(context);
createCeQueue(context);
createCeScannerContext(context);
createCeTaskCharacteristics(context);
createCeTaskInput(context);
createCeTaskMessage(context);
createComponents(context);
createDefaultQProfiles(context);
createDeprecatedRuleKeys(context);
createDuplicationsIndex(context);
createEsQueue(context);
createEventComponentChanges(context);
createEvents(context);
createFileSources(context);
createGroupRoles(context);
createGroups(context);
createGroupsUsers(context);
createInternalComponentProps(context);
createInternalProperties(context);
createIssueChanges(context);
createIssues(context);
createLiveMeasures(context);
createMetrics(context);
createNewCodePeriods(context);
createNewCodeReferenceIssues(context);
createNotifications(context);
createOrgQProfiles(context);
createPermTemplatesGroups(context);
createPermTemplatesUsers(context);
createPermTemplatesCharacteristics(context);
createPermissionTemplates(context);
createPlugins(context);
createPortfolioProjBranches(context);
createPortfolioProjects(context);
createPortfolioReferences(context);
createPortfolios(context);
createProjectBadgeToken(context);
createProjectBranches(context);
createProjectLinks(context);
createProjectMappings(context);
createProjectMeasures(context);
createProjectQprofiles(context);
createProjects(context);
createProjectQGates(context);
createProperties(context);
createPushEvents(context);
createQGateGroupPermissions(context);
createQGateUserPermissions(context);
createQProfileChanges(context);
createQProfileEditGroups(context);
createQProfileEditUsers(context);
createQualityGateConditions(context);
createQualityGates(context);
createScimUsers(context);
createSessionTokens(context);
createRulesRepository(context);
createRuleDescSections(context);
createRules(context);
createRulesParameters(context);
createRulesProfiles(context);
createSamlMessageIds(context);
createScannerAnalysisCache(context);
createSnapshots(context);
createUserRoles(context);
createUserDismissedMessage(context);
createUserTokens(context);
createUsers(context);
createWebhookDeliveries(context);
createWebhooks(context);
}
private void createActiveRuleParameters(Context context) {
String tableName = "active_rule_parameters";
VarcharColumnDef activeRuleUuidColumnDef = newVarcharColumnDefBuilder("active_rule_uuid").setLimit(UUID_SIZE).setIsNullable(false).build();
VarcharColumnDef rulesParameterUuidColumnDef = newVarcharColumnDefBuilder("rules_parameter_uuid").setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder(VALUE_COL_NAME).setLimit(MAX_SIZE).build())
.addColumn(newVarcharColumnDefBuilder("rules_parameter_key").setLimit(128).build())
.addColumn(activeRuleUuidColumnDef)
.addColumn(rulesParameterUuidColumnDef)
.build());
addIndex(context, tableName, "arp_active_rule_uuid", false, activeRuleUuidColumnDef);
}
private void createActiveRules(Context context) {
VarcharColumnDef profileUuidCol = newVarcharColumnDefBuilder("profile_uuid").setLimit(UUID_SIZE).setIsNullable(false).build();
VarcharColumnDef ruleUuidCol = newVarcharColumnDefBuilder(RULE_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(
newTableBuilder("active_rules")
.addPkColumn(UUID_COL)
.addColumn(newIntegerColumnDefBuilder().setColumnName("failure_level").setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder("inheritance").setLimit(10).build())
.addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
.addColumn(NULLABLE_TECHNICAL_UPDATED_AT_COL)
.addColumn(profileUuidCol)
.addColumn(ruleUuidCol)
.build());
addIndex(context, "active_rules", "uniq_profile_rule_uuids", true, profileUuidCol, ruleUuidCol);
}
private void createAlmPats(Context context) {
String tableName = "alm_pats";
VarcharColumnDef patCol = newVarcharColumnDefBuilder("pat").setIsNullable(false).setLimit(2000).build();
VarcharColumnDef userUuidCol = newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setIsNullable(false).setLimit(256).build();
VarcharColumnDef almSettingUuidCol = newVarcharColumnDefBuilder("alm_setting_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(patCol)
.addColumn(userUuidCol)
.addColumn(almSettingUuidCol)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "uniq_alm_pats", true, userUuidCol, almSettingUuidCol);
}
private void createAlmSettings(Context context) {
String tableName = "alm_settings";
VarcharColumnDef keeCol = newVarcharColumnDefBuilder("kee").setIsNullable(false).setLimit(200).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("alm_id").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(keeCol)
.addColumn(newVarcharColumnDefBuilder("url").setIsNullable(true).setLimit(2000).build())
.addColumn(newVarcharColumnDefBuilder("app_id").setIsNullable(true).setLimit(80).build())
.addColumn(newVarcharColumnDefBuilder("private_key").setIsNullable(true).setLimit(2500).build())
.addColumn(newVarcharColumnDefBuilder("pat").setIsNullable(true).setLimit(2000).build())
.addColumn(TECHNICAL_UPDATED_AT_COL)
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(newVarcharColumnDefBuilder("client_id").setIsNullable(true).setLimit(80).build())
.addColumn(newVarcharColumnDefBuilder("client_secret").setIsNullable(true).setLimit(160).build())
.addColumn(newVarcharColumnDefBuilder("webhook_secret").setIsNullable(true).setLimit(160).build())
.build());
addIndex(context, tableName, "uniq_alm_settings", true, keeCol);
}
private void createProjectAlmSettings(Context context) {
String tableName = "project_alm_settings";
VarcharColumnDef almSettingUuidCol = newVarcharColumnDefBuilder("alm_setting_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
VarcharColumnDef almRepoCol = newVarcharColumnDefBuilder("alm_repo").setIsNullable(true).setLimit(256).build();
VarcharColumnDef almSlugCol = newVarcharColumnDefBuilder("alm_slug").setIsNullable(true).setLimit(256).build();
BooleanColumnDef summaryCommentEnabledCol = newBooleanColumnDefBuilder("summary_comment_enabled").setIsNullable(true).build();
BooleanColumnDef monorepoCol = newBooleanColumnDefBuilder("monorepo").setIsNullable(false).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(almSettingUuidCol)
.addColumn(projectUuidCol)
.addColumn(almRepoCol)
.addColumn(almSlugCol)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(summaryCommentEnabledCol)
.addColumn(monorepoCol)
.build());
addIndex(context, tableName, "uniq_project_alm_settings", true, projectUuidCol);
addIndex(context, tableName, "project_alm_settings_alm", false, almSettingUuidCol);
addIndex(context, tableName, "project_alm_settings_slug", false, almSlugCol);
}
private void createAnalysisProperties(Context context) {
String tableName = "analysis_properties";
VarcharColumnDef snapshotUuidColumn = newVarcharColumnDefBuilder(ANALYSIS_UUID_COL_NAME)
.setIsNullable(false)
.setLimit(UUID_SIZE)
.build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(snapshotUuidColumn)
.addColumn(newVarcharColumnDefBuilder("kee").setIsNullable(false).setLimit(512).build())
.addColumn(newVarcharColumnDefBuilder(TEXT_VALUE_COL_NAME).setIsNullable(true).setLimit(MAX_SIZE).build())
.addColumn(newClobColumnDefBuilder().setColumnName(CLOB_VALUE_COL_NAME).setIsNullable(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName(IS_EMPTY_COL_NAME).setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "analysis_properties_analysis", false, snapshotUuidColumn);
}
private void createAppBranchProjectBranch(Context context) {
String tableName = "app_branch_project_branch";
VarcharColumnDef applicationBranchUuid = newVarcharColumnDefBuilder("application_branch_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef projectBranchUuid = newVarcharColumnDefBuilder("project_branch_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef applicationUuid = newVarcharColumnDefBuilder("application_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef projectUuid = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(applicationUuid)
.addColumn(applicationBranchUuid)
.addColumn(projectUuid)
.addColumn(projectBranchUuid)
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "uniq_app_branch_proj", true, applicationBranchUuid, projectBranchUuid);
addIndex(context, tableName, "idx_abpb_app_uuid", false, applicationUuid);
addIndex(context, tableName, "idx_abpb_app_branch_uuid", false, applicationBranchUuid);
addIndex(context, tableName, "idx_abpb_proj_uuid", false, projectUuid);
addIndex(context, tableName, "idx_abpb_proj_branch_uuid", false, projectBranchUuid);
}
private void createAppProjects(Context context) {
String tableName = "app_projects";
VarcharColumnDef applicationUuid = newVarcharColumnDefBuilder("application_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef projectUuid = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(applicationUuid)
.addColumn(projectUuid)
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "uniq_app_projects", true, applicationUuid, projectUuid);
addIndex(context, tableName, "idx_app_proj_application_uuid", false, applicationUuid);
addIndex(context, tableName, "idx_app_proj_project_uuid", false, projectUuid);
}
private void createAudits(Context context) {
String tableName = "audits";
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setIsNullable(false).setLimit(USER_UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder("user_login").setIsNullable(false).setLimit(USER_UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder("category").setIsNullable(false).setLimit(25).build())
.addColumn(newVarcharColumnDefBuilder("operation").setIsNullable(false).setLimit(50).build())
.addColumn(newVarcharColumnDefBuilder("new_value").setIsNullable(true).setLimit(4000).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(newBooleanColumnDefBuilder("user_triggered").setIsNullable(false).setDefaultValue(true).build())
.build());
addIndex(context, tableName, "audits_created_at", false, TECHNICAL_CREATED_AT_COL);
}
private void createCeActivity(Context context) {
String tableName = "ce_activity";
VarcharColumnDef uuidCol = UUID_COL;
VarcharColumnDef mainComponentUuidCol = newVarcharColumnDefBuilder("main_component_uuid").setLimit(UUID_SIZE).setIsNullable(true).build();
VarcharColumnDef componentUuidCol = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build();
VarcharColumnDef statusCol = newVarcharColumnDefBuilder(STATUS_COL_NAME).setLimit(15).setIsNullable(false).build();
BooleanColumnDef mainIsLastCol = newBooleanColumnDefBuilder().setColumnName("main_is_last").setIsNullable(false).build();
VarcharColumnDef mainIsLastKeyCol = newVarcharColumnDefBuilder("main_is_last_key").setLimit(55).setIsNullable(false).build();
BooleanColumnDef isLastCol = newBooleanColumnDefBuilder().setColumnName("is_last").setIsNullable(false).build();
VarcharColumnDef isLastKeyCol = newVarcharColumnDefBuilder("is_last_key").setLimit(55).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(uuidCol)
.addColumn(newVarcharColumnDefBuilder("task_type").setLimit(15).setIsNullable(false).build())
.addColumn(mainComponentUuidCol)
.addColumn(componentUuidCol)
.addColumn(statusCol)
.addColumn(mainIsLastCol)
.addColumn(mainIsLastKeyCol)
.addColumn(isLastCol)
.addColumn(isLastKeyCol)
.addColumn(newVarcharColumnDefBuilder("submitter_uuid").setLimit(USER_UUID_SIZE).setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("submitted_at").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("started_at").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("executed_at").setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("execution_count").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("execution_time_ms").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder(ANALYSIS_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("error_message").setLimit(1_000).setIsNullable(true).build())
.addColumn(newClobColumnDefBuilder().setColumnName("error_stacktrace").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("error_type").setLimit(20).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("worker_uuid").setLimit(UUID_SIZE).setIsNullable(true).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.addColumn(newVarcharColumnDefBuilder("node_name").setLimit(100).setIsNullable(true).build())
.build());
addIndex(context, tableName, "ce_activity_component", false, componentUuidCol);
addIndex(context, tableName, "ce_activity_islast", false, isLastCol, statusCol);
addIndex(context, tableName, "ce_activity_islast_key", false, isLastKeyCol);
addIndex(context, tableName, "ce_activity_main_component", false, mainComponentUuidCol);
addIndex(context, tableName, "ce_activity_main_islast", false, mainIsLastCol, statusCol);
addIndex(context, tableName, "ce_activity_main_islast_key", false, mainIsLastKeyCol);
}
private void createCeQueue(Context context) {
String tableName = "ce_queue";
VarcharColumnDef uuidCol = UUID_COL;
VarcharColumnDef mainComponentUuidCol = newVarcharColumnDefBuilder("main_component_uuid").setLimit(UUID_SIZE).setIsNullable(true).build();
VarcharColumnDef componentUuidCol = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(uuidCol)
.addColumn(newVarcharColumnDefBuilder("task_type").setLimit(15).setIsNullable(false).build())
.addColumn(mainComponentUuidCol)
.addColumn(componentUuidCol)
.addColumn(newVarcharColumnDefBuilder(STATUS_COL_NAME).setLimit(15).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("submitter_uuid").setLimit(USER_UUID_SIZE).setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("started_at").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("worker_uuid").setLimit(UUID_SIZE).setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("execution_count").setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.build());
addIndex(context, tableName, "ce_queue_main_component", false, mainComponentUuidCol);
addIndex(context, tableName, "ce_queue_component", false, componentUuidCol);
}
private void createCeScannerContext(Context context) {
context.execute(
newTableBuilder("ce_scanner_context")
.addPkColumn(newVarcharColumnDefBuilder(TASK_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("context_data").setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.build());
}
private void createCeTaskCharacteristics(Context context) {
String tableName = "ce_task_characteristics";
VarcharColumnDef ceTaskUuidColumn = newVarcharColumnDefBuilder(TASK_UUID_COL_NAME)
.setLimit(UUID_SIZE)
.setIsNullable(false)
.build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(ceTaskUuidColumn)
.addColumn(newVarcharColumnDefBuilder("kee").setLimit(512).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder(TEXT_VALUE_COL_NAME).setLimit(512).setIsNullable(true).build())
.build());
addIndex(context, tableName, "ce_characteristics_" + ceTaskUuidColumn.getName(), false, ceTaskUuidColumn);
}
private void createCeTaskInput(Context context) {
context.execute(
newTableBuilder("ce_task_input")
.addPkColumn(newVarcharColumnDefBuilder(TASK_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("input_data").setIsNullable(true).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.build());
}
private void createCeTaskMessage(Context context) {
String tableName = "ce_task_message";
VarcharColumnDef taskUuidCol = newVarcharColumnDefBuilder(TASK_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef messageTypeCol = newVarcharColumnDefBuilder("message_type").setIsNullable(false).setLimit(255).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(taskUuidCol)
.addColumn(newVarcharColumnDefBuilder("message").setIsNullable(false).setLimit(MAX_SIZE).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(messageTypeCol)
.build());
addIndex(context, tableName, tableName + "_task", false, taskUuidCol);
addIndex(context, tableName, "ctm_message_type", false, messageTypeCol);
}
private void createComponents(Context context) {
String tableName = "components";
VarcharColumnDef keeCol = newVarcharColumnDefBuilder("kee").setIsNullable(true).setLimit(1000).build();
VarcharColumnDef moduleUuidCol = newVarcharColumnDefBuilder("module_uuid").setIsNullable(true).setLimit(50).build();
VarcharColumnDef branchUuidCol = newVarcharColumnDefBuilder(BRANCH_UUID_COL_NAME).setIsNullable(false).setLimit(50).build();
VarcharColumnDef qualifierCol = newVarcharColumnDefBuilder("qualifier").setIsNullable(true).setLimit(10).build();
VarcharColumnDef rootUuidCol = newVarcharColumnDefBuilder("root_uuid").setIsNullable(false).setLimit(50).build();
VarcharColumnDef uuidCol = newVarcharColumnDefBuilder("uuid").setIsNullable(false).setLimit(50).build();
VarcharColumnDef mainBranchProjectUuidCol = newVarcharColumnDefBuilder("main_branch_project_uuid").setIsNullable(true).setLimit(50).build();
context.execute(newTableBuilder(tableName)
.addColumn(uuidCol)
.addColumn(keeCol)
.addColumn(newVarcharColumnDefBuilder("deprecated_kee").setIsNullable(true).setLimit(400).build())
.addColumn(newVarcharColumnDefBuilder("name").setIsNullable(true).setLimit(2000).build())
.addColumn(newVarcharColumnDefBuilder("long_name").setIsNullable(true).setLimit(2000).build())
.addColumn(newVarcharColumnDefBuilder(DESCRIPTION_COL_NAME).setIsNullable(true).setLimit(2000).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("enabled").setIsNullable(false).setDefaultValue(true).build())
.addColumn(newVarcharColumnDefBuilder("scope").setIsNullable(true).setLimit(3).build())
.addColumn(qualifierCol)
.addColumn(newBooleanColumnDefBuilder().setColumnName(PRIVATE_COL_NAME).setIsNullable(false).build())
.addColumn(rootUuidCol)
.addColumn(newVarcharColumnDefBuilder(LANGUAGE_COL_NAME).setIsNullable(true).setLimit(20).build())
.addColumn(newVarcharColumnDefBuilder("copy_component_uuid").setIsNullable(true).setLimit(50).build())
.addColumn(newVarcharColumnDefBuilder("path").setIsNullable(true).setLimit(2000).build())
.addColumn(newVarcharColumnDefBuilder("uuid_path").setIsNullable(false).setLimit(1500).build())
.addColumn(branchUuidCol)
.addColumn(moduleUuidCol)
.addColumn(newVarcharColumnDefBuilder("module_uuid_path").setIsNullable(true).setLimit(1500).build())
.addColumn(mainBranchProjectUuidCol)
.addColumn(newBooleanColumnDefBuilder().setColumnName("b_changed").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("b_name").setIsNullable(true).setLimit(500).build())
.addColumn(newVarcharColumnDefBuilder("b_long_name").setIsNullable(true).setLimit(500).build())
.addColumn(newVarcharColumnDefBuilder("b_description").setIsNullable(true).setLimit(2000).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("b_enabled").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("b_qualifier").setIsNullable(true).setLimit(10).build())
.addColumn(newVarcharColumnDefBuilder("b_language").setIsNullable(true).setLimit(20).build())
.addColumn(newVarcharColumnDefBuilder("b_copy_component_uuid").setIsNullable(true).setLimit(50).build())
.addColumn(newVarcharColumnDefBuilder("b_path").setIsNullable(true).setLimit(2000).build())
.addColumn(newVarcharColumnDefBuilder("b_uuid_path").setIsNullable(true).setLimit(1500).build())
.addColumn(newVarcharColumnDefBuilder("b_module_uuid").setIsNullable(true).setLimit(50).build())
.addColumn(newVarcharColumnDefBuilder("b_module_uuid_path").setIsNullable(true).setLimit(1500).build())
.addColumn(newTimestampColumnDefBuilder().setColumnName(CREATED_AT_COL_NAME).setIsNullable(true).build())
.build());
addIndex(context, tableName, "projects_module_uuid", false, moduleUuidCol);
addIndex(context, tableName, "projects_qualifier", false, qualifierCol);
addIndex(context, tableName, "projects_root_uuid", false, rootUuidCol);
addIndex(context, tableName, "idx_main_branch_prj_uuid", false, mainBranchProjectUuidCol);
addIndex(context, tableName, "components_uuid", true, uuidCol);
addIndex(context, tableName, "components_branch_uuid", false, branchUuidCol);
addIndex(context, tableName, "components_kee_branch_uuid", true, keeCol, branchUuidCol);
}
private void createDefaultQProfiles(Context context) {
String tableName = "default_qprofiles";
VarcharColumnDef profileUuidColumn = newVarcharColumnDefBuilder(QPROFILE_UUID_COL_NAME)
.setLimit(255)
.setIsNullable(false)
.build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(newVarcharColumnDefBuilder(LANGUAGE_COL_NAME).setLimit(20).setIsNullable(false).build())
.addColumn(profileUuidColumn)
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.build());
addIndex(context, tableName, "uniq_default_qprofiles_uuid", true, profileUuidColumn);
}
private void createDeprecatedRuleKeys(Context context) {
String tableName = "deprecated_rule_keys";
VarcharColumnDef ruleUuidCol = newVarcharColumnDefBuilder(RULE_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef oldRepositoryKeyCol = newVarcharColumnDefBuilder("old_repository_key").setIsNullable(false).setLimit(255).build();
VarcharColumnDef oldRuleKeyCol = newVarcharColumnDefBuilder("old_rule_key").setIsNullable(false).setLimit(200).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(oldRepositoryKeyCol)
.addColumn(oldRuleKeyCol)
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(ruleUuidCol)
.build());
addIndex(context, tableName, "uniq_deprecated_rule_keys", true, oldRepositoryKeyCol, oldRuleKeyCol);
addIndex(context, tableName, "rule_uuid_deprecated_rule_keys", false, ruleUuidCol);
}
private void createDuplicationsIndex(Context context) {
String tableName = "duplications_index";
VarcharColumnDef hashCol = newVarcharColumnDefBuilder("hash").setLimit(50).setIsNullable(false).build();
VarcharColumnDef analysisUuidCol = newVarcharColumnDefBuilder(ANALYSIS_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
VarcharColumnDef componentUuidCol = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(analysisUuidCol)
.addColumn(componentUuidCol)
.addColumn(hashCol)
.addColumn(newIntegerColumnDefBuilder().setColumnName("index_in_file").setIsNullable(false).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("start_line").setIsNullable(false).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("end_line").setIsNullable(false).build())
.build());
addIndex(context, tableName, "duplications_index_hash", false, hashCol);
addIndex(context, tableName, "duplication_analysis_component", false, analysisUuidCol, componentUuidCol);
}
private void createEsQueue(Context context) {
String tableName = "es_queue";
BigIntegerColumnDef createdAtCol = TECHNICAL_CREATED_AT_COL;
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("doc_type").setIsNullable(false).setLimit(40).build())
.addColumn(newVarcharColumnDefBuilder("doc_id").setIsNullable(false).setLimit(MAX_SIZE).build())
.addColumn(newVarcharColumnDefBuilder("doc_id_type").setIsNullable(true).setLimit(20).build())
.addColumn(newVarcharColumnDefBuilder("doc_routing").setIsNullable(true).setLimit(MAX_SIZE).build())
.addColumn(createdAtCol)
.build());
addIndex(context, tableName, "es_queue_created_at", false, createdAtCol);
}
private void createEventComponentChanges(Context context) {
String tableName = "event_component_changes";
VarcharColumnDef eventUuidCol = newVarcharColumnDefBuilder("event_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef eventComponentUuidCol = newVarcharColumnDefBuilder("event_component_uuid").setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
VarcharColumnDef eventAnalysisUuidCol = newVarcharColumnDefBuilder("event_analysis_uuid").setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
VarcharColumnDef changeCategoryCol = newVarcharColumnDefBuilder("change_category").setIsNullable(false).setLimit(12).build();
VarcharColumnDef componentUuidCol = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(eventUuidCol)
.addColumn(eventComponentUuidCol)
.addColumn(eventAnalysisUuidCol)
.addColumn(changeCategoryCol)
.addColumn(componentUuidCol)
.addColumn(newVarcharColumnDefBuilder("component_key").setIsNullable(false).setLimit(400).build())
.addColumn(newVarcharColumnDefBuilder("component_name").setIsNullable(false).setLimit(2000).build())
.addColumn(newVarcharColumnDefBuilder("component_branch_key").setIsNullable(true).setLimit(255).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, tableName + UNIQUE_INDEX_SUFFIX, true, eventUuidCol, changeCategoryCol, componentUuidCol);
addIndex(context, tableName, "event_cpnt_changes_cpnt", false, eventComponentUuidCol);
addIndex(context, tableName, "event_cpnt_changes_analysis", false, eventAnalysisUuidCol);
}
private void createEvents(Context context) {
String tableName = "events";
VarcharColumnDef uuidCol = UUID_COL;
VarcharColumnDef analysisUuidCol = newVarcharColumnDefBuilder(ANALYSIS_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
VarcharColumnDef componentUuid = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(uuidCol)
.addColumn(analysisUuidCol)
.addColumn(newVarcharColumnDefBuilder("name").setLimit(400).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("category").setLimit(50).build())
.addColumn(newVarcharColumnDefBuilder(DESCRIPTION_COL_NAME).setLimit(MAX_SIZE).build())
.addColumn(newVarcharColumnDefBuilder("event_data").setLimit(MAX_SIZE).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("event_date").setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(componentUuid)
.build());
addIndex(context, tableName, "events_analysis", false, analysisUuidCol);
addIndex(context, tableName, "events_component_uuid", false, componentUuid);
}
private void createFileSources(Context context) {
String tableName = "file_sources";
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
BigIntegerColumnDef updatedAtCol = TECHNICAL_UPDATED_AT_COL;
VarcharColumnDef fileUuidCol = newVarcharColumnDefBuilder("file_uuid").setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(projectUuidCol)
.addColumn(fileUuidCol)
.addColumn(newClobColumnDefBuilder().setColumnName("line_hashes").setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("line_hashes_version").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("data_hash").setLimit(50).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("src_hash").setLimit(50).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("revision").setLimit(100).setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("line_count").setIsNullable(false).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("binary_data").setIsNullable(true).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(updatedAtCol)
.build());
addIndex(context, tableName, "file_sources_file_uuid", true, fileUuidCol);
addIndex(context, tableName, "file_sources_project_uuid", false, projectUuidCol);
addIndex(context, tableName, "file_sources_updated_at", false, updatedAtCol);
}
private void createGroupRoles(Context context) {
String tableName = "group_roles";
VarcharColumnDef roleCol = newVarcharColumnDefBuilder("role").setLimit(64).setIsNullable(false).build();
VarcharColumnDef componentUuidCol = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setIsNullable(true).setLimit(UUID_SIZE).build();
VarcharColumnDef groupUuidCol = newVarcharColumnDefBuilder(GROUP_UUID_COL_NAME).setIsNullable(true).setLimit(UUID_SIZE).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(roleCol)
.addColumn(componentUuidCol)
.addColumn(groupUuidCol)
.build());
addIndex(context, tableName, "group_roles_component_uuid", false, componentUuidCol);
addIndex(context, tableName, "uniq_group_roles", true, groupUuidCol, componentUuidCol, roleCol);
}
private void createGroups(Context context) {
String tableName = "groups";
VarcharColumnDef nameCol = newVarcharColumnDefBuilder("name").setLimit(500).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(nameCol)
.addColumn(newVarcharColumnDefBuilder(DESCRIPTION_COL_NAME).setLimit(200).setIsNullable(true).build())
.addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
.addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
.build());
addIndex(context, tableName, "uniq_groups_name", true, nameCol);
}
private void createGroupsUsers(Context context) {
String tableName = "groups_users";
VarcharColumnDef groupUuidCol = newVarcharColumnDefBuilder(GROUP_UUID_COL_NAME).setLimit(40).setIsNullable(false).build();
VarcharColumnDef userUuidCol = newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setLimit(255).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addColumn(groupUuidCol)
.addColumn(userUuidCol)
.build());
addIndex(context, tableName, "index_groups_users_group_uuid", false, groupUuidCol);
addIndex(context, tableName, "index_groups_users_user_uuid", false, userUuidCol);
addIndex(context, tableName, "groups_users_unique", true, userUuidCol, groupUuidCol);
}
private void createInternalComponentProps(Context context) {
String tableName = "internal_component_props";
VarcharColumnDef componentUuidCol = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
VarcharColumnDef keeCol = newVarcharColumnDefBuilder("kee").setIsNullable(false).setLimit(512).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(componentUuidCol)
.addColumn(keeCol)
.addColumn(newVarcharColumnDefBuilder(VALUE_COL_NAME).setIsNullable(true).setLimit(MAX_SIZE).build())
.addColumn(TECHNICAL_UPDATED_AT_COL)
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "unique_component_uuid_kee", true, componentUuidCol, keeCol);
}
private void createInternalProperties(Context context) {
context.execute(
newTableBuilder("internal_properties")
.addPkColumn(newVarcharColumnDefBuilder("kee").setLimit(20).setIsNullable(false).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName(IS_EMPTY_COL_NAME).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName(TEXT_VALUE_COL_NAME).setLimit(MAX_SIZE).setIgnoreOracleUnit(true).build())
.addColumn(newClobColumnDefBuilder().setColumnName(CLOB_VALUE_COL_NAME).setIsNullable(true).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
}
private void createIssueChanges(Context context) {
String tableName = "issue_changes";
VarcharColumnDef issueKeyCol = newVarcharColumnDefBuilder("issue_key").setLimit(50).setIsNullable(false).build();
VarcharColumnDef keeCol = newVarcharColumnDefBuilder("kee").setLimit(50).build();
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setLimit(50).setIsNullable(false).build();
VarcharColumnDef changeTypeCol = newVarcharColumnDefBuilder("change_type").setLimit(20).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(keeCol)
.addColumn(issueKeyCol)
.addColumn(newVarcharColumnDefBuilder("user_login").setLimit(USER_UUID_SIZE).build())
.addColumn(changeTypeCol)
.addColumn(newClobColumnDefBuilder().setColumnName("change_data").build())
.addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
.addColumn(NULLABLE_TECHNICAL_UPDATED_AT_COL)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_change_creation_date").build())
.addColumn(projectUuidCol)
.build());
addIndex(context, tableName, "issue_changes_issue_key", false, issueKeyCol);
addIndex(context, tableName, "issue_changes_kee", false, keeCol);
addIndex(context, tableName, "issue_changes_project_uuid", false, projectUuidCol);
addIndex(context, tableName, "issue_changes_issue_key_type", false, issueKeyCol, changeTypeCol);
}
private void createIssues(Context context) {
var tableName = "issues";
VarcharColumnDef assigneeCol = newVarcharColumnDefBuilder("assignee").setLimit(USER_UUID_SIZE).build();
VarcharColumnDef componentUuidCol = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setLimit(50).build();
BigIntegerColumnDef issueCreationDateCol = newBigIntegerColumnDefBuilder().setColumnName("issue_creation_date").build();
VarcharColumnDef keeCol = newVarcharColumnDefBuilder("kee").setLimit(50).setIsNullable(false).build();
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setLimit(50).build();
VarcharColumnDef resolutionCol = newVarcharColumnDefBuilder("resolution").setLimit(20).build();
VarcharColumnDef ruleUuidCol = newVarcharColumnDefBuilder(RULE_UUID_COL_NAME).setLimit(40).setIsNullable(true).build();
BigIntegerColumnDef updatedAtCol = NULLABLE_TECHNICAL_UPDATED_AT_COL;
context.execute(
newTableBuilder(tableName)
.addPkColumn(keeCol)
.addColumn(ruleUuidCol)
.addColumn(newVarcharColumnDefBuilder("severity").setLimit(10).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("manual_severity").setIsNullable(false).build())
// unit has been fixed in SonarQube 5.6 (see migration 1151, SONAR-7493)
.addColumn(newVarcharColumnDefBuilder("message").setLimit(MAX_SIZE).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("line").build())
.addColumn(newDecimalColumnDefBuilder().setColumnName("gap").setPrecision(30).setScale(20).build())
.addColumn(newVarcharColumnDefBuilder(STATUS_COL_NAME).setLimit(20).build())
.addColumn(resolutionCol)
.addColumn(newVarcharColumnDefBuilder("checksum").setLimit(1000).build())
.addColumn(assigneeCol)
.addColumn(newVarcharColumnDefBuilder("author_login").setLimit(255).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("effort").build())
.addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
.addColumn(updatedAtCol)
.addColumn(issueCreationDateCol)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_update_date").build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_close_date").build())
.addColumn(newVarcharColumnDefBuilder("tags").setLimit(MAX_SIZE).build())
.addColumn(componentUuidCol)
.addColumn(projectUuidCol)
.addColumn(newBlobColumnDefBuilder().setColumnName("locations").build())
.addColumn(new TinyIntColumnDef.Builder().setColumnName("issue_type").build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("from_hotspot").setIsNullable(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("quick_fix_available").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("rule_description_context_key").setLimit(50).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("message_formattings").build())
.build());
addIndex(context, tableName, "issues_assignee", false, assigneeCol);
addIndex(context, tableName, "issues_component_uuid", false, componentUuidCol);
addIndex(context, tableName, "issues_creation_date", false, issueCreationDateCol);
addIndex(context, tableName, "issues_project_uuid", false, projectUuidCol);
addIndex(context, tableName, "issues_resolution", false, resolutionCol);
addIndex(context, tableName, "issues_updated_at", false, updatedAtCol);
addIndex(context, tableName, "issues_rule_uuid", false, ruleUuidCol);
}
private void createLiveMeasures(Context context) {
String tableName = "live_measures";
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
VarcharColumnDef componentUuidCol = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
VarcharColumnDef metricUuidCol = newVarcharColumnDefBuilder(METRIC_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(projectUuidCol)
.addColumn(componentUuidCol)
.addColumn(metricUuidCol)
.addColumn(newDecimalColumnDefBuilder().setColumnName(VALUE_COL_NAME).setPrecision(38).setScale(20).build())
.addColumn(newVarcharColumnDefBuilder(TEXT_VALUE_COL_NAME).setIsNullable(true).setLimit(MAX_SIZE).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("measure_data").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("update_marker").setIsNullable(true).setLimit(UUID_SIZE).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.build());
addIndex(context, tableName, "live_measures_project", false, projectUuidCol);
addIndex(context, tableName, "live_measures_component", true, componentUuidCol, metricUuidCol);
}
private void createMetrics(Context context) {
String tableName = "metrics";
VarcharColumnDef nameCol = newVarcharColumnDefBuilder("name").setLimit(64).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(nameCol)
.addColumn(newVarcharColumnDefBuilder(DESCRIPTION_COL_NAME).setLimit(255).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("direction").setIsNullable(false).setDefaultValue(0).build())
.addColumn(newVarcharColumnDefBuilder("domain").setLimit(64).build())
.addColumn(newVarcharColumnDefBuilder("short_name").setLimit(64).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("qualitative").setDefaultValue(false).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder("val_type").setLimit(8).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("enabled").setDefaultValue(true).build())
.addColumn(newDecimalColumnDefBuilder().setColumnName("worst_value").setPrecision(38).setScale(20).build())
.addColumn(newDecimalColumnDefBuilder().setColumnName("best_value").setPrecision(38).setScale(20).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("optimized_best_value").build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("hidden").build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("delete_historical_data").build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("decimal_scale").build())
.build());
addIndex(context, tableName, "metrics_unique_name", true, nameCol);
}
private void createNewCodePeriods(Context context) {
String tableName = "new_code_periods";
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build();
VarcharColumnDef branchUuidCol = newVarcharColumnDefBuilder(BRANCH_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build();
VarcharColumnDef typeCol = newVarcharColumnDefBuilder("type").setLimit(30).setIsNullable(false).build();
VarcharColumnDef valueCol = newVarcharColumnDefBuilder(VALUE_COL_NAME).setLimit(255).setIsNullable(true).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(projectUuidCol)
.addColumn(branchUuidCol)
.addColumn(typeCol)
.addColumn(valueCol)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "uniq_new_code_periods", true, projectUuidCol, branchUuidCol);
addIndex(context, tableName, "idx_ncp_type", false, typeCol);
addIndex(context, tableName, "idx_ncp_value", false, valueCol);
}
private void createNewCodeReferenceIssues(Context context) {
String tableName = "new_code_reference_issues";
VarcharColumnDef issueKeyCol = newVarcharColumnDefBuilder("issue_key").setLimit(50).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(issueKeyCol)
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "uniq_new_code_reference_issues", true, issueKeyCol);
}
private void createNotifications(Context context) {
context.execute(
newTableBuilder("notifications")
.addPkColumn(UUID_COL)
.addColumn(newBlobColumnDefBuilder().setColumnName("data").build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
}
private void createOrgQProfiles(Context context) {
String tableName = "org_qprofiles";
int profileUuidSize = 255;
VarcharColumnDef rulesProfileUuidCol = newVarcharColumnDefBuilder("rules_profile_uuid").setLimit(profileUuidSize).setIsNullable(false).build();
VarcharColumnDef parentUuidCol = newVarcharColumnDefBuilder("parent_uuid").setLimit(profileUuidSize).setIsNullable(true).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(255).build())
.addColumn(rulesProfileUuidCol)
.addColumn(parentUuidCol)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("last_used").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("user_updated_at").setIsNullable(true).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.build());
addIndex(context, tableName, "qprofiles_rp_uuid", false, rulesProfileUuidCol);
addIndex(context, tableName, "org_qprofiles_parent_uuid", false, parentUuidCol);
}
private void createPermTemplatesGroups(Context context) {
context.execute(
newTableBuilder("perm_templates_groups")
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("permission_reference").setLimit(64).setIsNullable(false).build())
.addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
.addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
.addColumn(newVarcharColumnDefBuilder(TEMPLATE_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder(GROUP_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build())
.build());
}
private void createPermTemplatesUsers(Context context) {
context.execute(
newTableBuilder("perm_templates_users")
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("permission_reference").setLimit(64).setIsNullable(false).build())
.addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
.addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
.addColumn(newVarcharColumnDefBuilder(TEMPLATE_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setLimit(USER_UUID_SIZE).setIsNullable(false).build())
.build());
}
private void createPermTemplatesCharacteristics(Context context) {
String tableName = "perm_tpl_characteristics";
VarcharColumnDef permissionKeyColumn = newVarcharColumnDefBuilder("permission_key").setLimit(64).setIsNullable(false).build();
VarcharColumnDef templateUuidColumn = newVarcharColumnDefBuilder(TEMPLATE_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(permissionKeyColumn)
.addColumn(newBooleanColumnDefBuilder().setColumnName("with_project_creator").setIsNullable(false).setDefaultValue(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.addColumn(templateUuidColumn)
.build());
addIndex(context, tableName, "uniq_perm_tpl_charac", true, templateUuidColumn, permissionKeyColumn);
}
private void createPermissionTemplates(Context context) {
context.execute(
newTableBuilder("permission_templates")
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("name").setLimit(100).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder(DESCRIPTION_COL_NAME).setLimit(MAX_SIZE).build())
.addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
.addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
.addColumn(newVarcharColumnDefBuilder("key_pattern").setLimit(500).build())
.build());
}
private void createPlugins(Context context) {
int pluginKeyMaxSize = 200;
String tableName = "plugins";
VarcharColumnDef keyColumn = newVarcharColumnDefBuilder("kee").setLimit(pluginKeyMaxSize).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(keyColumn)
.addColumn(newVarcharColumnDefBuilder("base_plugin_key").setLimit(pluginKeyMaxSize).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("file_hash").setLimit(200).setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.addColumn(newVarcharColumnDefBuilder("type").setLimit(10).setIsNullable(false).build())
.addColumn(newBooleanColumnDefBuilder("removed").setDefaultValue(false).setIsNullable(false).build())
.build());
addIndex(context, tableName, "plugins_key", true, keyColumn);
}
private void createPortfolioProjBranches(Context context) {
String tableName = "portfolio_proj_branches";
context.execute(new CreateTableBuilder(getDialect(), tableName)
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder().setColumnName("portfolio_project_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName(BRANCH_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
}
private void createPortfolioProjects(Context context) {
String tableName = "portfolio_projects";
VarcharColumnDef portfolioUuidColumn = newVarcharColumnDefBuilder().setColumnName("portfolio_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef projectUuidColumn = newVarcharColumnDefBuilder().setColumnName(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
context.execute(new CreateTableBuilder(getDialect(), tableName)
.addPkColumn(UUID_COL)
.addColumn(portfolioUuidColumn)
.addColumn(projectUuidColumn)
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "uniq_portfolio_projects", true, portfolioUuidColumn, projectUuidColumn);
}
private void createPortfolioReferences(Context context) {
String tableName = "portfolio_references";
VarcharColumnDef portfolioUuidColumn = newVarcharColumnDefBuilder().setColumnName("portfolio_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef referenceUuidColumn = newVarcharColumnDefBuilder().setColumnName("reference_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef branchUuidColumn = newVarcharColumnDefBuilder().setColumnName(BRANCH_UUID_COL_NAME).setIsNullable(true).setLimit(255).build();
context.execute(new CreateTableBuilder(getDialect(), tableName)
.addPkColumn(UUID_COL)
.addColumn(portfolioUuidColumn)
.addColumn(referenceUuidColumn)
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(branchUuidColumn)
.build());
addIndex(context, tableName, "uniq_portfolio_references", true, portfolioUuidColumn, referenceUuidColumn, branchUuidColumn);
}
private void createPortfolios(Context context) {
String tableName = "portfolios";
VarcharColumnDef keeColumn = newVarcharColumnDefBuilder().setColumnName("kee").setIsNullable(false).setLimit(400).build();
context.execute(new CreateTableBuilder(getDialect(), tableName)
.addPkColumn(UUID_COL)
.addColumn(keeColumn)
.addColumn(newVarcharColumnDefBuilder().setColumnName("name").setIsNullable(false).setLimit(2000).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName(DESCRIPTION_COL_NAME).setIsNullable(true).setLimit(2000).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("root_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("parent_uuid").setIsNullable(true).setLimit(UUID_SIZE).build())
.addColumn(newBooleanColumnDefBuilder(PRIVATE_COL_NAME).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("selection_mode").setIsNullable(false).setLimit(50).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("selection_expression").setIsNullable(true).setLimit(4000).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.addColumn(newVarcharColumnDefBuilder().setColumnName("branch_key").setIsNullable(true).setLimit(255).build())
.build());
addIndex(context, tableName, "uniq_portfolios_kee", true, keeColumn);
}
private void createProjectBadgeToken(Context context) {
String tableName = "project_badge_token";
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("token").setIsNullable(false).setLimit(255).build())
.addColumn(projectUuidCol)
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.build());
addIndex(context, tableName, "uniq_project_badge_token", true, projectUuidCol);
}
private void createProjectBranches(Context context) {
String tableName = "project_branches";
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
VarcharColumnDef keeCol = newVarcharColumnDefBuilder("kee").setIsNullable(false).setLimit(255).build();
VarcharColumnDef branchTypeCol = newVarcharColumnDefBuilder("branch_type").setIsNullable(false).setLimit(12).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(newVarcharColumnDefBuilder("uuid").setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build())
.addColumn(projectUuidCol)
.addColumn(keeCol)
.addColumn(branchTypeCol)
.addColumn(newVarcharColumnDefBuilder("merge_branch_uuid").setIsNullable(true).setLimit(OLD_UUID_VARCHAR_SIZE).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("pull_request_binary").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("manual_baseline_analysis_uuid").setIsNullable(true).setLimit(UUID_SIZE).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.addColumn(newBooleanColumnDefBuilder("exclude_from_purge").setDefaultValue(false).setIsNullable(false).build())
.addColumn(newBooleanColumnDefBuilder("need_issue_sync").setIsNullable(false).build())
.build());
addIndex(context, tableName, "uniq_project_branches", true, branchTypeCol, projectUuidCol, keeCol);
}
private void createProjectLinks(Context context) {
String tableName = "project_links";
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(projectUuidCol)
.addColumn(newVarcharColumnDefBuilder("link_type").setLimit(20).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder("name").setLimit(128).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("href").setLimit(2048).setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.build());
addIndex(context, tableName, "project_links_project", false, projectUuidCol);
}
private void createProjectMappings(Context context) {
String tableName = "project_mappings";
VarcharColumnDef keyTypeCol = newVarcharColumnDefBuilder("key_type").setIsNullable(false).setLimit(200).build();
VarcharColumnDef keyCol = newVarcharColumnDefBuilder("kee").setIsNullable(false).setLimit(MAX_SIZE).build();
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(keyTypeCol)
.addColumn(keyCol)
.addColumn(projectUuidCol)
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "key_type_kee", true, keyTypeCol, keyCol);
addIndex(context, tableName, PROJECT_UUID_COL_NAME, false, projectUuidCol);
}
private void createProjectMeasures(Context context) {
String tableName = "project_measures";
IntegerColumnDef personIdCol = newIntegerColumnDefBuilder().setColumnName("person_id").build();
VarcharColumnDef metricUuidCol = newVarcharColumnDefBuilder(METRIC_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
VarcharColumnDef analysisUuidCol = newVarcharColumnDefBuilder(ANALYSIS_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
VarcharColumnDef componentUuidCol = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(newDecimalColumnDefBuilder().setColumnName(VALUE_COL_NAME).setPrecision(38).setScale(20).build())
.addColumn(analysisUuidCol)
.addColumn(componentUuidCol)
.addColumn(newVarcharColumnDefBuilder(TEXT_VALUE_COL_NAME).setLimit(MAX_SIZE).build())
.addColumn(newVarcharColumnDefBuilder("alert_status").setLimit(5).build())
.addColumn(newVarcharColumnDefBuilder("alert_text").setLimit(MAX_SIZE).build())
.addColumn(personIdCol)
.addColumn(newBlobColumnDefBuilder().setColumnName("measure_data").build())
.addColumn(metricUuidCol)
.build());
addIndex(context, tableName, "measures_component_uuid", false, componentUuidCol);
addIndex(context, tableName, "measures_analysis_metric", false, analysisUuidCol, metricUuidCol);
addIndex(context, tableName, "project_measures_metric", false, metricUuidCol);
}
private void createProjectQprofiles(Context context) {
String tableName = "project_qprofiles";
VarcharColumnDef projectUuid = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setLimit(50).setIsNullable(false).build();
VarcharColumnDef profileKey = newVarcharColumnDefBuilder("profile_key").setLimit(50).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(projectUuid)
.addColumn(profileKey)
.build());
addIndex(context, tableName, "uniq_project_qprofiles", true, projectUuid, profileKey);
}
private void createProjects(Context context) {
String tableName = "projects";
VarcharColumnDef uuidCol = UUID_COL;
VarcharColumnDef keeCol = newVarcharColumnDefBuilder("kee").setLimit(400).setIsNullable(false).build();
VarcharColumnDef qualifierCol = newVarcharColumnDefBuilder("qualifier").setLimit(10).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(uuidCol)
.addColumn(keeCol)
.addColumn(qualifierCol)
.addColumn(newVarcharColumnDefBuilder("name").setLimit(2_000).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder(DESCRIPTION_COL_NAME).setLimit(2_000).setIsNullable(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName(PRIVATE_COL_NAME).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder("tags").setLimit(500).setIsNullable(true).build())
.addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.withPkConstraintName("pk_new_projects")
.build());
addIndex(context, tableName, "uniq_projects_kee", true, keeCol);
addIndex(context, tableName, "idx_qualifier", false, qualifierCol);
}
private void createProjectQGates(Context context) {
String tableName = "project_qgates";
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
VarcharColumnDef qualityGateUuidCol = newVarcharColumnDefBuilder(QUALITY_GATE_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(projectUuidCol)
.addColumn(qualityGateUuidCol)
.build());
addIndex(context, tableName, "uniq_project_qgates", true, projectUuidCol, qualityGateUuidCol);
}
private void createProperties(Context context) {
String tableName = "properties";
VarcharColumnDef propKey = newVarcharColumnDefBuilder("prop_key").setLimit(512).setIsNullable(false).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(propKey)
.addColumn(newBooleanColumnDefBuilder().setColumnName(IS_EMPTY_COL_NAME).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder(TEXT_VALUE_COL_NAME).setLimit(MAX_SIZE).build())
.addColumn(newClobColumnDefBuilder().setColumnName(CLOB_VALUE_COL_NAME).setIsNullable(true).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(newVarcharColumnDefBuilder().setColumnName(COMPONENT_UUID_COL_NAME).setIsNullable(true).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName(USER_UUID_COL_NAME).setIsNullable(true).setLimit(USER_UUID_SIZE).build())
// table with be renamed to properties in following migration, use final constraint name right away
.withPkConstraintName("pk_properties")
.build());
addIndex(context, tableName, "properties_key", false, propKey);
}
private void createPushEvents(Context context) {
String tableName = "push_events";
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("name").setLimit(40).setIsNullable(false).build())
.addColumn(projectUuidCol)
.addColumn(newBlobColumnDefBuilder().setColumnName("payload").setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(newVarcharColumnDefBuilder(LANGUAGE_COL_NAME).setLimit(20).build())
.build());
addIndex(context, tableName, "idx_push_even_crea_uuid_proj", false, TECHNICAL_CREATED_AT_COL, UUID_COL, projectUuidCol);
}
private void createQGateGroupPermissions(Context context) {
String tableName = "qgate_group_permissions";
VarcharColumnDef qualityGateUuidColumn = newVarcharColumnDefBuilder(QUALITY_GATE_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(qualityGateUuidColumn)
.addColumn(newVarcharColumnDefBuilder(GROUP_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "qg_groups_uuid_idx", false, qualityGateUuidColumn);
}
private void createQGateUserPermissions(Context context) {
String tableName = "qgate_user_permissions";
VarcharColumnDef qualityGateUuidColumn = newVarcharColumnDefBuilder(QUALITY_GATE_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(qualityGateUuidColumn)
.addColumn(newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "quality_gate_uuid_idx", false, qualityGateUuidColumn);
}
private void createQProfileChanges(Context context) {
String tableName = "qprofile_changes";
VarcharColumnDef rulesProfileUuidCol = newVarcharColumnDefBuilder("rules_profile_uuid").setLimit(255).setIsNullable(false).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(newVarcharColumnDefBuilder("kee").setLimit(UUID_SIZE).setIsNullable(false).build())
.addColumn(rulesProfileUuidCol)
.addColumn(newVarcharColumnDefBuilder("change_type").setLimit(20).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setLimit(USER_UUID_SIZE).setIsNullable(true).build())
.addColumn(newClobColumnDefBuilder().setColumnName("change_data").setIsNullable(true).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "qp_changes_rules_profile_uuid", false, rulesProfileUuidCol);
}
private void createQProfileEditGroups(Context context) {
String tableName = "qprofile_edit_groups";
VarcharColumnDef qProfileUuidCol = newVarcharColumnDefBuilder(QPROFILE_UUID_COL_NAME).setIsNullable(false).setLimit(255).build();
VarcharColumnDef groupUuidCol = newVarcharColumnDefBuilder(GROUP_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(qProfileUuidCol)
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(groupUuidCol)
.build());
addIndex(context, tableName, tableName + "_qprofile", false, qProfileUuidCol);
addIndex(context, tableName, tableName + UNIQUE_INDEX_SUFFIX, true, groupUuidCol, qProfileUuidCol);
}
private void createQProfileEditUsers(Context context) {
String tableName = "qprofile_edit_users";
VarcharColumnDef qProfileUuidCol = newVarcharColumnDefBuilder(QPROFILE_UUID_COL_NAME).setLimit(255).setIsNullable(false).build();
VarcharColumnDef userUuidCol = newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setLimit(255).setIsNullable(false).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(qProfileUuidCol)
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(userUuidCol)
.build());
addIndex(context, tableName, tableName + "_qprofile", false, qProfileUuidCol);
addIndex(context, tableName, tableName + UNIQUE_INDEX_SUFFIX, true, userUuidCol, qProfileUuidCol);
}
private void createQualityGateConditions(Context context) {
context.execute(
newTableBuilder("quality_gate_conditions")
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("operator").setLimit(3).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("value_error").setLimit(64).setIsNullable(true).build())
.addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
.addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
.addColumn(newVarcharColumnDefBuilder(METRIC_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder("qgate_uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
.build());
}
private void createQualityGates(Context context) {
context.execute(
newTableBuilder("quality_gates")
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("name").setLimit(100).setIsNullable(false).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("is_built_in").setIsNullable(false).build())
.addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
.addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
.build());
}
private void createScimUsers(Context context) {
String tableName = "scim_users";
VarcharColumnDef userUuidCol = newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("scim_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(userUuidCol)
.build());
addIndex(context, tableName, "uniq_scim_users_user_uuid", true, userUuidCol);
}
private void createSessionTokens(Context context) {
String tableName = "session_tokens";
VarcharColumnDef userUuidCol = newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setLimit(255).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(userUuidCol)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName(EXPIRATION_DATE_COL_NAME).setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(TECHNICAL_UPDATED_AT_COL)
.build());
addIndex(context, tableName, "session_tokens_user_uuid", false, userUuidCol);
}
private void createRulesRepository(Context context) {
String tableName = "rule_repositories";
context.execute(newTableBuilder(tableName)
.addPkColumn(newVarcharColumnDefBuilder("kee").setLimit(200).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder(LANGUAGE_COL_NAME).setLimit(20).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder("name").setLimit(4_000).setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
}
private void createRuleDescSections(Context context) {
String tableName = "rule_desc_sections";
VarcharColumnDef ruleUuidCol = newVarcharColumnDefBuilder().setColumnName(RULE_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
VarcharColumnDef keeCol = newVarcharColumnDefBuilder().setColumnName("kee").setIsNullable(false).setLimit(DESCRIPTION_SECTION_KEY_SIZE).build();
VarcharColumnDef contextKeyCol = newVarcharColumnDefBuilder().setColumnName("context_key").setIsNullable(true).setLimit(DESCRIPTION_SECTION_KEY_SIZE).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(ruleUuidCol)
.addColumn(keeCol)
.addColumn(newClobColumnDefBuilder().setColumnName("content").setIsNullable(false).build())
.addColumn(contextKeyCol)
.addColumn(newVarcharColumnDefBuilder().setColumnName("context_display_name").setIsNullable(true).setLimit(50).build())
.build());
addIndex(context, tableName, "uniq_rule_desc_sections", true, ruleUuidCol, keeCol, contextKeyCol);
}
private void createRules(Context context) {
VarcharColumnDef pluginRuleKeyCol = newVarcharColumnDefBuilder("plugin_rule_key").setLimit(200).setIsNullable(false).build();
VarcharColumnDef pluginNameCol = newVarcharColumnDefBuilder("plugin_name").setLimit(255).setIsNullable(false).build();
context.execute(
newTableBuilder("rules")
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("name").setLimit(200).setIsNullable(true).build())
.addColumn(pluginRuleKeyCol)
.addColumn(newVarcharColumnDefBuilder("plugin_key").setLimit(200).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("plugin_config_key").setLimit(200).setIsNullable(true).build())
.addColumn(pluginNameCol)
.addColumn(newVarcharColumnDefBuilder("scope").setLimit(20).setIsNullable(false).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("priority").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder(STATUS_COL_NAME).setLimit(40).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder(LANGUAGE_COL_NAME).setLimit(20).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("def_remediation_function").setLimit(20).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("def_remediation_gap_mult").setLimit(20).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("def_remediation_base_effort").setLimit(20).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("gap_description").setLimit(MAX_SIZE).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("system_tags").setLimit(MAX_SIZE).setIsNullable(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("is_template").setIsNullable(false).setDefaultValue(false).build())
.addColumn(newVarcharColumnDefBuilder("description_format").setLimit(20).setIsNullable(true).build())
.addColumn(new TinyIntColumnDef.Builder().setColumnName("rule_type").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("security_standards").setIsNullable(true).setLimit(4_000).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("is_ad_hoc").setIsNullable(false).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("is_external").setIsNullable(false).build())
.addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
.addColumn(NULLABLE_TECHNICAL_UPDATED_AT_COL)
.addColumn(newVarcharColumnDefBuilder(TEMPLATE_UUID_COL_NAME).setIsNullable(true).setLimit(UUID_SIZE).build())
.addColumn(newClobColumnDefBuilder().setColumnName("note_data").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("note_user_uuid").setLimit(USER_UUID_SIZE).setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("note_created_at").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("note_updated_at").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("remediation_function").setLimit(20).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("remediation_gap_mult").setLimit(20).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("remediation_base_effort").setLimit(20).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("tags").setLimit(4_000).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("ad_hoc_name").setLimit(200).setIsNullable(true).build())
.addColumn(newClobColumnDefBuilder().setColumnName("ad_hoc_description").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("ad_hoc_severity").setLimit(10).setIsNullable(true).build())
.addColumn(newTinyIntColumnDefBuilder().setColumnName("ad_hoc_type").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("education_principles").setLimit(255).setIsNullable(true).build())
.build());
addIndex(context, "rules", "rules_repo_key", true, pluginRuleKeyCol, pluginNameCol);
}
private void createRulesParameters(Context context) {
String tableName = "rules_parameters";
VarcharColumnDef ruleUuidCol = newVarcharColumnDefBuilder(RULE_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
VarcharColumnDef nameCol = newVarcharColumnDefBuilder("name").setLimit(128).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(nameCol)
.addColumn(newVarcharColumnDefBuilder(DESCRIPTION_COL_NAME).setLimit(MAX_SIZE).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("param_type").setLimit(512).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder("default_value").setLimit(MAX_SIZE).setIsNullable(true).build())
.addColumn(ruleUuidCol)
.build());
addIndex(context, tableName, "rules_parameters_rule_uuid", false, ruleUuidCol);
addIndex(context, tableName, "rules_parameters_unique", true, ruleUuidCol, nameCol);
}
private void createRulesProfiles(Context context) {
String tableName = "rules_profiles";
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("name").setLimit(100).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder(LANGUAGE_COL_NAME).setLimit(20).setIsNullable(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("is_built_in").setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder("rules_updated_at").setLimit(100).setIsNullable(true).build())
.addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
.addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
.build());
}
private void createSamlMessageIds(Context context) {
String tableName = "saml_message_ids";
VarcharColumnDef messageIdCol = newVarcharColumnDefBuilder("message_id").setLimit(255).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(messageIdCol)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName(EXPIRATION_DATE_COL_NAME).setIsNullable(false).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "saml_message_ids_unique", true, messageIdCol);
}
private void createScannerAnalysisCache(Context context) {
String tableName = "scanner_analysis_cache";
context.execute(
newTableBuilder(tableName)
.addPkColumn(newVarcharColumnDefBuilder().setColumnName(BRANCH_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newBlobColumnDefBuilder().setColumnName("data").setIsNullable(false).build())
.build());
}
private void createSnapshots(Context context) {
String tableName = "snapshots";
VarcharColumnDef uuidCol = newVarcharColumnDefBuilder("uuid").setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
VarcharColumnDef componentUuidCol = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(uuidCol)
.addColumn(componentUuidCol)
.addColumn(newVarcharColumnDefBuilder(STATUS_COL_NAME).setLimit(4).setIsNullable(false).setDefaultValue("U").build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("islast").setIsNullable(false).setDefaultValue(false).build())
.addColumn(newVarcharColumnDefBuilder("version").setLimit(500).setIsNullable(true).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("purge_status").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("build_string").setLimit(100).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("revision").setLimit(100).setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("build_date").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("period1_mode").setLimit(100).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("period1_param").setLimit(100).setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("period1_date").setIsNullable(true).build())
.addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "snapshot_component", false, componentUuidCol);
}
private void createUserRoles(Context context) {
String tableName = "user_roles";
VarcharColumnDef componentUuidCol = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build();
VarcharColumnDef userUuidCol = newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setLimit(USER_UUID_SIZE).setIsNullable(true).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(newVarcharColumnDefBuilder("role").setLimit(64).setIsNullable(false).build())
.addColumn(componentUuidCol)
.addColumn(userUuidCol)
.build());
addIndex(context, tableName, "user_roles_component_uuid", false, componentUuidCol);
addIndex(context, tableName, "user_roles_user", false, userUuidCol);
}
private void createUserDismissedMessage(Context context) {
String tableName = "user_dismissed_messages";
VarcharColumnDef userUuidCol = newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setLimit(USER_UUID_SIZE).setIsNullable(false).build();
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
VarcharColumnDef messageTypeCol = newVarcharColumnDefBuilder("message_type").setLimit(255).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(userUuidCol)
.addColumn(projectUuidCol)
.addColumn(messageTypeCol)
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, "uniq_user_dismissed_messages", true, userUuidCol, projectUuidCol, messageTypeCol);
addIndex(context, tableName, "udm_project_uuid", false, projectUuidCol);
addIndex(context, tableName, "udm_message_type", false, messageTypeCol);
}
private void createUserTokens(Context context) {
String tableName = "user_tokens";
VarcharColumnDef userUuidCol = newVarcharColumnDefBuilder(USER_UUID_COL_NAME).setLimit(USER_UUID_SIZE).setIsNullable(false).build();
VarcharColumnDef nameCol = newVarcharColumnDefBuilder("name").setLimit(100).setIsNullable(false).build();
VarcharColumnDef tokenHashCol = newVarcharColumnDefBuilder("token_hash").setLimit(255).setIsNullable(false).build();
VarcharColumnDef projectKeyCol = newVarcharColumnDefBuilder("project_key").setLimit(255).setIsNullable(true).build();
VarcharColumnDef typeCol = newVarcharColumnDefBuilder("type").setLimit(100).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(userUuidCol)
.addColumn(nameCol)
.addColumn(tokenHashCol)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("last_connection_date").setIsNullable(true).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(projectKeyCol)
.addColumn(typeCol)
.addColumn(newBigIntegerColumnDefBuilder().setColumnName(EXPIRATION_DATE_COL_NAME).setIsNullable(true).build())
.build());
addIndex(context, tableName, "user_tokens_user_uuid_name", true, userUuidCol, nameCol);
addIndex(context, tableName, "user_tokens_token_hash", true, tokenHashCol);
}
private void createUsers(Context context) {
String tableName = "users";
VarcharColumnDef loginCol = newVarcharColumnDefBuilder("login").setLimit(255).setIsNullable(false).build();
VarcharColumnDef externalLoginCol = newVarcharColumnDefBuilder("external_login").setLimit(255).setIsNullable(false).build();
VarcharColumnDef externalIdentityProviderCol = newVarcharColumnDefBuilder("external_identity_provider").setLimit(100).setIsNullable(false).build();
VarcharColumnDef externalIdCol = newVarcharColumnDefBuilder("external_id").setLimit(255).setIsNullable(false).build();
context.execute(
newTableBuilder(tableName)
.addPkColumn(newVarcharColumnDefBuilder("uuid").setLimit(USER_UUID_SIZE).setIsNullable(false).build())
.addColumn(loginCol)
.addColumn(newVarcharColumnDefBuilder("name").setLimit(200).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("email").setLimit(100).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("crypted_password").setLimit(100).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("salt").setLimit(40).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("hash_method").setLimit(10).setIsNullable(true).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("active").setDefaultValue(true).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("scm_accounts").setLimit(MAX_SIZE).build())
.addColumn(externalLoginCol)
.addColumn(externalIdentityProviderCol)
.addColumn(externalIdCol)
.addColumn(newBooleanColumnDefBuilder().setColumnName("user_local").setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("homepage_type").setLimit(40).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("homepage_parameter").setLimit(40).setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("last_connection_date").setIsNullable(true).build())
.addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
.addColumn(NULLABLE_TECHNICAL_UPDATED_AT_COL)
.addColumn(newBooleanColumnDefBuilder().setColumnName("reset_password").setIsNullable(false).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("last_sonarlint_connection").setIsNullable(true).build())
.build());
addIndex(context, tableName, "users_login", true, loginCol);
addIndex(context, tableName, "users_updated_at", false, NULLABLE_TECHNICAL_UPDATED_AT_COL);
addIndex(context, tableName, "uniq_external_id", true, externalIdentityProviderCol, externalIdCol);
addIndex(context, tableName, "uniq_external_login", true, externalIdentityProviderCol, externalLoginCol);
}
private void createWebhookDeliveries(Context context) {
String tableName = "webhook_deliveries";
VarcharColumnDef componentUuidColumn = newVarcharColumnDefBuilder(COMPONENT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
VarcharColumnDef ceTaskUuidColumn = newVarcharColumnDefBuilder("ce_task_uuid").setLimit(UUID_SIZE).setIsNullable(true).build();
VarcharColumnDef webhookUuidColumn = newVarcharColumnDefBuilder("webhook_uuid").setLimit(UUID_SIZE).setIsNullable(false).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(webhookUuidColumn)
.addColumn(componentUuidColumn)
.addColumn(ceTaskUuidColumn)
.addColumn(newVarcharColumnDefBuilder(ANALYSIS_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build())
.addColumn(newVarcharColumnDefBuilder("name").setLimit(100).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder("url").setLimit(2_000).setIsNullable(false).build())
.addColumn(newBooleanColumnDefBuilder().setColumnName("success").setIsNullable(false).build())
.addColumn(newIntegerColumnDefBuilder().setColumnName("http_status").setIsNullable(true).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("duration_ms").setIsNullable(false).build())
.addColumn(newClobColumnDefBuilder().setColumnName("payload").setIsNullable(false).build())
.addColumn(newClobColumnDefBuilder().setColumnName("error_stacktrace").setIsNullable(true).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.build());
addIndex(context, tableName, COMPONENT_UUID_COL_NAME, false, componentUuidColumn);
addIndex(context, tableName, "ce_task_uuid", false, ceTaskUuidColumn);
addIndex(context, tableName, "idx_wbhk_dlvrs_wbhk_uuid", false, webhookUuidColumn);
}
private void createWebhooks(Context context) {
String tableName = "webhooks";
VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder(PROJECT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build();
context.execute(newTableBuilder(tableName)
.addPkColumn(UUID_COL)
.addColumn(projectUuidCol)
.addColumn(newVarcharColumnDefBuilder("name").setLimit(100).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder("url").setLimit(2_000).setIsNullable(false).build())
.addColumn(newVarcharColumnDefBuilder("secret").setLimit(200).setIsNullable(true).build())
.addColumn(TECHNICAL_CREATED_AT_COL)
.addColumn(NULLABLE_TECHNICAL_UPDATED_AT_COL)
.build());
}
private static void addIndex(Context context, String table, String index, boolean unique, ColumnDef firstColumn, ColumnDef... otherColumns) {
CreateIndexBuilder builder = new CreateIndexBuilder()
.setTable(table)
.setName(index)
.setUnique(unique);
concat(of(firstColumn), stream(otherColumns)).forEach(builder::addColumn);
context.execute(builder.build());
}
private CreateTableBuilder newTableBuilder(String tableName) {
return new CreateTableBuilder(getDialect(), tableName);
}
}
| 96,975 | 58.751078 | 174 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/DbVersion00.java | /*
* 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.v00;
import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
import org.sonar.server.platform.db.migration.version.DbVersion;
public class DbVersion00 implements DbVersion {
@Override
public void addSteps(MigrationStepRegistry registry) {
registry
.add(1, "Create initial schema", CreateInitialSchema.class)
.add(2, "Populate initial schema", PopulateInitialSchema.class);
}
}
| 1,317 | 38.939394 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchema.java | /*
* 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.v00;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.sonar.api.utils.System2;
import org.sonar.core.platform.SonarQubeVersion;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.Upsert;
import static java.util.Arrays.stream;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Stream.concat;
import static java.util.stream.Stream.of;
public class PopulateInitialSchema extends DataChange {
private static final String ADMINS_GROUP = "sonar-administrators";
private static final String USERS_GROUP = "sonar-users";
private static final String ADMIN_USER = "admin";
private static final String ADMIN_CRYPTED_PASSWORD = "$2a$12$uCkkXmhW5ThVK8mpBvnXOOJRLd64LJeHTeCkSuB3lfaR2N0AYBaSi";
private static final List<String> ADMIN_ROLES = Arrays.asList("admin", "profileadmin", "gateadmin", "provisioning", "applicationcreator", "portfoliocreator");
private final System2 system2;
private final UuidFactory uuidFactory;
private final SonarQubeVersion sonarQubeVersion;
public PopulateInitialSchema(Database db, System2 system2, UuidFactory uuidFactory, SonarQubeVersion sonarQubeVersion) {
super(db);
this.system2 = system2;
this.uuidFactory = uuidFactory;
this.sonarQubeVersion = sonarQubeVersion;
}
@Override
public void execute(Context context) throws SQLException {
String adminUserUuid = insertAdminUser(context);
Groups groups = insertGroups(context);
String defaultQGUuid = insertQualityGate(context);
insertInternalProperty(context);
insertProperties(context, defaultQGUuid);
insertGroupRoles(context, groups);
insertGroupUsers(context, adminUserUuid, groups);
}
private String insertAdminUser(Context context) throws SQLException {
truncateTable(context, "users");
long now = system2.now();
context.prepareUpsert("insert into users " +
"(uuid, login, name, email, external_id, external_login, external_identity_provider, user_local, crypted_password, salt, hash_method, reset_password, " +
"created_at, updated_at)" +
" values " +
"(?, ?, 'Administrator', null, 'admin', 'admin', 'sonarqube', ?, ?, null, 'BCRYPT', ?, ?, ?)")
.setString(1, uuidFactory.create())
.setString(2, ADMIN_USER)
.setBoolean(3, true)
.setString(4, ADMIN_CRYPTED_PASSWORD)
.setBoolean(5, true)
.setLong(6, now)
.setLong(7, now)
.execute()
.commit();
String res = context.prepareSelect("select uuid from users where login=?")
.setString(1, ADMIN_USER)
.get(t -> t.getString(1));
return requireNonNull(res);
}
private void insertInternalProperty(Context context) throws SQLException {
String tableName = "internal_properties";
truncateTable(context, tableName);
long now = system2.now();
Upsert upsert = context.prepareUpsert(createInsertStatement(tableName, "kee", "is_empty", "text_value", "created_at"));
upsert
.setString(1, "installation.date")
.setBoolean(2, false)
.setString(3, String.valueOf(system2.now()))
.setLong(4, now)
.addBatch();
upsert
.setString(1, "installation.version")
.setBoolean(2, false)
.setString(3, sonarQubeVersion.get().toString())
.setLong(4, now)
.addBatch();
upsert
.execute()
.commit();
}
private void insertProperties(Context context, String defaultQualityGate) throws SQLException {
var tableName = "properties";
truncateTable(context, tableName);
long now = system2.now();
var upsert = context
.prepareUpsert(createInsertStatement(tableName, "uuid", "prop_key", "is_empty", "text_value", "created_at"));
upsert.setString(1, uuidFactory.create())
.setString(2, "sonar.forceAuthentication")
.setBoolean(3, false)
.setString(4, "true")
.setLong(5, now)
.addBatch();
upsert
.setString(1, uuidFactory.create())
.setString(2, "projects.default.visibility")
.setBoolean(3, false)
.setString(4, "public")
.setLong(5, system2.now())
.addBatch();
upsert
.setString(1, uuidFactory.create())
.setString(2, "qualitygate.default")
.setBoolean(3, false)
.setString(4, defaultQualityGate)
.setLong(5, system2.now())
.addBatch();
upsert
.execute()
.commit();
}
private Groups insertGroups(Context context) throws SQLException {
truncateTable(context, "groups");
Date now = new Date(system2.now());
Upsert upsert = context.prepareUpsert(createInsertStatement(
"groups",
"uuid", "name", "description", "created_at", "updated_at"));
upsert
.setString(1, uuidFactory.create())
.setString(2, ADMINS_GROUP)
.setString(3, "System administrators")
.setDate(4, now)
.setDate(5, now)
.addBatch();
upsert
.setString(1, uuidFactory.create())
.setString(2, USERS_GROUP)
.setString(3, "Every authenticated user automatically belongs to this group")
.setDate(4, now)
.setDate(5, now)
.addBatch();
upsert
.execute()
.commit();
return new Groups(getGroupUuid(context, ADMINS_GROUP), getGroupUuid(context, USERS_GROUP));
}
private static String getGroupUuid(Context context, String groupName) throws SQLException {
String res = context.prepareSelect("select uuid from groups where name=?")
.setString(1, groupName)
.get(t -> t.getString(1));
return requireNonNull(res);
}
private String insertQualityGate(Context context) throws SQLException {
truncateTable(context, "quality_gates");
String uuid = uuidFactory.create();
Date now = new Date(system2.now());
context.prepareUpsert(createInsertStatement("quality_gates", "uuid", "name", "is_built_in", "created_at", "updated_at"))
.setString(1, uuid)
.setString(2, "Sonar way")
.setBoolean(3, true)
.setDate(4, now)
.setDate(5, now)
.execute()
.commit();
return uuid;
}
private record Groups(String adminGroupUuid, String userGroupUuid) {
}
private void insertGroupRoles(Context context, Groups groups) throws SQLException {
truncateTable(context, "group_roles");
Upsert upsert = context.prepareUpsert(createInsertStatement("group_roles", "uuid","group_uuid", "role"));
for (String adminRole : ADMIN_ROLES) {
upsert
.setString(1, uuidFactory.create())
.setString(2, groups.adminGroupUuid())
.setString(3, adminRole)
.addBatch();
}
for (String anyoneRole : Arrays.asList("scan", "provisioning")) {
upsert
.setString(1, uuidFactory.create())
.setString(2, groups.userGroupUuid())
.setString(3, anyoneRole)
.addBatch();
}
upsert
.execute()
.commit();
}
private static void insertGroupUsers(Context context, String adminUserUuid, Groups groups) throws SQLException {
truncateTable(context, "groups_users");
Upsert upsert = context.prepareUpsert(createInsertStatement("groups_users", "user_uuid", "group_uuid"));
upsert
.setString(1, adminUserUuid)
.setString(2, groups.userGroupUuid())
.addBatch();
upsert
.setString(1, adminUserUuid)
.setString(2, groups.adminGroupUuid())
.addBatch();
upsert
.execute()
.commit();
}
private static void truncateTable(Context context, String table) throws SQLException {
context.prepareUpsert("truncate table " + table).execute().commit();
}
private static String createInsertStatement(String tableName, String firstColumn, String... otherColumns) {
return "insert into " + tableName + " " +
"(" + concat(of(firstColumn), stream(otherColumns)).collect(joining(",")) + ")" +
" values" +
" (" + concat(of(firstColumn), stream(otherColumns)).map(t -> "?").collect(joining(",")) + ")";
}
}
| 9,034 | 33.88417 | 160 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/package-info.java | /*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.server.platform.db.migration.version.v00;
import javax.annotation.ParametersAreNonnullByDefault;
| 991 | 38.68 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/AddNclocToProjects.java | /*
* 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.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef;
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
public class AddNclocToProjects extends DdlChange {
public static final String PROJECT_TABLE_NAME = "projects";
public static final String NCLOC_COLUMN_NAME = "ncloc";
public AddNclocToProjects(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
if (checkIfColumnExists()) {
return;
}
BigIntegerColumnDef columnDef = BigIntegerColumnDef.newBigIntegerColumnDefBuilder().setColumnName(NCLOC_COLUMN_NAME).setIsNullable(true).build();
String request = new AddColumnsBuilder(getDialect(), PROJECT_TABLE_NAME).addColumn(columnDef).build();
context.execute(request);
}
public boolean checkIfColumnExists() throws SQLException {
try (var connection = getDatabase().getDataSource().getConnection()) {
if (DatabaseUtils.tableColumnExists(connection, PROJECT_TABLE_NAME, NCLOC_COLUMN_NAME)) {
return true;
}
}
return false;
}
}
| 2,149 | 36.719298 | 149 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/CreateScimGroupsTable.java | /*
* 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.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.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
public class CreateScimGroupsTable extends CreateTableChange {
static final String TABLE_NAME = "scim_groups";
public CreateScimGroupsTable(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("scim_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("group_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.build());
}
}
| 1,917 | 41.622222 | 124 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/CreateUniqueIndexForScimGroupsUuid.java | /*
* 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.CreateScimGroupsTable.TABLE_NAME;
public class CreateUniqueIndexForScimGroupsUuid extends DdlChange {
@VisibleForTesting
static final String COLUMN_NAME = "group_uuid";
@VisibleForTesting
static final String INDEX_NAME = "uniq_scim_group_uuid";
public CreateUniqueIndexForScimGroupsUuid(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
createUserUuidUniqueIndex(context, connection);
}
}
private static void createUserUuidUniqueIndex(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(true)
.build());
}
}
}
| 2,207 | 34.612903 | 99 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DbVersion100.java | /*
* 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 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 DbVersion100 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_0_000, "Remove orphan rules in Quality Profiles", RemoveOrphanRulesFromQualityProfiles.class)
.add(10_0_001, "Drop index 'projects_module_uuid' in the 'Components' table", DropIndexProjectsModuleUuidInComponents.class)
.add(10_0_002, "Drop column 'module_uuid' in the 'Components' table", DropModuleUuidInComponents.class)
.add(10_0_003, "Drop column 'module_uuid_path' in the 'Components' table", DropModuleUuidPathInComponents.class)
.add(10_0_004, "Drop column 'b_module_uuid' in the 'Components' table", DropBModuleUuidInComponents.class)
.add(10_0_005, "Drop column 'b_module_uuid_path' in the 'Components' table", DropBModuleUuidPathInComponents.class)
.add(10_0_006, "Drop index 'projects_root_uuid' in the 'Components' table", DropIndexProjectsRootUuidInComponents.class)
.add(10_0_007, "Drop column 'root_uuid' in the 'Components' table", DropRootUuidInComponents.class)
.add(10_0_008, "Update value of 'user_local' in the 'users' table", UpdateUserLocalValueInUsers.class)
.add(10_0_009, "Make column 'user_local' not nullable in the 'users' table", MakeColumnUserLocalNotNullableInUsers.class)
.add(10_0_010, "Create 'scim_groups' table", CreateScimGroupsTable.class)
.add(10_0_011, "Create unique index on scim_groups.group_uuid", CreateUniqueIndexForScimGroupsUuid.class)
.add(10_0_012, "Log a warning message if 'sonar.scim.enabled' is used", LogMessageIfSonarScimEnabledPresentProperty.class)
.add(10_0_013, "Drop 'sonar.scim.enabled' property", DropSonarScimEnabledProperty.class)
.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)
;
}
}
| 3,457 | 53.03125 | 130 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidInComponents.java | /*
* 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 org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropColumnChange;
public class DropBModuleUuidInComponents extends DropColumnChange {
private static final String COLUMN_NAME = "b_module_uuid";
private static final String TABLE_NAME = "components";
public DropBModuleUuidInComponents(Database db) {
super(db, TABLE_NAME, COLUMN_NAME);
}
}
| 1,290 | 38.121212 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidPathInComponents.java | /*
* 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 org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropColumnChange;
public class DropBModuleUuidPathInComponents extends DropColumnChange {
private static final String COLUMN_NAME = "b_module_uuid_path";
private static final String TABLE_NAME = "components";
public DropBModuleUuidPathInComponents(Database db) {
super(db, TABLE_NAME, COLUMN_NAME);
}
}
| 1,303 | 38.515152 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsModuleUuidInComponents.java | /*
* 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 org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;
public class DropIndexProjectsModuleUuidInComponents extends DropIndexChange {
private static final String INDEX_NAME = "projects_module_uuid";
private static final String TABLE_NAME = "components";
public DropIndexProjectsModuleUuidInComponents(Database db) {
super(db, INDEX_NAME, TABLE_NAME);
}
}
| 1,317 | 38.939394 | 78 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsRootUuidInComponents.java | /*
* 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 org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;
public class DropIndexProjectsRootUuidInComponents extends DropIndexChange {
private static final String INDEX_NAME = "projects_root_uuid";
private static final String TABLE_NAME = "components";
public DropIndexProjectsRootUuidInComponents(Database db) {
super(db, INDEX_NAME, TABLE_NAME);
}
}
| 1,311 | 38.757576 | 76 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidInComponents.java | /*
* 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 org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropColumnChange;
public class DropModuleUuidInComponents extends DropColumnChange {
private static final String COLUMN_NAME = "module_uuid";
private static final String TABLE_NAME = "components";
public DropModuleUuidInComponents(Database db) {
super(db, TABLE_NAME, COLUMN_NAME);
}
}
| 1,286 | 38 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidPathInComponents.java | /*
* 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 org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropColumnChange;
public class DropModuleUuidPathInComponents extends DropColumnChange {
private static final String COLUMN_NAME = "module_uuid_path";
private static final String TABLE_NAME = "components";
public DropModuleUuidPathInComponents(Database db) {
super(db, TABLE_NAME, COLUMN_NAME);
}
}
| 1,299 | 38.393939 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropRootUuidInComponents.java | /*
* 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 org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropColumnChange;
public class DropRootUuidInComponents extends DropColumnChange {
private static final String COLUMN_NAME = "root_uuid";
private static final String TABLE_NAME = "components";
protected DropRootUuidInComponents(Database db) {
super(db, TABLE_NAME, COLUMN_NAME);
}
}
| 1,283 | 37.909091 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioning.java | /*
* 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.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
public class DropScimUserProvisioning extends DataChange {
public DropScimUserProvisioning(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
context.prepareUpsert("delete from scim_users").execute().commit();
}
}
| 1,312 | 34.486486 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledProperty.java | /*
* 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.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
public class DropSonarScimEnabledProperty extends DataChange {
public DropSonarScimEnabledProperty(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
context.prepareUpsert("delete from properties where prop_key = ?")
.setString(1, "sonar.scim.enabled")
.execute()
.commit();
}
}
| 1,395 | 33.9 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentProperty.java | /*
* 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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
public class LogMessageIfSonarScimEnabledPresentProperty extends DataChange {
private static final Logger LOG = LoggerFactory.getLogger(LogMessageIfSonarScimEnabledPresentProperty.class);
public static final String SONAR_SCIM_ENABLED = "sonar.scim.enabled";
private static final String SCIM_DOC_URL = "https://docs.sonarqube.org/10.1/instance-administration/authentication/saml/scim/overview/";
public LogMessageIfSonarScimEnabledPresentProperty(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
context.prepareSelect("select * from properties where prop_key = ?")
.setString(1, SONAR_SCIM_ENABLED)
.scroll(row -> LOG.warn("'{}' property is defined but not read anymore." +
" Please read the upgrade notes for the instruction to upgrade. User provisioning is deactivated until reactivated" +
" from the SonarQube Administration Interface (\"General->Authentication\"). See documentation: {}", SONAR_SCIM_ENABLED,
SCIM_DOC_URL));
}
}
| 2,132 | 43.4375 | 138 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/MakeColumnUserLocalNotNullableInUsers.java | /*
* 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.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
public class MakeColumnUserLocalNotNullableInUsers extends DdlChange {
private static final String TABLE_NAME = "users";
private static final String COLUMN_NAME = "user_local";
private static final BooleanColumnDef columnDefinition = BooleanColumnDef.newBooleanColumnDefBuilder()
.setColumnName(COLUMN_NAME)
.setIsNullable(false)
.build();
public MakeColumnUserLocalNotNullableInUsers(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME)
.updateColumn(columnDefinition)
.build());
}
}
| 1,813 | 36.791667 | 104 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjects.java | /*
* 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.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;
public class PopulateNclocForForProjects extends DataChange {
private static final String SELECT_QUERY = """
SELECT b.project_uuid AS projectUuid, max(lm.value) AS maxncloc
FROM live_measures lm
INNER JOIN metrics m ON m.uuid = lm.metric_uuid
INNER JOIN project_branches b ON b.uuid = lm.component_uuid
INNER JOIN projects p on p.uuid = b.project_uuid and p.qualifier = 'TRK'
WHERE m.name = 'ncloc'
GROUP BY b.project_uuid
""";
public PopulateNclocForForProjects(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select(SELECT_QUERY);
massUpdate.update("update projects set ncloc = ? where uuid = ?");
massUpdate.execute((row, update) -> {
String uuid = row.getString(1);
Long ncloc = row.getLong(2);
update.setLong(1, ncloc);
update.setString(2, uuid);
return true;
});
}
}
| 2,083 | 35.561404 | 76 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfiles.java | /*
* 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.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;
import org.sonar.server.platform.db.migration.step.Select;
import org.sonar.server.platform.db.migration.step.SqlStatement;
public class RemoveOrphanRulesFromQualityProfiles extends DataChange {
private final UuidFactory uuidFactory;
private final System2 system2;
public RemoveOrphanRulesFromQualityProfiles(Database db, UuidFactory uuidFactory, System2 system2) {
super(db);
this.uuidFactory = uuidFactory;
this.system2 = system2;
}
@Override
protected void execute(Context context) throws SQLException {
final String SELECT_QUERY = "select ar.uuid, ar.profile_uuid, ar.rule_uuid from rules_profiles rp " +
"inner join active_rules ar on ar.profile_uuid = rp.uuid " +
"inner join rules r on r.uuid = ar.rule_uuid " +
"where rp.language != r.language";
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select(SELECT_QUERY);
final String UPDATE_QUERY = """
INSERT INTO qprofile_changes
(kee, rules_profile_uuid, change_type, created_at, user_uuid, change_data)
VALUES(?, ?, ?, ?, ?, ?)
""";
massUpdate.update(UPDATE_QUERY);
massUpdate.update("delete from active_rules where uuid = ?");
massUpdate.execute((row, update, index) -> {
if (index == 0) {
prepareUpdateForQProfileChanges(row, update);
}
if (index == 1) {
update.setString(1, row.getString(1));
}
return true;
});
}
private void prepareUpdateForQProfileChanges(Select.Row selectedRow, SqlStatement update) throws SQLException {
update.setString(1, uuidFactory.create())
.setString(2, selectedRow.getString(2))
.setString(3, "DEACTIVATED")
.setLong(4, system2.now())
.setString(5, null)
.setString(6, "ruleUuid=" + selectedRow.getString(3));
}
}
| 2,979 | 36.721519 | 113 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/UpdateUserLocalValueInUsers.java | /*
* 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.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;
public class UpdateUserLocalValueInUsers extends DataChange {
public UpdateUserLocalValueInUsers(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select uuid from users where user_local is null");
massUpdate.update("update users set user_local = ? where uuid = ?");
massUpdate.execute((row, update) -> {
String uuid = row.getString(1);
update.setBoolean(1, true);
update.setString(2, uuid);
return true;
});
}
}
| 1,687 | 35.695652 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/package-info.java | /*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.server.platform.db.migration.version.v100;
import javax.annotation.ParametersAreNonnullByDefault;
| 991 | 40.333333 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/AddCodeVariantsColumnInIssuesTable.java | /*
* 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.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.ColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
public class AddCodeVariantsColumnInIssuesTable extends DdlChange {
private static final String TABLE_NAME = "issues";
private static final String COLUMN_NAME = "code_variants";
private static final int COLUMN_SIZE = 4000;
public AddCodeVariantsColumnInIssuesTable(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
if (!DatabaseUtils.tableColumnExists(connection, TABLE_NAME, COLUMN_NAME)) {
ColumnDef columnDef = VarcharColumnDef.newVarcharColumnDefBuilder()
.setColumnName(COLUMN_NAME)
.setLimit(COLUMN_SIZE)
.setIsNullable(true)
.build();
context.execute(new AddColumnsBuilder(getDialect(), TABLE_NAME).addColumn(columnDef).build());
}
}
}
}
| 2,158 | 38.254545 | 102 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/AddIsMainColumnInProjectBranches.java | /*
* 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.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
import org.sonar.server.platform.db.migration.def.ColumnDef;
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
public class AddIsMainColumnInProjectBranches extends DdlChange {
private static final String TABLE_NAME = "project_branches";
private static final String COLUMN_NAME = "is_main";
public AddIsMainColumnInProjectBranches(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
try (Connection c = getDatabase().getDataSource().getConnection()) {
if (!DatabaseUtils.tableColumnExists(c, TABLE_NAME, COLUMN_NAME)) {
ColumnDef columnDef = BooleanColumnDef.newBooleanColumnDefBuilder()
.setColumnName(COLUMN_NAME)
.setIsNullable(true)
.build();
context.execute(new AddColumnsBuilder(getDialect(), TABLE_NAME).addColumn(columnDef).build());
}
}
}
}
| 2,061 | 37.185185 | 102 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/AddReportSchedulesTable.java | /*
* 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.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.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
public class AddReportSchedulesTable extends CreateTableChange {
static final String TABLE_NAME = "report_schedules";
public AddReportSchedulesTable(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("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("portfolio_uuid").setIsNullable(true).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("branch_uuid").setIsNullable(true).setLimit(UUID_SIZE).build())
.addColumn(newBigIntegerColumnDefBuilder().setColumnName("last_send_time_in_ms").setIsNullable(false).build())
.build());
}
}
| 2,274 | 45.428571 | 126 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/AddReportSubscriptionsTable.java | /*
* 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.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.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
public class AddReportSubscriptionsTable extends CreateTableChange {
static final String TABLE_NAME = "report_subscriptions";
public AddReportSubscriptionsTable(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("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("portfolio_uuid").setIsNullable(true).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("branch_uuid").setIsNullable(true).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("user_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.build());
}
}
| 2,184 | 44.520833 | 126 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/AlterIsMainColumnInProjectBranches.java | /*
* 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.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
public class AlterIsMainColumnInProjectBranches extends DdlChange {
private static final String TABLE_NAME = "project_branches";
private static final String COLUMN_NAME = "is_main";
public AlterIsMainColumnInProjectBranches(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
BooleanColumnDef newColumnDef = new BooleanColumnDef.Builder()
.setColumnName(COLUMN_NAME)
.setIsNullable(false)
.build();
context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME).updateColumn(newColumnDef).build());
}
}
| 1,765 | 37.391304 | 106 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateExternalGroupsTable.java | /*
* 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.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
public class CreateExternalGroupsTable extends CreateTableChange {
static final String TABLE_NAME = "external_groups";
@VisibleForTesting
static final String GROUP_UUID_COLUMN_NAME = "group_uuid";
static final String EXTERNAL_GROUP_ID_COLUMN_NAME = "external_group_id";
static final String EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME = "external_identity_provider";
public CreateExternalGroupsTable(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(GROUP_UUID_COLUMN_NAME).setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName(EXTERNAL_GROUP_ID_COLUMN_NAME).setIsNullable(false).setLimit(255).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName(EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME).setIsNullable(false).setLimit(100).build())
.build());
}
}
| 2,402 | 45.211538 | 143 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTable.java | /*
* 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());
}
}
}
| 2,116 | 33.704918 | 83 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTable.java | /*
* 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.SCM_ACCOUNTS_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(SCM_ACCOUNTS_TABLE_NAME, INDEX_NAME, connection)) {
context.execute(new CreateIndexBuilder()
.setTable(SCM_ACCOUNTS_TABLE_NAME)
.setName(INDEX_NAME)
.addColumn(SCM_ACCOUNT_COLUMN_NAME)
.setUnique(false)
.build());
}
}
}
| 2,287 | 37.133333 | 113 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable.java | /*
* 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.CreateExternalGroupsTable.EXTERNAL_GROUP_ID_COLUMN_NAME;
import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME;
import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.TABLE_NAME;
public class CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable extends DdlChange {
@VisibleForTesting
static final String INDEX_NAME = "uniq_ext_grp_ext_id_provider";
public CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable(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(EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME)
.addColumn(EXTERNAL_GROUP_ID_COLUMN_NAME)
.setUnique(true)
.build());
}
}
}
| 2,494 | 38.603175 | 131 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateProjectUuidInUserTokens.java | /*
* 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.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.ColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
public class CreateProjectUuidInUserTokens extends DdlChange {
private static final String TABLE_NAME = "user_tokens";
private static final String COLUMN_NAME = "project_uuid";
public CreateProjectUuidInUserTokens(Database db) {
super(db);
}
@Override
public void execute(DdlChange.Context context) throws SQLException {
try (Connection c = getDatabase().getDataSource().getConnection()) {
if (!DatabaseUtils.tableColumnExists(c, TABLE_NAME, COLUMN_NAME)) {
ColumnDef columnDef = VarcharColumnDef.newVarcharColumnDefBuilder()
.setColumnName(COLUMN_NAME)
.setIsNullable(true)
.setLimit(UUID_SIZE)
.build();
context.execute(new AddColumnsBuilder(getDialect(), TABLE_NAME).addColumn(columnDef).build());
}
}
}
}
| 2,181 | 37.964286 | 102 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTable.java | /*
* 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 SCM_ACCOUNTS_TABLE_NAME = "scm_accounts";
static final String SCM_ACCOUNT_COLUMN_NAME = "scm_account";
@VisibleForTesting
static final String USER_UUID_COLUMN_NAME = "user_uuid";
@VisibleForTesting
static final int SCM_ACCOUNT_SIZE = 255;
public CreateScmAccountsTable(Database db) {
super(db, SCM_ACCOUNTS_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());
}
}
| 2,243 | 42.153846 | 143 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSchedulesTable.java | /*
* 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.AddReportSchedulesTable.TABLE_NAME;
public class CreateUniqueIndexForReportSchedulesTable extends DdlChange {
@VisibleForTesting
static final String COLUMN_NAME_PORTFOLIO = "portfolio_uuid";
@VisibleForTesting
static final String COLUMN_NAME_BRANCH = "branch_uuid";
@VisibleForTesting
static final String INDEX_NAME = "uniq_report_schedules";
public CreateUniqueIndexForReportSchedulesTable(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
createUserUuidUniqueIndex(context, connection);
}
}
private static void createUserUuidUniqueIndex(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_PORTFOLIO)
.addColumn(COLUMN_NAME_BRANCH)
.setUnique(true)
.build());
}
}
}
| 2,366 | 34.328358 | 101 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSubscriptionsTable.java | /*
* 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.AddReportSubscriptionsTable.TABLE_NAME;
public class CreateUniqueIndexForReportSubscriptionsTable extends DdlChange{
@VisibleForTesting
static final String COLUMN_NAME_PORTFOLIO = "portfolio_uuid";
@VisibleForTesting
static final String COLUMN_NAME_BRANCH = "branch_uuid";
@VisibleForTesting
static final String COLUMN_NAME_USER = "user_uuid";
@VisibleForTesting
static final String INDEX_NAME = "uniq_report_subscriptions";
public CreateUniqueIndexForReportSubscriptionsTable(Database db) {
super(db);
}
@Override
public void execute(DdlChange.Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
createUserUuidUniqueIndex(context, connection);
}
}
private static void createUserUuidUniqueIndex(DdlChange.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_PORTFOLIO)
.addColumn(COLUMN_NAME_BRANCH)
.addColumn(COLUMN_NAME_USER)
.setUnique(true)
.build());
}
}
}
| 2,514 | 34.422535 | 105 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/DbVersion101.java | /*
* 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;
// 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)
.add(10_1_008, "Increase size of 'internal_properties.kee' from 20 to 40 characters", IncreaseKeeColumnSizeInInternalProperties.class)
.add(10_1_009, "Create column 'project_uuid' in 'user_tokens", CreateProjectUuidInUserTokens.class)
.add(10_1_010, "Remove user tokens linked to unexistent project", RemoveOrphanUserTokens.class)
.add(10_1_011, "Populate 'project_key' in 'user_tokens'", PopulateProjectUuidInUserTokens.class)
.add(10_1_012, "Drop column 'project_key' in 'user_tokens", DropProjectKeyInUserTokens.class)
.add(10_1_013, "Increase size of 'ce_queue.task_type' from 15 to 40 characters", IncreaseTaskTypeColumnSizeInCeQueue.class)
.add(10_1_014, "Increase size of 'ce_activity.task_type' from 15 to 40 characters", IncreaseTaskTypeColumnSizeInCeActivity.class)
.add(10_1_015, "Add 'external_groups' table.", CreateExternalGroupsTable.class)
.add(10_1_016, "Add index on 'external_groups(external_identity_provider, external_id).", CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable.class)
.add(10_1_017, "Add 'code_variants' column in 'issues' table", AddCodeVariantsColumnInIssuesTable.class)
.add(10_1_018, "Fix different uuids for subportfolios", FixDifferentUuidsForSubportfolios.class)
.add(10_1_019, "Add report_schedules table", AddReportSchedulesTable.class)
.add(10_1_020, "Add report_subscriptions table", AddReportSubscriptionsTable.class)
.add(10_1_021, "Add report_schedules unique index", CreateUniqueIndexForReportSchedulesTable.class)
.add(10_1_022, "Add report_subscriptions unique index", CreateUniqueIndexForReportSubscriptionsTable.class)
.add(10_1_023, "Rename column 'component_uuid' to 'entity_uuid' in the 'properties' table", RenameColumnComponentUuidInProperties.class)
.add(10_1_024, "Populate report_schedules table", PopulateReportSchedules.class)
.add(10_1_025, "Populate report_subscriptions table", PopulateReportSubscriptions.class)
.add(10_1_026, "Remove report properties", RemoveReportProperties.class)
;
}
}
| 4,541 | 60.378378 | 158 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/DropProjectKeyInUserTokens.java | /*
* 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 DropProjectKeyInUserTokens extends DropColumnChange {
static final String TABLE_NAME = "user_tokens";
static final String COLUMN_NAME = "project_key";
public DropProjectKeyInUserTokens(Database db) {
super(db, TABLE_NAME, COLUMN_NAME);
}
}
| 1,264 | 37.333333 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsers.java | /*
* 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);
}
}
| 1,251 | 36.939394 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/FixDifferentUuidsForSubportfolios.java | /*
* 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.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;
public class FixDifferentUuidsForSubportfolios extends DataChange {
private static final String SELECT_QUERY = """
SELECT p.uuid, c.uuid
FROM portfolios p
INNER join components c on p.kee = c.kee AND p.uuid != c.uuid
and p.parent_uuid IS NOT NULL and p.root_uuid = c.branch_uuid and c.qualifier = 'SVW'
""";
public FixDifferentUuidsForSubportfolios(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select(SELECT_QUERY);
massUpdate.update("update portfolios set parent_uuid=? where parent_uuid=?");
massUpdate.update("update portfolios set uuid=? where uuid=?");
massUpdate.update("update portfolio_projects set portfolio_uuid=? where portfolio_uuid=?");
massUpdate.update("update portfolio_references set portfolio_uuid=? where portfolio_uuid=?");
massUpdate.execute((row, update, index) -> {
String portfolioUuid = row.getString(1);
String componentUuid = row.getString(2);
update.setString(1, componentUuid);
update.setString(2, portfolioUuid);
return true;
});
}
}
}
| 2,418 | 39.316667 | 99 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalProperties.java | /*
* 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.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
public class IncreaseKeeColumnSizeInInternalProperties extends DdlChange {
@VisibleForTesting
static final String TABLE_NAME = "internal_properties";
@VisibleForTesting
static final String COLUMN_NAME = "kee";
@VisibleForTesting
static final int NEW_COLUMN_SIZE = 40;
private static final VarcharColumnDef COLUMN_DEFINITION = VarcharColumnDef.newVarcharColumnDefBuilder()
.setColumnName(COLUMN_NAME)
.setLimit(NEW_COLUMN_SIZE)
.setIsNullable(false)
.build();
public IncreaseKeeColumnSizeInInternalProperties(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME)
.updateColumn(COLUMN_DEFINITION)
.build());
}
}
| 2,005 | 36.148148 | 105 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivity.java | /*
* 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.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
public class IncreaseTaskTypeColumnSizeInCeActivity extends DdlChange {
@VisibleForTesting
static final String TABLE_NAME = "ce_activity";
@VisibleForTesting
static final String COLUMN_NAME = "task_type";
@VisibleForTesting
static final int NEW_COLUMN_SIZE = 40;
private static final VarcharColumnDef COLUMN_DEFINITION = VarcharColumnDef.newVarcharColumnDefBuilder()
.setColumnName(COLUMN_NAME)
.setLimit(NEW_COLUMN_SIZE)
.setIsNullable(false)
.build();
public IncreaseTaskTypeColumnSizeInCeActivity(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME)
.updateColumn(COLUMN_DEFINITION)
.build());
}
}
| 1,997 | 36 | 105 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueue.java | /*
* 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.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
public class IncreaseTaskTypeColumnSizeInCeQueue extends DdlChange {
@VisibleForTesting
static final String TABLE_NAME = "ce_queue";
@VisibleForTesting
static final String COLUMN_NAME = "task_type";
@VisibleForTesting
static final int NEW_COLUMN_SIZE = 40;
private static final VarcharColumnDef COLUMN_DEFINITION = VarcharColumnDef.newVarcharColumnDefBuilder()
.setColumnName(COLUMN_NAME)
.setLimit(NEW_COLUMN_SIZE)
.setIsNullable(false)
.build();
public IncreaseTaskTypeColumnSizeInCeQueue(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME)
.updateColumn(COLUMN_DEFINITION)
.build());
}
}
| 1,988 | 35.833333 | 105 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccounts.java | /*
* 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) {
}
}
| 3,458 | 35.410526 | 171 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/PopulateProjectUuidInUserTokens.java | /*
* 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.Connection;
import java.sql.SQLException;
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.MassUpdate;
public class PopulateProjectUuidInUserTokens extends DataChange {
private static final String SELECT_QUERY = """
SELECT ut.uuid as tokenUuid, p.uuid as projectUuid
FROM user_tokens ut
INNER JOIN projects p ON ut.project_key = p.kee and ut.project_key is not null
""";
public PopulateProjectUuidInUserTokens(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
if (!DatabaseUtils.tableColumnExists(connection, "user_tokens", "project_key")) {
return;
}
}
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select(SELECT_QUERY);
massUpdate.update("update user_tokens set project_uuid = ? where uuid = ?");
massUpdate.execute((row, update) -> {
String uuid = row.getString(1);
String projectUuid = row.getString(2);
update.setString(1, projectUuid);
update.setString(2, uuid);
return true;
});
}
}
| 2,200 | 36.305085 | 87 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSchedules.java | /*
* 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.sonar.core.util.UuidFactoryImpl;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;
public class PopulateReportSchedules extends DataChange {
private static final String SELECT_QUERY = """
SELECT port.uuid as portfolioUuid, pb.uuid as branchUuid, p.text_value as value
FROM properties p
LEFT JOIN portfolios port ON p.entity_uuid = port.uuid
LEFT JOIN project_branches pb ON p.entity_uuid = pb.uuid
WHERE p.prop_key = 'sonar.governance.report.lastSendTimeInMs' or p.prop_key = 'sonar.governance.report.project.branch.lastSendTimeInMs'
AND NOT EXISTS (
SELECT * FROM report_schedules rs
WHERE rs.branch_uuid = p.entity_uuid or rs.portfolio_uuid = p.entity_uuid
)
""";
public PopulateReportSchedules(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select(SELECT_QUERY);
massUpdate.update("insert into report_schedules (uuid, branch_uuid, portfolio_uuid, last_send_time_in_ms) values (?, ?, ?, ?)");
massUpdate.execute((row, update) -> {
String portfolioUuid = row.getString(1);
String branchUuid = row.getString(2);
// one and only one needs to be null
if ((portfolioUuid == null) == (branchUuid == null)) {
return false;
}
String value = row.getString(3);
long ms = Long.parseLong(value);
update.setString(1, UuidFactoryImpl.INSTANCE.create());
update.setString(2, branchUuid);
update.setString(3, portfolioUuid);
update.setLong(4, ms);
return true;
});
}
}
| 2,691 | 37.457143 | 140 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSubscriptions.java | /*
* 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.sonar.core.util.UuidFactoryImpl;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;
public class PopulateReportSubscriptions extends DataChange {
private static final String SELECT_QUERY = """
SELECT port.uuid as portfolioUuid, pb.uuid as branchUuid, p.user_uuid as userUuid
FROM properties p
LEFT JOIN portfolios port ON p.entity_uuid = port.uuid
LEFT JOIN project_branches pb ON p.entity_uuid = pb.uuid
WHERE p.prop_key = 'sonar.governance.report.userNotification' or p.prop_key = 'sonar.governance.report.project.branch.userNotification'
AND NOT EXISTS (
SELECT * FROM report_subscriptions rs
WHERE (rs.branch_uuid = p.entity_uuid or rs.portfolio_uuid = p.entity_uuid) and rs.user_uuid = p.user_uuid
)
""";
public PopulateReportSubscriptions(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select(SELECT_QUERY);
massUpdate.update("insert into report_subscriptions (uuid, branch_uuid, portfolio_uuid, user_uuid) values (?, ?, ?, ?)");
massUpdate.execute((row, update) -> {
String portfolioUuid = row.getString(1);
String branchUuid = row.getString(2);
// one and only one needs to be null
if ((portfolioUuid == null) == (branchUuid == null)) {
return false;
}
String userUuid = row.getString(3);
update.setString(1, UuidFactoryImpl.INSTANCE.create());
update.setString(2, branchUuid);
update.setString(3, portfolioUuid);
update.setString(4, userUuid);
return true;
});
}
}
| 2,702 | 38.173913 | 139 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/RemoveOrphanUserTokens.java | /*
* 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.Connection;
import java.sql.SQLException;
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.MassUpdate;
public class RemoveOrphanUserTokens extends DataChange {
private static final String SELECT_QUERY = """
SELECT ut.uuid as tokenUuid
FROM user_tokens ut
LEFT OUTER JOIN projects p ON ut.project_key = p.kee
WHERE p.uuid is null and ut.project_key IS NOT NULL
""";
public RemoveOrphanUserTokens(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
if (DatabaseUtils.tableColumnExists(connection, "user_tokens", "project_key")) {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select(SELECT_QUERY);
massUpdate.update("delete from user_tokens where uuid = ?");
massUpdate.execute((row, update) -> {
String uuid = row.getString(1);
update.setString(1, uuid);
return true;
});
}
}
}
}
| 2,103 | 35.912281 | 86 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/RemoveReportProperties.java | /*
* 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.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;
public class RemoveReportProperties extends DataChange {
private static final String SELECT_QUERY = """
SELECT p.uuid as uuid from properties p
WHERE p.prop_key = 'sonar.governance.report.lastSendTimeInMs' or p.prop_key = 'sonar.governance.report.project.branch.lastSendTimeInMs'
or p.prop_key = 'sonar.governance.report.userNotification' or p.prop_key = 'sonar.governance.report.project.branch.userNotification'
""";
public RemoveReportProperties(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select(SELECT_QUERY);
massUpdate.update("delete from properties where uuid = ?");
massUpdate.execute((row, delete) -> {
String uuid = row.getString(1);
delete.setString(1, uuid);
return true;
});
}
}
}
| 2,110 | 38.830189 | 141 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/RenameColumnComponentUuidInProperties.java | /*
* 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.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.ColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.RenameColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
public class RenameColumnComponentUuidInProperties extends DdlChange {
public static final String TABLE_NAME = "properties";
public static final String OLD_COLUMN_NAME = "component_uuid";
public static final String NEW_COLUMN_NAME = "entity_uuid";
public RenameColumnComponentUuidInProperties(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
try (Connection c = getDatabase().getDataSource().getConnection()) {
if (!DatabaseUtils.tableColumnExists(c, TABLE_NAME, NEW_COLUMN_NAME)) {
ColumnDef newColumnDef = new VarcharColumnDef.Builder()
.setColumnName(NEW_COLUMN_NAME)
.setIsNullable(true)
.setLimit(40)
.build();
context.execute(new RenameColumnsBuilder(getDialect(), TABLE_NAME).renameColumn(OLD_COLUMN_NAME, newColumnDef).build());
}
}
}
} | 2,185 | 38.035714 | 128 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/UpdateIsMainColumnInProjectBranches.java | /*
* 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.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;
public class UpdateIsMainColumnInProjectBranches extends DataChange {
public UpdateIsMainColumnInProjectBranches(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
// we need to use case/when/then because Oracle doesn't accept simple solution uuid = project_uuid here
massUpdate.select("select uuid, case when uuid = project_uuid then 'true' else 'false' end from project_branches");
massUpdate.update("update project_branches set is_main = ? where uuid = ?");
massUpdate.execute((row, update) -> {
String uuid = row.getString(1);
boolean isMain = row.getBoolean(2);
update.setBoolean(1, isMain);
update.setString(2, uuid);
return true;
});
}
}
| 1,912 | 37.26 | 120 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/package-info.java | /*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.server.platform.db.migration.version.v101;
import javax.annotation.ParametersAreNonnullByDefault;
| 991 | 40.333333 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivity.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn;
public class CreateIndexEntityUuidInCeActivity extends CreateIndexOnColumn {
private static final String TABLE_NAME = "ce_activity";
private static final String COLUMN_NAME = "entity_uuid";
public CreateIndexEntityUuidInCeActivity(Database db) {
super(db, TABLE_NAME, COLUMN_NAME, false);
}
}
| 1,315 | 37.705882 | 76 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueue.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn;
public class CreateIndexEntityUuidInCeQueue extends CreateIndexOnColumn {
private static final String TABLE_NAME = "ce_queue";
private static final String COLUMN_NAME = "entity_uuid";
public CreateIndexEntityUuidInCeQueue(Database db) {
super(db, TABLE_NAME, COLUMN_NAME, false);
}
}
| 1,306 | 37.441176 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRoles.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn;
public class CreateIndexEntityUuidInGroupRoles extends CreateIndexOnColumn {
private static final String TABLE_NAME = "group_roles";
private static final String COLUMN_NAME = "entity_uuid";
public CreateIndexEntityUuidInGroupRoles(Database db) {
super(db, TABLE_NAME, COLUMN_NAME, false);
}
}
| 1,315 | 37.705882 | 76 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRoles.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn;
public class CreateIndexEntityUuidInUserRoles extends CreateIndexOnColumn {
private static final String TABLE_NAME = "user_roles";
private static final String COLUMN_NAME = "entity_uuid";
public CreateIndexEntityUuidInUserRoles(Database db) {
super(db, TABLE_NAME, COLUMN_NAME, false);
}
}
| 1,312 | 37.617647 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInWebhookDeliveries.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn;
public class CreateIndexProjectUuidInWebhookDeliveries extends CreateIndexOnColumn {
private static final String TABLE_NAME = "webhook_deliveries";
private static final String COLUMN_NAME = "project_uuid";
public CreateIndexProjectUuidInWebhookDeliveries(Database db) {
super(db, TABLE_NAME, COLUMN_NAME, false);
}
/**
* There is a limit of 30 characters for index name, that's why this one has a different name
*/
@Override
public String newIndexName() {
return "wd_" + COLUMN_NAME;
}
}
| 1,529 | 35.428571 | 95 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshots.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn;
public class CreateIndexRootComponentUuidInSnapshots extends CreateIndexOnColumn {
private static final String TABLE_NAME = "snapshots";
private static final String COLUMN_NAME = "root_component_uuid";
public CreateIndexRootComponentUuidInSnapshots(Database db) {
super(db, TABLE_NAME, COLUMN_NAME, false);
}
}
| 1,333 | 38.235294 | 82 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import 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 DbVersion102 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_2_000, "Rename 'component_uuid' in 'user_roles' table to 'entity_uuid'", RenameComponentUuidInUserRoles.class)
.add(10_2_001, "Rename 'component_uuid' in 'group_roles' table to 'entity_uuid'", RenameComponentUuidInGroupRoles.class)
.add(10_2_002, "Drop index 'group_roles_component_uuid' in 'group_roles'", DropIndexComponentUuidInGroupRoles.class)
.add(10_2_003, "Create index 'entity_uuid_user_roles' in 'group_roles' table", CreateIndexEntityUuidInGroupRoles.class)
.add(10_2_004, "Drop index 'user_roles_component_uuid' in 'user_roles' table", DropIndexComponentUuidInUserRoles.class)
.add(10_2_005, "Create index 'user_roles_entity_uuid' in 'user_roles'", CreateIndexEntityUuidInUserRoles.class)
.add(10_2_006, "Drop index 'ce_activity_component' in 'ce_activity'", DropIndexMainComponentUuidInCeActivity.class)
.add(10_2_007, "Rename 'main_component_uuid' in 'ce_activity' table to 'entity_uuid'", RenameMainComponentUuidInCeActivity.class)
.add(10_2_008, "Create index 'ce_activity_entity_uuid' in 'ce_activity' table'", CreateIndexEntityUuidInCeActivity.class)
.add(10_2_009, "Drop index 'ce_queue_main_component' in 'ce_queue' table", DropIndexMainComponentUuidInCeQueue.class)
.add(10_2_010, "Rename 'main_component_uuid' in 'ce_queue' table to 'entity_uuid'", RenameMainComponentUuidInCeQueue.class)
.add(10_2_011, "Create index 'ce_queue_entity_uuid' in 'ce_queue' table", CreateIndexEntityUuidInCeQueue.class)
.add(10_2_012, "Drop 'project_mappings' table", DropTableProjectMappings.class)
.add(10_2_013, "Drop index on 'components.main_branch_project_uuid", DropIndexOnMainBranchProjectUuid.class)
.add(10_2_014, "Drop column 'main_branch_project_uuid' in the components table", DropMainBranchProjectUuidInComponents.class)
.add(10_2_015, "Drop index 'component_uuid' in 'webhook_deliveries' table", DropIndexComponentUuidInWebhookDeliveries.class)
.add(10_2_016, "Rename 'component_uuid' in 'webhook_deliveries' table to 'project_uuid'", RenameComponentUuidInWebhookDeliveries.class)
.add(10_2_017, "Create index 'webhook_deliveries_project_uuid' in 'webhook_deliveries' table", CreateIndexProjectUuidInWebhookDeliveries.class)
.add(10_2_018, "Drop index 'component_uuid' in 'snapshots' table", DropIndexComponentUuidInSnapshots.class)
.add(10_2_019, "Rename 'component_uuid' in 'snapshots' table to 'root_component_uuid'", RenameComponentUuidInSnapshots.class)
.add(10_2_020, "Create index 'snapshots_root_component_uuid' in 'snapshots' table", CreateIndexRootComponentUuidInSnapshots.class)
;
}
}
| 4,231 | 54.684211 | 149 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRoles.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;
public class DropIndexComponentUuidInGroupRoles extends DropIndexChange {
private static final String TABLE_NAME = "group_roles";
private static final String INDEX_NAME = "group_roles_component_uuid";
public DropIndexComponentUuidInGroupRoles(Database db) {
super(db, INDEX_NAME, TABLE_NAME);
}
}
| 1,315 | 37.705882 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshots.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;
public class DropIndexComponentUuidInSnapshots extends DropIndexChange {
private static final String TABLE_NAME = "snapshots";
private static final String INDEX_NAME = "snapshot_component";
public DropIndexComponentUuidInSnapshots(Database db) {
super(db, INDEX_NAME, TABLE_NAME);
}
} | 1,302 | 38.484848 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRoles.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;
public class DropIndexComponentUuidInUserRoles extends DropIndexChange {
private static final String TABLE_NAME = "user_roles";
private static final String INDEX_NAME = "user_roles_component_uuid";
public DropIndexComponentUuidInUserRoles(Database db) {
super(db, INDEX_NAME, TABLE_NAME);
}
}
| 1,311 | 37.588235 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveries.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;
public class DropIndexComponentUuidInWebhookDeliveries extends DropIndexChange {
private static final String TABLE_NAME = "webhook_deliveries";
private static final String INDEX_NAME = "component_uuid";
public DropIndexComponentUuidInWebhookDeliveries(Database db) {
super(db, INDEX_NAME, TABLE_NAME);
}
}
| 1,324 | 37.970588 | 80 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivity.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;
public class DropIndexMainComponentUuidInCeActivity extends DropIndexChange {
private static final String TABLE_NAME = "ce_activity";
private static final String INDEX_NAME = "ce_activity_main_component";
public DropIndexMainComponentUuidInCeActivity(Database db) {
super(db, INDEX_NAME, TABLE_NAME);
}
}
| 1,323 | 37.941176 | 77 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueue.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;
public class DropIndexMainComponentUuidInCeQueue extends DropIndexChange {
private static final String TABLE_NAME = "ce_queue";
private static final String INDEX_NAME = "ce_queue_main_component";
public DropIndexMainComponentUuidInCeQueue(Database db) {
super(db, INDEX_NAME, TABLE_NAME);
}
}
| 1,311 | 37.588235 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuid.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropIndexChange;
public class DropIndexOnMainBranchProjectUuid extends DropIndexChange {
private static final String INDEX_NAME = "idx_main_branch_prj_uuid";
private static final String TABLE_NAME = "components";
public DropIndexOnMainBranchProjectUuid(Database db) {
super(db, INDEX_NAME, TABLE_NAME);
}
}
| 1,307 | 38.636364 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponents.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v102;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DropColumnChange;
class DropMainBranchProjectUuidInComponents extends DropColumnChange {
static final String TABLE_NAME = "components";
static final String COLUMN_NAME = "main_branch_project_uuid";
public DropMainBranchProjectUuidInComponents(Database db) {
super(db, TABLE_NAME, COLUMN_NAME);
}
}
| 1,298 | 38.363636 | 75 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.