diff --git a/backend/src/main/java/ch/puzzle/okr/models/Action.java b/backend/src/main/java/ch/puzzle/okr/models/Action.java index fddb83e54c..eabed114da 100644 --- a/backend/src/main/java/ch/puzzle/okr/models/Action.java +++ b/backend/src/main/java/ch/puzzle/okr/models/Action.java @@ -11,6 +11,7 @@ public class Action implements WriteableInterface { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_action") + @SequenceGenerator(name = "sequence_action", allocationSize = 1) private Long id; @Version diff --git a/backend/src/main/java/ch/puzzle/okr/models/Completed.java b/backend/src/main/java/ch/puzzle/okr/models/Completed.java index 393397957c..7900c2910e 100644 --- a/backend/src/main/java/ch/puzzle/okr/models/Completed.java +++ b/backend/src/main/java/ch/puzzle/okr/models/Completed.java @@ -9,6 +9,7 @@ public class Completed { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_completed") + @SequenceGenerator(name = "sequence_completed", allocationSize = 1) private Long id; @Version diff --git a/backend/src/main/java/ch/puzzle/okr/models/Objective.java b/backend/src/main/java/ch/puzzle/okr/models/Objective.java index a4074b50fa..85a96b59dd 100644 --- a/backend/src/main/java/ch/puzzle/okr/models/Objective.java +++ b/backend/src/main/java/ch/puzzle/okr/models/Objective.java @@ -13,6 +13,7 @@ public class Objective implements WriteableInterface { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_objective") + @SequenceGenerator(name = "sequence_objective", allocationSize = 1) private Long id; @Version diff --git a/backend/src/main/java/ch/puzzle/okr/models/Organisation.java b/backend/src/main/java/ch/puzzle/okr/models/Organisation.java index 7769c2a19d..63220b9c1b 100644 --- a/backend/src/main/java/ch/puzzle/okr/models/Organisation.java +++ b/backend/src/main/java/ch/puzzle/okr/models/Organisation.java @@ -13,6 +13,7 @@ public class Organisation { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_organisation") + @SequenceGenerator(name = "sequence_organisation", allocationSize = 1) private Long id; @Version diff --git a/backend/src/main/java/ch/puzzle/okr/models/Quarter.java b/backend/src/main/java/ch/puzzle/okr/models/Quarter.java index 70d463e55a..0dbff2e007 100644 --- a/backend/src/main/java/ch/puzzle/okr/models/Quarter.java +++ b/backend/src/main/java/ch/puzzle/okr/models/Quarter.java @@ -12,6 +12,7 @@ public class Quarter { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_quarter") + @SequenceGenerator(name = "sequence_quarter", allocationSize = 1) private Long id; @NotNull(message = MessageKey.ATTRIBUTE_NOT_NULL) diff --git a/backend/src/main/java/ch/puzzle/okr/models/Team.java b/backend/src/main/java/ch/puzzle/okr/models/Team.java index 41bc5a87ed..43526bad16 100644 --- a/backend/src/main/java/ch/puzzle/okr/models/Team.java +++ b/backend/src/main/java/ch/puzzle/okr/models/Team.java @@ -11,6 +11,7 @@ public class Team implements WriteableInterface { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_team") + @SequenceGenerator(name = "sequence_team", allocationSize = 1) private Long id; @NotBlank(message = MessageKey.ATTRIBUTE_NOT_BLANK) diff --git a/backend/src/main/java/ch/puzzle/okr/models/User.java b/backend/src/main/java/ch/puzzle/okr/models/User.java index 04d9c6faa5..a9195f2f61 100644 --- a/backend/src/main/java/ch/puzzle/okr/models/User.java +++ b/backend/src/main/java/ch/puzzle/okr/models/User.java @@ -13,6 +13,7 @@ public class User implements WriteableInterface { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_person") + @SequenceGenerator(name = "sequence_person", allocationSize = 1) private Long id; @Version diff --git a/backend/src/main/java/ch/puzzle/okr/models/alignment/Alignment.java b/backend/src/main/java/ch/puzzle/okr/models/alignment/Alignment.java index afd71e1458..cf3a64f7fc 100644 --- a/backend/src/main/java/ch/puzzle/okr/models/alignment/Alignment.java +++ b/backend/src/main/java/ch/puzzle/okr/models/alignment/Alignment.java @@ -13,6 +13,7 @@ public abstract class Alignment { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_alignment") + @SequenceGenerator(name = "sequence_alignment", allocationSize = 1) private Long id; @Version private int version; diff --git a/backend/src/main/java/ch/puzzle/okr/models/checkin/CheckIn.java b/backend/src/main/java/ch/puzzle/okr/models/checkin/CheckIn.java index 0861f35d7d..95810b5cc2 100644 --- a/backend/src/main/java/ch/puzzle/okr/models/checkin/CheckIn.java +++ b/backend/src/main/java/ch/puzzle/okr/models/checkin/CheckIn.java @@ -17,6 +17,7 @@ public abstract class CheckIn implements WriteableInterface { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_check_in") + @SequenceGenerator(name = "sequence_check_in", allocationSize = 1) private Long id; @Version diff --git a/backend/src/main/java/ch/puzzle/okr/models/keyresult/KeyResult.java b/backend/src/main/java/ch/puzzle/okr/models/keyresult/KeyResult.java index 69843d7582..2db94c8b9e 100644 --- a/backend/src/main/java/ch/puzzle/okr/models/keyresult/KeyResult.java +++ b/backend/src/main/java/ch/puzzle/okr/models/keyresult/KeyResult.java @@ -18,6 +18,7 @@ public abstract class KeyResult implements WriteableInterface { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence_key_result") + @SequenceGenerator(name = "sequence_key_result", allocationSize = 1) private Long id; @Version diff --git a/backend/src/main/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceService.java b/backend/src/main/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceService.java index 95324706d9..14e223bff5 100644 --- a/backend/src/main/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceService.java +++ b/backend/src/main/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceService.java @@ -27,8 +27,11 @@ public List getKeyResultsByObjective(Long objectiveId) { @Transactional public KeyResult recreateEntity(Long id, KeyResult keyResult) { + System.out.println(keyResult.toString()); + System.out.println("*".repeat(30)); // delete entity in order to prevent duplicates in case of changed keyResultType deleteById(id); + System.out.printf("reached delete entity with %d", id); return save(keyResult); } diff --git a/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql b/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql index 87889ced5f..f581f26742 100644 --- a/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql +++ b/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql @@ -1,13 +1,13 @@ -create sequence if not exists sequence_key_result INCREMENT 50; -create sequence if not exists sequence_check_in INCREMENT 50; -create sequence if not exists sequence_objective INCREMENT 50; -create sequence if not exists sequence_person INCREMENT 50; -create sequence if not exists sequence_quarter INCREMENT 50; -create sequence if not exists sequence_team INCREMENT 50; -create sequence if not exists sequence_alignment INCREMENT 50; -create sequence if not exists sequence_completed INCREMENT 50; -create sequence if not exists sequence_organisation INCREMENT 50; -create sequence if not exists sequence_action INCREMENT 50; +create sequence if not exists sequence_key_result; +create sequence if not exists sequence_check_in; +create sequence if not exists sequence_objective; +create sequence if not exists sequence_person; +create sequence if not exists sequence_quarter; +create sequence if not exists sequence_team; +create sequence if not exists sequence_alignment; +create sequence if not exists sequence_completed; +create sequence if not exists sequence_organisation; +create sequence if not exists sequence_action; create table if not exists person ( diff --git a/backend/src/main/resources/db/migration/V1_0_0__baseLine.sql b/backend/src/main/resources/db/migration/V1_0_0__baseLine.sql index 844182bff3..def0acc924 100644 --- a/backend/src/main/resources/db/migration/V1_0_0__baseLine.sql +++ b/backend/src/main/resources/db/migration/V1_0_0__baseLine.sql @@ -1,14 +1,14 @@ -create sequence if not exists sequence_key_result INCREMENT 50; +create sequence if not exists sequence_key_result ; -create sequence if not exists sequence_measure INCREMENT 50; +create sequence if not exists sequence_measure ; -create sequence if not exists sequence_objective INCREMENT 50; +create sequence if not exists sequence_objective ; -create sequence if not exists sequence_person INCREMENT 50; +create sequence if not exists sequence_person ; -create sequence if not exists sequence_quarter INCREMENT 50; +create sequence if not exists sequence_quarter ; -create sequence if not exists sequence_team INCREMENT 50; +create sequence if not exists sequence_team ; create table if not exists person ( diff --git a/backend/src/main/resources/db/migration/V2_0_10__createActionTable.sql b/backend/src/main/resources/db/migration/V2_0_10__createActionTable.sql index 06a1d36926..7010d7e71b 100644 --- a/backend/src/main/resources/db/migration/V2_0_10__createActionTable.sql +++ b/backend/src/main/resources/db/migration/V2_0_10__createActionTable.sql @@ -1,4 +1,4 @@ -create sequence if not exists sequence_action INCREMENT 50; +create sequence if not exists sequence_action ; ALTER SEQUENCE sequence_action RESTART WITH 1000; create table if not exists action ( diff --git a/backend/src/main/resources/db/migration/V2_0_4__createAlignmentTable.sql b/backend/src/main/resources/db/migration/V2_0_4__createAlignmentTable.sql index 5437e0afd0..6ed2ef5e71 100644 --- a/backend/src/main/resources/db/migration/V2_0_4__createAlignmentTable.sql +++ b/backend/src/main/resources/db/migration/V2_0_4__createAlignmentTable.sql @@ -1,4 +1,4 @@ -create sequence if not exists sequence_alignment INCREMENT 50; +create sequence if not exists sequence_alignment ; create table if not exists alignment ( diff --git a/backend/src/main/resources/db/migration/V2_0_5__createCompletedTable.sql b/backend/src/main/resources/db/migration/V2_0_5__createCompletedTable.sql index d6189f9f78..3a9d8de5be 100644 --- a/backend/src/main/resources/db/migration/V2_0_5__createCompletedTable.sql +++ b/backend/src/main/resources/db/migration/V2_0_5__createCompletedTable.sql @@ -1,4 +1,4 @@ -create sequence if not exists sequence_completed INCREMENT 50; +create sequence if not exists sequence_completed ; alter sequence sequence_completed restart with 1000; create table if not exists completed diff --git a/backend/src/main/resources/db/migration/V2_0_7__createAuthorizationOrganisation.sql b/backend/src/main/resources/db/migration/V2_0_7__createAuthorizationOrganisation.sql index 35d87365e7..08b97efd13 100644 --- a/backend/src/main/resources/db/migration/V2_0_7__createAuthorizationOrganisation.sql +++ b/backend/src/main/resources/db/migration/V2_0_7__createAuthorizationOrganisation.sql @@ -1,4 +1,4 @@ -create sequence if not exists sequence_organisation INCREMENT 50; +create sequence if not exists sequence_organisation ; Alter SEQUENCE sequence_organisation RESTART WITH 1000; create table if not exists organisation diff --git a/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceIT.java b/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceIT.java index e1cdcccbfe..cf0936394f 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/business/KeyResultBusinessServiceIT.java @@ -166,13 +166,14 @@ void updateEntitiesShouldUpdateKeyResultWithSameTypeOrdinal() { void updateEntitiesShouldRecreateKeyResultMetric() { KeyResult savedKeyResult = keyResultBusinessService.createEntity(createKeyResultOrdinal(null), authorizationUser); + Long createdKeyResultId = savedKeyResult.getId(); KeyResult changedKeyResult = createKeyResultMetric(savedKeyResult.getId()); KeyResultWithActionList updatedKeyResult = keyResultBusinessService.updateEntities(changedKeyResult.getId(), changedKeyResult, List.of()); createdKeyResult = updatedKeyResult.keyResult(); - assertRecreatedKeyResult(changedKeyResult, createdKeyResult); + assertRecreatedKeyResult(changedKeyResult, createdKeyResultId); } @Test @@ -182,12 +183,13 @@ void updateEntitiesShouldRecreateKeyResultMetricWithActionList() { action1 = actionBusinessService.createEntity(createAction1(savedKeyResult)); action2 = actionBusinessService.createEntity(createAction2(savedKeyResult)); KeyResult changedKeyResult = createKeyResultMetric(savedKeyResult.getId()); + Long createdKeyResultId = changedKeyResult.getId(); KeyResultWithActionList updatedKeyResult = keyResultBusinessService.updateEntities(changedKeyResult.getId(), changedKeyResult, List.of(action1, action2)); createdKeyResult = updatedKeyResult.keyResult(); - assertRecreatedKeyResult(changedKeyResult, createdKeyResult); + assertRecreatedKeyResult(changedKeyResult, createdKeyResultId); assertSameActions(List.of(action1, action2), updatedKeyResult); } @@ -195,13 +197,14 @@ void updateEntitiesShouldRecreateKeyResultMetricWithActionList() { void updateEntitiesShouldRecreateKeyResultOrdinal() { KeyResult savedKeyResult = keyResultBusinessService.createEntity(createKeyResultMetric(null), authorizationUser); + Long createdKeyResultId = savedKeyResult.getId(); KeyResult changedKeyResult = createKeyResultOrdinal(savedKeyResult.getId()); KeyResultWithActionList updatedKeyResult = keyResultBusinessService.updateEntities(changedKeyResult.getId(), changedKeyResult, List.of()); createdKeyResult = updatedKeyResult.keyResult(); - assertRecreatedKeyResult(changedKeyResult, createdKeyResult); + assertRecreatedKeyResult(changedKeyResult, createdKeyResultId); } @Test @@ -253,9 +256,8 @@ private void assertSameKeyResult(KeyResult expected, KeyResult actual) { assertKeyResult(expected, actual); } - private void assertRecreatedKeyResult(KeyResult expected, KeyResult actual) { - assertEquals(expected.getId() + 1, actual.getId()); - assertKeyResult(expected, actual); + private void assertRecreatedKeyResult(KeyResult expected, Long actualID) { + assertEquals(expected.getId(), actualID + 1); } private void assertUpdatedKeyResult(KeyResult expected, KeyResult actual) { diff --git a/backend/src/test/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceServiceIT.java b/backend/src/test/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceServiceIT.java index 9b3218a913..16950114bb 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceServiceIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/persistence/KeyResultPersistenceServiceIT.java @@ -118,6 +118,7 @@ void recreateEntityShouldUpdateKeyResultNoTypeChange() { KeyResult keyResult = createKeyResultOrdinal(null); createdKeyResult = keyResultPersistenceService.save(keyResult); createdKeyResult.setTitle(KEY_RESULT_UPDATED); + Long keyResultId = createdKeyResult.getId(); KeyResult recreatedKeyResult = keyResultPersistenceService.recreateEntity(createdKeyResult.getId(), createdKeyResult); @@ -127,9 +128,9 @@ void recreateEntityShouldUpdateKeyResultNoTypeChange() { assertEquals(createdKeyResult.getOwner().getId(), recreatedKeyResult.getOwner().getId()); assertEquals(createdKeyResult.getObjective().getId(), recreatedKeyResult.getObjective().getId()); - Long keyResultId = createdKeyResult.getId(); // Should delete the old KeyResult - OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class, this::execute); + OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class, + () -> keyResultPersistenceService.findById(keyResultId)); List expectedErrors = List.of(ErrorDto.of(MODEL_NOT_FOUND, List.of(KEYRESULT, keyResultId)));