summaryrefslogtreecommitdiff
path: root/util/gendevdb.sh
diff options
context:
space:
mode:
Diffstat (limited to 'util/gendevdb.sh')
-rwxr-xr-xutil/gendevdb.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/util/gendevdb.sh b/util/gendevdb.sh
new file mode 100755
index 00000000..466d3f65
--- /dev/null
+++ b/util/gendevdb.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# This script generates util/sql/devdb.sql from the current DB. It assumes that
+# the DB is accessible through a passwordless 'psql -U vndb'.
+
+# WARNING: This script will throw away sessions and IP addresses from the DB!
+
+psql -U vndb -c 'TRUNCATE sessions'
+psql -U vndb -c "UPDATE users SET ip = '0.0.0.0'"
+psql -U vndb -c "UPDATE changes SET ip = '0.0.0.0'"
+
+cat <<'EOF' >util/sql/devdb.sql
+-- See the README for instructions.
+-- This file was automatically generated by util/gendevdb.sh.
+
+SET CONSTRAINTS ALL DEFERRED;
+-- Hack to disable triggers
+SET session_replication_role = replica;
+EOF
+
+psql -U vndb -qAtc \
+ "SELECT 'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE;'
+ FROM pg_class WHERE relkind = 'r' AND relnamespace = 'public'::regnamespace"\
+ >>util/sql/devdb.sql
+
+pg_dump -U vndb --data-only | grep -Ev '^(--( .*|$))?$' >>util/sql/devdb.sql