Skip to content

Commit d8f6f9a

Browse files
committed
tech: ajout script dump db pour app de test
1 parent b8da991 commit d8f6f9a

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

.scalingo/first-deploy.sh

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ echo "First deploy"
44

55
if [[ $APP =~ "pa-back-staging-pr" ]] ; then
66
echo "Dump de la DB de staging"
7+
8+
if [[ $DATABASE_URL == *"pa_back_pro_817"* ]]; then
9+
echo "Error: Target must not be production"
10+
exit 1
11+
fi
12+
713
export PATH=$HOME/bin:$PATH
814
dbclient-fetcher psql 13
915
psql --dbname $DATABASE_URL -c "CREATE extension postgis;"

.scalingo/post-deploy.sh

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
#!/bin/bash
22

3+
echo "Post deploy"
4+
35
if [[ $APP =~ "pa-back-staging-pr" ]] ; then
46
echo "Dump de la DB de staging"
7+
8+
if [[ $DATABASE_URL == *"pa_back_pro_817"* ]]; then
9+
echo "Error: Target must not be production"
10+
exit 1
11+
fi
12+
513
export PATH=$HOME/bin:$PATH
614
dbclient-fetcher psql 13
715
pg_dump --clean --if-exists --format c --no-owner --no-privileges --no-comments -n 'public' -n 'sequelize' --exclude-schema 'information_schema' --exclude-schema '^pg_*' --exclude-schema 'tiger' --exclude-schema 'tiger_data' --exclude-schema 'topology' --dbname $STAGING_DATABASE_URL --file dump.pgsql

scripts/perf/db_dump_restore.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $APP =~ "pa-back-prod-test" ]] ; then
4+
echo "Dump de la DB de prod vers la db de perf"
5+
6+
if [ -z "$PROD_DATABASE_URL" ]; then
7+
echo "error: env var PROD_DATABASE_URL must be set"
8+
exit 1
9+
fi
10+
11+
if [ -z "$DATABASE_URL" ]; then
12+
echo "error: env var DATABASE_URL must be set"
13+
exit 1
14+
fi
15+
16+
if [[ $DATABASE_URL == *"pa_back_pro_817"* ]]; then
17+
echo "Error: Target must not be production"
18+
exit 1
19+
fi
20+
21+
export PATH=$HOME/bin:$PATH
22+
dbclient-fetcher psql 13
23+
24+
echo "Drop conflicting extensions (if they exist)"
25+
psql --dbname $DATABASE_URL -c "DROP EXTENSION IF EXISTS postgis CASCADE;"
26+
psql --dbname $DATABASE_URL -c "DROP EXTENSION IF EXISTS postgis_tiger_geocoder CASCADE;"
27+
psql --dbname $DATABASE_URL -c "DROP EXTENSION IF EXISTS postgis_topology CASCADE;"
28+
psql --dbname $DATABASE_URL -c "DROP EXTENSION IF EXISTS pg_trgm CASCADE;"
29+
30+
echo "Dump production database (excluding unnecessary schemas)"
31+
pg_dump --clean --if-exists --format c --no-owner --no-privileges --no-comments \
32+
-n 'public' -n 'sequelize' \
33+
--exclude-schema 'information_schema' --exclude-schema '^pg_*' \
34+
--exclude-schema 'tiger' --exclude-schema 'tiger_data' --exclude-schema 'topology' \
35+
--dbname $PROD_DATABASE_URL --file dump.pgsql
36+
37+
echo "Restore database dump (WITHOUT extensions yet)"
38+
pg_restore --clean --if-exists --no-owner --no-privileges --no-comments --dbname $DATABASE_URL dump.pgsql
39+
40+
echo "Recreate extensions AFTER restore"
41+
psql --dbname $DATABASE_URL -c "CREATE EXTENSION postgis;"
42+
psql --dbname $DATABASE_URL -c "CREATE EXTENSION postgis_tiger_geocoder CASCADE;"
43+
psql --dbname $DATABASE_URL -c "CREATE EXTENSION postgis_topology;"
44+
psql --dbname $DATABASE_URL -c "CREATE EXTENSION pg_trgm;"
45+
46+
echo "Grant correct privileges"
47+
psql --dbname $DATABASE_URL -c "GRANT USAGE, CREATE ON SCHEMA public TO pa_back_pro_4110;"
48+
psql --dbname $DATABASE_URL -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO pa_back_pro_4110;"
49+
50+
fi
51+
52+
rm -f dump.pgsql

0 commit comments

Comments
 (0)