--- a/dist/restore/restore-postgresql.sh
+++ b/dist/restore/restore-postgresql.sh
@@ -2,18 +2,20 @@
 # bbou@ac-toulouse;fr
 # 25/11/2013
 
+dbdelete=
+if [ "$1" == "-d" ]; then
+	dbdelete=true
+	shift
+fi
 db=$1
 dbtype=postgresql
 if [ -z "${db}" ]; then
-	read -s -p "enter ${dbtype} database name: " db
+	read -p "enter ${dbtype} database name: " db
 	echo
 	export db
 fi
 dbuser=postgres
-dbdelete=
-if [ "$2" == "-d" ]; then
-	dbdelete=true
-fi
+
 modules="wn legacy vn bnc sumo xwn glf ilfwn logs"
 
 function process()
@@ -53,7 +55,7 @@
 getpassword
 
 #database
-if [ ! -z ${dbdelete} ]; then
+if [ ! -z "${dbdelete}" ]; then
 	deletedb
 fi
 if ! dbexists; then
@@ -63,18 +65,19 @@
 # module tables
 for m in ${modules}; do
 	sql=${dbtype}-${m}-schema.sql
-	process ${sql} schema ${db}
+	process ${sql} "schema ${m}" ${db}
 done
 for m in ${modules}; do
 	sql=${dbtype}-${m}-data.sql
-	process ${sql} data ${db}
+	process ${sql} "data ${m}" ${db}
 done
 for m in ${modules}; do
-	sql=${dbtype}-${m}-constraints.sql
-	process ${sql} constraints ${db} --force
+	sql=${dbtype}-${m}-unconstrain.sql
+	process ${sql} "unconstrain ${m}" ${db} --force 2> /dev/null
+	sql=${dbtype}-${m}-constrain.sql
+	process ${sql} "constrain ${m}" ${db} --force
 done
 for m in ${modules}; do
 	sql=${dbtype}-${m}-views.sql
-	process ${sql} views ${db}
+	process ${sql} "views ${m}" ${db}
 done
-