From a60f3c39d100eb0eae125c01c6932ddfb37417c9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 7 Feb 2017 17:43:58 +0100 Subject: [PATCH] SONAR-8754 add column ORGANIZATIONS.GUARDED --- .../v63/AddColumnGuardedToOrganizations.java | 44 +++++++++ .../db/migration/version/v63/DbVersion63.java | 5 +- ...lumnGuardedOfOrganizationsNotNullable.java | 44 +++++++++ .../PopulateColumnGuardedOfOrganizations.java | 46 +++++++++ .../AddColumnGuardedToOrganizationsTest.java | 55 +++++++++++ .../version/v63/DbVersion63Test.java | 2 +- ...GuardedOfOrganizationsNotNullableTest.java | 63 ++++++++++++ ...ulateColumnGuardedOfOrganizationsTest.java | 96 +++++++++++++++++++ .../previous-organizations.sql | 14 +++ .../organizations_with_nullable_guarded.sql | 15 +++ .../organizations.sql | 15 +++ .../org/sonar/db/version/rows-h2.sql | 3 + .../org/sonar/db/version/schema-h2.ddl | 1 + 13 files changed, 401 insertions(+), 2 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizations.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizations.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizationsTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizationsTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizationsTest/previous-organizations.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest/organizations_with_nullable_guarded.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizationsTest/organizations.sql diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizations.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizations.java new file mode 100644 index 00000000000..74573572260 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizations.java @@ -0,0 +1,44 @@ +/* + * 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.BooleanColumnDef; +import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class AddColumnGuardedToOrganizations extends DdlChange { + public AddColumnGuardedToOrganizations(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute( + new AddColumnsBuilder(getDialect(), "organizations") + .addColumn( + BooleanColumnDef.newBooleanColumnDefBuilder() + .setColumnName("guarded") + .setIsNullable(true) + .build()) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java index 9aae9b502f7..82fc9f8f641 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java @@ -41,6 +41,9 @@ public class DbVersion63 implements DbVersion { .add(1506, "Add index on PROJECTS.ORGANIZATION_UUID", AddIndexOnOrganizationUuidOfProjects.class) .add(1507, "Drop table RESOURCE_INDEX", DropTableResourceIndex.class) .add(1508, "Add columns ORGANIZATIONS.DEFAULT_PERM_TEMPLATE_*", AddDefaultPermTemplateColumnsToOrganizations.class) - .add(1509, "Populate columns ORGANIZATIONS.DEFAULT_PERM_TEMPLATE_*", PopulateDefaultPermTemplateColumnsOfOrganizations.class); + .add(1509, "Populate columns ORGANIZATIONS.DEFAULT_PERM_TEMPLATE_*", PopulateDefaultPermTemplateColumnsOfOrganizations.class) + .add(1510, "Add ORGANIZATIONS.GUARDED", AddColumnGuardedToOrganizations.class) + .add(1511, "Populate ORGANIZATIONS.GUARDED", PopulateColumnGuardedOfOrganizations.class) + .add(1512, "Make ORGANIZATIONS.GUARDED not nullable", MakeColumnGuardedOfOrganizationsNotNullable.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullable.java new file mode 100644 index 00000000000..bfbbe6d00ed --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullable.java @@ -0,0 +1,44 @@ +/* + * 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.BooleanColumnDef; +import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class MakeColumnGuardedOfOrganizationsNotNullable extends DdlChange { + public MakeColumnGuardedOfOrganizationsNotNullable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute( + new AlterColumnsBuilder(getDialect(), "organizations") + .updateColumn( + BooleanColumnDef.newBooleanColumnDefBuilder() + .setColumnName("guarded") + .setIsNullable(false) + .build()) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizations.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizations.java new file mode 100644 index 00000000000..887ca6f1d43 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizations.java @@ -0,0 +1,46 @@ +/* + * 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.step.DataChange; +import org.sonar.server.platform.db.migration.step.MassUpdate; + +public class PopulateColumnGuardedOfOrganizations extends DataChange { + public PopulateColumnGuardedOfOrganizations(Database db) { + super(db); + } + + @Override + protected void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select uuid from organizations where guarded is null"); + massUpdate.update("update organizations set guarded=? where uuid=?"); + massUpdate.rowPluralName("organizations"); + massUpdate.execute((row, statement) -> { + String organizationUuid = row.getString(1); + + statement.setBoolean(1, false); + statement.setString(2, organizationUuid); + return true; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizationsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizationsTest.java new file mode 100644 index 00000000000..de8ced8dd0e --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizationsTest.java @@ -0,0 +1,55 @@ +/* + * 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 AddColumnGuardedToOrganizationsTest { + + @Rule + public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, AddColumnGuardedToOrganizationsTest.class, "previous-organizations.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private AddColumnGuardedToOrganizations underTest = new AddColumnGuardedToOrganizations(dbTester.database()); + + @Test + public void add_nullable_boolean_column_guarded_to_table_organizations() throws SQLException { + underTest.execute(); + + dbTester.assertColumnDefinition("organizations", "guarded", Types.BOOLEAN, null, true); + } + + @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/v63/DbVersion63Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java index 3512ef01c85..d9c06f27d62 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java @@ -41,7 +41,7 @@ public class DbVersion63Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 10); + verifyMigrationCount(underTest, 13); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest.java new file mode 100644 index 00000000000..b60f8971570 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest.java @@ -0,0 +1,63 @@ +package org.sonar.server.platform.db.migration.version.v63; + +import java.sql.SQLException; +import java.sql.Types; +import javax.annotation.Nullable; +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 MakeColumnGuardedOfOrganizationsNotNullableTest { + private static final String TABLE_ORGANIZATIONS = "organizations"; + + @Rule + public DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, MakeColumnGuardedOfOrganizationsNotNullableTest.class, "organizations_with_nullable_guarded.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private MakeColumnGuardedOfOrganizationsNotNullable underTest = new MakeColumnGuardedOfOrganizationsNotNullable(dbTester.database()); + + @Test + public void migration_sets_guarded_column_not_nullable_on_empty_table() throws SQLException { + underTest.execute(); + + verifyColumnDefinition(); + } + + @Test + public void migration_sets_guarded_column_not_nullable_on_populated_table() throws SQLException { + insertOrganization("org_A", true); + insertOrganization("org_B", false); + + underTest.execute(); + + verifyColumnDefinition(); + } + + @Test + public void migration_fails_if_some_row_has_a_null_guarded() throws SQLException { + insertOrganization("org_c", null); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Fail to execute"); + + underTest.execute(); + } + + private void verifyColumnDefinition() { + dbTester.assertColumnDefinition(TABLE_ORGANIZATIONS, "guarded", Types.BOOLEAN, null, false); + } + + private void insertOrganization(String uuid, @Nullable Boolean guarded) { + dbTester.executeInsert( + "ORGANIZATIONS", + "UUID", uuid, + "KEE", uuid, + "NAME", uuid, + "GUARDED", guarded == null ? null : String.valueOf(guarded), + "CREATED_AT", "1000", + "UPDATED_AT", "1000"); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizationsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizationsTest.java new file mode 100644 index 00000000000..657a470be7d --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizationsTest.java @@ -0,0 +1,96 @@ +/* + * 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 javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PopulateColumnGuardedOfOrganizationsTest { + + @Rule + public DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, PopulateColumnGuardedOfOrganizationsTest.class, "organizations.sql"); + + private PopulateColumnGuardedOfOrganizations underTest = new PopulateColumnGuardedOfOrganizations(dbTester.database()); + + @Test + public void execute_has_no_effect_when_table_is_empty() throws SQLException { + underTest.execute(); + } + + @Test + public void execute_is_reentrant_when_table_is_empty() throws SQLException { + underTest.execute(); + + underTest.execute(); + } + + @Test + public void execute_sets_is_protected_to_false_for_all_rows() throws SQLException { + insertOrganization("u1", null); + insertOrganization("u2", null); + + underTest.execute(); + + assertThat(dbTester.countSql("select count(*) from organizations where guarded is null")).isEqualTo(0); + assertThat(dbTester.countSql("select count(*) from organizations where guarded is not null")).isEqualTo(2); + assertThat(dbTester.countSql("select count(*) from organizations where guarded=false")).isEqualTo(2); + } + + @Test + public void execute_is_reentrant_when_table_had_data() throws SQLException { + insertOrganization("u1", true); + insertOrganization("u2", null); + + underTest.execute(); + + assertThat(dbTester.countSql("select count(*) from organizations where guarded is null")).isEqualTo(0); + assertThat(dbTester.countSql("select count(*) from organizations where guarded is not null")).isEqualTo(2); + assertThat(dbTester.countSql("select count(*) from organizations where guarded=false")).isEqualTo(1); + assertThat(dbTester.countSql("select count(*) from organizations where guarded=true")).isEqualTo(1); + + underTest.execute(); + } + + @Test + public void execute_is_reentrant_when_table_had_partially_migrated_data() throws SQLException { + insertOrganization("u1", false); + insertOrganization("u2", null); + + underTest.execute(); + } + + private void insertOrganization(String uuid, @Nullable Boolean guarded) { + dbTester.executeInsert( + "ORGANIZATIONS", + "UUID", uuid, + "KEE", uuid, + "NAME", uuid, + "GUARDED", guarded == null ? null : String.valueOf(guarded), + "CREATED_AT", "1000", + "UPDATED_AT", "1000"); + } + +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizationsTest/previous-organizations.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizationsTest/previous-organizations.sql new file mode 100644 index 00000000000..9275a44ab8d --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/AddColumnGuardedToOrganizationsTest/previous-organizations.sql @@ -0,0 +1,14 @@ +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), + "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40), + "DEFAULT_PERM_TEMPLATE_VIEW" VARCHAR(40), + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL +); +CREATE UNIQUE INDEX "PK_ORGANIZATIONS" ON "ORGANIZATIONS" ("UUID"); +CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS" ("KEE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest/organizations_with_nullable_guarded.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest/organizations_with_nullable_guarded.sql new file mode 100644 index 00000000000..0600e9c8101 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest/organizations_with_nullable_guarded.sql @@ -0,0 +1,15 @@ +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), + "GUARDED" BOOLEAN, + "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40), + "DEFAULT_PERM_TEMPLATE_VIEW" VARCHAR(40), + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL +); +CREATE UNIQUE INDEX "PK_ORGANIZATIONS" ON "ORGANIZATIONS" ("UUID"); +CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS" ("KEE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizationsTest/organizations.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizationsTest/organizations.sql new file mode 100644 index 00000000000..0600e9c8101 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/PopulateColumnGuardedOfOrganizationsTest/organizations.sql @@ -0,0 +1,15 @@ +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), + "GUARDED" BOOLEAN, + "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40), + "DEFAULT_PERM_TEMPLATE_VIEW" VARCHAR(40), + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL +); +CREATE UNIQUE INDEX "PK_ORGANIZATIONS" ON "ORGANIZATIONS" ("UUID"); +CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS" ("KEE"); diff --git a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql index 26c5cd9909f..00d131c627c 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql +++ b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql @@ -523,6 +523,9 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1506'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1507'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1508'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1509'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1510'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1511'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1512'); 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; diff --git a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl index ab505c6741f..742cdc0d75c 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -5,6 +5,7 @@ CREATE TABLE "ORGANIZATIONS" ( "DESCRIPTION" VARCHAR(256), "URL" VARCHAR(256), "AVATAR_URL" VARCHAR(256), + "GUARDED" BOOLEAN NOT NULL, "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40), "DEFAULT_PERM_TEMPLATE_VIEW" VARCHAR(40), "CREATED_AT" BIGINT NOT NULL, -- 2.39.5