From 4946bf706116b0aa5667c159e3a016842b349ffc Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Sun, 7 Sep 2025 22:27:01 +0000 Subject: [PATCH] Adjust to allow conversion to take a connection string --- conversion/Makefile | 25 +++++++++++++------------ conversion/copy_schema.sh | 14 ++++++++------ conversion/make_tidy.sh | 8 +++++--- make_files/defaults.mk | 6 +++++- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/conversion/Makefile b/conversion/Makefile index cce4fc6..e5b0d31 100644 --- a/conversion/Makefile +++ b/conversion/Makefile @@ -173,9 +173,9 @@ libconv: $(PSQL_DEPENDS) copy_tidy: $(PSQL_DEPENDS) # Copy the raw schema to the tidy schema PSQL_SETUP="$(PSQL_SETUP)" \ - PSQL_ARGS="$(PSQL_ARGS)" \ - PSQL_ARGS_MINIMAL="$(PSQL_ARGS_MINIMAL)" \ - PSQL_SINGLE_TRANS="$(PSQL_SINGLE_TRANS)" \ + PSQL_ARGS_BASE='$(PSQL_ARGS_BASE)' \ + PSQL_ARGS_MINIMAL=$(PSQL_ARGS_MINIMAL) \ + PSQL_SINGLE_TRANS='$(PSQL_SINGLE_TRANS)' \ ./copy_schema.sh raw tidy ## after_copy_tidy @@ -188,9 +188,10 @@ after_copy_tidy: make_tidy after_make_tidy .PHONY: make_tidy make_tidy: $(PSQL_DEPENDS) libconv PSQL_TIDY_SETUP="$(PSQL_TIDY_SETUP)" \ - PSQL_ARGS="$(PSQL_ARGS)" \ - PSQL_SINGLE_TRANS="$(PSQL_SINGLE_TRANS)" \ - ./make_tidy.sh + PSQL_ARGS_MINIMAL=$(PSQL_ARGS_MINIMAL) \ + PSQL_ARGS_BASE='$(PSQL_ARGS_BASE)' \ + PSQL_SINGLE_TRANS='$(PSQL_SINGLE_TRANS)' \ + ./make_tidy.sh ## after_make_tidy ## Complete the conversion steps that follow the @@ -203,9 +204,9 @@ after_make_tidy: copy_easy after_copy_easy copy_easy: $(PSQL_DEPENDS) # Copy the tidy schema to the easy schema PSQL_SETUP="$(PSQL_SETUP)" \ - PSQL_ARGS="$(PSQL_ARGS)" \ - PSQL_ARGS_MINIMAL="$(PSQL_ARGS_MINIMAL)" \ - PSQL_SINGLE_TRANS="$(PSQL_SINGLE_TRANS)" \ + PSQL_ARGS_BASE='$(PSQL_ARGS_BASE)' \ + PSQL_ARGS_MINIMAL=$(PSQL_ARGS_MINIMAL) \ + PSQL_SINGLE_TRANS='$(PSQL_SINGLE_TRANS)' \ ./copy_schema.sh tidy easy ## after_copy_easy @@ -233,9 +234,9 @@ after_make_easy: copy_clean after_copy_clean copy_clean: $(PSQL_DEPENDS) # Copy the easy schema to the clean schema PSQL_SETUP="$(PSQL_SETUP)" \ - PSQL_ARGS="$(PSQL_ARGS)" \ - PSQL_ARGS_MINIMAL="$(PSQL_ARGS_MINIMAL)" \ - PSQL_SINGLE_TRANS="$(PSQL_SINGLE_TRANS)" \ + PSQL_ARGS_BASE='$(PSQL_ARGS_BASE)' \ + PSQL_ARGS_MINIMAL=$(PSQL_ARGS_MINIMAL) \ + PSQL_SINGLE_TRANS='$(PSQL_SINGLE_TRANS)' \ ./copy_schema.sh easy clean ## after_copy_clean diff --git a/conversion/copy_schema.sh b/conversion/copy_schema.sh index 505c9be..2a3405c 100755 --- a/conversion/copy_schema.sh +++ b/conversion/copy_schema.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright (C) 2023 The Meme Factory, Inc. http://www.karlpinc.com/ +# Copyright (C) 2023, 2025 The Meme Factory, Inc. http://www.karlpinc.com/ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -23,7 +23,7 @@ # # Relies on the following environment variables: # PSQL_SETUP -# PSQL_ARGS +# PSQL_ARGS_BASE # PSQL_ARGS_MINIMAL # PSQL_SINGLE_TRANS # @@ -45,16 +45,18 @@ trap cleanup EXIT { ${PSQL_SETUP} ; printf 'drop schema if exists %s cascade;\n' "${NEW}" ; printf 'alter schema %s rename to %s;\n' "${OLD}" "${NEW}" ; -} | psql ${PSQL_ARGS} ${PSQL_SINGLE_TRANS} --set=ON_ERROR_STOP=y +} | psql ${PSQL_ARGS_BASE} "${PSQL_ARGS_MINIMAL}" ${PSQL_SINGLE_TRANS} \ + --set=ON_ERROR_STOP=y # Dump the NEW -pg_dump ${PSQL_ARGS_MINIMAL} --blobs --schema="${NEW}" -Fc --no-owner \ +pg_dump "${PSQL_ARGS_MINIMAL}" --blobs --schema="${NEW}" -Fc --no-owner \ > ${dump_file} # Rename the NEW to the OLD, restoring it { ${PSQL_SETUP} ; printf 'alter schema %s rename to %s;\n' "${NEW}" "${OLD}" ; - } | psql ${PSQL_ARGS} ${PSQL_SINGLE_TRANS} --set=ON_ERROR_STOP=y +} | psql ${PSQL_ARGS_BASE} "${PSQL_ARGS_MINIMAL}" ${PSQL_SINGLE_TRANS} \ + --set=ON_ERROR_STOP=y # Restore the NEW -pg_restore ${PSQL_ARGS_MINIMAL} < ${dump_file} +pg_restore --dbname "${PSQL_ARGS_MINIMAL}" < ${dump_file} diff --git a/conversion/make_tidy.sh b/conversion/make_tidy.sh index f334973..1b53e3b 100755 --- a/conversion/make_tidy.sh +++ b/conversion/make_tidy.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (C) 2023 The Meme Factory, Inc. http://www.karlpinc.com/ +# Copyright (C) 2023, 2025 The Meme Factory, Inc. http://www.karlpinc.com/ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -20,7 +20,8 @@ # # Relies on the following environment variables: # PSQL_TIDY_SETUP -# PSQL_ARGS +# PSQL_ARGS_BASE +# PSQL_ARGS_MINIMAL # PSQL_SINGLE_TRANS # # Karl O. Pinc @@ -36,5 +37,6 @@ set -o pipefail ./speedups.sh ; cat tidy_cleanups.sql ; cat tidy.sql ; -} | psql ${PSQL_ARGS} ${PSQL_SINGLE_TRANS} --set=ON_ERROR_STOP=y \ +} | psql ${PSQL_ARGS_BASE} "${PSQL_ARGS_MINIMAL}" ${PSQL_SINGLE_TRANS} \ + --set=ON_ERROR_STOP=y \ | { ! grep -v '^[[:space:]]*$' ; } diff --git a/make_files/defaults.mk b/make_files/defaults.mk index 9b42ce4..2a926fb 100644 --- a/make_files/defaults.mk +++ b/make_files/defaults.mk @@ -54,7 +54,11 @@ export ADMINUSER := $(USER) # For invoking psql everywhere. export PSQL_ARGS_MINIMAL := "user=$(ADMINUSER) dbname=$(TARGET_DB) host=$(HOST) sslmode=require" -export PSQL_ARGS := --tuples-only -q $(PSQL_ARGS_MINIMAL) +# Separate variables to support passing shell a quoted argument +# (See conversion/copy_schema.sh, etc., where PSQL_ARGS_MINIMAL +# is the connection string, and passed separately.) +export PSQL_ARGS_BASE := --tuples-only -q +export PSQL_ARGS := $(PSQL_ARGS_BASE) $(PSQL_ARGS_MINIMAL) export PSQL_SINGLE_TRANS := --single-transaction --file - # Variable to setup connections before use. -- 2.34.1