-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tech: ajout script dump db pour app de test
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
#!/bin/bash | ||
|
||
echo "Post deploy" | ||
|
||
if [[ $APP =~ "pa-back-staging-pr" ]] ; then | ||
echo "Dump de la DB de staging" | ||
|
||
if [[ $DATABASE_URL == *"pa_back_pro_817"* ]]; then | ||
echo "Error: Target must not be production" | ||
exit 1 | ||
fi | ||
|
||
export PATH=$HOME/bin:$PATH | ||
dbclient-fetcher psql 13 | ||
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 | ||
psql --dbname $DATABASE_URL -c "CREATE EXTENSION IF NOT EXISTS postgis; CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder; CREATE EXTENSION IF NOT EXISTS pg_trgm;" | ||
pg_restore --clean --if-exists --no-owner --no-privileges --no-comments --dbname $DATABASE_URL dump.pgsql | ||
fi | ||
|
||
if [[ $APP =~ "pa-back-prod-test" ]] ; then | ||
echo "Dump de la DB de prod" | ||
|
||
if [[ $DATABASE_URL == *"pa_back_pro_817"* ]]; then | ||
echo "Error: Target must not be production" | ||
exit 1 | ||
fi | ||
|
||
export PATH=$HOME/bin:$PATH | ||
dbclient-fetcher psql 13 | ||
|
||
psql --dbname $DATABASE_URL -c "CREATE extension postgis;" | ||
psql --dbname $DATABASE_URL -c "CREATE extension postgis_tiger_geocoder CASCADE;" | ||
psql --dbname $DATABASE_URL -c "CREATE extension postgis_topology;" | ||
psql --dbname $DATABASE_URL -c "CREATE extension pg_trgm;" | ||
|
||
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 $PROD_DATABASE_URL --file dump.pgsql | ||
psql --dbname $DATABASE_URL -c "CREATE EXTENSION IF NOT EXISTS postgis; CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder; CREATE EXTENSION IF NOT EXISTS pg_trgm;" | ||
pg_restore --clean --if-exists --no-owner --no-privileges --no-comments --dbname $DATABASE_URL dump.pgsql | ||
fi | ||
|
||
yarn migration | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "dump cej db and restore to another" | ||
|
||
#DUMP_RESTORE_DB_SOURCE= | ||
#DUMP_RESTORE_DB_TARGET= | ||
|
||
if [[ $DUMP_RESTORE_DB_TARGET == *"pa_back_pro_817"* ]]; then | ||
echo "Error: Target must not be production" | ||
exit 1 | ||
fi | ||
|
||
if [[ $DUMP_RESTORE_DB_SOURCE = $DUMP_RESTORE_DB_TARGET ]]; then | ||
echo "error: source must be different from target" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$DUMP_RESTORE_DB_SOURCE" ]; then | ||
echo "error: env var DUMP_RESTORE_DB_SOURCE must be set" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$DUMP_RESTORE_DB_TARGET" ]; then | ||
echo "error: env var DUMP_RESTORE_DB_TARGET must be set" | ||
exit 1 | ||
fi | ||
|
||
export PATH=$HOME/bin:$PATH | ||
dbclient-fetcher psql 13 | ||
|
||
pg_dump --clean --if-exists --format c --dbname "$DUMP_RESTORE_DB_SOURCE" --no-owner --no-privileges --no-comments --schema 'public' --file dump.pgsql \ | ||
--exclude-table 'spatial_ref_sys' \ | ||
--exclude-table 'log_api_partenaire' \ | ||
--exclude-table 'suivi_job' \ | ||
--exclude-table 'evenement_engagement' \ | ||
--exclude-table 'evenement_engagement_hebdo' | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "Error: pg_dump command failed" | ||
exit 1 | ||
fi | ||
echo "pg_dump OK" | ||
|
||
psql -d ${DUMP_RESTORE_DB_TARGET} \ | ||
-c "CREATE EXTENSION IF NOT EXISTS postgis SCHEMA public;" \ | ||
-c "CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder CASCADE SCHEMA public;" \ | ||
-c "CREATE EXTENSION IF NOT EXISTS postgis_topology SCHEMA topology;" \ | ||
-c "CREATE EXTENSION IF NOT EXISTS pg_trgm SCHEMA public;" | ||
|
||
echo "extensions crées" | ||
|
||
pg_restore --clean --if-exists --no-owner --no-privileges --no-comments --dbname "${DUMP_RESTORE_DB_TARGET}" dump.pgsql | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "Error: pg_restore command failed gracefully" | ||
fi | ||
echo "pg_restore OK" | ||
|
||
rm -f dump.pgsql |