From d4f91aea3b28e01988584dc1cadcc9ff92f9edab Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Wed, 12 Aug 2020 14:23:34 +0200 Subject: [PATCH] Add script to update template schema from database --- README.md | 7 ++++--- sbin/dump_schema.sh | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100755 sbin/dump_schema.sh diff --git a/README.md b/README.md index eac53a1..a74403a 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,10 @@ ## Structure of this repo * `bin/` Scripts that import / export data into / out of the database. -* `etc/` Configuration files -* `lib/` Code files - - `lib/www/` Web interface and API +* `etc/` Configuration files. +* `lib/` Code files. + - `lib/www/` Web interface and API. - `lib/www/client/` Frontend. - `lib/www/server/` Backend. +* `sbin/` System maintenance scripts. diff --git a/sbin/dump_schema.sh b/sbin/dump_schema.sh new file mode 100755 index 0000000..ab11690 --- /dev/null +++ b/sbin/dump_schema.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Use this to create a new template schema based on an existing schema in the database. +# +# The template schema is used by bin/create_survey.sh to initialise a new set of tables for a prospect. + +SCHEMA_NAME=${SCHEMA_NAME:-survey_1} +EPSG_CODE=${EPSG_CODE:-23031} +DEST=${DEST:-"$(dirname "$0")/../etc/db/schema-template.sql"} + +pg_dump -U postgres --schema="$SCHEMA_NAME" --schema-only --host=localhost dougal | + sed -r "s/$SCHEMA_NAME/_SURVEY__TEMPLATE_/g;s/$EPSG_CODE/_EPSG__CODE_/g" >"$DEST" && + echo "Schema $SCHEMA_NAME dumped to $DEST"