ar_redadeg/scripts/create_database.sh

53 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
2019-01-01 19:52:23 +00:00
# exit dès que qqch se passe mal
#set -e
# ?
set -u
2019-01-01 19:52:23 +00:00
# utiliser un compte SUPERUSER pour exécuter ce script
# argument 1 = millesime redadeg
millesime=$1
2021-03-10 07:57:08 +00:00
PSQL=/usr/bin/psql
DB_HOST=localhost
DB_NAME=redadeg_$millesime
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo " Création de la base de données $DB_NAME"
echo ""
echo ""
echo "La base de données $DB_NAME va être supprimée !!"
if [ ! -t 0 ]; then x-terminal-emulator -e "$0"; exit 0; fi
read -r -p "Appuyer sur n'importe quelle touche pour continuer..." key
# suppression de la base de données existantes
echo "DROP DATABASE $DB_NAME ;" | psql -U postgres -w
2019-01-01 19:52:23 +00:00
# create role
2021-03-10 08:00:24 +00:00
psql -h $DB_HOST -d postgres -c "CREATE USER redadeg WITH PASSWORD 'redadeg' SUPERUSER;"
2019-01-01 19:52:23 +00:00
# create database with owner redadeg
2021-03-10 08:00:24 +00:00
psql -h $DB_HOST -d postgres -c "CREATE DATABASE $DB_NAME WITH OWNER = redadeg ENCODING = 'UTF8';"
# extensions postgis
2021-03-10 08:00:24 +00:00
psql -h $DB_HOST -d $DB_NAME -c "CREATE EXTENSION postgis;"
psql -h $DB_HOST -d $DB_NAME -c "CREATE EXTENSION postgis_topology;"
psql -h $DB_HOST -d $DB_NAME -c "CREATE EXTENSION pgrouting;"
2019-01-01 19:52:23 +00:00
# permissions
2021-03-10 08:00:24 +00:00
psql -h $DB_HOST -d $DB_NAME -c "ALTER SCHEMA public OWNER TO redadeg;"
psql -h $DB_HOST -d $DB_NAME -c "ALTER TABLE topology.layer OWNER TO redadeg ;"
psql -h $DB_HOST -d $DB_NAME -c "ALTER TABLE topology.topology OWNER TO redadeg ;"
2019-01-01 19:52:23 +00:00
# vérifications
2021-03-10 08:00:24 +00:00
psql -h $DB_HOST -d $DB_NAME -c "SELECT * FROM postgis_version();"
psql -h $DB_HOST -d $DB_NAME -c "SELECT * FROM pgr_version();"
2019-01-01 19:52:23 +00:00