-- MariaDB bootstrap for CandleCraft Academy.
--
--   1. Adjust the password below to something you will remember.
--   2. Run this file as a MariaDB admin user (typically root):
--        mariadb -u root -p < database/mariadb-setup.sql
--   3. Export the matching env vars, e.g.:
--        export DB_HOST=127.0.0.1
--        export DB_PORT=3306
--        export DB_USERNAME=candlecraft
--        export DB_PASSWORD='<the password you chose below>'
--        export DB_DATABASE=candlecraft
--   4. Run migrations from the project root:
--        bin/cake migrations migrate

CREATE DATABASE IF NOT EXISTS `candlecraft`
    CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE DATABASE IF NOT EXISTS `candlecraft_test`
    CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Create (or update) a local-only application user.
-- CHANGE THE PASSWORD BEFORE RUNNING.
CREATE USER IF NOT EXISTS 'candlecraft'@'127.0.0.1' IDENTIFIED BY ' ';
CREATE USER IF NOT EXISTS 'candlecraft'@'localhost' IDENTIFIED BY ' ';

GRANT ALL PRIVILEGES ON `candlecraft`.*       TO 'candlecraft'@'127.0.0.1';
GRANT ALL PRIVILEGES ON `candlecraft`.*       TO 'candlecraft'@'localhost';
GRANT ALL PRIVILEGES ON `candlecraft_test`.*  TO 'candlecraft'@'127.0.0.1';
GRANT ALL PRIVILEGES ON `candlecraft_test`.*  TO 'candlecraft'@'localhost';

FLUSH PRIVILEGES;
