From 414f3f9b734e242d8fd02cada04cf0000e40339a Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Tue, 30 Oct 2018 09:28:38 +0100 Subject: [PATCH] Update database config --- README.md | 11 +++++++---- examples/create-db.sh | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 53164936..cbea64aa 100644 --- a/README.md +++ b/README.md @@ -35,10 +35,12 @@ call the new file ``app.py``. Create a PostgreSQL database called *devicehub* by running [create-db](examples/create-db.sh): -- In a Debian 9 terminal, execute the following two commands: +- In a Debian 9 bash terminal, execute the following two commands: 1. `sudo su - postgres`. - 2. `bash examples/create-db.sh devicehub`. -- In MacOS: `examples/create-db.sh devicehub`. + 2. `bash examples/create-db.sh devicehub dhub`, + and password `ereuse`. +- In MacOS: `bash examples/create-db.sh devicehub dhub`, + and password `ereuse`. Create the tables in the database by executing in the same directory where `app.py` is: @@ -85,7 +87,8 @@ To run the tests you will need to: 1. `git clone` this project. 2. Create a database for testing executing `create-db.sh` like the normal installation but changing the first parameter - from `devicehub` to `dh_test`: `create-db.sh dh_test`. + from `devicehub` to `dh_test`: `create-db.sh dh_test dhub` and + password `ereuse`. 3. Execute at the root folder of the project `python3 setup.py test`. ## Generating the docs diff --git a/examples/create-db.sh b/examples/create-db.sh index b74fa7b0..f9848904 100644 --- a/examples/create-db.sh +++ b/examples/create-db.sh @@ -1,9 +1,13 @@ #!/usr/bin/env bash # Creates a database, user, and extensions to use Devicehub +# $1 is the database to create +# $2 is the user to create and give full permissions on the database +# This script asks for the password of such user +read -s -p "Password for $2": pass createdb $1 # Create main database -psql -d $1 -c "CREATE USER dhub WITH PASSWORD 'ereuse';" # Create user Devicehub uses to access db -psql -d $1 -c "GRANT ALL PRIVILEGES ON DATABASE $1 TO dhub;" # Give access to the db +psql -d $1 -c "CREATE USER $2 WITH PASSWORD '$pass';" # Create user Devicehub uses to access db +psql -d $1 -c "GRANT ALL PRIVILEGES ON DATABASE $1 TO $2;" # Give access to the db psql -d $1 -c "CREATE EXTENSION pgcrypto SCHEMA public;" # Enable pgcrypto psql -d $1 -c "CREATE EXTENSION ltree SCHEMA public;" # Enable ltree psql -d $1 -c "CREATE EXTENSION citext SCHEMA public;" # Enable citext