--- /dev/null
+#!/bin/sh
+# Copyright (C) 2023 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
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+# Compare the Azure server json config files
+#
+# All "id" keys are removed before comparison because they are
+# always going to be different.
+#
+# The assumption is that an Azure server config is going to be a
+# json list of objects.
+#
+# See: https://jqlang.github.io/jq/manual/
+#
+# Note: It would be nice to use jd (https://github.com/josephburnett/jd)
+# but it isn't packaged.
+#
+# Bugs:
+# It's hard to tell if the output is useful when it comes to
+# determining what configuration has changed. But it's a start.
+#
+# Karl O. Pinc <kop@karlpinc.com>
+#
+
+tfile="$(mktemp)"
+
+cleanup () {
+ rm -rf "${tfile}"
+}
+
+trap cleanup EXIT
+
+jq --sort-keys '[sort | .[] | del(.id)]' < db/az_server_info > "${tfile}" \
+ || exit $?
+
+jq --sort-keys '[sort | .[] | del(.id)]' \
+ | diff -U 25 "${tfile}" /dev/stdin
GET_PG_SETTINGS := SELECT name, setting, unit, pending_restart \
FROM pg_settings \
ORDER BY name;
+GET_AZ_SERVER_SETTINGS:= az postgres flexible-server parameter list \
+ --resource-group $(RESOURCEGROUP) \
+ --server $(TARGET_SERVER)
##
## The available targets for make (make TARGET) are:
| sort --stable \
| diff -U 0 db/pg_settings /dev/stdin
+## db/az_server_info.new
+## Save a file of all configuration and other
+## information about an MS Azure Postgres
+## flexible-serve named TARGET_SERVER in the
+## RESOURCEGROUP resource group. See the
+## "compare-az-server" target. Azure must be logged
+## into and defaults established in order to use this
+## target. See "Usage" above. After changing a
+## setting, create "db/az_server_info.new", rename it
+## to "db/az_server_info", and commit the change to
+## revision control.
+.PHONY: db/az_server_info.new
+db/az_server_info.new:
+ [ -n "$(TARGET_SERVER)" ] \
+ || { printf 'The TARGET_SERVER variable must be set\n' >&2 ; \
+ exit 1 ; }
+ [ -n "$(RESOURCEGROUP)" ] \
+ || { printf 'The RESOURCEGROUP variable must be set\n' >&2 ; \
+ exit 1 ; }
+ $(GET_AZ_SERVER_SETTINGS) \
+ | jq --sort-keys \
+ > db/az_server_info.new
+
+## compare-az-server Diff the configuration settings of the MS Azure
+## Postgres flexible-serve named TARGET_SERVER in the
+## RESOURCEGROUP resource group. Azure must be
+## logged into and defaults established in order to
+## use this target. See "Usage" above. This ensures
+## that your TARGET_SERVER is configured as expected.
+## Before changing server settings run this target.
+.PHONY: compare-az-server
+compare-az-server:
+ [ -n "$(TARGET_SERVER)" ] \
+ || { printf 'The TARGET_SERVER variable must be set\n' >&2 ; \
+ exit 1 ; }
+ [ -n "$(RESOURCEGROUP)" ] \
+ || { printf 'The RESOURCEGROUP variable must be set\n' >&2 ; \
+ exit 1 ; }
+ $(GET_AZ_SERVER_SETTINGS) \
+ | db/compare-az-server.sh
+
##
## Lesser used targets:
##