Skip to content

Commit 094480b

Browse files
committed
chore: new DB init file and test fixes
1 parent 4e6cbf6 commit 094480b

File tree

5 files changed

+148
-52
lines changed

5 files changed

+148
-52
lines changed

src/main/resources/liquibase/changelog-init.xml

+30-30
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
22
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
3-
<property name="NOW" value="now()" dbms="mysql,h2"/>
3+
<property name="NOW" value="now() " dbms="mysql,h2"/>
44
<property name="NOW" value="CURRENT_TIMESTAMP" dbms="postgresql"/>
55
<property name="NOW" value="sysdate" dbms="oracle"/>
6-
7-
<changeSet author="wagner.wutzke" id="1740060932516-1">
6+
7+
<changeSet author="wagner.wutzke" id="1740266386086-1">
88
<createTable tableName="meeting">
99
<column name="id" type="UUID">
1010
<constraints nullable="false" primaryKey="true" primaryKeyName="meeting_pkey"/>
@@ -50,7 +50,7 @@
5050
<column name="series_end_time" type="TIMESTAMP WITH TIME ZONE"/>
5151
</createTable>
5252
</changeSet>
53-
<changeSet author="wagner.wutzke" id="1740060932516-2">
53+
<changeSet author="wagner.wutzke" id="1740266386086-2">
5454
<createTable tableName="notification">
5555
<column name="id" type="UUID">
5656
<constraints nullable="false" primaryKey="true" primaryKeyName="notification_pkey"/>
@@ -69,7 +69,7 @@
6969
<column name="room_deletion_due_date" type="TIMESTAMP WITH TIME ZONE"/>
7070
</createTable>
7171
</changeSet>
72-
<changeSet author="wagner.wutzke" id="1740060932516-3">
72+
<changeSet author="wagner.wutzke" id="1740266386086-3">
7373
<createTable tableName="meeting_participant">
7474
<column name="id" type="UUID">
7575
<constraints nullable="false" primaryKey="true" primaryKeyName="meeting_participant_pkey"/>
@@ -88,7 +88,7 @@
8888
</column>
8989
</createTable>
9090
</changeSet>
91-
<changeSet author="wagner.wutzke" id="1740060932516-4">
91+
<changeSet author="wagner.wutzke" id="1740266386086-4">
9292
<createTable tableName="batch_job_instance">
9393
<column name="job_instance_id" type="BIGINT">
9494
<constraints nullable="false" primaryKey="true" primaryKeyName="batch_job_instance_pkey"/>
@@ -102,44 +102,44 @@
102102
</column>
103103
</createTable>
104104
</changeSet>
105-
<changeSet author="wagner.wutzke" id="1740060932516-5">
105+
<changeSet author="wagner.wutzke" id="1740266386086-5">
106106
<createIndex indexName="meeting_end_time_idx" tableName="meeting">
107107
<column name="end_time"/>
108108
</createIndex>
109109
</changeSet>
110-
<changeSet author="wagner.wutzke" id="1740060932516-6">
110+
<changeSet author="wagner.wutzke" id="1740266386086-6">
111111
<createIndex indexName="meeting_created_at_idx" tableName="meeting">
112-
<column name="created_at"/>
112+
<column defaultValueComputed="${NOW}" name="created_at"/>
113113
</createIndex>
114114
</changeSet>
115-
<changeSet author="wagner.wutzke" id="1740060932516-7">
115+
<changeSet author="wagner.wutzke" id="1740266386086-7">
116116
<createIndex indexName="notification_user_id_idx" tableName="notification">
117117
<column name="user_id"/>
118118
</createIndex>
119119
</changeSet>
120-
<changeSet author="wagner.wutzke" id="1740060932516-8">
120+
<changeSet author="wagner.wutzke" id="1740266386086-8">
121121
<createIndex indexName="meeting_participant_meeting_id_idx" tableName="meeting_participant">
122122
<column name="meeting_id"/>
123123
</createIndex>
124124
</changeSet>
125-
<changeSet author="wagner.wutzke" id="1740060932516-9" dbms="postgresql">
125+
<changeSet author="wagner.wutzke" id="1740266386086-9" dbms="postgresql">
126126
<createIndex indexName="meeting_participant_email_upper_idx" tableName="meeting_participant">
127127
<column computed="true" name="upper((email)::text)"/>
128128
</createIndex>
129129
</changeSet>
130-
<changeSet author="wagner.wutzke" id="1740060932516-10">
130+
<changeSet author="wagner.wutzke" id="1740266386086-10">
131131
<addUniqueConstraint columnNames="job_name, job_key" constraintName="job_inst_un" tableName="batch_job_instance"/>
132132
</changeSet>
133-
<changeSet author="wagner.wutzke" id="1740060932516-11">
133+
<changeSet author="wagner.wutzke" id="1740266386086-11">
134134
<createSequence cacheSize="1" cycle="false" dataType="bigint" incrementBy="1" maxValue="9223372036854775807" minValue="1" sequenceName="batch_job_execution_seq" startValue="1"/>
135135
</changeSet>
136-
<changeSet author="wagner.wutzke" id="1740060932516-12">
136+
<changeSet author="wagner.wutzke" id="1740266386086-12">
137137
<createSequence cacheSize="1" cycle="false" dataType="bigint" incrementBy="1" maxValue="9223372036854775807" minValue="1" sequenceName="batch_job_seq" startValue="1"/>
138138
</changeSet>
139-
<changeSet author="wagner.wutzke" id="1740060932516-13">
139+
<changeSet author="wagner.wutzke" id="1740266386086-13">
140140
<createSequence cacheSize="1" cycle="false" dataType="bigint" incrementBy="1" maxValue="9223372036854775807" minValue="1" sequenceName="batch_step_execution_seq" startValue="1"/>
141141
</changeSet>
142-
<changeSet author="wagner.wutzke" id="1740060932516-14">
142+
<changeSet author="wagner.wutzke" id="1740266386086-14">
143143
<createTable tableName="batch_job_execution">
144144
<column name="job_execution_id" type="BIGINT">
145145
<constraints nullable="false" primaryKey="true" primaryKeyName="batch_job_execution_pkey"/>
@@ -159,7 +159,7 @@
159159
<column name="last_updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
160160
</createTable>
161161
</changeSet>
162-
<changeSet author="wagner.wutzke" id="1740060932516-15">
162+
<changeSet author="wagner.wutzke" id="1740266386086-15">
163163
<createTable tableName="batch_job_execution_context">
164164
<column name="job_execution_id" type="BIGINT">
165165
<constraints nullable="false" primaryKey="true" primaryKeyName="batch_job_execution_context_pkey"/>
@@ -170,7 +170,7 @@
170170
<column name="serialized_context" type="TEXT"/>
171171
</createTable>
172172
</changeSet>
173-
<changeSet author="wagner.wutzke" id="1740060932516-16">
173+
<changeSet author="wagner.wutzke" id="1740266386086-16">
174174
<createTable tableName="batch_job_execution_params">
175175
<column name="job_execution_id" type="BIGINT">
176176
<constraints nullable="false"/>
@@ -187,7 +187,7 @@
187187
</column>
188188
</createTable>
189189
</changeSet>
190-
<changeSet author="wagner.wutzke" id="1740060932516-17">
190+
<changeSet author="wagner.wutzke" id="1740266386086-17">
191191
<createTable tableName="batch_step_execution">
192192
<column name="step_execution_id" type="BIGINT">
193193
<constraints nullable="false" primaryKey="true" primaryKeyName="batch_step_execution_pkey"/>
@@ -220,7 +220,7 @@
220220
<column name="last_updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
221221
</createTable>
222222
</changeSet>
223-
<changeSet author="wagner.wutzke" id="1740060932516-18">
223+
<changeSet author="wagner.wutzke" id="1740266386086-18">
224224
<createTable tableName="batch_step_execution_context">
225225
<column name="step_execution_id" type="BIGINT">
226226
<constraints nullable="false" primaryKey="true" primaryKeyName="batch_step_execution_context_pkey"/>
@@ -231,7 +231,7 @@
231231
<column name="serialized_context" type="TEXT"/>
232232
</createTable>
233233
</changeSet>
234-
<changeSet author="wagner.wutzke" id="1740060932516-19">
234+
<changeSet author="wagner.wutzke" id="1740266386086-19">
235235
<createTable tableName="shedlock">
236236
<column name="name" type="VARCHAR(64)">
237237
<constraints nullable="false" primaryKey="true" primaryKeyName="shedlock_pkey"/>
@@ -247,28 +247,28 @@
247247
</column>
248248
</createTable>
249249
</changeSet>
250-
<changeSet author="wagner.wutzke" id="1740060932516-20">
250+
<changeSet author="wagner.wutzke" id="1740266386086-20">
251251
<addForeignKeyConstraint baseColumnNames="parent_id" baseTableName="meeting" constraintName="fk_child_meeting_on_parent_meeting" deferrable="false" initiallyDeferred="false" onDelete="CASCADE" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="meeting" validate="true"/>
252252
</changeSet>
253-
<changeSet author="wagner.wutzke" id="1740060932516-21" dbms="postgresql">
253+
<changeSet author="wagner.wutzke" id="1740266386086-21">
254254
<addForeignKeyConstraint baseColumnNames="meeting_id" baseTableName="meeting_participant" constraintName="fk_meeting_participant_on_meeting" deferrable="false" initiallyDeferred="false" onDelete="CASCADE" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="meeting" validate="true"/>
255255
</changeSet>
256-
<changeSet author="wagner.wutzke" id="1740060932516-22">
256+
<changeSet author="wagner.wutzke" id="1740266386086-22">
257257
<addForeignKeyConstraint baseColumnNames="meeting_id" baseTableName="notification" constraintName="fk_notification_on_meeting" deferrable="false" initiallyDeferred="false" onDelete="CASCADE" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="meeting" validate="true"/>
258258
</changeSet>
259-
<changeSet author="wagner.wutzke" id="1740060932516-23">
259+
<changeSet author="wagner.wutzke" id="1740266386086-23">
260260
<addForeignKeyConstraint baseColumnNames="job_execution_id" baseTableName="batch_job_execution_context" constraintName="job_exec_ctx_fk" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="job_execution_id" referencedTableName="batch_job_execution" validate="true"/>
261261
</changeSet>
262-
<changeSet author="wagner.wutzke" id="1740060932516-24">
262+
<changeSet author="wagner.wutzke" id="1740266386086-24">
263263
<addForeignKeyConstraint baseColumnNames="job_execution_id" baseTableName="batch_job_execution_params" constraintName="job_exec_params_fk" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="job_execution_id" referencedTableName="batch_job_execution" validate="true"/>
264264
</changeSet>
265-
<changeSet author="wagner.wutzke" id="1740060932516-25">
265+
<changeSet author="wagner.wutzke" id="1740266386086-25">
266266
<addForeignKeyConstraint baseColumnNames="job_execution_id" baseTableName="batch_step_execution" constraintName="job_exec_step_fk" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="job_execution_id" referencedTableName="batch_job_execution" validate="true"/>
267267
</changeSet>
268-
<changeSet author="wagner.wutzke" id="1740060932516-26">
268+
<changeSet author="wagner.wutzke" id="1740266386086-26">
269269
<addForeignKeyConstraint baseColumnNames="job_instance_id" baseTableName="batch_job_execution" constraintName="job_inst_exec_fk" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="job_instance_id" referencedTableName="batch_job_instance" validate="true"/>
270270
</changeSet>
271-
<changeSet author="wagner.wutzke" id="1740060932516-27">
271+
<changeSet author="wagner.wutzke" id="1740266386086-27">
272272
<addForeignKeyConstraint baseColumnNames="step_execution_id" baseTableName="batch_step_execution_context" constraintName="step_exec_ctx_fk" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="step_execution_id" referencedTableName="batch_step_execution" validate="true"/>
273273
</changeSet>
274274
</databaseChangeLog>

