"PERIOD4_DATE" BIGINT,
"PERIOD5_MODE" VARCHAR(100),
"PERIOD5_PARAM" VARCHAR(100),
- "PERIOD5_DATE" BIGINT
+ "PERIOD5_DATE" BIGINT,
+ "REVISION" VARCHAR(100)
);
CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS" ("COMPONENT_UUID");
CREATE UNIQUE INDEX "ANALYSES_UUID" ON "SNAPSHOTS" ("UUID");
build_date="1228222680000"
version="[null]"
build_string="[null]"
+ revision="[null]"
/>
<analysis_properties uuid="u1"
snapshot_uuid="u1"
build_date="1228222680000"
version="[null]"
build_string="[null]"
+ revision="[null]"
/>
<analysis_properties uuid="u2"
build_date="1228222680000"
version="[null]"
build_string="[null]"
+ revision="[null]"
/>
<!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete -->
build_date="1228222680000"
version="[null]"
build_string="[null]"
+ revision="[null]"
/>
</dataset>
build_date="1228222680000"
version="[null]"
build_string="[null]"
+ revision="[null]"
/>
<!-- delete only resource 1 -->
build_date="1228222680000"
version="[null]"
build_string="[null]"
+ revision="[null]"
/>
</dataset>
build_date="1228222680000"
version="[null]"
build_string="[null]"
+ revision="[null]"
/>
<project_measures id="1"
build_date="1228222680000"
version="[null]"
build_string="[null]"
+ revision="[null]"
/>
<project_measures id="5"
build_date="1228222680000"
version="[null]"
build_string="[null]"
+ revision="[null]"
/>
build_date="1228222680000"
version="[null]"
build_string="[null]"
+ revision="[null]"
/>
<!-- snapshot to be purged -->
build_date="1228222680000"
version="[null]"
build_string="[null]"
+ revision="[null]"
/>
</dataset>
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.v78;
+
+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.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+@SupportsBlueGreen
+public class AddSnapshotRevision extends DdlChange {
+
+ public AddSnapshotRevision(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), "snapshots")
+ .addColumn(newVarcharColumnDefBuilder()
+ .setColumnName("revision")
+ .setIsNullable(true)
+ .setLimit(100)
+ .build())
+ .build());
+ }
+}
.add(2702, "Add column webhooks.secret", AddWebhooksSecret.class)
.add(2703, "Add security fields to Elasticsearch indices", AddSecurityFieldsToElasticsearchIndices.class)
.add(2704, "Add InternalComponentProperties table", CreateInternalComponentPropertiesTable.class)
+ .add(2705, "Add column snapshots.revision", AddSnapshotRevision.class)
.add(2707, "Update statuses of Security Hotspots", UpdateSecurityHotspotsStatuses.class);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.v78;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static java.sql.Types.VARCHAR;
+
+public class AddSnapshotRevisionTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(AddSnapshotRevisionTest.class, "snapshots.sql");
+
+ private DdlChange underTest = new AddSnapshotRevision(db.database());
+
+ @Test
+ public void creates_table_on_empty_db() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("snapshots", "revision", VARCHAR, 100, true);
+ }
+
+ @Test
+ public void migration_is_not_reentrant() throws SQLException {
+ underTest.execute();
+
+ expectedException.expect(IllegalStateException.class);
+
+ underTest.execute();
+ }
+}
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 6);
+ verifyMigrationCount(underTest, 7);
}
}
--- /dev/null
+CREATE TABLE "SNAPSHOTS" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "UUID" VARCHAR(50) NOT NULL,
+ "CREATED_AT" BIGINT,
+ "BUILD_DATE" BIGINT,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "STATUS" VARCHAR(4) NOT NULL DEFAULT 'U',
+ "PURGE_STATUS" INTEGER,
+ "ISLAST" BOOLEAN NOT NULL DEFAULT FALSE,
+ "VERSION" VARCHAR(500),
+ "BUILD_STRING" VARCHAR(100),
+ "PERIOD1_MODE" VARCHAR(100),
+ "PERIOD1_PARAM" VARCHAR(100),
+ "PERIOD1_DATE" BIGINT,
+ "PERIOD2_MODE" VARCHAR(100),
+ "PERIOD2_PARAM" VARCHAR(100),
+ "PERIOD2_DATE" BIGINT,
+ "PERIOD3_MODE" VARCHAR(100),
+ "PERIOD3_PARAM" VARCHAR(100),
+ "PERIOD3_DATE" BIGINT,
+ "PERIOD4_MODE" VARCHAR(100),
+ "PERIOD4_PARAM" VARCHAR(100),
+ "PERIOD4_DATE" BIGINT,
+ "PERIOD5_MODE" VARCHAR(100),
+ "PERIOD5_PARAM" VARCHAR(100),
+ "PERIOD5_DATE" BIGINT
+);
+CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS" ("COMPONENT_UUID");
+CREATE UNIQUE INDEX "ANALYSES_UUID" ON "SNAPSHOTS" ("UUID");