CREATE TABLE "AUDITS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
- "USER_UUID" CHARACTER VARYING(40) NOT NULL,
+ "USER_UUID" CHARACTER VARYING(255) NOT NULL,
"USER_LOGIN" CHARACTER VARYING(255) NOT NULL,
"CATEGORY" CHARACTER VARYING(25) NOT NULL,
"OPERATION" CHARACTER VARYING(50) NOT NULL,
public static AuditDto newAuditDto(long createdAt, String operation) {
AuditDto auditDto = new AuditDto();
- auditDto.setUuid(randomAlphanumeric(20));
- auditDto.setUserUuid(randomAlphanumeric(40));
- auditDto.setUserLogin(randomAlphanumeric(40));
+ auditDto.setUuid(randomAlphanumeric(40));
+ auditDto.setUserUuid(randomAlphanumeric(255));
+ auditDto.setUserLogin(randomAlphanumeric(255));
auditDto.setNewValue("{ \"someKey\": \"someValue\", \"anotherKey\": \"\\\"anotherValue\\\" with quotes \\ \n\t\b\f\r\"}");
auditDto.setOperation(operation);
auditDto.setCategory("category");
public void addSteps(MigrationStepRegistry registry) {
registry
.add(6800, "Add node_name column to ce_activity table", AddNodeNameColumnToCeActivityTable.class)
- .add(6801, "Delete all analysis cache", DeleteAnalysisCache.class);
+ .add(6801, "Delete all analysis cache", DeleteAnalysisCache.class)
+ .add(6802, "Change user_uuid field size to 255 for audit table", UpdateUserUuidColumnSizeInAuditTable.class);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v99;
+
+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;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class UpdateUserUuidColumnSizeInAuditTable extends DdlChange {
+
+ @VisibleForTesting
+ static final String TABLE_NAME = "audits";
+
+ @VisibleForTesting
+ static final String COLUMN_NAME = "user_uuid";
+
+ private static final VarcharColumnDef columnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName(COLUMN_NAME)
+ .setIsNullable(false)
+ .setLimit(255)
+ .build();
+
+ public UpdateUserUuidColumnSizeInAuditTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME)
+ .updateColumn(columnDefinition)
+ .build());
+
+
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v99;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.sonar.server.platform.db.migration.version.v99.UpdateUserUuidColumnSizeInAuditTable.COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v99.UpdateUserUuidColumnSizeInAuditTable.TABLE_NAME;
+
+
+public class UpdateUserUuidColumnSizeInAuditTableTest {
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(UpdateUserUuidColumnSizeInAuditTable.class, "schema.sql");
+
+ private final UpdateUserUuidColumnSizeInAuditTable underTest = new UpdateUserUuidColumnSizeInAuditTable(db.database());
+
+ @Test
+ public void migration_should_add_column() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, false);
+ underTest.execute();
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 255, false);
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, false);
+ // re-entrant
+ underTest.execute();
+ underTest.execute();
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 255, false);
+ }
+}
--- /dev/null
+CREATE TABLE "AUDITS"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "USER_UUID" CHARACTER VARYING(40) NOT NULL,
+ "USER_LOGIN" CHARACTER VARYING(255) NOT NULL,
+ "CATEGORY" CHARACTER VARYING(25) NOT NULL,
+ "OPERATION" CHARACTER VARYING(50) NOT NULL,
+ "NEW_VALUE" CHARACTER VARYING(4000),
+ "CREATED_AT" BIGINT NOT NULL,
+ "USER_TRIGGERED" BOOLEAN DEFAULT TRUE NOT NULL
+);
+ALTER TABLE "AUDITS" ADD CONSTRAINT "PK_AUDITS" PRIMARY KEY("UUID");
+CREATE INDEX "AUDITS_CREATED_AT" ON "AUDITS"("CREATED_AT" NULLS FIRST);