@@ -26,6 +26,9 @@ usage() {
26
26
echo " Defaults to 9999."
27
27
echo " -h"
28
28
echo " Display this help text."
29
+ echo " "
30
+ echo " NB: make sure to run this against the *oldest* supported version of postgres,"
31
+ echo " or else pg_dump might output non-backwards-compatible syntax."
29
32
}
30
33
31
34
SCHEMA_NUMBER=" 9999"
@@ -240,25 +243,54 @@ DROP TABLE user_directory_search_stat;
240
243
241
244
echo " Dumping SQLite3 schema..."
242
245
243
- mkdir -p " $OUTPUT_DIR /" {common,main,state}" /full_schema /$SCHEMA_NUMBER "
244
- sqlite3 " $SQLITE_COMMON_DB " " .schema --indent " > " $OUTPUT_DIR /common/full_schema /$SCHEMA_NUMBER /full.sql.sqlite"
245
- sqlite3 " $SQLITE_COMMON_DB " " .dump --data-only --nosys" >> " $OUTPUT_DIR /common/full_schema /$SCHEMA_NUMBER /full.sql.sqlite"
246
- sqlite3 " $SQLITE_MAIN_DB " " .schema --indent " > " $OUTPUT_DIR /main/full_schema /$SCHEMA_NUMBER /full.sql.sqlite"
247
- sqlite3 " $SQLITE_MAIN_DB " " .dump --data-only --nosys" >> " $OUTPUT_DIR /main/full_schema /$SCHEMA_NUMBER /full.sql.sqlite"
248
- sqlite3 " $SQLITE_STATE_DB " " .schema --indent " > " $OUTPUT_DIR /state/full_schema /$SCHEMA_NUMBER /full.sql.sqlite"
249
- sqlite3 " $SQLITE_STATE_DB " " .dump --data-only --nosys" >> " $OUTPUT_DIR /state/full_schema /$SCHEMA_NUMBER /full.sql.sqlite"
246
+ mkdir -p " $OUTPUT_DIR /" {common,main,state}" /full_schemas /$SCHEMA_NUMBER "
247
+ sqlite3 " $SQLITE_COMMON_DB " " .schema" > " $OUTPUT_DIR /common/full_schemas /$SCHEMA_NUMBER /full.sql.sqlite"
248
+ sqlite3 " $SQLITE_COMMON_DB " " .dump --data-only --nosys" >> " $OUTPUT_DIR /common/full_schemas /$SCHEMA_NUMBER /full.sql.sqlite"
249
+ sqlite3 " $SQLITE_MAIN_DB " " .schema" > " $OUTPUT_DIR /main/full_schemas /$SCHEMA_NUMBER /full.sql.sqlite"
250
+ sqlite3 " $SQLITE_MAIN_DB " " .dump --data-only --nosys" >> " $OUTPUT_DIR /main/full_schemas /$SCHEMA_NUMBER /full.sql.sqlite"
251
+ sqlite3 " $SQLITE_STATE_DB " " .schema" > " $OUTPUT_DIR /state/full_schemas /$SCHEMA_NUMBER /full.sql.sqlite"
252
+ sqlite3 " $SQLITE_STATE_DB " " .dump --data-only --nosys" >> " $OUTPUT_DIR /state/full_schemas /$SCHEMA_NUMBER /full.sql.sqlite"
250
253
251
254
cleanup_pg_schema () {
252
- sed -e ' /^$/d' -e ' /^--/d' -e ' s/public\.//g' -e ' /^SET /d' -e ' /^SELECT /d'
255
+ # Cleanup as follows:
256
+ # - Remove empty lines. pg_dump likes to output a lot of these.
257
+ # - Remove comment-only lines. pg_dump also likes to output a lot of these to visually
258
+ # separate tables etc.
259
+ # - Remove "public." prefix --- the schema name.
260
+ # - Remove "SET" commands. Last time I ran this, the output commands were
261
+ # SET statement_timeout = 0;
262
+ # SET lock_timeout = 0;
263
+ # SET idle_in_transaction_session_timeout = 0;
264
+ # SET client_encoding = 'UTF8';
265
+ # SET standard_conforming_strings = on;
266
+ # SET check_function_bodies = false;
267
+ # SET xmloption = content;
268
+ # SET client_min_messages = warning;
269
+ # SET row_security = off;
270
+ # SET default_table_access_method = heap;
271
+ # - Very carefully remove specific SELECT statements. We CANNOT blanket remove all
272
+ # SELECT statements because some of those have side-effects which we do want in the
273
+ # schema. Last time I ran this, the only SELECTS were
274
+ # SELECT pg_catalog.set_config('search_path', '', false);
275
+ # and
276
+ # SELECT pg_catalog.setval(text, bigint, bool);
277
+ # We do want to remove the former, but the latter is important. If the last argument
278
+ # is `true` or omitted, this marks the given integer as having been consumed and
279
+ # will NOT appear as the nextval.
280
+ sed -e ' /^$/d' \
281
+ -e ' /^--/d' \
282
+ -e ' s/public\.//g' \
283
+ -e ' /^SET /d' \
284
+ -e ' /^SELECT pg_catalog.set_config/d'
253
285
}
254
286
255
287
echo " Dumping Postgres schema..."
256
288
257
- pg_dump --format=plain --schema-only --no-tablespaces --no-acl --no-owner " $POSTGRES_COMMON_DB_NAME " | cleanup_pg_schema > " $OUTPUT_DIR /common/full_schema /$SCHEMA_NUMBER /full.sql.postgres"
258
- pg_dump --format=plain --data-only --inserts --no-tablespaces --no-acl --no-owner " $POSTGRES_COMMON_DB_NAME " | cleanup_pg_schema >> " $OUTPUT_DIR /common/full_schema /$SCHEMA_NUMBER /full.sql.postgres"
259
- pg_dump --format=plain --schema-only --no-tablespaces --no-acl --no-owner " $POSTGRES_MAIN_DB_NAME " | cleanup_pg_schema > " $OUTPUT_DIR /main/full_schema /$SCHEMA_NUMBER /full.sql.postgres"
260
- pg_dump --format=plain --data-only --inserts --no-tablespaces --no-acl --no-owner " $POSTGRES_MAIN_DB_NAME " | cleanup_pg_schema >> " $OUTPUT_DIR /main/full_schema /$SCHEMA_NUMBER /full.sql.postgres"
261
- pg_dump --format=plain --schema-only --no-tablespaces --no-acl --no-owner " $POSTGRES_STATE_DB_NAME " | cleanup_pg_schema > " $OUTPUT_DIR /state/full_schema /$SCHEMA_NUMBER /full.sql.postgres"
262
- pg_dump --format=plain --data-only --inserts --no-tablespaces --no-acl --no-owner " $POSTGRES_STATE_DB_NAME " | cleanup_pg_schema >> " $OUTPUT_DIR /state/full_schema /$SCHEMA_NUMBER /full.sql.postgres"
289
+ pg_dump --format=plain --schema-only --no-tablespaces --no-acl --no-owner " $POSTGRES_COMMON_DB_NAME " | cleanup_pg_schema > " $OUTPUT_DIR /common/full_schemas /$SCHEMA_NUMBER /full.sql.postgres"
290
+ pg_dump --format=plain --data-only --inserts --no-tablespaces --no-acl --no-owner " $POSTGRES_COMMON_DB_NAME " | cleanup_pg_schema >> " $OUTPUT_DIR /common/full_schemas /$SCHEMA_NUMBER /full.sql.postgres"
291
+ pg_dump --format=plain --schema-only --no-tablespaces --no-acl --no-owner " $POSTGRES_MAIN_DB_NAME " | cleanup_pg_schema > " $OUTPUT_DIR /main/full_schemas /$SCHEMA_NUMBER /full.sql.postgres"
292
+ pg_dump --format=plain --data-only --inserts --no-tablespaces --no-acl --no-owner " $POSTGRES_MAIN_DB_NAME " | cleanup_pg_schema >> " $OUTPUT_DIR /main/full_schemas /$SCHEMA_NUMBER /full.sql.postgres"
293
+ pg_dump --format=plain --schema-only --no-tablespaces --no-acl --no-owner " $POSTGRES_STATE_DB_NAME " | cleanup_pg_schema > " $OUTPUT_DIR /state/full_schemas /$SCHEMA_NUMBER /full.sql.postgres"
294
+ pg_dump --format=plain --data-only --inserts --no-tablespaces --no-acl --no-owner " $POSTGRES_STATE_DB_NAME " | cleanup_pg_schema >> " $OUTPUT_DIR /state/full_schemas /$SCHEMA_NUMBER /full.sql.postgres"
263
295
264
296
echo " Done! Files dumped to: $OUTPUT_DIR "
0 commit comments