Schema_151: Attempt to add created_on column if it doesn't exist

If the created_on column does not exist, attempt to create it.

This allows the direct migration from 2.14 to 2.16 to succeed
without requiring an intermediate migration to 2.15.

Bug: Issue 10248
Change-Id: I626f1e26d43b60c3fd62ef3ef9ce3d7047c1a383
This commit is contained in:
David Pursehouse
2020-02-12 15:31:28 +09:00
committed by Luca Milanesio
parent 5f73fd6555
commit a009567e10
2 changed files with 38 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.server.schema;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.server.schema.Schema_151.createdOnColumnExists;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
@@ -151,6 +152,17 @@ public class Schema_150_to_151_Test {
assertThat(createdOn).isEqualTo(AccountGroup.auditCreationInstantTs());
}
@Test
public void createdOnIsAddedWhenItIsMissing() throws Exception {
assertThat(createdOnColumnExists(connection)).isTrue();
try (Statement deleteColumn = connection.createStatement()) {
deleteColumn.execute("ALTER TABLE account_groups DROP COLUMN created_on");
}
assertThat(createdOnColumnExists(connection)).isFalse();
schema151.migrateData(db, new TestUpdateUI());
assertThat(createdOnColumnExists(connection)).isTrue();
}
private AccountGroup.Id createGroupInReviewDb(String name) throws Exception {
AccountGroup group =
new AccountGroup(