From 1a0235ebf3adfd83c254c4473b839f8a91b7ce7f Mon Sep 17 00:00:00 2001 From: jusabatier Date: Fri, 3 Mar 2023 15:44:16 +0100 Subject: [PATCH 1/5] Unique SequenceGenerator name accross persistence context --- .../cadastrapp/model/request/InformationRequest.java | 5 ++--- .../georchestra/cadastrapp/model/request/ObjectRequest.java | 4 ++-- .../georchestra/cadastrapp/model/request/UserRequest.java | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/InformationRequest.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/InformationRequest.java index b973df81..4f0f3b53 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/InformationRequest.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/InformationRequest.java @@ -9,7 +9,6 @@ import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; @@ -35,8 +34,8 @@ public class InformationRequest implements Serializable{ private static final long serialVersionUID = 5439786730972374577L; @Id - @SequenceGenerator(name = "HibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) - @GeneratedValue(generator = "HibernateSequence") + @SequenceGenerator(name = "RequestIdHibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) + @GeneratedValue(generator = "RequestIdHibernateSequence") private long requestId; @ManyToOne(optional=false, fetch = FetchType.EAGER) diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/ObjectRequest.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/ObjectRequest.java index 6f4aee3e..65633963 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/ObjectRequest.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/ObjectRequest.java @@ -22,8 +22,8 @@ public class ObjectRequest implements Serializable { private static final long serialVersionUID = 5439786730972374577L; @Id - @SequenceGenerator(name = "HibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) - @GeneratedValue(generator = "HibernateSequence") + @SequenceGenerator(name = "ObjectIdHibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) + @GeneratedValue(generator = "ObjectIdHibernateSequence") private long objectId; @Column(name = "type") diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/UserRequest.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/UserRequest.java index b99803ce..992cdaa2 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/UserRequest.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/UserRequest.java @@ -20,8 +20,8 @@ public class UserRequest implements Serializable { private static final long serialVersionUID = -9140660737315556020L; @Id - @SequenceGenerator(name = "HibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) - @GeneratedValue(generator = "HibernateSequence") + @SequenceGenerator(name = "UserIdHibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) + @GeneratedValue(generator = "UserIdHibernateSequence") @Column(name="userid") private long userId; From 529c2caaff5748fe86bc06cb5637e98111a5c298 Mon Sep 17 00:00:00 2001 From: jusabatier Date: Fri, 3 Mar 2023 15:47:59 +0100 Subject: [PATCH 2/5] Ajout d'un cheduler pour anonymiser les tables de demandes --- .../repository/RequestRepository.java | 8 ++++- .../scheduler/AnonymizationScheduler.java | 36 +++++++++++++++++++ cadastrapp/src/main/webapp/WEB-INF/beans.xml | 12 ++++++- database/sql/tables/request_information.sql | 6 ++-- 4 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 cadastrapp/src/main/java/org/georchestra/cadastrapp/scheduler/AnonymizationScheduler.java diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java index 22f45b1b..ed169d5f 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java @@ -56,5 +56,11 @@ public interface RequestRepository @Query(value="select COALESCE(SUM(ir.objectNumber),0) from InformationRequest ir inner join ir.user u where u.cni= ?1 and u.type = ?2 and ir.requestDate >= ?3") int sumObjectNumberByUserCniAndUserTypeAndRequestDateAfter(String cni, String type, Date date); - + /** + * Return all informationRequest done before the specified date + * + * @param date The date to use + * @return The list of informationRequest done before the date + */ + List findAllByRequestDateBefore(Date date); } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/scheduler/AnonymizationScheduler.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/scheduler/AnonymizationScheduler.java new file mode 100644 index 00000000..fa97183d --- /dev/null +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/scheduler/AnonymizationScheduler.java @@ -0,0 +1,36 @@ +package org.georchestra.cadastrapp.scheduler; + +import java.util.Calendar; +import java.util.List; + +import org.georchestra.cadastrapp.model.request.InformationRequest; +import org.georchestra.cadastrapp.model.request.ObjectRequest; +import org.georchestra.cadastrapp.repository.ObjectRequestRepository; +import org.georchestra.cadastrapp.repository.RequestRepository; +import org.georchestra.cadastrapp.repository.UserRequestRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component("anonymizationSchedulerBean") +public class AnonymizationScheduler { + @Autowired + RequestRepository requestRepository; + + @Autowired + ObjectRequestRepository objectRequestRepository; + + @Autowired + UserRequestRepository userRequestRepository; + + public void anonymize() { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MONTH, -1); + List ls = requestRepository.findAllByRequestDateBefore(cal.getTime()); + for (InformationRequest informationRequest : ls) { + for (ObjectRequest objectRequest : informationRequest.getObjectsRequest()) { + objectRequestRepository.delete(objectRequest); + } + userRequestRepository.delete(informationRequest.getUser()); + } + } +} diff --git a/cadastrapp/src/main/webapp/WEB-INF/beans.xml b/cadastrapp/src/main/webapp/WEB-INF/beans.xml index cccccab2..c72899dc 100644 --- a/cadastrapp/src/main/webapp/WEB-INF/beans.xml +++ b/cadastrapp/src/main/webapp/WEB-INF/beans.xml @@ -6,12 +6,14 @@ xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc" + xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd - http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"> + http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd + http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd"> @@ -144,4 +146,12 @@ + + + + + + + + diff --git a/database/sql/tables/request_information.sql b/database/sql/tables/request_information.sql index bcaf917f..3f12a6f6 100644 --- a/database/sql/tables/request_information.sql +++ b/database/sql/tables/request_information.sql @@ -51,7 +51,7 @@ ALTER TABLE #schema_cadastrapp.request_information ALTER TABLE #schema_cadastrapp.request_information ADD CONSTRAINT foreingKeyUserId FOREIGN KEY (userid) REFERENCES #schema_cadastrapp.request_user_information (userid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE NO ACTION; + ON UPDATE NO ACTION ON DELETE CASCADE; ALTER TABLE #schema_cadastrapp.request_information OWNER TO #user_cadastrapp; @@ -93,12 +93,12 @@ ALTER TABLE #schema_cadastrapp.request_information_object_request ALTER TABLE #schema_cadastrapp.request_information_object_request ADD CONSTRAINT foreingKeyRequestObjectRequestId FOREIGN KEY (request_information_requestid) REFERENCES #schema_cadastrapp.request_information (requestid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE NO ACTION; + ON UPDATE NO ACTION ON DELETE CASCADE; ALTER TABLE #schema_cadastrapp.request_information_object_request ADD CONSTRAINT foreingKeyRequestObjectRequestObjectId FOREIGN KEY (objectsrequest_objectid) REFERENCES #schema_cadastrapp.object_request (objectid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE NO ACTION; + ON UPDATE NO ACTION ON DELETE CASCADE; ALTER TABLE #schema_cadastrapp.request_information_object_request ADD CONSTRAINT request_information_object_request_objectsrequest_objectid_key UNIQUE (objectsrequest_objectid ); From e139e7357e53a964508c5b23d3d224e5a2f819b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20J=C3=A9go?= Date: Mon, 3 Jul 2023 18:15:20 +0200 Subject: [PATCH 3/5] Update configuration to be able to choose cron from external config file Add update db script to migrate constraint --- .../src/main/resources/cadastrapp.properties | 3 + cadastrapp/src/main/webapp/WEB-INF/beans.xml | 2 +- database/sql/updates/_update_2_1_0.sql | 24 ++++ database/update_db.sh | 120 ++++++++++++++++++ 4 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 database/sql/updates/_update_2_1_0.sql create mode 100755 database/update_db.sh diff --git a/cadastrapp/src/main/resources/cadastrapp.properties b/cadastrapp/src/main/resources/cadastrapp.properties index 8fd72632..4203e0dc 100644 --- a/cadastrapp/src/main/resources/cadastrapp.properties +++ b/cadastrapp/src/main/resources/cadastrapp.properties @@ -158,5 +158,8 @@ purge.hours=24 # See http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html for example purge.cronExpression=0 0 * * * ? +# Cron expression to launch information request anonymization +anonymization.cronExpression=0 0 0 L * * + diff --git a/cadastrapp/src/main/webapp/WEB-INF/beans.xml b/cadastrapp/src/main/webapp/WEB-INF/beans.xml index c72899dc..8e2bff25 100644 --- a/cadastrapp/src/main/webapp/WEB-INF/beans.xml +++ b/cadastrapp/src/main/webapp/WEB-INF/beans.xml @@ -151,7 +151,7 @@ - + diff --git a/database/sql/updates/_update_2_1_0.sql b/database/sql/updates/_update_2_1_0.sql new file mode 100644 index 00000000..21401781 --- /dev/null +++ b/database/sql/updates/_update_2_1_0.sql @@ -0,0 +1,24 @@ + +ALTER TABLE #schema_cadastrapp.request_information + DROP CONSTRAINT foreingKeyUserId; + +ALTER TABLE #schema_cadastrapp.request_information + ADD CONSTRAINT foreingKeyUserId FOREIGN KEY (userid) + REFERENCES #schema_cadastrapp.request_user_information (userid) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE CASCADE; + +ALTER TABLE #schema_cadastrapp.request_information_object_request + DROP CONSTRAINT foreingKeyRequestObjectRequestId; + +ALTER TABLE #schema_cadastrapp.request_information_object_request + ADD CONSTRAINT foreingKeyRequestObjectRequestId FOREIGN KEY (request_information_requestid) + REFERENCES #schema_cadastrapp.request_information (requestid) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE CASCADE; + +ALTER TABLE #schema_cadastrapp.request_information_object_request + DROP CONSTRAINT foreingKeyRequestObjectRequestObjectId; + +ALTER TABLE #schema_cadastrapp.request_information_object_request + ADD CONSTRAINT foreingKeyRequestObjectRequestObjectId FOREIGN KEY (objectsrequest_objectid) + REFERENCES #schema_cadastrapp.object_request (objectid) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE CASCADE; \ No newline at end of file diff --git a/database/update_db.sh b/database/update_db.sh new file mode 100755 index 00000000..e6d19f49 --- /dev/null +++ b/database/update_db.sh @@ -0,0 +1,120 @@ +#! /bin/bash + + +clear +git_version=$(git rev-parse HEAD) + +echo "---------------------------------------------------------------" +echo " Cadastrapp : script de mise à jour de la structure de données " +echo "---------------------------------------------------------------" +echo "" +echo " version : $git_version" +echo "" +echo "--------------------------------------------------------------" +echo " Lecture du fichier de configuration" +echo "--------------------------------------------------------------" +echo "" + +# lecture du fichier de configuration des connexions +. config.sh + +# verifie si le mode silencieux est activé +silentMode=False +while [[ "$#" -gt 0 ]] +do + case $1 in + -s|--silent) + silentMode=True + ;; + -*|--*) + echo "Invalid option: $1" + ;; + esac + shift +done + +if [ "$uniqueDB" = True ] ; then + echo " 1 seule base de données sera utilisée : $cadastrappDBName sur la machine $cadastrappDBHost" + echo " schéma des données cadastre QGIS : $qgisDBSchema" + echo " schéma des données cadastrapp : $cadastrappDBSchema" +elif [ "$uniqueDB" = False ] ; then + echo " 2 bases de données seront utilisées" + echo " host > db > schema" + echo " source QGIS : $qgisDBHost > $qgisDBName > $qgisDBSchema" + echo " cible cadastrapp : $cadastrappDBHost > $cadastrappDBName > $cadastrappDBSchema" +else + echo " pb de configuration : stop" + exit 1 +fi + +if [ "$orgsAutorisations" = True ] ; then + invalidLdapParam=False + if [ -z "$ldapUri" ] ; then + echo "Paramètre ldapUri manquant !" + invalidLdapParam=True + fi + + if [ -z "$ldapPath" ] ; then + echo "Paramètre ldapPath manquant !" + invalidLdapParam=True + fi + + if [ -z "$ldapBindDn" ] ; then + echo "Paramètre ldapBindDn manquant !" + invalidLdapParam=True + fi + + if [ -z "$ldapBindPwd" ] ; then + echo "Paramètre ldapBindPwd manquant !" + invalidLdapParam=True + fi + if [ "$invalidLdapParam" = True ] ; then + echo " pb de configuration : stop" + exit 1 + fi +fi + +if [ "$silentMode" = False ] ; then + echo "" + read -p " Si ces infos sont exactes : appuyer sur la touche [Entrée] sinon faire ctrl + C pour arrêter." + echo "" +fi + +# +# cette fonction permet de remplacer les infos de connection +# avant exécution +# +replaceAndLaunch (){ + + if [ -z "$1" ] || [ ! -e $1 ] ; then + echo "Le fichier SQL $1 n'existe pas." + exit 1 + else + echo " Exécution du fichier : $1" + fi + + cat $1 | sed "{ + s/#schema_cadastrapp/$cadastrappDBSchema/g + s/#user_cadastrapp/$cadastrappDBUser/g + s/#DBHost_qgis/$qgisDBHost/g + s/#DBPort_qgis/$qgisDBPort/g + s/#DBName_qgis/$qgisDBName/g + s/#DBSchema_qgis/$qgisDBSchema/g + s/#DBUser_qgis/$qgisDBUser/g + s/#DBpasswd_qgis/$qgisDBPassword/g + s|#ldap_uri|$ldapUri|g + s/#ldap_path/$ldapPath/g + s/#ldap_binddn/$ldapBindDn/g + s/#ldap_bindpwd/$ldapBindPwd/g + }" |\ + PGPASSWORD=$cadastrappDBPassword psql -h $cadastrappDBHost -p $cadastrappDBPort -d $cadastrappDBName -U $cadastrappDBUser + +} + +# on purge la BD cadastrapp existante +replaceAndLaunch sql/updates/_update_2_1_0.sql + +echo "" +echo "--------------------------------------------------------------" +echo " FIN " +echo "--------------------------------------------------------------" From 8b1edde53f653695a8c7013ef6b3c39916d024fe Mon Sep 17 00:00:00 2001 From: jusabatier Date: Tue, 4 Jul 2023 12:00:17 +0200 Subject: [PATCH 4/5] Remplacer suppression par anonymisation des demandes (Scheduler) --- .../repository/RequestRepository.java | 12 +++++- .../scheduler/AnonymizationScheduler.java | 38 +++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java index ed169d5f..593a60e2 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java @@ -4,6 +4,7 @@ import java.util.List; import org.georchestra.cadastrapp.model.request.InformationRequest; +import org.georchestra.cadastrapp.model.request.UserRequest; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -57,10 +58,19 @@ public interface RequestRepository int sumObjectNumberByUserCniAndUserTypeAndRequestDateAfter(String cni, String type, Date date); /** - * Return all informationRequest done before the specified date + * Return all informationRequest done before the specified date (exclusive) * * @param date The date to use * @return The list of informationRequest done before the date */ List findAllByRequestDateBefore(Date date); + + /** + * Count number of request between start and end dates (inclusive) by user + * + * @param start The start date to use + * @param end The end date to use + * @return Number of request between start and end dates (inclusive) by user + */ + int countByRequestDateBetweenAndUser(Date start, Date end, UserRequest user); } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/scheduler/AnonymizationScheduler.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/scheduler/AnonymizationScheduler.java index fa97183d..23422bcf 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/scheduler/AnonymizationScheduler.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/scheduler/AnonymizationScheduler.java @@ -1,10 +1,16 @@ package org.georchestra.cadastrapp.scheduler; +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.Calendar; import java.util.List; +import javax.xml.bind.DatatypeConverter; + import org.georchestra.cadastrapp.model.request.InformationRequest; import org.georchestra.cadastrapp.model.request.ObjectRequest; +import org.georchestra.cadastrapp.model.request.UserRequest; import org.georchestra.cadastrapp.repository.ObjectRequestRepository; import org.georchestra.cadastrapp.repository.RequestRepository; import org.georchestra.cadastrapp.repository.UserRequestRepository; @@ -22,15 +28,39 @@ public class AnonymizationScheduler { @Autowired UserRequestRepository userRequestRepository; - public void anonymize() { + public void anonymize() throws NoSuchAlgorithmException, UnsupportedEncodingException { + MessageDigest md = MessageDigest.getInstance("MD5"); + Calendar cal = Calendar.getInstance(); - cal.add(Calendar.MONTH, -1); + cal.add(Calendar.DAY_OF_YEAR, -30); + if(cal.after(Calendar.getInstance())){ + cal.roll(Calendar.YEAR, -1); + } + List ls = requestRepository.findAllByRequestDateBefore(cal.getTime()); + for (InformationRequest informationRequest : ls) { + UserRequest user = informationRequest.getUser(); + if( requestRepository.countByRequestDateBetweenAndUser(cal.getTime(),Calendar.getInstance().getTime(),user) == 0 ) { + user.setAdress(null); + user.setCni(null); + user.setCodePostal(null); + user.setCommune(null); + user.setFirstName(null); + user.setLastName(null); + user.setMail(null); + user.setType(null); + userRequestRepository.save(user); + } + for (ObjectRequest objectRequest : informationRequest.getObjectsRequest()) { - objectRequestRepository.delete(objectRequest); + String prop = objectRequest.getProprietaire(); + if( !prop.startsWith("{HASH}") ) { + String hash = DatatypeConverter.printHexBinary(md.digest(prop.getBytes("UTF-8"))).toUpperCase(); + objectRequest.setProprietaire("{HASH}"+hash); + objectRequestRepository.save(objectRequest); + } } - userRequestRepository.delete(informationRequest.getUser()); } } } From c92679ff95e19bd1f568fe015f2c0eb8d6bdcabb Mon Sep 17 00:00:00 2001 From: jusabatier Date: Tue, 4 Jul 2023 14:35:48 +0200 Subject: [PATCH 5/5] =?UTF-8?q?Suppression=20modifications=20BDD=20repouss?= =?UTF-8?q?=C3=A9es=20=C3=A0=20future=20release?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/sql/tables/request_information.sql | 6 +- database/sql/updates/_update_2_1_0.sql | 24 ---- database/update_db.sh | 120 -------------------- 3 files changed, 3 insertions(+), 147 deletions(-) delete mode 100644 database/sql/updates/_update_2_1_0.sql delete mode 100755 database/update_db.sh diff --git a/database/sql/tables/request_information.sql b/database/sql/tables/request_information.sql index 3f12a6f6..bcaf917f 100644 --- a/database/sql/tables/request_information.sql +++ b/database/sql/tables/request_information.sql @@ -51,7 +51,7 @@ ALTER TABLE #schema_cadastrapp.request_information ALTER TABLE #schema_cadastrapp.request_information ADD CONSTRAINT foreingKeyUserId FOREIGN KEY (userid) REFERENCES #schema_cadastrapp.request_user_information (userid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE CASCADE; + ON UPDATE NO ACTION ON DELETE NO ACTION; ALTER TABLE #schema_cadastrapp.request_information OWNER TO #user_cadastrapp; @@ -93,12 +93,12 @@ ALTER TABLE #schema_cadastrapp.request_information_object_request ALTER TABLE #schema_cadastrapp.request_information_object_request ADD CONSTRAINT foreingKeyRequestObjectRequestId FOREIGN KEY (request_information_requestid) REFERENCES #schema_cadastrapp.request_information (requestid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE CASCADE; + ON UPDATE NO ACTION ON DELETE NO ACTION; ALTER TABLE #schema_cadastrapp.request_information_object_request ADD CONSTRAINT foreingKeyRequestObjectRequestObjectId FOREIGN KEY (objectsrequest_objectid) REFERENCES #schema_cadastrapp.object_request (objectid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE CASCADE; + ON UPDATE NO ACTION ON DELETE NO ACTION; ALTER TABLE #schema_cadastrapp.request_information_object_request ADD CONSTRAINT request_information_object_request_objectsrequest_objectid_key UNIQUE (objectsrequest_objectid ); diff --git a/database/sql/updates/_update_2_1_0.sql b/database/sql/updates/_update_2_1_0.sql deleted file mode 100644 index 21401781..00000000 --- a/database/sql/updates/_update_2_1_0.sql +++ /dev/null @@ -1,24 +0,0 @@ - -ALTER TABLE #schema_cadastrapp.request_information - DROP CONSTRAINT foreingKeyUserId; - -ALTER TABLE #schema_cadastrapp.request_information - ADD CONSTRAINT foreingKeyUserId FOREIGN KEY (userid) - REFERENCES #schema_cadastrapp.request_user_information (userid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE CASCADE; - -ALTER TABLE #schema_cadastrapp.request_information_object_request - DROP CONSTRAINT foreingKeyRequestObjectRequestId; - -ALTER TABLE #schema_cadastrapp.request_information_object_request - ADD CONSTRAINT foreingKeyRequestObjectRequestId FOREIGN KEY (request_information_requestid) - REFERENCES #schema_cadastrapp.request_information (requestid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE CASCADE; - -ALTER TABLE #schema_cadastrapp.request_information_object_request - DROP CONSTRAINT foreingKeyRequestObjectRequestObjectId; - -ALTER TABLE #schema_cadastrapp.request_information_object_request - ADD CONSTRAINT foreingKeyRequestObjectRequestObjectId FOREIGN KEY (objectsrequest_objectid) - REFERENCES #schema_cadastrapp.object_request (objectid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE CASCADE; \ No newline at end of file diff --git a/database/update_db.sh b/database/update_db.sh deleted file mode 100755 index e6d19f49..00000000 --- a/database/update_db.sh +++ /dev/null @@ -1,120 +0,0 @@ -#! /bin/bash - - -clear -git_version=$(git rev-parse HEAD) - -echo "---------------------------------------------------------------" -echo " Cadastrapp : script de mise à jour de la structure de données " -echo "---------------------------------------------------------------" -echo "" -echo " version : $git_version" -echo "" -echo "--------------------------------------------------------------" -echo " Lecture du fichier de configuration" -echo "--------------------------------------------------------------" -echo "" - -# lecture du fichier de configuration des connexions -. config.sh - -# verifie si le mode silencieux est activé -silentMode=False -while [[ "$#" -gt 0 ]] -do - case $1 in - -s|--silent) - silentMode=True - ;; - -*|--*) - echo "Invalid option: $1" - ;; - esac - shift -done - -if [ "$uniqueDB" = True ] ; then - echo " 1 seule base de données sera utilisée : $cadastrappDBName sur la machine $cadastrappDBHost" - echo " schéma des données cadastre QGIS : $qgisDBSchema" - echo " schéma des données cadastrapp : $cadastrappDBSchema" -elif [ "$uniqueDB" = False ] ; then - echo " 2 bases de données seront utilisées" - echo " host > db > schema" - echo " source QGIS : $qgisDBHost > $qgisDBName > $qgisDBSchema" - echo " cible cadastrapp : $cadastrappDBHost > $cadastrappDBName > $cadastrappDBSchema" -else - echo " pb de configuration : stop" - exit 1 -fi - -if [ "$orgsAutorisations" = True ] ; then - invalidLdapParam=False - if [ -z "$ldapUri" ] ; then - echo "Paramètre ldapUri manquant !" - invalidLdapParam=True - fi - - if [ -z "$ldapPath" ] ; then - echo "Paramètre ldapPath manquant !" - invalidLdapParam=True - fi - - if [ -z "$ldapBindDn" ] ; then - echo "Paramètre ldapBindDn manquant !" - invalidLdapParam=True - fi - - if [ -z "$ldapBindPwd" ] ; then - echo "Paramètre ldapBindPwd manquant !" - invalidLdapParam=True - fi - if [ "$invalidLdapParam" = True ] ; then - echo " pb de configuration : stop" - exit 1 - fi -fi - -if [ "$silentMode" = False ] ; then - echo "" - read -p " Si ces infos sont exactes : appuyer sur la touche [Entrée] sinon faire ctrl + C pour arrêter." - echo "" -fi - -# -# cette fonction permet de remplacer les infos de connection -# avant exécution -# -replaceAndLaunch (){ - - if [ -z "$1" ] || [ ! -e $1 ] ; then - echo "Le fichier SQL $1 n'existe pas." - exit 1 - else - echo " Exécution du fichier : $1" - fi - - cat $1 | sed "{ - s/#schema_cadastrapp/$cadastrappDBSchema/g - s/#user_cadastrapp/$cadastrappDBUser/g - s/#DBHost_qgis/$qgisDBHost/g - s/#DBPort_qgis/$qgisDBPort/g - s/#DBName_qgis/$qgisDBName/g - s/#DBSchema_qgis/$qgisDBSchema/g - s/#DBUser_qgis/$qgisDBUser/g - s/#DBpasswd_qgis/$qgisDBPassword/g - s|#ldap_uri|$ldapUri|g - s/#ldap_path/$ldapPath/g - s/#ldap_binddn/$ldapBindDn/g - s/#ldap_bindpwd/$ldapBindPwd/g - }" |\ - PGPASSWORD=$cadastrappDBPassword psql -h $cadastrappDBHost -p $cadastrappDBPort -d $cadastrappDBName -U $cadastrappDBUser - -} - -# on purge la BD cadastrapp existante -replaceAndLaunch sql/updates/_update_2_1_0.sql - -echo "" -echo "--------------------------------------------------------------" -echo " FIN " -echo "--------------------------------------------------------------"