#1400 - Postgres @History table sys_period empty with multiple updates

This commit is contained in:
rob bygrave committed 2018-06-11 22:10:43 +12:00
1 parent 3238c0def4
commit 2427630c07
7 files changed
+187 -52

No files matched your search

@@ -4,6 +4,7 @@ import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.SqlQuery;
import io.ebean.SqlRow;
import io.ebean.Transaction;
import io.ebean.Version;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.Platform;
@@ -93,6 +94,52 @@ public class TestHistoryInsert extends BaseTestCase {
assertThat(versions).hasSize(3);
}
@Test
@ForPlatform({Platform.POSTGRES})
public void test_singleTransaction_multipleHistory() {
User user = new User();
user.setName("First");
user.setEmail("first@email.com");
user.setPasswordHash("someHash");
try (Transaction transaction = Ebean.beginTransaction()) {
// insert and many updates inside transaction
Ebean.save(user);
user.setEmail("first2@email.com");
Ebean.save(user);
user.setEmail("first3@email.com");
Ebean.save(user);
user.setEmail("first4@email.com");
Ebean.save(user);
transaction.commit();
}
// a couple more updates outside of the first transaction
user.setEmail("first5@email.com");
Ebean.save(user);
user.setEmail("first6@email.com");
Ebean.save(user);
List<SqlRow> sqlRows =
Ebean.createSqlQuery("select lower(sys_period) lowerBound, upper(sys_period) upperBound from c_user_history where id = :id order by when_modified")
.setParameter("id", user.getId())
.findList();
Timestamp previousUpper = null;
for (SqlRow sqlRow : sqlRows) {
Timestamp nextLower = sqlRow.getTimestamp("lowerBound");
Timestamp nextUpper = sqlRow.getTimestamp("upperBound");
if (previousUpper != null) {
assertThat(previousUpper).isEqualTo(nextLower);
}
previousUpper = nextUpper;
}
}
/**
* Use SqlQuery to query the history table directly.
*/