summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2022-04-29 16:15:50 +0200
committerYorhel <git@yorhel.nl>2022-04-29 16:18:13 +0200
commitfc852f24b040d088abab6bf5df2d04c96f6dae38 (patch)
tree687c15dd9b7a9188456ccb36ce80b50ca77c36cb /util
parent68bab7125bb74ec49c7c30c2d1e145833bddeb64 (diff)
SQL: Move utility functions to separate util.sql
This is a cleaner solution to the problem of the schema relying on a few utility functions and creating a dependency cycle between schema.sql and func.sql. Also fix dbdump.pl to not export generated columns. These changes are to prepare for an upgrade to PostgreSQL 14 with a clean import through dbdump.pl. Which appears to work surprisingly well in my testing so far.
Diffstat (limited to 'util')
-rwxr-xr-xutil/dbdump.pl3
-rwxr-xr-xutil/devdump.pl1
2 files changed, 3 insertions, 1 deletions
diff --git a/util/dbdump.pl b/util/dbdump.pl
index 5adf35de..f749ed72 100755
--- a/util/dbdump.pl
+++ b/util/dbdump.pl
@@ -305,6 +305,7 @@ sub export_data {
binmode($F, ":utf8");
select $F;
print "\\set ON_ERROR_STOP 1\n";
+ print "\\i sql/util.sql\n";
print "\\i sql/schema.sql\n";
# Would be nice if VNDB::Schema could list sequences, too.
my @seq = sort @{ $db->selectcol_arrayref(
@@ -312,7 +313,7 @@ sub export_data {
) };
printf "SELECT setval('%s', %d);\n", $_, $db->selectrow_array("SELECT last_value FROM \"$_\"", {}) for @seq;
for my $t (sort { $a->{name} cmp $b->{name} } values %$schema) {
- my $cols = join ',', map "\"$_->{name}\"", $t->{cols}->@*;
+ my $cols = join ',', map "\"$_->{name}\"", grep $_->{decl} !~ /\sGENERATED\s/, $t->{cols}->@*;
my $order = table_order $t->{name};
print "\nCOPY \"$t->{name}\" ($cols) FROM STDIN;\n";
$db->do("COPY (SELECT $cols FROM \"$t->{name}\" $order) TO STDOUT");
diff --git a/util/devdump.pl b/util/devdump.pl
index a36d0184..1cc54ea0 100755
--- a/util/devdump.pl
+++ b/util/devdump.pl
@@ -96,6 +96,7 @@ sub copy_entry {
print "-- This file replaces 'sql/all.sql'.\n";
print "\\set ON_ERROR_STOP 1\n";
+ print "\\i sql/util.sql\n";
print "\\i sql/schema.sql\n";
print "\\i sql/data.sql\n";
print "\\i sql/func.sql\n";