"qprofile_edit_groups",
"qprofile_edit_users",
"quality_gates",
+ "qgate_group_permissions",
"quality_gate_conditions",
"saml_message_ids",
"rules",
ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("UUID");
CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
+CREATE TABLE "QGATE_GROUP_PERMISSIONS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "QUALITY_GATE_UUID" VARCHAR(40) NOT NULL,
+ "GROUP_UUID" VARCHAR(40) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "QGATE_GROUP_PERMISSIONS" ADD CONSTRAINT "PK_QGATE_GROUP_PERMISSIONS" PRIMARY KEY("UUID");
+CREATE INDEX "QG_GROUPS_UUID_IDX" ON "QGATE_GROUP_PERMISSIONS"("QUALITY_GATE_UUID");
+
CREATE TABLE "QGATE_USER_PERMISSIONS"(
"UUID" VARCHAR(40) NOT NULL,
"QUALITY_GATE_UUID" VARCHAR(40) NOT NULL,
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v92;
+
+import org.sonar.db.Database;
+
+public class CreateQGateGroupPermissionsTable extends CreateQGatePermissionsTable {
+ private static final String TABLE_NAME = "qgate_group_permissions";
+ private static final String QUALITY_GATE_UUID_INDEX = "qg_groups_uuid_idx";
+ private static final String COLUMN_NAME = "group_uuid";
+
+ public CreateQGateGroupPermissionsTable(Database db) {
+ super(db, TABLE_NAME, QUALITY_GATE_UUID_INDEX, COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v92;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+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 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 abstract class CreateQGatePermissionsTable extends DdlChange {
+ private final String tableName;
+ private final String indexName;
+ private final String columnName;
+
+ protected CreateQGatePermissionsTable(Database db, String tableName, String indexName, String columnName) {
+ super(db);
+ this.tableName = tableName;
+ this.indexName = indexName;
+ this.columnName = columnName;
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (tableExists()) {
+ return;
+ }
+
+ VarcharColumnDef qualityGateUuidColumn = newVarcharColumnBuilder("quality_gate_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
+ context.execute(new CreateTableBuilder(getDialect(), tableName)
+ .addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
+ .addColumn(qualityGateUuidColumn)
+ .addColumn(newVarcharColumnBuilder(columnName).setIsNullable(false).setLimit(UUID_SIZE).build())
+ .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
+ .build());
+
+ CreateIndexBuilder builder = new CreateIndexBuilder()
+ .setTable(tableName)
+ .setName(indexName)
+ .setUnique(false)
+ .addColumn(qualityGateUuidColumn);
+ context.execute(builder.build());
+ }
+
+ private static VarcharColumnDef.Builder newVarcharColumnBuilder(String column) {
+ return newVarcharColumnDefBuilder().setColumnName(column);
+ }
+
+ private boolean tableExists() throws SQLException {
+ try (var connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.tableExists(tableName, connection);
+ }
+ }
+}
*/
package org.sonar.server.platform.db.migration.version.v92;
-import java.sql.SQLException;
import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
-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 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 CreateQGateUserPermissionsTable extends DdlChange {
+public class CreateQGateUserPermissionsTable extends CreateQGatePermissionsTable {
private static final String TABLE_NAME = "qgate_user_permissions";
private static final String QUALITY_GATE_UUID_INDEX = "quality_gate_uuid_idx";
+ private static final String COLUMN_NAME = "user_uuid";
public CreateQGateUserPermissionsTable(Database db) {
- super(db);
- }
-
- @Override
- public void execute(Context context) throws SQLException {
- if (tableExists()) {
- return;
- }
-
- VarcharColumnDef qualityGateUuidColumn = newVarcharColumnBuilder("quality_gate_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
- context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
- .addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
- .addColumn(qualityGateUuidColumn)
- .addColumn(newVarcharColumnBuilder("user_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
- .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
- .build());
-
- CreateIndexBuilder builder = new CreateIndexBuilder()
- .setTable(TABLE_NAME)
- .setName(QUALITY_GATE_UUID_INDEX)
- .setUnique(false)
- .addColumn(qualityGateUuidColumn);
- context.execute(builder.build());
- }
-
- private static VarcharColumnDef.Builder newVarcharColumnBuilder(String column) {
- return newVarcharColumnDefBuilder().setColumnName(column);
- }
-
- private boolean tableExists() throws SQLException {
- try (var connection = getDatabase().getDataSource().getConnection()) {
- return DatabaseUtils.tableExists(TABLE_NAME, connection);
- }
+ super(db, TABLE_NAME, QUALITY_GATE_UUID_INDEX, COLUMN_NAME);
}
}
.add(6101, "Change size of column 'selection_expression' in 'Portfolios'", AlterSelectionExpressionInPortfoliosTable.class)
.add(6102, "Migrate Bitbucket.org authentication plugin settings to built-in authentication settings", MigrateBibucketOrgPluginSettingsToBuiltInSettings.class)
.add(6103, "Create column quick_fix_available in 'issues'", AddQuickFixAvailableColumnInIssuesTable.class)
- .add(6104, "Create qgate_user_permissions Table", CreateQGateUserPermissionsTable.class);
+ .add(6104, "Create qgate_user_permissions Table", CreateQGateUserPermissionsTable.class)
+ .add(6105, "Create qgate_group_permissions Table", CreateQGateGroupPermissionsTable.class);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v92;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class CreateQGateGroupPermissionsTableTest {
+ private final static String TABLE_NAME = "qgate_group_permissions";
+ private final static String QUALITY_GATE_UUID_INDEX = "qg_groups_uuid_idx";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(CreateQGateGroupPermissionsTableTest.class, "schema.sql");
+
+ private final CreateQGateGroupPermissionsTable underTest = new CreateQGateGroupPermissionsTable(db.database());
+
+ @Test
+ public void migration_should_create_a_table_with_index() throws SQLException {
+ db.assertTableDoesNotExist(TABLE_NAME);
+
+ underTest.execute();
+
+ db.assertTableExists(TABLE_NAME);
+ db.assertIndex(TABLE_NAME, QUALITY_GATE_UUID_INDEX, "quality_gate_uuid");
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ db.assertTableDoesNotExist(TABLE_NAME);
+
+ underTest.execute();
+ //re-entrant
+ underTest.execute();
+
+ db.assertTableExists(TABLE_NAME);
+ db.assertIndex(TABLE_NAME, QUALITY_GATE_UUID_INDEX, "quality_gate_uuid");
+ }
+}
--- /dev/null
+DROP TABLE IF EXISTS qgate_group_permissions;