src/test/java/net/nordeck/ovc/backend/jobs/DeleteOldMeetingsJobTest.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.nordeck.ovc.backend.TestUtils;
44
import net.nordeck.ovc.backend.entity.MeetingEntity;
5+
import net.nordeck.ovc.backend.entity.MeetingParticipantEntity;
56
import net.nordeck.ovc.backend.repository.MeetingParticipantRepository;
67
import net.nordeck.ovc.backend.repository.MeetingRepository;
78
import org.junit.jupiter.api.AfterEach;
@@ -27,6 +28,7 @@
2728
import org.springframework.transaction.PlatformTransactionManager;
2829

2930
import java.time.ZonedDateTime;
31+
import java.util.Arrays;
3032
import java.util.Collection;
3133
import java.util.List;
3234
import java.util.UUID;
@@ -83,7 +85,27 @@ void initData() {
8385
m2.setEndTime(ZonedDateTime.now().minusDays(65));
8486
m3.setEndTime(ZonedDateTime.now().minusDays(30));
8587

86-
meetingRepository.saveAll(List.of(m1, m2, m3));
88+
List<List<MeetingParticipantEntity>> participants = List.of(
89+
m1.getParticipants(),
90+
m2.getParticipants(),
91+
m3.getParticipants()
92+
);
93+
94+
m1.setParticipants(null);
95+
m2.setParticipants(null);
96+
m3.setParticipants(null);
97+
98+
List<MeetingEntity> meetingEntities = meetingRepository
99+
.saveAll(List.of(m1, m2, m3));
100+
101+
// set meeting id for every participant
102+
for (int i=0; i<meetingEntities.size(); i++) {
103+
int finalI = i;
104+
participants.get(i).forEach(o -> o.setMeetingId(meetingEntities.get(finalI).getId()));
105+
meetingEntities.get(i).setParticipants(participants.get(i));
106+
}
107+
108+
meetingRepository.saveAll(meetingEntities);
87109

88110
mockedJob.meetingRepository = meetingRepository;
89111
mockedJob.chunkSize = chunkSize;

src/test/java/net/nordeck/ovc/backend/jobs/StaticRoomsDeleteUnusedJobTest.java

+37-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import net.nordeck.ovc.backend.TestUtils;
44
import net.nordeck.ovc.backend.entity.MeetingEntity;
5+
import net.nordeck.ovc.backend.entity.MeetingParticipantEntity;
6+
import net.nordeck.ovc.backend.repository.MeetingParticipantRepository;
57
import net.nordeck.ovc.backend.repository.MeetingRepository;
68
import org.junit.jupiter.api.AfterEach;
79
import org.junit.jupiter.api.BeforeEach;
@@ -25,6 +27,7 @@
2527
import org.springframework.transaction.PlatformTransactionManager;
2628

2729
import java.time.ZonedDateTime;
30+
import java.util.Arrays;
2831
import java.util.Collection;
2932
import java.util.List;
3033
import java.util.UUID;
@@ -47,6 +50,9 @@ public class StaticRoomsDeleteUnusedJobTest {
4750
@Autowired
4851
private MeetingRepository meetingRepository;
4952

53+
@Autowired
54+
private MeetingParticipantRepository meetingParticipantRepository;
55+
5056
@Mock
5157
private JobRepository jobRepository;
5258

@@ -84,19 +90,39 @@ void initData() {
8490
MeetingEntity room2 = TestUtils.getStaticRoom();
8591
MeetingEntity room3 = TestUtils.getStaticRoom();
8692

87-
room1.setLastVisitDate(ZonedDateTime.now().minusDays(6)); // should be deleted by step1
88-
room1.setRoomDeletionDueDate(ZonedDateTime.now().minusDays(10));
89-
room1.setDeleteCandidate(true);
93+
List<List<MeetingParticipantEntity>> participants = List.of(
94+
room1.getParticipants(),
95+
room2.getParticipants(),
96+
room3.getParticipants()
97+
);
98+
99+
room1.setParticipants(null);
100+
room2.setParticipants(null);
101+
room3.setParticipants(null);
102+
103+
List<MeetingEntity> meetingEntities = meetingRepository.saveAll(List.of(room1, room2, room3));
104+
105+
meetingEntities.get(0).setLastVisitDate(ZonedDateTime.now().minusDays(6)); // should be deleted by step1
106+
meetingEntities.get(0).setRoomDeletionDueDate(ZonedDateTime.now().minusDays(10));
107+
meetingEntities.get(0).setDeleteCandidate(true);
108+
109+
meetingEntities.get(1).setLastVisitDate(ZonedDateTime.now().minusDays(1)); // should be reset by step2
110+
meetingEntities.get(1).setRoomDeletionDueDate(ZonedDateTime.now().minusDays(10));
111+
meetingEntities.get(1).setDeleteCandidate(true);
112+
113+
meetingEntities.get(2).setLastVisitDate(ZonedDateTime.now().minusDays(3)); // should be marked as candidate by step3
114+
meetingEntities.get(2).setRoomDeletionDueDate(ZonedDateTime.now().minusDays(10));
115+
meetingEntities.get(2).setDeleteCandidate(false);
90116

91-
room2.setLastVisitDate(ZonedDateTime.now().minusDays(1)); // should be reset by step2
92-
room2.setRoomDeletionDueDate(ZonedDateTime.now().minusDays(10));
93-
room2.setDeleteCandidate(true);
94117

95-
room3.setLastVisitDate(ZonedDateTime.now().minusDays(3)); // should be marked as candidate by step3
96-
room3.setRoomDeletionDueDate(ZonedDateTime.now().minusDays(10));
97-
room3.setDeleteCandidate(false);
118+
// set meeting id for every participant
119+
for (int i=0; i<meetingEntities.size(); i++) {
120+
int finalI = i;
121+
participants.get(i).forEach(o -> o.setMeetingId(meetingEntities.get(finalI).getId()));
122+
meetingEntities.get(i).setParticipants(participants.get(i));
123+
}
98124

99-
meetingRepository.saveAll(List.of(room1, room2, room3));
125+
meetingRepository.saveAll(meetingEntities);
100126

101127
mockedJob.meetingRepository = meetingRepository;
102128
mockedJob.chunkSize = chunkSize;
@@ -106,6 +132,7 @@ void initData() {
106132
@AfterEach
107133
void cleanData() {
108134
meetingRepository.deleteAll();
135+
meetingParticipantRepository.deleteAll();
109136
jobRepositoryTestUtils.removeJobExecutions();
110137
}
111138

0 commit comments

Comments
 (0)