LP1901932 database rebuild script user/berick/lp1901932-data-script
authorBill Erickson <berickxx@gmail.com>
Tue, 26 Oct 2021 15:09:30 +0000 (11:09 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 26 Oct 2021 15:09:30 +0000 (11:09 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/sql/Pg/create-test-database.sh [new file with mode: 0644]

diff --git a/Open-ILS/src/sql/Pg/create-test-database.sh b/Open-ILS/src/sql/Pg/create-test-database.sh
new file mode 100644 (file)
index 0000000..bee9f32
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/bash
+
+PGUSER=evergreen
+PGPASS=evergreen
+DB_STAMP=1305;
+STOCK_DB=evergreen;
+DATA_SOURCE_STAMP=1305;
+DATA_DB="eg_$DB_STAMP";  
+SCHEMA_EXPORT="/tmp/eg-$DB_STAMP.schema.sql"
+
+# Extract the stock schema
+pg_dump -U $PGUSER --schema-only --format custom --file $SCHEMA_EXPORT $STOCK_DB
+
+# Extract the data from our data-full database
+# pg_dump -U $PGUSER --data-only --format custom --file Open-ILS/src/sql/Pg/data-snapshots/eg-$DATA_SOURCE_STAMP.data.sql $STOCK_DB
+
+# Create a new database from the stock schema.
+# This will have no schema or data
+sudo perl Open-ILS/src/support-scripts/eg_db_config --create-database --user $PGUSER --password $PGPASS --hostname localhost --database $DATA_DB
+
+# Apply the stock schema to the new database (without data)
+pg_restore -U $PGUSER --dbname $DATA_DB $SCHEMA_EXPORT
+
+# Load the full sample data into our new schema-only database
+pg_restore -U evergreen --dbname $DATA_DB --disable-triggers Open-ILS/src/sql/Pg/data-snapshots/eg-$DATA_SOURCE_STAMP.data.sql