#!/bin/sh

. /usr/share/postgresql-common/pgcommon.sh
locale_gen en_US.UTF-8 UTF-8
export LANG=en_US.UTF-8

(
    set -eu

    service mysql start

    # Create the MySQL test database and user.
    echo "== creating the MySQL test database"
    cat debian/tests/mysql.testschema.sql | mysql --defaults-file="/etc/mysql/debian.cnf" -v mysql

    UNSHARED=no pg_buildext installcheck
)
status=$?

(
    # Cleanup the MySQL test database (even in case of an error above)
    echo "== dropping the MySQL test database"
    echo "DROP USER 'foo'@'127.0.0.1'; DROP DATABASE testdb;" \
     | mysql --defaults-file="/etc/mysql/debian.cnf" -v mysql

    service mysql stop
)
exit $status
