]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8690 add columns ORGANIZATIONS.default_perm_template_*
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 24 Jan 2017 10:01:39 +0000 (11:01 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 27 Jan 2017 15:55:16 +0000 (16:55 +0100)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/AddDefaultPermTemplateColumnsToOrganizations.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/AddDefaultPermTemplateColumnsToOrganizationsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/AddDefaultPermTemplateColumnsToOrganizationsTest/previous-organizations.sql [new file with mode: 0644]
sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl

diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/AddDefaultPermTemplateColumnsToOrganizations.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/AddDefaultPermTemplateColumnsToOrganizations.java
new file mode 100644 (file)
index 0000000..06121fe
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.v63;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddDefaultPermTemplateColumnsToOrganizations extends DdlChange {
+  public AddDefaultPermTemplateColumnsToOrganizations(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(
+      new AddColumnsBuilder(getDialect(), "organizations")
+        .addColumn(
+          newVarcharColumnDefBuilder()
+            .setColumnName("default_perm_template_project")
+            .setLimit(VarcharColumnDef.UUID_SIZE)
+            .setIsNullable(true)
+            .build())
+        .addColumn(
+          newVarcharColumnDefBuilder()
+            .setColumnName("default_perm_template_view")
+            .setLimit(VarcharColumnDef.UUID_SIZE)
+            .setIsNullable(true)
+            .build())
+        .build());
+  }
+}
index 90725ae23c94a0b1870c6764ad7e2588c0c5c8b7..e42a5685b7e94e87dd355ad58a090c567cfcd1b9 100644 (file)
@@ -39,6 +39,7 @@ public class DbVersion63 implements DbVersion {
       .add(1504, "Populate PROJECTS.ORGANIZATION_UUID", PopulateOrganizationUuidToProjects.class)
       .add(1505, "Make PROJECTS.ORGANIZATION_UUID not nullable", MakeOrganizationUuidOfProjectsNotNullable.class)
       .add(1506, "Add index on PROJECTS.ORGANIZATION_UUID", AddIndexOnOrganizationUuidOfProjects.class)
-      .add(1507, "Drop table RESOURCE_INDEX", DropTableResourceIndex.class);
+      .add(1507, "Drop table RESOURCE_INDEX", DropTableResourceIndex.class)
+      .add(1508, "Add columns ORGANIZATIONS.DEFAULT_PERM_TEMPLATE_*", AddDefaultPermTemplateColumnsToOrganizations.class);
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/AddDefaultPermTemplateColumnsToOrganizationsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/AddDefaultPermTemplateColumnsToOrganizationsTest.java
new file mode 100644 (file)
index 0000000..e31edd3
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.v63;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+public class AddDefaultPermTemplateColumnsToOrganizationsTest {
+
+  @Rule
+  public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, AddDefaultPermTemplateColumnsToOrganizationsTest.class, "previous-organizations.sql");
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private AddDefaultPermTemplateColumnsToOrganizations underTest = new AddDefaultPermTemplateColumnsToOrganizations(dbTester.database());
+
+  @Test
+  public void creates_table_on_empty_db() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertColumnDefinition("organizations", "default_perm_template_project", Types.VARCHAR, 40, true);
+    dbTester.assertColumnDefinition("organizations", "default_perm_template_view", Types.VARCHAR, 40, true);
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+
+}
index 7b286029c7fc817689531b29f73a13e730754046..87ed043ecef00e881125eb6208ef0a1609af99bc 100644 (file)
@@ -41,7 +41,7 @@ public class DbVersion63Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 8);
+    verifyMigrationCount(underTest, 9);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/AddDefaultPermTemplateColumnsToOrganizationsTest/previous-organizations.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/AddDefaultPermTemplateColumnsToOrganizationsTest/previous-organizations.sql
new file mode 100644 (file)
index 0000000..825bf68
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "ORGANIZATIONS" (
+  "UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
+  "KEE" VARCHAR(32) NOT NULL,
+  "NAME" VARCHAR(64) NOT NULL,
+  "DESCRIPTION" VARCHAR(256),
+  "URL" VARCHAR(256),
+  "AVATAR_URL" VARCHAR(256),
+  "CREATED_AT" BIGINT NOT NULL,
+  "UPDATED_AT" BIGINT NOT NULL
+);
index d7ba8f8625d374346262a9de8ec5e71e57ab5cf2..e9f211edb22d9d4b5bf2f8c25a2097d6c4c0dffa 100644 (file)
@@ -521,6 +521,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1504');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1505');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1506');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1507');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1508');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, IS_ROOT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', true, '1418215735482', '1418215735482');
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 1ca427b7046b26ca8c38184dc6fef549172d5945..ab505c6741f24a9e1985b850ac7adf782d63016f 100644 (file)
@@ -5,6 +5,8 @@ CREATE TABLE "ORGANIZATIONS" (
   "DESCRIPTION" VARCHAR(256),
   "URL" VARCHAR(256),
   "AVATAR_URL" VARCHAR(256),
+  "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40),
+  "DEFAULT_PERM_TEMPLATE_VIEW" VARCHAR(40),
   "CREATED_AT" BIGINT NOT NULL,
   "UPDATED_AT" BIGINT NOT NULL
 );