cartodb-postgresql/util/create_from_unpackaged.sh

24 lines
795 B
Bash
Raw Normal View History

#!/bin/sh
ver=$1
input=cartodb--${ver}.sql
output=cartodb--unpackaged--${ver}.sql
echo "-- Script generated by $0 on `date`" > ${output}
# Migrate CDB functions from public schema to cartodb schema
cat ${input} |
grep '^ *CREATE OR REPLACE FUNCTION' |
grep -v ' cartodb\.' | # should only match DDL hooks
2019-10-28 21:08:35 +08:00
grep -v '.*\quit.*' |
sed 's/).*$/)/' |
sed 's/DEFAULT [^ ,)]*//g' |
sed 's/CREATE OR REPLACE FUNCTION /ALTER FUNCTION public./' |
sed 's/$/ SET SCHEMA cartodb;/' |
sed 's/^/DO LANGUAGE plpgsql \$\$ BEGIN /' |
sed "s/$/ EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'Got % (%)', SQLERRM, SQLSTATE; END; \$\$;/" |
cat >> ${output}
# Upgrade all functions
cat ${input} | grep -v 'duplicated extension$' | grep -v '\quit$' | grep -v 'pg_extension_config_dump' >> ${output}