This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/examples/create-db.sh

15 lines
768 B
Bash
Raw Normal View History

2018-09-16 11:53:07 +00:00
#!/usr/bin/env bash
# Creates a database, user, and extensions to use Devicehub
2018-10-30 08:28:38 +00:00
# $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
2018-09-16 11:53:07 +00:00
2018-10-30 08:28:38 +00:00
read -s -p "Password for $2": pass
2018-09-16 11:53:07 +00:00
createdb $1 # Create main database
2018-10-30 08:28:38 +00:00
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
2018-09-16 11:53:07 +00:00
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
psql -d $1 -c "CREATE EXTENSION pg_trgm SCHEMA public;" # Enable pg_trgm