-- TLCI CMS Authentication Database Setup

-- Drop the database if it exists (optional, for clean setup)
-- DROP DATABASE IF EXISTS tlci_cms;

-- Create the database
CREATE DATABASE IF NOT EXISTS tlci_cms;
USE tlci_cms;

-- Create users table
CREATE TABLE IF NOT EXISTS users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  username VARCHAR(50) UNIQUE NOT NULL,
  email VARCHAR(100) UNIQUE NOT NULL,
  password VARCHAR(255) NOT NULL,
  role ENUM('admin', 'editor') DEFAULT 'editor',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- Insert default admin user (password is 'admin123' hashed with bcrypt)
INSERT IGNORE INTO users (username, email, password, role) VALUES 
('admin', 'admin@example.com', '$2b$10$rOzJqQZ8QxQZ8QxQZ8QxQeO6.6JZ8QxQZ8QxQZ8QxQZ8QxQZ8', 'admin');
