--- /dev/null
+package org.sonar.server.platform.db.migration.version.v87;
+
+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;
+
+import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
+
+public class AddMonorepoColumnToProjectAlmSettingsTable extends DdlChange {
+
+ private static final String TABLE = "project_alm_settings";
+
+ private static final BooleanColumnDef MONOREPO = newBooleanColumnDefBuilder()
+ .setColumnName("monorepo")
+ .setIsNullable(true)
+ .build();
+
+ public AddMonorepoColumnToProjectAlmSettingsTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(MONOREPO)
+ .build());
+ }
+}
.add(4207, "Drop table 'alm_app_installs'", DropAlmAppInstallsTable.class)
.add(4208, "Drop table 'organizations'", DropOrganizationsTable.class)
.add(4209, "Drop table 'organization_members'", DropOrgMembersTable.class)
+
+ .add(4210, "Add column 'monorepo' to table 'project_alm_settings'", AddMonorepoColumnToProjectAlmSettingsTable.class)
+ .add(4211, "Populate column 'monorepo' to false in table 'project_alm_settings'", PopulateMonorepoColumnToProjectAlmSettingsTable.class)
+ .add(4212, "Make column 'monorepo' in table 'project_alm_settings' not Nullable", MakeMonorepoColumnInProjectAlmSettingsTableNotNullable.class)
;
}
}
--- /dev/null
+package org.sonar.server.platform.db.migration.version.v87;
+
+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;
+
+import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
+
+public class MakeMonorepoColumnInProjectAlmSettingsTableNotNullable extends DdlChange {
+ private static final String TABLE = "project_alm_settings";
+
+ private static final BooleanColumnDef MONOREPO = newBooleanColumnDefBuilder()
+ .setColumnName("monorepo")
+ .setIsNullable(false)
+ .build();
+
+ public MakeMonorepoColumnInProjectAlmSettingsTableNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(MONOREPO)
+ .build());
+ }
+}
--- /dev/null
+package org.sonar.server.platform.db.migration.version.v87;
+
+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 PopulateMonorepoColumnToProjectAlmSettingsTable extends DataChange {
+ public PopulateMonorepoColumnToProjectAlmSettingsTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select("select uuid from project_alm_settings where monorepo is null");
+ massUpdate.update("update project_alm_settings set monorepo = ? where uuid = ?");
+ massUpdate.execute((row, update) -> {
+ update.setBoolean(1, false);
+ update.setString(2, row.getString(1));
+ return true;
+ });
+ }
+}
--- /dev/null
+package org.sonar.server.platform.db.migration.version.v87;
+
+import java.sql.SQLException;
+import java.sql.Types;
+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 AddMonorepoColumnToProjectAlmSettingsTableTest {
+ private static final String TABLE_NAME = "project_alm_settings";
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddMonorepoColumnToProjectAlmSettingsTableTest.class, "schema.sql");
+
+ private final DdlChange underTest = new AddMonorepoColumnToProjectAlmSettingsTable(db.database());
+
+ @Test
+ public void add_monorepo_column() throws SQLException {
+ insertProjectAlmSettings(1);
+ insertProjectAlmSettings(2);
+ insertProjectAlmSettings(3);
+
+ underTest.execute();
+
+ db.assertColumnDefinition("project_alm_settings", "monorepo", Types.BOOLEAN, null, true);
+ assertThat(db.countRowsOfTable(TABLE_NAME)).isEqualTo(3);
+ }
+
+ private void insertProjectAlmSettings(int id) {
+ db.executeInsert("project_alm_settings",
+ "UUID", "uuid-" + id,
+ "ALM_SETTING_UUID", "ALM_SETTING_UUID",
+ "PROJECT_UUID", "PROJECT_UUID-" + id,
+ "ALM_REPO", "ALM_REPO",
+ "ALM_SLUG", "ALM_SLUG",
+ "UPDATED_AT", 12342342,
+ "CREATED_AT",1232342
+ );
+ }
+}
--- /dev/null
+package org.sonar.server.platform.db.migration.version.v87;
+
+import java.sql.SQLException;
+import java.sql.Types;
+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 MakeMonorepoColumnInProjectAlmSettingsTableNotNullableTest {
+ private static final String TABLE_NAME = "project_alm_settings";
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeMonorepoColumnInProjectAlmSettingsTableNotNullableTest.class, "schema.sql");
+
+ private final DdlChange underTest = new MakeMonorepoColumnInProjectAlmSettingsTableNotNullable(db.database());
+
+ @Test
+ public void verify_monorepo_column_not_nullable() throws SQLException {
+ insertProjectAlmSettings(1);
+ insertProjectAlmSettings(2);
+ insertProjectAlmSettings(3);
+
+ underTest.execute();
+
+ db.assertColumnDefinition(TABLE_NAME, "monorepo", Types.BOOLEAN, null, false);
+
+ assertThat(db.countRowsOfTable(TABLE_NAME)).isEqualTo(3);
+ }
+
+ private void insertProjectAlmSettings(int id) {
+ db.executeInsert("project_alm_settings",
+ "UUID", "uuid-" + id,
+ "ALM_SETTING_UUID", "ALM_SETTING_UUID",
+ "PROJECT_UUID", "PROJECT_UUID-" + id,
+ "ALM_REPO", "ALM_REPO",
+ "ALM_SLUG", "ALM_SLUG",
+ "MONOREPO", false,
+ "UPDATED_AT", 12342342,
+ "CREATED_AT",1232342
+ );
+ }
+}
--- /dev/null
+package org.sonar.server.platform.db.migration.version.v87;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateMonorepoColumnToProjectAlmSettingsTableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateMonorepoColumnToProjectAlmSettingsTableTest.class, "schema.sql");
+
+ private final DataChange underTest = new PopulateMonorepoColumnToProjectAlmSettingsTable(db.database());
+
+ @Test
+ public void populate_monorepo_on_empty_table() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from project_alm_settings")).isZero();
+ }
+
+ @Test
+ public void populate_monorepo_column() throws SQLException {
+ insertProjectAlmSettings(1);
+ insertProjectAlmSettings(2);
+ insertProjectAlmSettings(3);
+
+ underTest.execute();
+
+ db.assertColumnDefinition("project_alm_settings", "monorepo", Types.BOOLEAN, null, true);
+ assertThat(db.countSql("select count(uuid) from project_alm_settings where monorepo = false")).isEqualTo(3);
+ }
+
+ private void insertProjectAlmSettings(int id) {
+ db.executeInsert("project_alm_settings",
+ "UUID", "uuid-" + id,
+ "ALM_SETTING_UUID", "ALM_SETTING_UUID",
+ "PROJECT_UUID", "PROJECT_UUID-" + id,
+ "ALM_REPO", "ALM_REPO",
+ "ALM_SLUG", "ALM_SLUG",
+ "UPDATED_AT", 12342342,
+ "CREATED_AT",1232342
+ );
+ }
+}
--- /dev/null
+CREATE TABLE "PROJECT_ALM_SETTINGS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "ALM_SETTING_UUID" VARCHAR(40) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "ALM_REPO" VARCHAR(256),
+ "ALM_SLUG" VARCHAR(256),
+ "UPDATED_AT" BIGINT NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "SUMMARY_COMMENT_ENABLED" BOOLEAN
+);
+ALTER TABLE "PROJECT_ALM_SETTINGS" ADD CONSTRAINT "PK_PROJECT_ALM_SETTINGS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROJECT_ALM_SETTINGS" ON "PROJECT_ALM_SETTINGS"("PROJECT_UUID");
+CREATE INDEX "PROJECT_ALM_SETTINGS_ALM" ON "PROJECT_ALM_SETTINGS"("ALM_SETTING_UUID");
+CREATE INDEX "PROJECT_ALM_SETTINGS_SLUG" ON "PROJECT_ALM_SETTINGS"("ALM_SLUG");
--- /dev/null
+CREATE TABLE "PROJECT_ALM_SETTINGS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "ALM_SETTING_UUID" VARCHAR(40) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "ALM_REPO" VARCHAR(256),
+ "ALM_SLUG" VARCHAR(256),
+ "UPDATED_AT" BIGINT NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "SUMMARY_COMMENT_ENABLED" BOOLEAN,
+ "MONOREPO" BOOLEAN
+);
+ALTER TABLE "PROJECT_ALM_SETTINGS" ADD CONSTRAINT "PK_PROJECT_ALM_SETTINGS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROJECT_ALM_SETTINGS" ON "PROJECT_ALM_SETTINGS"("PROJECT_UUID");
+CREATE INDEX "PROJECT_ALM_SETTINGS_ALM" ON "PROJECT_ALM_SETTINGS"("ALM_SETTING_UUID");
+CREATE INDEX "PROJECT_ALM_SETTINGS_SLUG" ON "PROJECT_ALM_SETTINGS"("ALM_SLUG");
--- /dev/null
+CREATE TABLE "PROJECT_ALM_SETTINGS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "ALM_SETTING_UUID" VARCHAR(40) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "ALM_REPO" VARCHAR(256),
+ "ALM_SLUG" VARCHAR(256),
+ "UPDATED_AT" BIGINT NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "SUMMARY_COMMENT_ENABLED" BOOLEAN,
+ "MONOREPO" BOOLEAN
+);
+ALTER TABLE "PROJECT_ALM_SETTINGS" ADD CONSTRAINT "PK_PROJECT_ALM_SETTINGS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROJECT_ALM_SETTINGS" ON "PROJECT_ALM_SETTINGS"("PROJECT_UUID");
+CREATE INDEX "PROJECT_ALM_SETTINGS_ALM" ON "PROJECT_ALM_SETTINGS"("ALM_SETTING_UUID");
+CREATE INDEX "PROJECT_ALM_SETTINGS_SLUG" ON "PROJECT_ALM_SETTINGS"("ALM_SLUG");