Merge branch 'dev-merge' into dev
[gargantext.git] / devops / postgres / create
index 658826bfd596c63751626737e20a0cce5e86a8cf..5bdceb5a89b91af76ff8212abfc0e4b55978d6f5 100755 (executable)
@@ -1,23 +1,33 @@
 #!/bin/bash
 
 # sudo su postgres
-
 # postgresql://$USER:$PW@localhost/$DB
 
-PW="C8kdcUrAQy66U"
-DB="gargandbV5"
-USER="gargantua"
+INIFILE=$1
+
+getter () {
+  grep $1 $INIFILE | sed "s/^.*= //"
+}
+
+USER=$(getter "DB_USER")
+NAME=$(getter "DB_NAME")
+PASS=$(getter "DB_PASS")
+HOST=$(getter "DB_HOST")
+PORT=$(getter "DB_PORT")
+
 
 psql -c "CREATE USER \"${USER}\""
 psql -c "ALTER USER \"${USER}\" with PASSWORD '${PW}'"
+psql -c "DROP DATABASE IF EXISTS \"${NAME}\""
 
-psql -c "DROP DATABASE IF EXISTS \"${DB}\""
-createdb "${DB}"
-psql "${DB}" < schema.sql
-
-psql -c "ALTER DATABASE \"${DB}\" OWNER to \"${USER}\""
+createdb "${NAME}"
+psql "${NAME}" <  extensions.sql
 
+# if new
+#psql "${NAME}" < schema.sql
 
+psql ${NAME} < $2
 
+psql -c "ALTER DATABASE \"${NAME}\" OWNER to \"${USER}\""