Skip to content

Commit

Permalink
fix: add survey units unique constraints in DB (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
davdarras authored Jun 7, 2024
1 parent 54b49b1 commit 611f790
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<description>Modules for queen back-office</description>

<properties>
<revision>4.3.3</revision>
<revision>4.3.4</revision>
<changelist></changelist>
<java.version>21</java.version>
<maven.compiler.source>21</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fr.insee.queen.domain.surveyunit.gateway.SurveyUnitRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@AllArgsConstructor
Expand All @@ -19,6 +20,7 @@ public ObjectNode getComment(String surveyUnitId) {
}

@Override
@Transactional
public void updateComment(String surveyUnitId, ObjectNode commentValue) {
surveyUnitRepository.saveComment(surveyUnitId, commentValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
Expand All @@ -21,11 +22,13 @@ public ObjectNode getData(String surveyUnitId) {
}

@Override
@Transactional
public void saveData(String surveyUnitId, ObjectNode dataValue) {
surveyUnitRepository.saveData(surveyUnitId, dataValue);
}

@Override
@Transactional
public void updateCollectedData(String surveyUnitId, ObjectNode collectedData) {
surveyUnitRepository.updateCollectedData(surveyUnitId, collectedData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

Expand All @@ -27,6 +28,7 @@ public StateData getStateData(String surveyUnitId) {
}

@Override
@Transactional
public void saveStateData(String surveyUnitId, StateData stateData) throws StateDataInvalidDateException {
Optional<StateData> previousStateData = stateDataRepository.find(surveyUnitId);
if (previousStateData.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<changeSet author="davdarras" id="600-1">
<dropIndex indexName="idx_state_data_su"
tableName="state_data"/>
</changeSet>

<changeSet author="davdarras" id="600-2">
<createIndex indexName="idx_state_data_su" tableName="state_data" unique="true">
<column name="survey_unit_id"/>
</createIndex>
</changeSet>

<changeSet author="davdarras" id="600-3">
<dropIndex indexName="idx_comment_su"
tableName="comment"/>
</changeSet>

<changeSet author="davdarras" id="600-4">
<createIndex indexName="idx_comment_su" tableName="comment" unique="true">
<column name="survey_unit_id"/>
</createIndex>
</changeSet>

<changeSet author="davdarras" id="600-5">
<dropIndex indexName="idx_personalization_su"
tableName="personalization"/>
</changeSet>

<changeSet author="davdarras" id="600-6">
<createIndex indexName="idx_personalization_su" tableName="personalization" unique="true">
<column name="survey_unit_id"/>
</createIndex>
</changeSet>

<changeSet author="davdarras" id="600-7">
<dropIndex indexName="idx_data_su"
tableName="data"/>
</changeSet>

<changeSet author="davdarras" id="600-8">
<createIndex indexName="idx_data_su" tableName="data" unique="true">
<column name="survey_unit_id"/>
</createIndex>
</changeSet>
</databaseChangeLog>
1 change: 1 addition & 0 deletions queen-infra-db/src/main/resources/db/master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
<!-- handle migrations of comments/datas/personalization sto surveyu_unit table -->
<include file="changelog/500_add_fields_to_paradataevent.xml" relativeToChangelogFile="true"/>
<include file="changelog/501_migrate_data_to_new_fields.sql" relativeToChangelogFile="true"/>
<include file="changelog/600_unique_constraints.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

0 comments on commit 611f790

Please sign in to comment.