-- Domainsansar database bootstrap.
--
-- Run once as a MySQL user that can create databases and grant privileges:
--
--     sudo mysql < scripts/setup-database.sql
--
-- Then put the password you chose below into backend/.env as DB_PASSWORD.

-- utf8mb4 throughout: domain names and marketplace copy are internationalised,
-- and utf8mb3 cannot represent the full range (nor emoji in listing text).
CREATE DATABASE IF NOT EXISTS domainsansar
    CHARACTER SET utf8mb4
    COLLATE utf8mb4_0900_ai_ci;

-- The test database is separate so running the suite can never truncate
-- development data.
CREATE DATABASE IF NOT EXISTS domainsansar_test
    CHARACTER SET utf8mb4
    COLLATE utf8mb4_0900_ai_ci;

-- Change this password before running in any shared environment.
CREATE USER IF NOT EXISTS 'domainsansar'@'localhost'
    IDENTIFIED BY 'change-me-before-deploying';

-- The application account holds no privileges outside its own schemas, and no
-- server-wide privileges at all: an application-level SQL injection must not
-- become a database-server compromise.
GRANT ALL PRIVILEGES ON domainsansar.* TO 'domainsansar'@'localhost';
GRANT ALL PRIVILEGES ON domainsansar_test.* TO 'domainsansar'@'localhost';

FLUSH PRIVILEGES;

SELECT 'Databases and application user created.' AS result;
