MarseyWorld/scripts/schema.sh

23 lines
976 B
Bash
Raw Normal View History

2023-07-27 23:47:56 +00:00
#!/bin/bash
. /e
2023-08-04 13:30:06 +00:00
pg_dump -O -x --schema-only "$DATABASE_URL" > '/d/schema.sql'
2023-07-27 23:47:56 +00:00
pg_dump -O -x --data-only --inserts -t 'badge_defs' "$DATABASE_URL" > "/d/seed-badges.sql"
2023-07-27 23:47:56 +00:00
pg_dump -O -x --data-only --inserts -t 'hat_defs' "$DATABASE_URL" > "/d/seed-hats.sql"
2023-08-01 07:13:46 +00:00
sed -i -E "s/(INSERT INTO public.hat_defs VALUES \(.*', )[0-9]{2,}?,/\12,/g" "/d/seed-hats.sql"
sed -i -E "s/INSERT INTO public.hat_defs VALUES \(.*, [0-9]{1,6}, [0-9]{10}\);//g" "/d/seed-hats.sql"
2023-07-27 23:47:56 +00:00
EXPORT_EMOJIS=$(psql --csv --tuples-only -P "null=NULL" -c \
"SELECT ''''||name||'''', ''''||kind||'''', 2, ''''||tags||'''' FROM emojis WHERE submitter_id IS NULL ORDER BY name" \
"$DATABASE_URL")
EXPORT_EMOJIS=$(sed 's/.*/\(&\),/' <<< "$EXPORT_EMOJIS")
echo "INSERT INTO public.emojis (name, kind, author_id, tags) VALUES" > "/d/seed-emojis.sql"
2023-08-01 07:13:46 +00:00
echo "${EXPORT_EMOJIS%?}" >> "/d/seed-emojis.sql"
echo "ON CONFLICT (name) DO UPDATE SET tags = EXCLUDED.tags;" >> "/d/seed-emojis.sql"
2023-07-27 23:47:56 +00:00
#. /scripts/g