-- =============================================================================
-- Production MySQL provisioning - run on kreonAI5 as MySQL root.
-- Edit the password before running. Use a strong password (>=24 chars).
-- =============================================================================

-- ---- Database ----
CREATE DATABASE IF NOT EXISTS vihar_db
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

-- ---- App user (limited to vihar_db, localhost only since DB binds 127.0.0.1) ----
-- Replace REPLACE_WITH_STRONG_PASSWORD with a real password before running.
CREATE USER IF NOT EXISTS 'vihar_usr'@'127.0.0.1'
  IDENTIFIED BY 'REPLACE_WITH_STRONG_PASSWORD';
CREATE USER IF NOT EXISTS 'vihar_usr'@'localhost'
  IDENTIFIED BY 'REPLACE_WITH_STRONG_PASSWORD';

GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE,
      CREATE, ALTER, DROP, INDEX, REFERENCES, TRIGGER,
      CREATE TEMPORARY TABLES, LOCK TABLES
  ON vihar_db.*
  TO 'vihar_usr'@'127.0.0.1';

GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE,
      CREATE, ALTER, DROP, INDEX, REFERENCES, TRIGGER,
      CREATE TEMPORARY TABLES, LOCK TABLES
  ON vihar_db.*
  TO 'vihar_usr'@'localhost';

FLUSH PRIVILEGES;

-- ---- Read-only user for monitoring / dashboards ----
CREATE USER IF NOT EXISTS 'vihar_ro'@'127.0.0.1'
  IDENTIFIED BY 'REPLACE_WITH_ANOTHER_STRONG_PASSWORD';
GRANT SELECT ON vihar_db.* TO 'vihar_ro'@'127.0.0.1';
FLUSH PRIVILEGES;

SELECT 'Database vihar_db ready. Run prisma migrate deploy next.' AS status;
