Use composite primary key for DomainHistory (#767)

* Use composite primary key for DomainHistory

* Move History table's SequenceGenerator to orm.xml

* Rebase on HEAD and remove default value for key in History tables

* Use primitive type for id.

* Revert the cache change
This commit is contained in:
Shicong Huang 2020-09-03 10:21:23 -04:00 committed by GitHub
parent c6c8d21281
commit ecafebdc3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 219 additions and 78 deletions

View file

@ -14,6 +14,7 @@
package google.registry.model.history;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
@ -71,11 +72,15 @@ public class DomainHistoryTest extends EntityTestCase {
jpaTm()
.transact(
() -> {
DomainHistory fromDatabase =
jpaTm().load(VKey.createSql(DomainHistory.class, domainHistory.getId()));
DomainHistory fromDatabase = jpaTm().load(domainHistory.createVKey());
assertDomainHistoriesEqual(fromDatabase, domainHistory);
assertThat(fromDatabase.getDomainRepoId().getSqlKey())
.isEqualTo(domainHistory.getDomainRepoId().getSqlKey());
assertThat(fromDatabase.getNsHosts())
.containsExactlyElementsIn(
domainHistory.getNsHosts().stream()
.map(key -> VKey.createSql(HostResource.class, key.getSqlKey()))
.collect(toImmutableSet()));
});
}
@ -120,7 +125,7 @@ public class DomainHistoryTest extends EntityTestCase {
static void assertDomainHistoriesEqual(DomainHistory one, DomainHistory two) {
assertAboutImmutableObjects()
.that(one)
.isEqualExceptFields(two, "domainContent", "domainRepoId", "parent");
.isEqualExceptFields(two, "domainContent", "domainRepoId", "parent", "nsHosts");
}
private DomainHistory createDomainHistory(DomainContent domain) {
@ -134,7 +139,7 @@ public class DomainHistoryTest extends EntityTestCase {
.setReason("reason")
.setRequestedByRegistrar(true)
.setDomainContent(domain)
.setDomainRepoId(domain.createVKey())
.setDomainRepoId(domain.getRepoId())
.build();
}
}

View file

@ -270,9 +270,9 @@ class google.registry.model.domain.DomainHistory {
google.registry.model.domain.Period period;
google.registry.model.eppcommon.Trid trid;
google.registry.model.reporting.HistoryEntry$Type type;
google.registry.persistence.VKey<google.registry.model.domain.DomainBase> domainRepoId;
java.lang.Boolean requestedByRegistrar;
java.lang.String clientId;
java.lang.String domainRepoId;
java.lang.String otherClientId;
java.lang.String reason;
java.util.Set<google.registry.model.reporting.DomainTransactionRecord> domainTransactionRecords;