-- We use the values we previously defined on the Dockerfile:
-- ARG MAUTIC_DB_NAME=mautic-db
-- ARG MAUTIC_DB_USER=mautic-db-user
-- ARG MAUTIC_DB_PASSWORD=mautic-strong-password

-- Create a new database, but only if it doesn't exist yet.
CREATE DATABASE IF NOT EXISTS '$MAUTIC_DB_NAME' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Create a new user, if it doesn't yet exist.
CREATE USER IF NOT EXISTS '$MAUTIC_DB_USER'@'localhost' IDENTIFIED BY '$MAUTIC_DB_PASSWORD';

-- Create a new user and grant privileges.
GRANT ALL PRIVILEGES ON '$MAUTIC_DB_NAME'.* TO '$MAUTIC_DB_USER'@'localhost';

-- Out with the old and bring in the new!
FLUSH PRIVILEGES;
