2019-01-01 19:52:23 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
|
|
# utiliser un compte SUPERUSER pour exécuter ce script
|
|
|
|
|
2021-03-10 07:57:08 +00:00
|
|
|
millesime=2022
|
2020-02-10 12:31:30 +00:00
|
|
|
|
2021-03-10 07:57:08 +00:00
|
|
|
PSQL=/usr/bin/psql
|
|
|
|
DB_HOST=localhost
|
|
|
|
DB_NAME=redadeg_$millesime
|
|
|
|
|
2021-03-10 08:18:35 +00:00
|
|
|
|
|
|
|
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
|
2020-02-10 12:31:30 +00:00
|
|
|
|
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';"
|
2020-02-10 12:31:30 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
2020-02-10 12:31:30 +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
|
|
|
|
2020-02-10 12:31:30 +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
|
|
|
|