#!/bin/sh

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

MYSQL="mysql --defaults-file=/etc/mysql/debian.cnf -v mysql"

(
    set -eu

    service mariadb start || service mysql start

    # Create the MySQL test database and user.
    echo "== creating the MySQL test database"
    cat debian/tests/mysql.testschema.sql | $MYSQL
    ./mysql_init.sh

    PG_VIRTUALENV_UNSHARE="" 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 'edb'@'localhost'" | $MYSQL
    echo "DROP DATABASE mysql_fdw_regress" | $MYSQL
    echo "DROP DATABASE mysql_fdw_regress1" | $MYSQL

    service mariadb stop || service mysql stop
)

exit $status
