Fix id generation in PackagePromotion (#1788)

* Fix id generation in PackagePromotion

* Fix update command tests
This commit is contained in:
sarahcaseybot 2022-09-21 15:19:49 -04:00 committed by GitHub
parent 2139dd3a4a
commit 7f0ffb3d0b
4 changed files with 20 additions and 13 deletions

View file

@ -29,6 +29,8 @@ import java.util.Optional;
import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Type;
@ -41,7 +43,9 @@ import org.joda.time.DateTime;
public class PackagePromotion extends ImmutableObject implements Buildable {
/** An autogenerated identifier for the package promotion. */
@Id long packagePromotionId;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
long packagePromotionId;
/** The allocation token string for the package. */
@Column(nullable = false)

View file

@ -15,8 +15,9 @@
package google.registry.model.domain.token;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.loadByEntity;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -57,16 +58,18 @@ public class PackagePromotionTest extends EntityTestCase {
.build());
PackagePromotion packagePromotion =
persistResource(
new PackagePromotion.Builder()
.setToken(token)
.setPackagePrice(Money.of(CurrencyUnit.USD, 10000))
.setMaxCreates(40)
.setMaxDomains(10)
.setNextBillingDate(DateTime.parse("2011-11-12T05:00:00Z"))
.build());
new PackagePromotion.Builder()
.setToken(token)
.setPackagePrice(Money.of(CurrencyUnit.USD, 10000))
.setMaxCreates(40)
.setMaxDomains(10)
.setNextBillingDate(DateTime.parse("2011-11-12T05:00:00Z"))
.build();
assertThat(loadByEntity(packagePromotion)).isEqualTo(packagePromotion);
jpaTm().transact(() -> jpaTm().put(packagePromotion));
assertAboutImmutableObjects()
.that(jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123")).get())
.isEqualExceptFields(packagePromotion, "packagePromotionId");
}
@Test

View file

@ -58,7 +58,7 @@ public class UpdatePackagePromotionCommandTest
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.setLastNotificationSent(DateTime.parse("2010-11-12T05:00:00Z"))
.build();
persistResource(packagePromotion);
jpaTm().transact(() -> jpaTm().put(packagePromotion));
}
@Test

View file

@ -492,7 +492,7 @@
);
create table "PackagePromotion" (
package_promotion_id int8 not null,
package_promotion_id bigserial not null,
last_notification_sent timestamptz,
max_creates int4 not null,
max_domains int4 not null,