Skip to content
This repository was archived by the owner on Sep 15, 2023. It is now read-only.

Commit 90bd457

Browse files
authored
Merge pull request #49 from admin-ch/feature/db-push-cleanup
2 parents 77b66da + 953ae3b commit 90bd457

File tree

7 files changed

+32
-8
lines changed

7 files changed

+32
-8
lines changed

ch-covidcertificate-backend-delivery/ch-covidcertificate-backend-delivery-data/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>org.postgresql</groupId>
3838
<artifactId>postgresql</artifactId>
39-
<version>42.5.1</version>
39+
<version>42.5.4</version>
4040
</dependency>
4141
<dependency>
4242
<groupId>org.flywaydb</groupId>

ch-covidcertificate-backend-delivery/ch-covidcertificate-backend-delivery-data/src/main/java/ch/admin/bag/covidcertificate/backend/delivery/data/impl/JdbcDeliveryDataServiceImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public JdbcDeliveryDataServiceImpl(DataSource dataSource, int pushBatchSize) {
5252
this.pushRegistrationInsert =
5353
new SimpleJdbcInsert(dataSource)
5454
.withTableName("t_push_registration")
55-
.usingGeneratedKeyColumns("pk_push_registration_id", "created_at");
55+
.usingGeneratedKeyColumns("pk_push_registration_id", "created_at", "updated_at");
5656
this.covidCertInsert =
5757
new SimpleJdbcInsert(dataSource)
5858
.withTableName("t_covidcert")
@@ -165,7 +165,7 @@ public void upsertPushRegistration(PushRegistration registration) {
165165
} else {
166166
var sql =
167167
"update t_push_registration "
168-
+ "set push_token = :push_token, register_id = :register_id "
168+
+ "set push_token = :push_token, register_id = :register_id, updated_at = now() "
169169
+ "where push_token = :push_token or register_id = :register_id";
170170
jt.update(sql, createPushRegistrationParams(registration));
171171
}
@@ -241,10 +241,14 @@ public void insertCovidCert(DbCovidCert covidCert) {
241241
@Override
242242
@Transactional(readOnly = false)
243243
public void cleanDB(Duration retentionPeriod) {
244-
var sql = "delete from t_transfer where created_at < :retention_time";
244+
var transferSql = "delete from t_transfer where created_at < :retention_time";
245+
var pushSql = "delete from t_push_registration where created_at < :retention_time";
246+
245247
var retentionTime = Instant.now().minus(retentionPeriod);
246248
var params = new MapSqlParameterSource("retention_time", Date.from(retentionTime));
247-
jt.update(sql, params);
249+
250+
jt.update(transferSql, params);
251+
jt.update(pushSql, params);
248252
}
249253

250254
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Remove all existing push registrations since we don't know how old they are.
3+
* The apps will re-register themselves periodically.
4+
*/
5+
6+
alter table t_push_registration add column updated_at timestamp with time zone NOT NULL DEFAULT now();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Remove all existing push registrations since we don't know how old they are.
3+
* The apps will re-register themselves periodically.
4+
*/
5+
6+
alter table t_push_registration add column updated_at timestamp with time zone NOT NULL DEFAULT now();

ch-covidcertificate-backend-delivery/ch-covidcertificate-backend-delivery-data/src/test/java/ch/admin/bag/covidcertificate/backend/delivery/data/DeliveryDataServiceTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ void testCleanDB() throws Exception {
245245
// init transfer
246246
DeliveryRegistration registration = getDeliveryRegistration(CODE);
247247
deliveryDataService.initTransfer(registration);
248+
// insert push registration
249+
PushRegistration pushRegistration = new PushRegistration();
250+
pushRegistration.setPushToken("push_token");
251+
pushRegistration.setPushType(PushType.IOS);
252+
pushRegistration.setRegisterId("register_id");
253+
deliveryDataService.upsertPushRegistration(pushRegistration);
248254
// insert covid cert
249255
var dbCovidCert = new DbCovidCert();
250256
dbCovidCert.setFkTransfer(deliveryDataService.findPkTransferId(CODE));
@@ -256,6 +262,7 @@ void testCleanDB() throws Exception {
256262
deliveryDataService.cleanDB(Duration.ofDays(-1));
257263
assertThrows(CodeNotFoundException.class, () -> deliveryDataService.findTransfer(CODE));
258264
assertThrows(CodeNotFoundException.class, () -> deliveryDataService.findCovidCerts(CODE));
265+
assertEquals(0, deliveryDataService.countRegistrations());
259266
}
260267

261268
@Test

ch-covidcertificate-backend-delivery/ch-covidcertificate-backend-delivery-model/src/main/java/ch/admin/bag/covidcertificate/backend/delivery/model/app/PushRegistration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class PushRegistration {
1313
@NotNull private String registerId;
1414
@JsonIgnore private int id;
1515
@JsonIgnore private Instant lastPush;
16+
@JsonIgnore private Instant updatedAt;
1617

1718
public String getPushToken() {
1819
return pushToken;

ch-covidcertificate-backend-delivery/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1818

19-
<spring-boot-version>2.7.8</spring-boot-version>
19+
<spring-boot-version>2.7.9</spring-boot-version>
2020
<jackson-version>2.11.1</jackson-version>
2121
<jsonwebtoken-version>0.11.5</jsonwebtoken-version>
2222
<testcontainers-version>1.17.6</testcontainers-version>
2323
<shedlock.version>4.44.0</shedlock.version>
24-
<spring-cloud-sleuth-version>3.1.6</spring-cloud-sleuth-version>
24+
<spring-cloud-sleuth-version>3.1.7</spring-cloud-sleuth-version>
2525

2626
<itCoverageAgent/>
2727

@@ -221,7 +221,7 @@
221221
<plugin>
222222
<groupId>org.apache.maven.plugins</groupId>
223223
<artifactId>maven-compiler-plugin</artifactId>
224-
<version>3.10.1</version>
224+
<version>3.11.0</version>
225225
</plugin>
226226
<plugin>
227227
<groupId>org.springframework.boot</groupId>

0 commit comments

Comments
 (0)