From 48603acf7442237c1405740994ee112a1a622c62 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 21 Apr 2020 15:21:59 -0500 Subject: [PATCH] SONAR-13221 PERM_TEMPLATES_USERS --- ...nUuidColumnOfPermTemplatesGroupsTable.java | 38 +++++++++ ...dUuidColumnToPermTemplatesGroupsTable.java | 31 +++++++ ...ropIdColumnOfPermTemplatesGroupsTable.java | 31 +++++++ ...yOnIdColumnOfPermTemplatesGroupsTable.java | 32 ++++++++ ...mTemplatesGroupsUuidColumnNotNullable.java | 31 +++++++ .../PopulatePermTemplatesGroupsUuid.java | 50 +++++++++++ ...OnUuidColumnOfPermTemplatesUsersTable.java | 38 +++++++++ ...ddUuidColumnToPermTemplatesUsersTable.java | 31 +++++++ ...DropIdColumnOfPermTemplatesUsersTable.java | 31 +++++++ ...eyOnIdColumnOfPermTemplatesUsersTable.java | 32 ++++++++ ...rmTemplatesUsersUuidColumnNotNullable.java | 31 +++++++ .../PopulatePermTemplatesUsersUuid.java | 50 +++++++++++ ...idColumnOfPermTplCharacteristicsTable.java | 38 +++++++++ ...idColumnToPermTplCharacteristicsTable.java | 31 +++++++ ...IdColumnOfPermTplCharacteristicsTable.java | 31 +++++++ ...IdColumnOfPermTplCharacteristicsTable.java | 32 ++++++++ ...lCharacteristicsUuidColumnNotNullable.java | 31 +++++++ .../PopulatePermTplCharacteristicsUuid.java | 50 +++++++++++ ...dColumnOfPermTemplatesGroupsTableTest.java | 52 ++++++++++++ ...dColumnToPermTemplatesGroupsTableTest.java | 68 +++++++++++++++ ...dColumnOfPermTemplatesGroupsTableTest.java | 52 ++++++++++++ ...dColumnOfPermTemplatesGroupsTableTest.java | 58 +++++++++++++ ...platesGroupsUuidColumnNotNullableTest.java | 43 ++++++++++ .../PopulatePermTemplatesGroupsUuidTest.java | 82 +++++++++++++++++++ ...idColumnOfPermTemplatesUsersTableTest.java | 51 ++++++++++++ ...idColumnToPermTemplatesUsersTableTest.java | 64 +++++++++++++++ ...IdColumnOfPermTemplatesUsersTableTest.java | 51 ++++++++++++ ...IdColumnOfPermTemplatesUsersTableTest.java | 57 +++++++++++++ ...mplatesUsersUuidColumnNotNullableTest.java | 42 ++++++++++ .../PopulatePermTemplatesUsersUuidTest.java | 81 ++++++++++++++++++ ...lumnOfPermTplCharacteristicsTableTest.java | 52 ++++++++++++ ...lumnToPermTplCharacteristicsTableTest.java | 64 +++++++++++++++ ...lumnOfPermTplCharacteristicsTableTest.java | 52 ++++++++++++ ...lumnOfPermTplCharacteristicsTableTest.java | 58 +++++++++++++ ...racteristicsUuidColumnNotNullableTest.java | 43 ++++++++++ ...opulatePermTplCharacteristicsUuidTest.java | 82 +++++++++++++++++++ .../schema.sql | 9 ++ .../schema.sql | 9 ++ .../schema.sql | 10 +++ .../schema.sql | 10 +++ .../schema.sql | 10 +++ .../schema.sql | 10 +++ .../schema.sql | 9 ++ .../schema.sql | 9 ++ .../schema.sql | 10 +++ .../schema.sql | 10 +++ .../schema.sql | 10 +++ .../schema.sql | 10 +++ .../schema.sql | 9 ++ .../schema.sql | 9 ++ .../schema.sql | 10 +++ .../schema.sql | 10 +++ .../schema.sql | 10 +++ .../schema.sql | 10 +++ 54 files changed, 1865 insertions(+) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuid.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuid.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuid.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuidTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuidTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuidTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuidTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuidTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuidTest/schema.sql diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable.java new file mode 100644 index 00000000000..42d6af094a7 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable.java @@ -0,0 +1,38 @@ +/* + * 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.permtemplatesusers; + +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 AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable extends DdlChange { + + public AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddPrimaryKeyBuilder("perm_templates_users", "uuid").build()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTable.java new file mode 100644 index 00000000000..1fc2d72952a --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTable.java @@ -0,0 +1,31 @@ +/* + * 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.permtemplatesusers; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable; + +public class AddUuidColumnToPermTemplatesUsersTable extends AddUuidColumnToTable { + private static final String TABLE = "perm_templates_users"; + + public AddUuidColumnToPermTemplatesUsersTable(Database db) { + super(db, TABLE); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTable.java new file mode 100644 index 00000000000..978a431df6d --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTable.java @@ -0,0 +1,31 @@ +/* + * 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.permtemplatesusers; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn; + +public class DropIdColumnOfPermTemplatesUsersTable extends DropIdColumn { + private static final String TABLE = "perm_templates_users"; + + public DropIdColumnOfPermTemplatesUsersTable(Database db) { + super(db, TABLE); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable.java new file mode 100644 index 00000000000..46bf6a4c8c6 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable.java @@ -0,0 +1,32 @@ +/* + * 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.permtemplatesusers; + +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 DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable extends DropPrimaryKeyOnIdColumn { + private static final String TABLE_NAME = "perm_templates_users"; + + public DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) { + super(db, dropPrimaryKeySqlGenerator, TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullable.java new file mode 100644 index 00000000000..6c2b9bedca3 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullable.java @@ -0,0 +1,31 @@ +/* + * 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.permtemplatesusers; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable; + +public class MakePermTemplatesUsersUuidColumnNotNullable extends MakeUuidColumnNotNullable { + private static final String TABLE = "perm_templates_users"; + + public MakePermTemplatesUsersUuidColumnNotNullable(Database db) { + super(db, TABLE); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuid.java new file mode 100644 index 00000000000..e15d013b4a4 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuid.java @@ -0,0 +1,50 @@ +/* + * 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.permtemplatesusers; + +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 PopulatePermTemplatesUsersUuid extends DataChange { + + private final UuidFactory uuidFactory; + + public PopulatePermTemplatesUsersUuid(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 perm_templates_users where uuid is null order by id asc"); + massUpdate.update("update perm_templates_users set uuid = ? where id = ?"); + + massUpdate.execute((row, update) -> { + update.setString(1, uuidFactory.create()); + update.setLong(2, row.getLong(1)); + return true; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable.java new file mode 100644 index 00000000000..42d6af094a7 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable.java @@ -0,0 +1,38 @@ +/* + * 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.permtemplatesusers; + +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 AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable extends DdlChange { + + public AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddPrimaryKeyBuilder("perm_templates_users", "uuid").build()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTable.java new file mode 100644 index 00000000000..1fc2d72952a --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTable.java @@ -0,0 +1,31 @@ +/* + * 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.permtemplatesusers; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable; + +public class AddUuidColumnToPermTemplatesUsersTable extends AddUuidColumnToTable { + private static final String TABLE = "perm_templates_users"; + + public AddUuidColumnToPermTemplatesUsersTable(Database db) { + super(db, TABLE); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTable.java new file mode 100644 index 00000000000..978a431df6d --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTable.java @@ -0,0 +1,31 @@ +/* + * 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.permtemplatesusers; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn; + +public class DropIdColumnOfPermTemplatesUsersTable extends DropIdColumn { + private static final String TABLE = "perm_templates_users"; + + public DropIdColumnOfPermTemplatesUsersTable(Database db) { + super(db, TABLE); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable.java new file mode 100644 index 00000000000..46bf6a4c8c6 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable.java @@ -0,0 +1,32 @@ +/* + * 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.permtemplatesusers; + +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 DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable extends DropPrimaryKeyOnIdColumn { + private static final String TABLE_NAME = "perm_templates_users"; + + public DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) { + super(db, dropPrimaryKeySqlGenerator, TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullable.java new file mode 100644 index 00000000000..6c2b9bedca3 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullable.java @@ -0,0 +1,31 @@ +/* + * 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.permtemplatesusers; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable; + +public class MakePermTemplatesUsersUuidColumnNotNullable extends MakeUuidColumnNotNullable { + private static final String TABLE = "perm_templates_users"; + + public MakePermTemplatesUsersUuidColumnNotNullable(Database db) { + super(db, TABLE); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuid.java new file mode 100644 index 00000000000..e15d013b4a4 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuid.java @@ -0,0 +1,50 @@ +/* + * 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.permtemplatesusers; + +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 PopulatePermTemplatesUsersUuid extends DataChange { + + private final UuidFactory uuidFactory; + + public PopulatePermTemplatesUsersUuid(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 perm_templates_users where uuid is null order by id asc"); + massUpdate.update("update perm_templates_users set uuid = ? where id = ?"); + + massUpdate.execute((row, update) -> { + update.setString(1, uuidFactory.create()); + update.setLong(2, row.getLong(1)); + return true; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable.java new file mode 100644 index 00000000000..384e8fc35a1 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable.java @@ -0,0 +1,38 @@ +/* + * 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.permtplcharacteristics; + +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 AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable extends DdlChange { + + public AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddPrimaryKeyBuilder("perm_templates_users", "uuid").build()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTable.java new file mode 100644 index 00000000000..c436b6afd0a --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTable.java @@ -0,0 +1,31 @@ +/* + * 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.permtplcharacteristics; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable; + +public class AddUuidColumnToPermTemplatesUsersTable extends AddUuidColumnToTable { + private static final String TABLE = "perm_templates_users"; + + public AddUuidColumnToPermTemplatesUsersTable(Database db) { + super(db, TABLE); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTable.java new file mode 100644 index 00000000000..34ec9c1db69 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTable.java @@ -0,0 +1,31 @@ +/* + * 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.permtplcharacteristics; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn; + +public class DropIdColumnOfPermTemplatesUsersTable extends DropIdColumn { + private static final String TABLE = "perm_templates_users"; + + public DropIdColumnOfPermTemplatesUsersTable(Database db) { + super(db, TABLE); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable.java new file mode 100644 index 00000000000..9b0dd8f5ea3 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable.java @@ -0,0 +1,32 @@ +/* + * 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.permtplcharacteristics; + +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 DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable extends DropPrimaryKeyOnIdColumn { + private static final String TABLE_NAME = "perm_templates_users"; + + public DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) { + super(db, dropPrimaryKeySqlGenerator, TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullable.java new file mode 100644 index 00000000000..5557aab2a74 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullable.java @@ -0,0 +1,31 @@ +/* + * 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.permtplcharacteristics; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable; + +public class MakePermTemplatesUsersUuidColumnNotNullable extends MakeUuidColumnNotNullable { + private static final String TABLE = "perm_templates_users"; + + public MakePermTemplatesUsersUuidColumnNotNullable(Database db) { + super(db, TABLE); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuid.java new file mode 100644 index 00000000000..0f5d2b1421d --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuid.java @@ -0,0 +1,50 @@ +/* + * 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.permtplcharacteristics; + +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 PopulatePermTemplatesUsersUuid extends DataChange { + + private final UuidFactory uuidFactory; + + public PopulatePermTemplatesUsersUuid(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 perm_templates_users where uuid is null order by id asc"); + massUpdate.update("update perm_templates_users set uuid = ? where id = ?"); + + massUpdate.execute((row, update) -> { + update.setString(1, uuidFactory.create()); + update.setLong(2, row.getLong(1)); + return true; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTableTest.java new file mode 100644 index 00000000000..a11d47f56c2 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTableTest.java @@ -0,0 +1,52 @@ +/* + * 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.permtemplategroups; + +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.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.permtemplatesgroups.AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema( + AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTableTest.class, "schema.sql"); + + private DdlChange underTest = new AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertPrimaryKey("perm_templates_groups", "pk_perm_templates_groups", "uuid"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTableTest.java new file mode 100644 index 00000000000..1a8b7e40800 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTableTest.java @@ -0,0 +1,68 @@ +/* + * 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.permtemplategroups; + +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 org.sonar.server.platform.db.migration.version.v83.permtemplatesgroups.AddUuidColumnToPermTemplatesGroupsTable; + +import static org.assertj.core.api.Assertions.assertThat; + +public class AddUuidColumnToPermTemplatesGroupsTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToPermTemplatesGroupsTableTest.class, "schema.sql"); + + private DdlChange underTest = new AddUuidColumnToPermTemplatesGroupsTable(db.database()); + + private UuidFactoryFast uuidFactory = UuidFactoryFast.getInstance(); + + @Before + public void setup() { + insertPermTemplatesGroups(1L); + insertPermTemplatesGroups(2L); + insertPermTemplatesGroups(3L); + } + + @Test + public void add_uuid_column() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("perm_templates_groups", "uuid", Types.VARCHAR, 40, true); + + assertThat(db.countRowsOfTable("perm_templates_groups")) + .isEqualTo(3); + } + + private void insertPermTemplatesGroups(Long id) { + db.executeInsert("perm_templates_groups", + "id", id, + "user_id", id + 1, + "template_id", id + 2, + "permission_reference", "ref" + id); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTableTest.java new file mode 100644 index 00000000000..7b43a955ab5 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTableTest.java @@ -0,0 +1,52 @@ +/* + * 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.permtemplategroups; + +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.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.permtemplatesgroups.DropIdColumnOfPermTemplatesGroupsTable; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class DropIdColumnOfPermTemplatesGroupsTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfPermTemplatesGroupsTableTest.class, "schema.sql"); + + private DdlChange underTest = new DropIdColumnOfPermTemplatesGroupsTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertColumnDoesNotExist("perm_templates_groups", "id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.java new file mode 100644 index 00000000000..5331ec4f683 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.java @@ -0,0 +1,58 @@ +/* + * 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.permtemplategroups; + +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.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.permtemplatesgroups.DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable; +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 DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest { + + private static final String TABLE_NAME = "perm_templates_groups"; + @Rule + public CoreDbTester db = CoreDbTester.createForSchema( + DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.class, "schema.sql"); + + private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())); + + private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable(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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullableTest.java new file mode 100644 index 00000000000..45149db4899 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullableTest.java @@ -0,0 +1,43 @@ +/* + * 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.permtemplategroups; + +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 org.sonar.server.platform.db.migration.version.v83.permtemplatesgroups.MakePermTemplatesGroupsUuidColumnNotNullable; + +import static java.sql.Types.VARCHAR; + +public class MakePermTemplatesGroupsUuidColumnNotNullableTest { + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(MakePermTemplatesGroupsUuidColumnNotNullableTest.class, "schema.sql"); + + private MigrationStep underTest = new MakePermTemplatesGroupsUuidColumnNotNullable(db.database()); + + @Test + public void uuid_column_is_not_nullable() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("perm_templates_groups", "uuid", VARCHAR, null, false); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuidTest.java new file mode 100644 index 00000000000..78c8a928c87 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuidTest.java @@ -0,0 +1,82 @@ +/* + * 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.permtemplategroups; + +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 org.sonar.server.platform.db.migration.version.v83.permtemplatesgroups.PopulatePermTemplatesGroupsUuid; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PopulatePermTemplatesGroupsUuidTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulatePermTemplatesGroupsUuidTest.class, "schema.sql"); + + private UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + private DataChange underTest = new PopulatePermTemplatesGroupsUuid(db.database(), uuidFactory); + + @Test + public void populate_uuids() throws SQLException { + insertPermTemplatesGroups(1L); + insertPermTemplatesGroups(2L); + insertPermTemplatesGroups(3L); + + underTest.execute(); + + verifyUuidsAreNotNull(); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertPermTemplatesGroups(1L); + insertPermTemplatesGroups(2L); + insertPermTemplatesGroups(3L); + + underTest.execute(); + // re-entrant + underTest.execute(); + + verifyUuidsAreNotNull(); + } + + private void verifyUuidsAreNotNull() { + assertThat(db.select("select uuid from perm_templates_groups") + .stream() + .map(row -> row.get("UUID")) + .filter(Objects::isNull) + .collect(Collectors.toList())).isEmpty(); + } + + private void insertPermTemplatesGroups(Long id) { + db.executeInsert("perm_templates_groups", + "id", id, + "user_id", id + 1, + "template_id", id + 2, + "permission_reference", "ref" + id); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTableTest.java new file mode 100644 index 00000000000..ff248edcc9c --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTableTest.java @@ -0,0 +1,51 @@ +/* + * 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.permtemplatesusers; + +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.DdlChange; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema( + AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTableTest.class, "schema.sql"); + + private DdlChange underTest = new AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertPrimaryKey("perm_templates_users", "pk_perm_templates_users", "uuid"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTableTest.java new file mode 100644 index 00000000000..2f9472a0c74 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTableTest.java @@ -0,0 +1,64 @@ +/* + * 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.permtemplatesusers; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.assertj.core.api.Assertions.assertThat; + +public class AddUuidColumnToPermTemplatesUsersTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToPermTemplatesUsersTableTest.class, "schema.sql"); + + private DdlChange underTest = new AddUuidColumnToPermTemplatesUsersTable(db.database()); + + @Before + public void setup() { + insertPermTemplatesUsers(1L); + insertPermTemplatesUsers(2L); + insertPermTemplatesUsers(3L); + } + + @Test + public void add_uuid_column() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("perm_templates_users", "uuid", Types.VARCHAR, 40, true); + + assertThat(db.countRowsOfTable("perm_templates_users")) + .isEqualTo(3); + } + + private void insertPermTemplatesUsers(Long id) { + db.executeInsert("perm_templates_users", + "id", id, + "user_id", id + 1, + "template_id", id + 2, + "permission_reference", "ref" + id); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTableTest.java new file mode 100644 index 00000000000..632991e4778 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTableTest.java @@ -0,0 +1,51 @@ +/* + * 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.permtemplatesusers; + +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.DdlChange; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class DropIdColumnOfPermTemplatesUsersTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfPermTemplatesUsersTableTest.class, "schema.sql"); + + private DdlChange underTest = new DropIdColumnOfPermTemplatesUsersTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertColumnDoesNotExist("perm_templates_users", "id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.java new file mode 100644 index 00000000000..709bc7b426f --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.java @@ -0,0 +1,57 @@ +/* + * 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.permtemplatesusers; + +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.DdlChange; +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 DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest { + + private static final String TABLE_NAME = "perm_templates_users"; + @Rule + public CoreDbTester db = CoreDbTester.createForSchema( + DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.class, "schema.sql"); + + private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())); + + private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable(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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullableTest.java new file mode 100644 index 00000000000..030f1eb90ca --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullableTest.java @@ -0,0 +1,42 @@ +/* + * 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.permtemplatesusers; + +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 MakePermTemplatesUsersUuidColumnNotNullableTest { + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(MakePermTemplatesUsersUuidColumnNotNullableTest.class, "schema.sql"); + + private MigrationStep underTest = new MakePermTemplatesUsersUuidColumnNotNullable(db.database()); + + @Test + public void uuid_column_is_not_nullable() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("perm_templates_users", "uuid", VARCHAR, null, false); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuidTest.java new file mode 100644 index 00000000000..bb397042444 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuidTest.java @@ -0,0 +1,81 @@ +/* + * 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.permtemplatesusers; + +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 PopulatePermTemplatesUsersUuidTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulatePermTemplatesUsersUuidTest.class, "schema.sql"); + + private UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + private DataChange underTest = new PopulatePermTemplatesUsersUuid(db.database(), uuidFactory); + + @Test + public void populate_uuids() throws SQLException { + insertPermTemplatesUsers(1L); + insertPermTemplatesUsers(2L); + insertPermTemplatesUsers(3L); + + underTest.execute(); + + verifyUuidsAreNotNull(); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertPermTemplatesUsers(1L); + insertPermTemplatesUsers(2L); + insertPermTemplatesUsers(3L); + + underTest.execute(); + // re-entrant + underTest.execute(); + + verifyUuidsAreNotNull(); + } + + private void verifyUuidsAreNotNull() { + assertThat(db.select("select uuid from perm_templates_users") + .stream() + .map(row -> row.get("UUID")) + .filter(Objects::isNull) + .collect(Collectors.toList())).isEmpty(); + } + + private void insertPermTemplatesUsers(Long id) { + db.executeInsert("perm_templates_users", + "id", id, + "user_id", id + 1, + "template_id", id + 2, + "permission_reference", "ref" + id); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTableTest.java new file mode 100644 index 00000000000..6b314cfe2ae --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTableTest.java @@ -0,0 +1,52 @@ +/* + * 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.permtplcharacteristics; + +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.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.permtemplatesgroups.AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema( + AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTableTest.class, "schema.sql"); + + private DdlChange underTest = new AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertPrimaryKey("perm_tpl_characteristics", "pk_perm_tpl_characteristics", "uuid"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTableTest.java new file mode 100644 index 00000000000..c7bfd06f325 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTableTest.java @@ -0,0 +1,64 @@ +/* + * 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.permtplcharacteristics; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.assertj.core.api.Assertions.assertThat; + +public class AddUuidColumnToPermTplCharacteristicsTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToPermTplCharacteristicsTableTest.class, "schema.sql"); + + private DdlChange underTest = new AddUuidColumnToPermTplCharacteristicsTable(db.database()); + + @Before + public void setup() { + insertPermTplCharacteristics(1L); + insertPermTplCharacteristics(2L); + insertPermTplCharacteristics(3L); + } + + @Test + public void add_uuid_column() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("perm_tpl_characteristics", "uuid", Types.VARCHAR, 40, true); + + assertThat(db.countRowsOfTable("perm_tpl_characteristics")) + .isEqualTo(3); + } + + private void insertPermTplCharacteristics(Long id) { + db.executeInsert("perm_tpl_characteristics", + "id", id, + "group_id", id + 1, + "template_id", id + 2, + "permission_reference", "ref" + id); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTableTest.java new file mode 100644 index 00000000000..7955292b680 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTableTest.java @@ -0,0 +1,52 @@ +/* + * 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.permtplcharacteristics; + +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.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.permtemplatesgroups.DropIdColumnOfPermTplCharacteristicsTable; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class DropIdColumnOfPermTplCharacteristicsTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfPermTplCharacteristicsTableTest.class, "schema.sql"); + + private DdlChange underTest = new DropIdColumnOfPermTplCharacteristicsTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertColumnDoesNotExist("perm_tpl_characteristics", "id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.java new file mode 100644 index 00000000000..f41a4603236 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.java @@ -0,0 +1,58 @@ +/* + * 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.permtplcharacteristics; + +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.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.permtemplatesgroups.DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable; +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 DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest { + + private static final String TABLE_NAME = "perm_tpl_characteristics"; + @Rule + public CoreDbTester db = CoreDbTester.createForSchema( + DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.class, "schema.sql"); + + private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())); + + private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable(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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullableTest.java new file mode 100644 index 00000000000..825203e4456 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullableTest.java @@ -0,0 +1,43 @@ +/* + * 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.permtplcharacteristics; + +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 org.sonar.server.platform.db.migration.version.v83.permtemplatesgroups.MakePermTplCharacteristicsUuidColumnNotNullable; + +import static java.sql.Types.VARCHAR; + +public class MakePermTplCharacteristicsUuidColumnNotNullableTest { + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(MakePermTplCharacteristicsUuidColumnNotNullableTest.class, "schema.sql"); + + private MigrationStep underTest = new MakePermTplCharacteristicsUuidColumnNotNullable(db.database()); + + @Test + public void uuid_column_is_not_nullable() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("perm_tpl_characteristics", "uuid", VARCHAR, null, false); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuidTest.java new file mode 100644 index 00000000000..d05ccb45730 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuidTest.java @@ -0,0 +1,82 @@ +/* + * 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.permtplcharacteristics; + +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 org.sonar.server.platform.db.migration.version.v83.permtemplatesgroups.PopulatePermTplCharacteristicsUuid; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PopulatePermTplCharacteristicsUuidTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulatePermTplCharacteristicsUuidTest.class, "schema.sql"); + + private UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + private DataChange underTest = new PopulatePermTplCharacteristicsUuid(db.database(), uuidFactory); + + @Test + public void populate_uuids() throws SQLException { + insertPermTplCharacteristics(1L); + insertPermTplCharacteristics(2L); + insertPermTplCharacteristics(3L); + + underTest.execute(); + + verifyUuidsAreNotNull(); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertPermTplCharacteristics(1L); + insertPermTplCharacteristics(2L); + insertPermTplCharacteristics(3L); + + underTest.execute(); + // re-entrant + underTest.execute(); + + verifyUuidsAreNotNull(); + } + + private void verifyUuidsAreNotNull() { + assertThat(db.select("select uuid from perm_tpl_characteristics") + .stream() + .map(row -> row.get("UUID")) + .filter(Objects::isNull) + .collect(Collectors.toList())).isEmpty(); + } + + private void insertPermTplCharacteristics(Long id) { + db.executeInsert("perm_tpl_characteristics", + "id", id, + "group_id", id + 1, + "template_id", id + 2, + "permission_reference", "ref" + id); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTableTest/schema.sql new file mode 100644 index 00000000000..07a2bfd5bb7 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTableTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTableTest/schema.sql new file mode 100644 index 00000000000..285b963b8cd --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/AddUuidColumnToPermTemplatesGroupsTableTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_USERS" ADD CONSTRAINT "PK_PERM_TEMPLATES_USERS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTableTest/schema.sql new file mode 100644 index 00000000000..d6e978cbe1d --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropIdColumnOfPermTemplatesGroupsTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_USERS" ADD CONSTRAINT "PK_PERM_TEMPLATES_USERS" PRIMARY KEY("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest/schema.sql new file mode 100644 index 00000000000..dc2d8b31e74 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_USERS" ADD CONSTRAINT "PK_PERM_TEMPLATES_USERS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullableTest/schema.sql new file mode 100644 index 00000000000..23c2c4f21e6 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/MakePermTemplatesGroupsUuidColumnNotNullableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40), + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_USERS" ADD CONSTRAINT "PK_PERM_TEMPLATES_USERS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuidTest/schema.sql new file mode 100644 index 00000000000..23c2c4f21e6 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesgroups/PopulatePermTemplatesGroupsUuidTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40), + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_USERS" ADD CONSTRAINT "PK_PERM_TEMPLATES_USERS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTableTest/schema.sql new file mode 100644 index 00000000000..d51c8ba2245 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTableTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL, + "UUID" VARCHAR(40) NOT NULL, + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTableTest/schema.sql new file mode 100644 index 00000000000..285b963b8cd --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/AddUuidColumnToPermTemplatesUsersTableTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_USERS" ADD CONSTRAINT "PK_PERM_TEMPLATES_USERS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTableTest/schema.sql new file mode 100644 index 00000000000..f2974f76813 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropIdColumnOfPermTemplatesUsersTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL, + "UUID" VARCHAR(40) NOT NULL, + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_USERS" ADD CONSTRAINT "PK_PERM_TEMPLATES_USERS" PRIMARY KEY("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest/schema.sql new file mode 100644 index 00000000000..dc2d8b31e74 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_USERS" ADD CONSTRAINT "PK_PERM_TEMPLATES_USERS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullableTest/schema.sql new file mode 100644 index 00000000000..23c2c4f21e6 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/MakePermTemplatesUsersUuidColumnNotNullableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40), + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_USERS" ADD CONSTRAINT "PK_PERM_TEMPLATES_USERS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuidTest/schema.sql new file mode 100644 index 00000000000..23c2c4f21e6 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtemplatesusers/PopulatePermTemplatesUsersUuidTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_USERS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40), + "USER_ID" INTEGER NOT NULL, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_USERS" ADD CONSTRAINT "PK_PERM_TEMPLATES_USERS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTableTest/schema.sql new file mode 100644 index 00000000000..b6b8edee12c --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTableTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "PERM_TEMPLATES_GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTableTest/schema.sql new file mode 100644 index 00000000000..fa6baad81b0 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/AddUuidColumnToPermTplCharacteristicsTableTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "PERM_TEMPLATES_GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "GROUP_ID" INTEGER, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_GROUPS" ADD CONSTRAINT "PK_PERM_TEMPLATES_GROUPS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTableTest/schema.sql new file mode 100644 index 00000000000..731962e11a9 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropIdColumnOfPermTplCharacteristicsTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_GROUPS" ADD CONSTRAINT "PK_PERM_TEMPLATES_GROUPS" PRIMARY KEY("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest/schema.sql new file mode 100644 index 00000000000..dcef0db3e5e --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_GROUPS" ADD CONSTRAINT "PK_PERM_TEMPLATES_GROUPS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullableTest/schema.sql new file mode 100644 index 00000000000..a1d04848527 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/MakePermTplCharacteristicsUuidColumnNotNullableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40), + "GROUP_ID" INTEGER, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_GROUPS" ADD CONSTRAINT "PK_PERM_TEMPLATES_GROUPS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuidTest/schema.sql new file mode 100644 index 00000000000..a1d04848527 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permtplcharacteristics/PopulatePermTplCharacteristicsUuidTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40), + "GROUP_ID" INTEGER, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "PERM_TEMPLATES_GROUPS" ADD CONSTRAINT "PK_PERM_TEMPLATES_GROUPS" PRIMARY KEY("ID"); -- 2.39.5