From 108a4e2929b9e50ffb8dbbd82d2eaa3197df0345 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 4 Nov 2023 18:53:42 +0200 Subject: [PATCH] order seed-badges.sql by badge id --- scripts/schema.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/schema.sh b/scripts/schema.sh index 4053c9217..5bc5cfd34 100755 --- a/scripts/schema.sh +++ b/scripts/schema.sh @@ -5,7 +5,13 @@ pg_dump -O -x --schema-only "$DATABASE_URL" > '/d/schema.sql' #generate seed-badges.sql -pg_dump -O -x --data-only --inserts -t 'badge_defs' "$DATABASE_URL" > "/d/seed-badges.sql" +EXPORT_BADGES=$(psql --csv --tuples-only -P "null=NULL" -c \ + "SELECT ''||id||'', ' '''||name||'''', ' '''||description||'''', ' '||created_utc||'' FROM badge_defs ORDER BY id" \ + "$DATABASE_URL") +EXPORT_BADGES=$(sed 's/.*/\(&\),/' <<< "$EXPORT_BADGES") +echo "INSERT INTO public.badge_defs VALUES" > "/d/seed-badges.sql" +echo "${EXPORT_BADGES%?}" >> "/d/seed-badges.sql" +echo "ON CONFLICT (id) DO nothing;" >> "/d/seed-badges.sql" #generate seed-hats.sql pg_dump -O -x --data-only --inserts -t 'hat_defs' "$DATABASE_URL" > "/d/seed-hats.sql"