"DEFAULT_GROUP_ID" INTEGER,
"DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL,
"NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL,
- "SUBSCRIPTION" VARCHAR(40),
+ "SUBSCRIPTION" VARCHAR(40) NOT NULL,
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL,
private String key;
/** Name, can't be null */
private String name;
- /** description can be null */
+ /** description can't be null */
private String description;
/** url can be null */
private String url;
}
public Subscription getSubscription() {
- // TODO directly return subscription when column will be NOT NULLABLE (SONAR-10965)
- return subscription == null ? Subscription.FREE : subscription;
+ return subscription;
}
public OrganizationDto setSubscription(Subscription subscription) {
.setUrl("the url 1")
.setAvatarUrl("the avatar url 1")
.setGuarded(false)
+ .setSubscription(FREE)
.setDefaultQualityGateUuid("1");
private static final OrganizationDto ORGANIZATION_DTO_2 = new OrganizationDto()
.setUuid("uuid 2")
.setUrl("the url 2")
.setAvatarUrl("the avatar url 2")
.setGuarded(true)
+ .setSubscription(FREE)
.setDefaultQualityGateUuid("1");
private static final String PERMISSION_1 = "foo";
private static final String PERMISSION_2 = "bar";
.setDescription(organizationDto.getDescription())
.setUrl(organizationDto.getUrl())
.setDefaultQualityGateUuid(organizationDto.getDefaultQualityGateUuid())
+ .setSubscription(organizationDto.getSubscription())
.setAvatarUrl(organizationDto.getAvatarUrl());
}
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.db.organization.OrganizationDto.Subscription.SONARQUBE;
import static org.sonar.db.user.GroupTesting.newGroupDto;
public class GroupDaoTest {
.setKey("an-org")
.setName("An Org")
.setDefaultQualityGateUuid("1")
+ .setSubscription(SONARQUBE)
.setUuid("abcde");
private System2 system2 = mock(System2.class);
.add(2208, "Add rules.security_standards", AddSecurityStandardsToRules.class)
.add(2209, "Fix missing quality profiles on organizations", FixMissingQualityProfilesOnOrganizations.class)
.add(2210, "Add 'securityhotspotadmin' permission to templates characteristics already having 'issueadmin'", PopulateHotspotAdminPermissionOnTemplatesCharacteristics.class)
+ .add(2211, "Set SUBSCRIPTION not nullable in ORGANIZATIONS", SetSubscriptionOnOrganizationsNotNullable.class)
;
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.v73;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.SupportsBlueGreen;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+@SupportsBlueGreen
+public class SetSubscriptionOnOrganizationsNotNullable extends DdlChange {
+
+ public SetSubscriptionOnOrganizationsNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), "organizations")
+ .updateColumn(newVarcharColumnDefBuilder()
+ .setColumnName("subscription")
+ .setLimit(40)
+ .setIsNullable(false)
+ .build())
+ .build());
+ }
+}
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 11);
+ verifyMigrationCount(underTest, 12);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.v73;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+
+public class SetSubscriptionOnOrganizationsNotNullableTest {
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(SetSubscriptionOnOrganizationsNotNullableTest.class, "organizations.sql");
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private SetSubscriptionOnOrganizationsNotNullable underTest = new SetSubscriptionOnOrganizationsNotNullable(db.database());
+
+ @Test
+ public void column_is_added_to_table() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("organizations", "subscription", VARCHAR, 40, false);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ underTest.execute();
+
+ underTest.execute();
+ }
+
+}
--- /dev/null
+CREATE TABLE "ORGANIZATIONS" (
+ "UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(32) NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "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),
+ "DEFAULT_GROUP_ID" INTEGER,
+ "DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL,
+ "NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "SUBSCRIPTION" VARCHAR(40),
+ CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY ("UUID")
+);
+CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS" ("KEE");