diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-09-21 11:57:23 +0200 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-10-02 17:18:15 +0200 |
commit | d899635a55db0dc8ff37c9ce88df82af190c469c (patch) | |
tree | 0abbcd4f9bf87f1fda04f646c5565cc885af59ed /server/sonar-db-migration/src | |
parent | e52aa133123efef9ae7b9099b1a620bad795e010 (diff) | |
download | sonarqube-d899635a55db0dc8ff37c9ce88df82af190c469c.tar.gz sonarqube-d899635a55db0dc8ff37c9ce88df82af190c469c.zip |
SONAR-1330 Create table QPROFILE_EDIT_USERS
Diffstat (limited to 'server/sonar-db-migration/src')
5 files changed, 150 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditUsers.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditUsers.java new file mode 100644 index 00000000000..841dca5540b --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditUsers.java @@ -0,0 +1,82 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.v66; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.IntegerColumnDef; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; +import org.sonar.server.platform.db.migration.sql.CreateTableBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder; + +public class CreateTableQProfileEditUsers extends DdlChange { + + private static final String TABLE_NAME = "qprofile_edit_users"; + + public CreateTableQProfileEditUsers(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + IntegerColumnDef userLoginColumn = IntegerColumnDef.newIntegerColumnDefBuilder() + .setColumnName("user_id") + .setIsNullable(false) + .build(); + VarcharColumnDef qProfileUuidColumn = VarcharColumnDef.newVarcharColumnDefBuilder() + .setColumnName("qprofile_uuid") + .setIsNullable(false) + .setLimit(255) + .build(); + context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME) + .addPkColumn(VarcharColumnDef.newVarcharColumnDefBuilder() + .setColumnName("uuid") + .setIsNullable(false) + .setLimit(40) + .build()) + .addColumn(userLoginColumn) + .addColumn(qProfileUuidColumn) + .addColumn(newBigIntegerColumnDefBuilder() + .setColumnName("created_at") + .setIsNullable(false) + .build()) + .build() + ); + + context.execute( + new CreateIndexBuilder(getDialect()) + .setTable(TABLE_NAME) + .setName(TABLE_NAME + "_qprofile") + .addColumn(qProfileUuidColumn) + .setUnique(false) + .build()); + context.execute( + new CreateIndexBuilder(getDialect()) + .setTable(TABLE_NAME) + .setName(TABLE_NAME + "_unique") + .addColumn(userLoginColumn) + .addColumn(qProfileUuidColumn) + .setUnique(true) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java index 3cb9ff5735c..2a5736a2d59 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java @@ -37,6 +37,7 @@ public class DbVersion66 implements DbVersion { .add(1808, "Add branch column to projects table", AddBranchColumnToProjectsTable.class) .add(1809, "Populate project_branches with existing main branches", PopulateMainProjectBranches.class) .add(1810, "Add ce_activity.error_type", AddErrorTypeColumnToCeActivityTable.class) + .add(1811, "Create table qprofile_edit_users", CreateTableQProfileEditUsers.class) ; } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditUsersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditUsersTest.java new file mode 100644 index 00000000000..6d7b69332fd --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditUsersTest.java @@ -0,0 +1,66 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.v66; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.db.CoreDbTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CreateTableQProfileEditUsersTest { + + private static final String TABLE = "qprofile_edit_users"; + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(CreateTableQProfileEditUsersTest.class, "empty.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private CreateTableQProfileEditUsers underTest = new CreateTableQProfileEditUsers(db.database()); + + @Test + public void creates_table_on_empty_db() throws SQLException { + underTest.execute(); + + assertThat(db.countRowsOfTable(TABLE)).isEqualTo(0); + + db.assertColumnDefinition(TABLE, "uuid", Types.VARCHAR, 40, false); + db.assertColumnDefinition(TABLE, "user_id", Types.INTEGER, null, false); + db.assertColumnDefinition(TABLE, "qprofile_uuid", Types.VARCHAR, 255, false); + db.assertColumnDefinition(TABLE, "created_at", Types.BIGINT, null, false); + db.assertPrimaryKey(TABLE, "pk_" + TABLE, "uuid"); + db.assertIndex(TABLE, "qprofile_edit_users_qprofile", "qprofile_uuid"); + db.assertUniqueIndex(TABLE, "qprofile_edit_users_unique", "user_id", "qprofile_uuid"); + } + + @Test + public void migration_is_not_reentrant() throws SQLException { + underTest.execute(); + + expectedException.expect(IllegalStateException.class); + + underTest.execute(); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java index 6ebcf647366..d12cb8ada98 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java @@ -36,7 +36,7 @@ public class DbVersion66Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 10); + verifyMigrationCount(underTest, 11); } } diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditUsersTest/empty.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditUsersTest/empty.sql new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditUsersTest/empty.sql |