import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.sonar.api.security.DefaultGroups;
+import org.sonar.core.util.Uuids;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentMapper;
}
public void insert(DbSession dbSession, GroupPermissionDto dto) {
+ dto.setUuid(Uuids.create());
ensureComponentPermissionConsistency(dbSession, dto);
ensureGroupPermissionConsistency(dbSession, dto);
mapper(dbSession).insert(dto);
import javax.annotation.Nullable;
public class GroupPermissionDto {
-
+ private String uuid;
private String organizationUuid;
private Integer groupId;
private String componentUuid;
private String role;
+ public String getUuid() {
+ return uuid;
+ }
+
+ public GroupPermissionDto setUuid(String uuid) {
+ this.uuid = uuid;
+ return this;
+ }
+
public Integer getGroupId() {
return groupId;
}
<sql id="groupsByQuery">
from (
- select g.id as groupId, g.name as name, gr.role as permission, gr.component_uuid as componentUuid, gr.id as id
+ select g.id as groupId, g.name as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
from groups g
left join group_roles gr on g.id = gr.group_id
<if test="query.componentUuid == null">
union all
- select 0 as groupId, 'Anyone' as name, gr.role as permission, gr.component_uuid as componentUuid, gr.id as id
+ select 0 as groupId, 'Anyone' as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
from group_roles gr
<where>
<if test="query.componentUuid == null">
)
</select>
- <insert id="insert" parameterType="GroupPermission" keyColumn="id" useGeneratedKeys="false" keyProperty="id">
+ <insert id="insert" parameterType="GroupPermission">
insert into group_roles (
+ uuid,
organization_uuid,
group_id,
component_uuid,
role
) values (
+ #{uuid,jdbcType=VARCHAR},
#{organizationUuid,jdbcType=VARCHAR},
#{groupId,jdbcType=INTEGER},
#{componentUuid,jdbcType=BIGINT},
underTest.deleteByRootComponentUuid(dbSession, project1.uuid());
dbSession.commit();
- assertThat(db.countSql("select count(id) from group_roles where component_uuid='" + project1.uuid() + "'")).isEqualTo(0);
+ assertThat(db.countSql("select count(uuid) from group_roles where component_uuid='" + project1.uuid() + "'")).isEqualTo(0);
assertThat(db.countRowsOfTable("group_roles")).isEqualTo(2);
}
underTest.deleteByRootComponentUuid(dbSession, project1.uuid());
dbSession.commit();
- assertThat(db.countSql("select count(id) from group_roles where component_uuid='" + project1.uuid() + "'")).isEqualTo(0);
+ assertThat(db.countSql("select count(uuid) from group_roles where component_uuid='" + project1.uuid() + "'")).isEqualTo(0);
assertThat(db.countRowsOfTable("group_roles")).isEqualTo(3);
}
}
private void assertThatNoPermission(String permission) {
- assertThat(db.countSql("select count(id) from group_roles where role='" + permission + "'")).isEqualTo(0);
+ assertThat(db.countSql("select count(uuid) from group_roles where role='" + permission + "'")).isEqualTo(0);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder;
+
+public class AddPrimaryKeyOnUuidColumnOfGroupRolesTable extends DdlChange {
+
+ public AddPrimaryKeyOnUuidColumnOfGroupRolesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddPrimaryKeyBuilder("group_roles", "uuid").build());
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable;
+
+public class AddUuidColumnToGroupRolesTable extends AddUuidColumnToTable {
+ private static final String TABLE = "group_roles";
+
+ public AddUuidColumnToGroupRolesTable(Database db) {
+ super(db, TABLE);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIdColumnOfGroupRolesTable extends DdlChange {
+
+ private Database db;
+
+ public DropIdColumnOfGroupRolesTable(Database db) {
+ super(db);
+ this.db = db;
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(db.getDialect(), "group_roles", "id").build());
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.DropPrimaryKeyOnIdColumn;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfGroupRolesTable extends DropPrimaryKeyOnIdColumn {
+ private static final String TABLE_NAME = "group_roles";
+
+ public DropPrimaryKeyOnIdColumnOfGroupRolesTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+ super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+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 MakeGroupRolesUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE = "group_roles";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeGroupRolesUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+import java.sql.SQLException;
+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;
+
+public class PopulateGroupRolesUuid extends DataChange {
+
+ private final UuidFactory uuidFactory;
+
+ public PopulateGroupRolesUuid(Database db, UuidFactory uuidFactory) {
+ super(db);
+ this.uuidFactory = uuidFactory;
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select id from group_roles where uuid is null order by id asc");
+ massUpdate.update("update group_roles set uuid = ? where id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, uuidFactory.create());
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
* 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.v83;
+package org.sonar.server.platform.db.migration.version.v83.grouproles;
import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v83.grouproles.AddComponentUuidColumnToGroupRoles;
import static java.sql.Types.VARCHAR;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest.class, "schema.sql");
+
+ private AddPrimaryKeyOnUuidColumnOfGroupRolesTable underTest = new AddPrimaryKeyOnUuidColumnOfGroupRolesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertPrimaryKey("group_roles", "pk_group_roles", "uuid");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddUuidColumnToGroupRolesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToGroupRolesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddUuidColumnToGroupRolesTable(db.database());
+
+ private UuidFactoryFast uuidFactory = UuidFactoryFast.getInstance();
+
+ @Before
+ public void setup() {
+ insertGroupRoles(1L);
+ insertGroupRoles(2L);
+ insertGroupRoles(3L);
+ }
+
+ @Test
+ public void add_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("group_roles", "uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countRowsOfTable("group_roles"))
+ .isEqualTo(3);
+ }
+
+ private void insertGroupRoles(Long id) {
+ db.executeInsert("group_roles",
+ "id", id,
+ "organization_uuid", uuidFactory.create(),
+ "group_id", id + 1,
+ "role", id + 2,
+ "component_uuid", uuidFactory.create());
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropIdColumnOfGroupRolesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfGroupRolesTableTest.class, "schema.sql");
+
+ private DropIdColumnOfGroupRolesTable underTest = new DropIdColumnOfGroupRolesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("group_roles", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfGroupRolesTableTest {
+
+ private static final String TABLE_NAME = "group_roles";
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.class, "schema.sql");
+
+ private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+
+ private DropPrimaryKeyOnIdColumnOfGroupRolesTable underTest = new DropPrimaryKeyOnIdColumnOfGroupRolesTable(db.database(), dropPrimaryKeySqlGenerator);
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertNoPrimaryKey(TABLE_NAME);
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
* 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.v83;
+package org.sonar.server.platform.db.migration.version.v83.grouproles;
import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v83.grouproles.DropResourceIdFromGroupRolesTable;
import static java.sql.Types.INTEGER;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeGroupRolesUuidColumnNotNullableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeGroupRolesUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeGroupRolesUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_nullable() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("group_roles", "uuid", VARCHAR, null, false);
+ }
+}
* 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.v83;
+package org.sonar.server.platform.db.migration.version.v83.grouproles;
import java.sql.SQLException;
import java.util.Date;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v83.grouproles.MigrateResourceIdToUuidInGroupRoles;
import static org.assertj.core.api.Assertions.assertThat;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.grouproles;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateGroupRolesUuidTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateGroupRolesUuidTest.class, "schema.sql");
+
+ private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+ private DataChange underTest = new PopulateGroupRolesUuid(db.database(), uuidFactory);
+
+ @Test
+ public void populate_uuids() throws SQLException {
+ insertGroupRoles(1L);
+ insertGroupRoles(2L);
+ insertGroupRoles(3L);
+
+ underTest.execute();
+
+ verifyUuidsAreNotNull();
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertGroupRoles(1L);
+ insertGroupRoles(2L);
+ insertGroupRoles(3L);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ verifyUuidsAreNotNull();
+ }
+
+ private void verifyUuidsAreNotNull() {
+ assertThat(db.select("select uuid from group_roles")
+ .stream()
+ .map(row -> row.get("UUID"))
+ .filter(Objects::isNull)
+ .collect(Collectors.toList())).isEmpty();
+ }
+
+ private void insertGroupRoles(Long id) {
+ db.executeInsert("group_roles",
+ "id", id,
+ "uuid", uuidFactory.create(),
+ "organization_uuid", uuidFactory.create(),
+ "group_id", id + 1,
+ "role", id + 2,
+ "component_uuid", uuidFactory.create());
+ }
+
+}
+++ /dev/null
-CREATE TABLE "GROUP_ROLES"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
- "GROUP_ID" INTEGER,
- "RESOURCE_ID" INTEGER,
- "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
-CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
+++ /dev/null
-CREATE TABLE "PROPERTIES"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "PROP_KEY" VARCHAR(512) NOT NULL,
- "RESOURCE_ID" BIGINT,
- "USER_ID" BIGINT,
- "IS_EMPTY" BOOLEAN NOT NULL,
- "TEXT_VALUE" VARCHAR(4000),
- "CLOB_VALUE" CLOB(2147483647),
- "CREATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
-CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
+++ /dev/null
-CREATE TABLE "USER_ROLES"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
- "USER_ID" INTEGER,
- "RESOURCE_ID" INTEGER,
- "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
-CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
-CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
+++ /dev/null
-CREATE TABLE "GROUP_ROLES"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
- "COMPONENT_UUID" VARCHAR(50),
- "GROUP_ID" INTEGER,
- "RESOURCE_ID" INTEGER,
- "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
-CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
-CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+++ /dev/null
-CREATE TABLE "PROPERTIES"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "COMPONENT_UUID" VARCHAR(50),
- "PROP_KEY" VARCHAR(512) NOT NULL,
- "RESOURCE_ID" BIGINT,
- "USER_ID" BIGINT,
- "IS_EMPTY" BOOLEAN NOT NULL,
- "TEXT_VALUE" VARCHAR(4000),
- "CLOB_VALUE" CLOB(2147483647),
- "CREATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
-CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
+++ /dev/null
-CREATE TABLE "USER_ROLES"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
- "COMPONENT_UUID" VARCHAR(50),
- "USER_ID" INTEGER,
- "RESOURCE_ID" INTEGER,
- "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
-CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
-CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
-CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID");
+++ /dev/null
-CREATE TABLE "GROUP_ROLES"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
- "COMPONENT_UUID" VARCHAR(50),
- "GROUP_ID" INTEGER,
- "RESOURCE_ID" INTEGER,
- "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
-CREATE UNIQUE INDEX "GROUP_ROLES_UNIQ" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
-CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
-CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
-
-CREATE TABLE "COMPONENTS"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "UUID" VARCHAR(50) NOT NULL,
- "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
- "KEE" VARCHAR(400),
- "DEPRECATED_KEE" VARCHAR(400),
- "NAME" VARCHAR(2000),
- "LONG_NAME" VARCHAR(2000),
- "DESCRIPTION" VARCHAR(2000),
- "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
- "SCOPE" VARCHAR(3),
- "QUALIFIER" VARCHAR(10),
- "PRIVATE" BOOLEAN NOT NULL,
- "ROOT_UUID" VARCHAR(50) NOT NULL,
- "LANGUAGE" VARCHAR(20),
- "COPY_COMPONENT_UUID" VARCHAR(50),
- "PATH" VARCHAR(2000),
- "UUID_PATH" VARCHAR(1500) NOT NULL,
- "PROJECT_UUID" VARCHAR(50) NOT NULL,
- "MODULE_UUID" VARCHAR(50),
- "MODULE_UUID_PATH" VARCHAR(1500),
- "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
- "B_CHANGED" BOOLEAN,
- "B_NAME" VARCHAR(500),
- "B_LONG_NAME" VARCHAR(500),
- "B_DESCRIPTION" VARCHAR(2000),
- "B_ENABLED" BOOLEAN,
- "B_QUALIFIER" VARCHAR(10),
- "B_LANGUAGE" VARCHAR(20),
- "B_COPY_COMPONENT_UUID" VARCHAR(50),
- "B_PATH" VARCHAR(2000),
- "B_UUID_PATH" VARCHAR(1500),
- "B_MODULE_UUID" VARCHAR(50),
- "B_MODULE_UUID_PATH" VARCHAR(1500),
- "CREATED_AT" TIMESTAMP
-);
-ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
-CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
-CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
-CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
-CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
-CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
-CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
-CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
+++ /dev/null
-CREATE TABLE "PROPERTIES"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "COMPONENT_UUID" VARCHAR(50),
- "PROP_KEY" VARCHAR(512) NOT NULL,
- "RESOURCE_ID" BIGINT,
- "USER_ID" BIGINT,
- "IS_EMPTY" BOOLEAN NOT NULL,
- "TEXT_VALUE" VARCHAR(4000),
- "CLOB_VALUE" CLOB(2147483647),
- "CREATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
-CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
-
-CREATE TABLE "COMPONENTS"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "UUID" VARCHAR(50) NOT NULL,
- "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
- "KEE" VARCHAR(400),
- "DEPRECATED_KEE" VARCHAR(400),
- "NAME" VARCHAR(2000),
- "LONG_NAME" VARCHAR(2000),
- "DESCRIPTION" VARCHAR(2000),
- "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
- "SCOPE" VARCHAR(3),
- "QUALIFIER" VARCHAR(10),
- "PRIVATE" BOOLEAN NOT NULL,
- "ROOT_UUID" VARCHAR(50) NOT NULL,
- "LANGUAGE" VARCHAR(20),
- "COPY_COMPONENT_UUID" VARCHAR(50),
- "PATH" VARCHAR(2000),
- "UUID_PATH" VARCHAR(1500) NOT NULL,
- "PROJECT_UUID" VARCHAR(50) NOT NULL,
- "MODULE_UUID" VARCHAR(50),
- "MODULE_UUID_PATH" VARCHAR(1500),
- "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
- "B_CHANGED" BOOLEAN,
- "B_NAME" VARCHAR(500),
- "B_LONG_NAME" VARCHAR(500),
- "B_DESCRIPTION" VARCHAR(2000),
- "B_ENABLED" BOOLEAN,
- "B_QUALIFIER" VARCHAR(10),
- "B_LANGUAGE" VARCHAR(20),
- "B_COPY_COMPONENT_UUID" VARCHAR(50),
- "B_PATH" VARCHAR(2000),
- "B_UUID_PATH" VARCHAR(1500),
- "B_MODULE_UUID" VARCHAR(50),
- "B_MODULE_UUID_PATH" VARCHAR(1500),
- "CREATED_AT" TIMESTAMP
-);
-ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
-CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
-CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
-CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
-CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
-CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
-CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
-CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
+++ /dev/null
-CREATE TABLE "USER_ROLES"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
- "COMPONENT_UUID" VARCHAR(50),
- "USER_ID" INTEGER,
- "RESOURCE_ID" INTEGER,
- "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
-CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
-CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
-CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID");
-
-CREATE TABLE "COMPONENTS"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "UUID" VARCHAR(50) NOT NULL,
- "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
- "KEE" VARCHAR(400),
- "DEPRECATED_KEE" VARCHAR(400),
- "NAME" VARCHAR(2000),
- "LONG_NAME" VARCHAR(2000),
- "DESCRIPTION" VARCHAR(2000),
- "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
- "SCOPE" VARCHAR(3),
- "QUALIFIER" VARCHAR(10),
- "PRIVATE" BOOLEAN NOT NULL,
- "ROOT_UUID" VARCHAR(50) NOT NULL,
- "LANGUAGE" VARCHAR(20),
- "COPY_COMPONENT_UUID" VARCHAR(50),
- "PATH" VARCHAR(2000),
- "UUID_PATH" VARCHAR(1500) NOT NULL,
- "PROJECT_UUID" VARCHAR(50) NOT NULL,
- "MODULE_UUID" VARCHAR(50),
- "MODULE_UUID_PATH" VARCHAR(1500),
- "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
- "B_CHANGED" BOOLEAN,
- "B_NAME" VARCHAR(500),
- "B_LONG_NAME" VARCHAR(500),
- "B_DESCRIPTION" VARCHAR(2000),
- "B_ENABLED" BOOLEAN,
- "B_QUALIFIER" VARCHAR(10),
- "B_LANGUAGE" VARCHAR(20),
- "B_COPY_COMPONENT_UUID" VARCHAR(50),
- "B_PATH" VARCHAR(2000),
- "B_UUID_PATH" VARCHAR(1500),
- "B_MODULE_UUID" VARCHAR(50),
- "B_MODULE_UUID_PATH" VARCHAR(1500),
- "CREATED_AT" TIMESTAMP
-);
-ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
-CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
-CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
-CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
-CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
-CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
-CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
-CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
--- /dev/null
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "GROUP_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
+CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
--- /dev/null
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL,
+ "UUID" VARCHAR(40) NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "GROUP_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(40)
+);
+
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
--- /dev/null
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "GROUP_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
--- /dev/null
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL,
+ "UUID" VARCHAR(40) NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "GROUP_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("UUID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
--- /dev/null
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "GROUP_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
--- /dev/null
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50),
+ "GROUP_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
+CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
--- /dev/null
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL,
+ "UUID" VARCHAR(40),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "GROUP_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
--- /dev/null
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50),
+ "GROUP_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
+CREATE UNIQUE INDEX "GROUP_ROLES_UNIQ" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
+CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+
+CREATE TABLE "COMPONENTS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(50) NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(400),
+ "DEPRECATED_KEE" VARCHAR(400),
+ "NAME" VARCHAR(2000),
+ "LONG_NAME" VARCHAR(2000),
+ "DESCRIPTION" VARCHAR(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" VARCHAR(50) NOT NULL,
+ "LANGUAGE" VARCHAR(20),
+ "COPY_COMPONENT_UUID" VARCHAR(50),
+ "PATH" VARCHAR(2000),
+ "UUID_PATH" VARCHAR(1500) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "MODULE_UUID" VARCHAR(50),
+ "MODULE_UUID_PATH" VARCHAR(1500),
+ "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" VARCHAR(500),
+ "B_LONG_NAME" VARCHAR(500),
+ "B_DESCRIPTION" VARCHAR(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" VARCHAR(10),
+ "B_LANGUAGE" VARCHAR(20),
+ "B_COPY_COMPONENT_UUID" VARCHAR(50),
+ "B_PATH" VARCHAR(2000),
+ "B_UUID_PATH" VARCHAR(1500),
+ "B_MODULE_UUID" VARCHAR(50),
+ "B_MODULE_UUID_PATH" VARCHAR(1500),
+ "CREATED_AT" TIMESTAMP
+);
+ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
+CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
--- /dev/null
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL,
+ "UUID" VARCHAR(40),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "GROUP_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
--- /dev/null
+CREATE TABLE "PROPERTIES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "PROP_KEY" VARCHAR(512) NOT NULL,
+ "RESOURCE_ID" BIGINT,
+ "USER_ID" BIGINT,
+ "IS_EMPTY" BOOLEAN NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "CLOB_VALUE" CLOB(2147483647),
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
--- /dev/null
+CREATE TABLE "PROPERTIES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROP_KEY" VARCHAR(512) NOT NULL,
+ "RESOURCE_ID" BIGINT,
+ "USER_ID" BIGINT,
+ "IS_EMPTY" BOOLEAN NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "CLOB_VALUE" CLOB(2147483647),
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
--- /dev/null
+CREATE TABLE "PROPERTIES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROP_KEY" VARCHAR(512) NOT NULL,
+ "RESOURCE_ID" BIGINT,
+ "USER_ID" BIGINT,
+ "IS_EMPTY" BOOLEAN NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "CLOB_VALUE" CLOB(2147483647),
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
+
+CREATE TABLE "COMPONENTS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(50) NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(400),
+ "DEPRECATED_KEE" VARCHAR(400),
+ "NAME" VARCHAR(2000),
+ "LONG_NAME" VARCHAR(2000),
+ "DESCRIPTION" VARCHAR(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" VARCHAR(50) NOT NULL,
+ "LANGUAGE" VARCHAR(20),
+ "COPY_COMPONENT_UUID" VARCHAR(50),
+ "PATH" VARCHAR(2000),
+ "UUID_PATH" VARCHAR(1500) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "MODULE_UUID" VARCHAR(50),
+ "MODULE_UUID_PATH" VARCHAR(1500),
+ "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" VARCHAR(500),
+ "B_LONG_NAME" VARCHAR(500),
+ "B_DESCRIPTION" VARCHAR(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" VARCHAR(10),
+ "B_LANGUAGE" VARCHAR(20),
+ "B_COPY_COMPONENT_UUID" VARCHAR(50),
+ "B_PATH" VARCHAR(2000),
+ "B_UUID_PATH" VARCHAR(1500),
+ "B_MODULE_UUID" VARCHAR(50),
+ "B_MODULE_UUID_PATH" VARCHAR(1500),
+ "CREATED_AT" TIMESTAMP
+);
+ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
+CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
--- /dev/null
+CREATE TABLE "USER_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "USER_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
--- /dev/null
+CREATE TABLE "USER_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50),
+ "USER_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
+CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID");
--- /dev/null
+CREATE TABLE "USER_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50),
+ "USER_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
+CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID");
+
+CREATE TABLE "COMPONENTS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(50) NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(400),
+ "DEPRECATED_KEE" VARCHAR(400),
+ "NAME" VARCHAR(2000),
+ "LONG_NAME" VARCHAR(2000),
+ "DESCRIPTION" VARCHAR(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" VARCHAR(50) NOT NULL,
+ "LANGUAGE" VARCHAR(20),
+ "COPY_COMPONENT_UUID" VARCHAR(50),
+ "PATH" VARCHAR(2000),
+ "UUID_PATH" VARCHAR(1500) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "MODULE_UUID" VARCHAR(50),
+ "MODULE_UUID_PATH" VARCHAR(1500),
+ "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" VARCHAR(500),
+ "B_LONG_NAME" VARCHAR(500),
+ "B_DESCRIPTION" VARCHAR(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" VARCHAR(10),
+ "B_LANGUAGE" VARCHAR(20),
+ "B_COPY_COMPONENT_UUID" VARCHAR(50),
+ "B_PATH" VARCHAR(2000),
+ "B_UUID_PATH" VARCHAR(1500),
+ "B_MODULE_UUID" VARCHAR(50),
+ "B_MODULE_UUID_PATH" VARCHAR(1500),
+ "CREATED_AT" TIMESTAMP
+);
+ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
+CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");