MarseyWorld/scripts/schema.sh

22 lines
1.0 KiB
Bash
Raw Normal View History

2023-07-27 23:47:56 +00:00
. /e
2023-10-06 12:28:40 +00:00
#generate schema.sql
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
2023-10-06 12:28:40 +00:00
#generate seed-badges.sql
pg_dump -O -x --data-only --inserts -t 'badge_defs' "$DATABASE_URL" > "/d/seed-badges.sql"
2023-07-27 23:47:56 +00:00
2023-10-06 12:28:40 +00:00
#generate seed-hats.sql
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
2023-10-06 12:28:40 +00:00
#generate seed-emojis.sql
2023-07-27 23:47:56 +00:00
EXPORT_EMOJIS=$(psql --csv --tuples-only -P "null=NULL" -c \
2023-10-08 21:33:50 +00:00
"SELECT ''''||name||'''', ''''||kind||'''', 2, ''''||tags||'''', ''||nsfw||'' FROM emojis WHERE submitter_id IS NULL ORDER BY name" \
2023-07-27 23:47:56 +00:00
"$DATABASE_URL")
EXPORT_EMOJIS=$(sed 's/.*/\(&\),/' <<< "$EXPORT_EMOJIS")
2023-10-08 20:56:27 +00:00
echo "INSERT INTO public.emojis (name, kind, author_id, tags, nsfw) 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"