-- Migration 004: tabel user untuk login dashboard

CREATE TABLE IF NOT EXISTS dashboard_user (
    User_ID          INT AUTO_INCREMENT PRIMARY KEY,
    User_Username    VARCHAR(50) NOT NULL,
    User_Password    VARCHAR(255) NOT NULL,   -- bcrypt hash
    User_DisplayName VARCHAR(100),
    User_IsActive    CHAR(1) DEFAULT 'Y',
    User_CreatedAt   DATETIME DEFAULT CURRENT_TIMESTAMP,
    User_UpdatedAt   DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uq_username (User_Username),
    INDEX idx_is_active (User_IsActive)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Default user: admin / admin123  (ganti password setelah pertama login)
INSERT IGNORE INTO dashboard_user (User_Username, User_Password, User_DisplayName)
VALUES ('admin', '$2a$10$dArL7F97pp/JdtIYhY/xD.W5RqAgKiW/ZvJoY75b6oer7xrQx1UNC', 'Administrator');
