v2 : create database

This commit is contained in:
MaelREBOUX 2021-04-17 09:35:34 +02:00
parent 90ddfded3b
commit c12f764f79
2 changed files with 89 additions and 0 deletions

36
scripts_v2/config.sh Normal file
View file

@ -0,0 +1,36 @@
#! /bin/bash
# exit dès que qqch se passe mal
set -e
# sortir si "unbound variqble"
#set -u
# argument 1 passé au script = millesime redadeg
millesime=$1
# configuration des infos de connexions aux bases de données
# >>>> pas besoin de mettre ces infos dans le .pgpass <<<<<
# chemin vers psql (en cas de multi-versions sur la machine)
PSQL=/usr/bin/psql
# penser à mettre les permissions au rôle redadeg sur la base osm
# BD Ar Redadeg
DB_HOST=localhost
DB_PORT=5432
DB_NAME=redadeg_$millesime
DB_USER=redadeg
DB_PASSWD=redadeg
# BD OSM
osmDBHost=localhost
osmDBPort=5432
osmDBName=osm
osmDBSchema=public
osmDBUser=redadeg
osmDBPassword=redadeg

53
scripts_v2/create_database.sh Executable file
View file

@ -0,0 +1,53 @@
#!/bin/bash
if [ -z "$1" ]
then
echo "Pas de millésime en argument --> stop"
exit 1
fi
# lecture du fichier de configuration
. config.sh
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo " Création de la base de données $DB_NAME"
echo ""
echo ""
echo " /!\ Le compte $DB_USER doit être SUPERUSER pour exécuter ce script"
echo " /!\ La base de données $DB_NAME va être supprimée !!"
echo ""
read -p " Appuyer sur la touche [Entrée] pour continuer sinon faire ctrl + C pour arrêter."
echo ""
# create role
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -d postgres -U $DB_USER -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASSWD' SUPERUSER;" || true
# suppression de la base de données existantes
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -d postgres -U $DB_USER -c "DROP DATABASE $DB_NAME ;" || true
# create database with owner redadeg
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -d postgres -U $DB_USER -c "CREATE DATABASE $DB_NAME WITH OWNER = $DB_USER ENCODING = 'UTF8';" || true
# extensions postgis
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -d postgres -U $DB_USER -c "CREATE EXTENSION postgis;" || true
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -d postgres -U $DB_USER -c "CREATE EXTENSION postgis_topology;" || true
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -d postgres -U $DB_USER -c "CREATE EXTENSION pgrouting;" || true
# permissions
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -d postgres -U $DB_USER -c "ALTER SCHEMA public OWNER TO $DB_USER;" || true
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -d postgres -U $DB_USER -c "ALTER TABLE topology.layer OWNER TO $DB_USER ;" || true
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -d postgres -U $DB_USER -c "ALTER TABLE topology.topology OWNER TO $DB_USER ;" || true
# vérifications
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -d postgres -U $DB_USER -c "SELECT * FROM postgis_version();"
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -d postgres -U $DB_USER -c "SELECT * FROM pgr_version();"
echo ""
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo " F I N"
echo ""