: asapien/signet

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
#!/bin/sh
# Isolated legacy-schema fixture; never changes the running application database.
set -eu
DB=upload_upgrade_$$
T=$(mktemp -d /tmp/upload-migration.XXXXXX)
cleanup() { su-exec postgres dropdb --if-exists "$DB" >/dev/null; rm -rf "$T"; }
trap cleanup EXIT
su-exec postgres createdb "$DB"
sql() { su-exec postgres psql -X -qAt -v ON_ERROR_STOP=1 -d "$DB" "$@"; }
sql -c "CREATE TABLE documents (id uuid PRIMARY KEY DEFAULT gen_random_uuid(),title text NOT NULL,status text NOT NULL,layout_json jsonb NOT NULL); INSERT INTO documents (title,status,layout_json) VALUES ('Old draft','DRAFT','{}'),('Old pending','PENDING','{\"imprints\":[]}'),('Old released','RELEASED','{}')" >/dev/null
facts() { sql -c "SELECT md5(string_agg((to_jsonb(d)-'source_total'-'source_received')::text,E'\\n' ORDER BY id)) FROM documents d"; }
facts > "$T/before"
for n in 1 2; do
 sql -f /src/sql/migrations/003-bounded-pdf-uploads.sql >/dev/null
 facts > "$T/after"
 cmp "$T/before" "$T/after"
done
[ "$(sql -c 'SELECT count(*) FROM documents WHERE source_total IS NULL AND source_received IS NULL')" = 3 ]
if sql -c 'UPDATE documents SET source_total=524288' > "$T/rejected" 2>&1; then echo 'FAIL - partial NULL counter accepted' >&2; exit 1; fi
if sql -c 'UPDATE documents SET source_total=33554433,source_received=1' > "$T/rejected" 2>&1; then echo 'FAIL - oversized total accepted' >&2; exit 1; fi
if sql -c 'UPDATE documents SET source_total=6,source_received=7' > "$T/rejected" 2>&1; then echo 'FAIL - received beyond total accepted' >&2; exit 1; fi
echo 'upload migration: old fields/NULL source meaning preserved; repeat apply and constraints passed'