-- ================================================================
-- MIGRATION SIMPLES v2.0 - MySQL
-- Dental Image Server
-- ================================================================

-- Execute: mysql -u root -p dental_images < migration-simple.sql
-- OU via phpMyAdmin: Import este arquivo

-- ================================================================
-- CRIAR BANCO
-- ================================================================

CREATE DATABASE IF NOT EXISTS dental_images 
CHARACTER SET utf8mb4 
COLLATE utf8mb4_unicode_ci;

USE dental_images;

-- ================================================================
-- CRIAR TABELA USERS
-- ================================================================

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_hash TEXT NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ================================================================
-- CRIAR TABELA IMAGES (COMPLETA)
-- ================================================================

CREATE TABLE IF NOT EXISTS images (
  id INT AUTO_INCREMENT PRIMARY KEY,
  image_guid VARCHAR(255) NOT NULL,
  patient_name TEXT,
  original_filename TEXT,
  filename TEXT NOT NULL,
  enabled TINYINT(1) DEFAULT 1,
  tooth_number VARCHAR(10),
  tooth_side VARCHAR(10),
  patient_name_resumed VARCHAR(50),
  original_image_id INT,
  rotation INT DEFAULT 0,
  flip_horizontal INT DEFAULT 0,
  flip_vertical INT DEFAULT 0,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_enabled (enabled),
  INDEX idx_original (original_image_id),
  INDEX idx_guid (image_guid),
  INDEX idx_created (created_at),
  INDEX idx_patient_name (patient_name(100))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ================================================================
-- CONCLUÍDO
-- ================================================================

SELECT 'Tables created successfully!' AS result;
DESCRIBE images;
