mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 22:59:25 +00:00
#1400 - Postgres @History table sys_period empty with multiple updates
This commit is contained in:
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.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user