#!/bin/bash

# Load environment variables from current directory
if [ ! -f .env ]; then
    echo "Error: .env file not found in current directory!"
    exit 1
fi

source .env

# Connect to MySQL as root
mysql -u root -p"$DEV_DB_ROOT_PASSWORD" <<EOF
    CREATE DATABASE IF NOT EXISTS \`$DEV_DB_NAME\`;
    CREATE USER IF NOT EXISTS '$DEV_DB_USER'@'%' IDENTIFIED BY '$DEV_DB_PASSWORD';
    GRANT ALL PRIVILEGES ON \`$DEV_DB_NAME\`.* TO '$DEV_DB_USER'@'%';
    FLUSH PRIVILEGES;
EOF

echo "Database initialized successfully!"