-- Database: ecommerce -- Generated: 2025-11-21 11:25:26 -- Total Tables: 62 CREATE DATABASE IF NOT EXISTS ecommerce; USE ecommerce; -- Table: addresses CREATE TABLE IF NOT EXISTS `addresses` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `title` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `full_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `phone` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, `address_line1` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `address_line2` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `city` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `state` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `postal_code` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `location` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'الموقع الجغرافي (lat,lng)', `latitude` decimal(10,8) DEFAULT NULL COMMENT 'خط العرض', `longitude` decimal(11,8) DEFAULT NULL COMMENT 'خط الطول', `is_default` tinyint(1) DEFAULT '0', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), CONSTRAINT `addresses_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: announcements CREATE TABLE IF NOT EXISTS `announcements` ( `id` int NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'عنوان العرض', `message` text COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'نص الإعلان', `background_color` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT '#dc3545' COMMENT 'لون الخلفية', `text_color` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT '#ffffff' COMMENT 'لون النص', `link_url` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'رابط العرض', `link_text` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'نص الرابط', `coupon_code` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'كود الكوبون (اختياري)', `is_active` tinyint(1) DEFAULT '1' COMMENT 'نشط', `start_date` datetime DEFAULT NULL COMMENT 'تاريخ البداية', `end_date` datetime DEFAULT NULL COMMENT 'تاريخ النهاية', `display_order` int DEFAULT '0' COMMENT 'ترتيب العرض', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_active` (`is_active`), KEY `idx_dates` (`start_date`,`end_date`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: beauty_bookings CREATE TABLE IF NOT EXISTS `beauty_bookings` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int DEFAULT NULL, `name` varchar(255) NOT NULL, `phone` varchar(20) NOT NULL, `email` varchar(255) DEFAULT NULL, `service_id` int NOT NULL, `appointment_date` date NOT NULL, `appointment_time` time NOT NULL, `status` enum('pending','confirmed','completed','cancelled') DEFAULT 'pending', `notes` text, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), KEY `service_id` (`service_id`), CONSTRAINT `beauty_bookings_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL, CONSTRAINT `beauty_bookings_ibfk_2` FOREIGN KEY (`service_id`) REFERENCES `beauty_services` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: beauty_services CREATE TABLE IF NOT EXISTS `beauty_services` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `description` text, `price` decimal(10,2) NOT NULL, `discount_percentage` decimal(5,2) DEFAULT '0.00', `duration` int NOT NULL, `category` varchar(100) DEFAULT NULL, `image` varchar(255) DEFAULT NULL, `additional_images` json DEFAULT NULL, `variations` json DEFAULT NULL, `available_branches` json DEFAULT NULL, `is_limited_stock` tinyint(1) DEFAULT '0', `is_free_shipping` tinyint(1) DEFAULT '1', `is_medicinal` tinyint(1) DEFAULT '0', `medicinal_leaflet` text, `usage_instructions` text, `stock_quantity` int DEFAULT '0', `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: bookings CREATE TABLE IF NOT EXISTS `bookings` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int DEFAULT NULL, `service_id` int NOT NULL, `branch_id` int DEFAULT NULL, `customer_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `customer_phone` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `booking_date` date NOT NULL, `booking_time` time NOT NULL, `status` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT 'pending', `notes` text COLLATE utf8mb4_unicode_ci, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `service_id` (`service_id`), CONSTRAINT `bookings_ibfk_1` FOREIGN KEY (`service_id`) REFERENCES `beauty_services` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: branches CREATE TABLE IF NOT EXISTS `branches` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `address` text NOT NULL, `phone` varchar(20) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `working_hours` json DEFAULT NULL, `is_active` tinyint(1) DEFAULT '1', `latitude` decimal(10,8) DEFAULT NULL, `longitude` decimal(11,8) DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: business_licenses CREATE TABLE IF NOT EXISTS `business_licenses` ( `id` int NOT NULL AUTO_INCREMENT, `document_type` enum('commercial_register','tax_card','national_id','business_address','company_registration') NOT NULL, `document_name` varchar(255) NOT NULL, `document_path` varchar(500) DEFAULT NULL, `expiry_date` date DEFAULT NULL, `is_verified` tinyint(1) DEFAULT '0', `verification_date` timestamp NULL DEFAULT NULL, `notes` text, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: cart CREATE TABLE IF NOT EXISTS `cart` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `product_id` int NOT NULL, `quantity` int NOT NULL DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `unique_cart_item` (`user_id`,`product_id`), KEY `product_id` (`product_id`), CONSTRAINT `cart_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE, CONSTRAINT `cart_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=44 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: categories CREATE TABLE IF NOT EXISTS `categories` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `description` text, `image` varchar(255) DEFAULT NULL, `type` enum('product','service') DEFAULT 'product', `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: consultation_bookings CREATE TABLE IF NOT EXISTS `consultation_bookings` ( `id` int NOT NULL AUTO_INCREMENT, `consultation_id` int NOT NULL, `user_id` int DEFAULT NULL, `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'اسم العميل', `phone` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'رقم الهاتف', `email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'البريد الإلكتروني', `booking_date` date NOT NULL COMMENT 'تاريخ الحجز', `booking_time` time NOT NULL COMMENT 'وقت الحجز', `notes` text COLLATE utf8mb4_unicode_ci COMMENT 'ملاحظات', `status` enum('pending','confirmed','completed','cancelled') COLLATE utf8mb4_unicode_ci DEFAULT 'pending' COMMENT 'حالة الحجز', `payment_status` enum('pending','paid','refunded') COLLATE utf8mb4_unicode_ci DEFAULT 'pending' COMMENT 'حالة الدفع', `total_price` decimal(10,2) NOT NULL COMMENT 'السعر الإجمالي', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `consultation_id` (`consultation_id`), KEY `user_id` (`user_id`), KEY `idx_status` (`status`), KEY `idx_date` (`booking_date`), CONSTRAINT `consultation_bookings_ibfk_1` FOREIGN KEY (`consultation_id`) REFERENCES `consultations` (`id`) ON DELETE CASCADE, CONSTRAINT `consultation_bookings_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='جدول حجوزات الاستشارات'; -- Table: consultations CREATE TABLE IF NOT EXISTS `consultations` ( `id` int NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'عنوان الاستشارة', `description` text COLLATE utf8mb4_unicode_ci COMMENT 'وصف الاستشارة', `image` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'صورة الاستشارة', `duration` int NOT NULL COMMENT 'المدة بالدقائق', `price` decimal(10,2) NOT NULL COMMENT 'السعر الأصلي', `discount_price` decimal(10,2) DEFAULT NULL COMMENT 'السعر بعد الخصم', `consultant_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'اسم المستشار', `consultant_title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'لقب المستشار', `features` json DEFAULT NULL COMMENT 'مميزات الاستشارة', `is_active` tinyint(1) DEFAULT '1' COMMENT 'نشط', `order_position` int DEFAULT '0' COMMENT 'ترتيب العرض', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_active` (`is_active`), KEY `idx_order` (`order_position`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='جدول الاستشارات والمكالمات'; -- Table: coupons CREATE TABLE IF NOT EXISTS `coupons` ( `id` int NOT NULL AUTO_INCREMENT, `code` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `discount_type` enum('percentage','fixed') COLLATE utf8mb4_unicode_ci DEFAULT 'percentage', `discount_value` decimal(10,2) NOT NULL, `usage_limit` int DEFAULT NULL, `usage_count` int DEFAULT '0', `expiry_date` date DEFAULT NULL, `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `show_in_banner` tinyint(1) DEFAULT '0' COMMENT 'عرض في شريط الإعلانات', `banner_text` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'نص الإعلان', `banner_color` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT '#dc3545' COMMENT 'لون الشريط', PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: device_pins CREATE TABLE IF NOT EXISTS `device_pins` ( `id` int NOT NULL AUTO_INCREMENT, `device_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `pin_number` tinyint NOT NULL, `pin_gpio` tinyint NOT NULL, `pin_type` enum('relay','sensor','led','button','pwm') COLLATE utf8mb4_unicode_ci DEFAULT 'relay', `pin_mode` enum('OUTPUT','INPUT') COLLATE utf8mb4_unicode_ci DEFAULT 'OUTPUT', `pin_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `pin_location` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `pin_icon` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT 'fa-plug', `is_active` tinyint(1) DEFAULT '1', `current_state` tinyint(1) DEFAULT '0', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `unique_device_pin` (`device_id`,`pin_gpio`), KEY `idx_device_pins` (`device_id`,`is_active`) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: fawry_applications CREATE TABLE IF NOT EXISTS `fawry_applications` ( `id` int NOT NULL AUTO_INCREMENT, `application_status` enum('draft','submitted','under_review','approved','rejected') DEFAULT 'draft', `business_name` varchar(255) NOT NULL, `business_type` varchar(100) DEFAULT NULL, `owner_name` varchar(255) NOT NULL, `owner_phone` varchar(20) NOT NULL, `owner_email` varchar(255) DEFAULT NULL, `business_address` text, `commercial_register_number` varchar(100) DEFAULT NULL, `tax_card_number` varchar(100) DEFAULT NULL, `national_id_number` varchar(20) DEFAULT NULL, `application_data` json DEFAULT NULL, `submission_date` timestamp NULL DEFAULT NULL, `review_notes` text, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: identity_profiles CREATE TABLE IF NOT EXISTS `identity_profiles` ( `id` int NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `description` text COLLATE utf8mb4_unicode_ci, `profile_image` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `product_id` int DEFAULT NULL, `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `product_id` (`product_id`), CONSTRAINT `identity_profiles_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: inventory_alerts CREATE TABLE IF NOT EXISTS `inventory_alerts` ( `id` int NOT NULL AUTO_INCREMENT, `product_id` int NOT NULL, `alert_type` enum('low_stock','out_of_stock') NOT NULL, `current_quantity` int NOT NULL, `threshold_quantity` int NOT NULL, `is_resolved` tinyint(1) DEFAULT '0', `resolved_at` timestamp NULL DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_product_id` (`product_id`), KEY `idx_is_resolved` (`is_resolved`), CONSTRAINT `inventory_alerts_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: inventory_movements CREATE TABLE IF NOT EXISTS `inventory_movements` ( `id` int NOT NULL AUTO_INCREMENT, `product_id` int NOT NULL, `movement_type` enum('in','out','adjustment','return') NOT NULL, `quantity` int NOT NULL, `previous_quantity` int NOT NULL, `new_quantity` int NOT NULL, `reference_type` varchar(50) DEFAULT NULL, `reference_id` int DEFAULT NULL, `notes` text, `created_by` int DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_product_id` (`product_id`), KEY `idx_movement_type` (`movement_type`), KEY `idx_created_at` (`created_at`), CONSTRAINT `inventory_movements_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: iot_commands CREATE TABLE IF NOT EXISTS `iot_commands` ( `id` int NOT NULL AUTO_INCREMENT, `device_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `action` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `payload` json DEFAULT NULL, `priority` tinyint DEFAULT '5', `status` enum('pending','sent','executed','failed','cancelled') COLLATE utf8mb4_unicode_ci DEFAULT 'pending', `sent_at` datetime DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `executed_at` timestamp NULL DEFAULT NULL, `created_by` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `error_message` text COLLATE utf8mb4_unicode_ci, PRIMARY KEY (`id`), KEY `idx_device_id` (`device_id`), KEY `idx_status` (`status`), KEY `idx_created_at` (`created_at`), CONSTRAINT `iot_commands_ibfk_1` FOREIGN KEY (`device_id`) REFERENCES `iot_devices` (`device_id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: iot_devices CREATE TABLE IF NOT EXISTS `iot_devices` ( `id` int NOT NULL AUTO_INCREMENT, `device_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `device_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `device_type` enum('esp8266','esp32','arduino','other') COLLATE utf8mb4_unicode_ci DEFAULT 'esp8266', `description` text COLLATE utf8mb4_unicode_ci, `location` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `pin_config` json DEFAULT NULL, `is_online` tinyint(1) DEFAULT '0', `status` enum('online','offline') COLLATE utf8mb4_unicode_ci DEFAULT 'offline', `is_active` tinyint(1) DEFAULT '1', `last_seen` timestamp NULL DEFAULT NULL, `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `firmware_version` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `device_id` (`device_id`), KEY `idx_device_id` (`device_id`), KEY `idx_online` (`is_online`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: iot_logs CREATE TABLE IF NOT EXISTS `iot_logs` ( `id` int NOT NULL AUTO_INCREMENT, `device_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `log_type` enum('info','warning','error','command','status') COLLATE utf8mb4_unicode_ci DEFAULT 'info', `message` text COLLATE utf8mb4_unicode_ci NOT NULL, `data` json DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_device_log` (`device_id`,`log_type`), KEY `idx_created_at` (`created_at`) ) ENGINE=InnoDB AUTO_INCREMENT=67 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: iot_schedules CREATE TABLE IF NOT EXISTS `iot_schedules` ( `id` int NOT NULL AUTO_INCREMENT, `device_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `schedule_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `action` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `payload` json DEFAULT NULL, `cron_expression` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `is_active` tinyint(1) DEFAULT '1', `last_run` datetime DEFAULT NULL, `next_run` datetime DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_device_schedule` (`device_id`,`is_active`), KEY `idx_next_run` (`next_run`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: iot_sensors_data CREATE TABLE IF NOT EXISTS `iot_sensors_data` ( `id` int NOT NULL AUTO_INCREMENT, `device_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `sensor_type` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `value` decimal(10,2) DEFAULT NULL, `unit` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `raw_data` json DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_device_sensor` (`device_id`,`sensor_type`), KEY `idx_created_at` (`created_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: iot_settings CREATE TABLE IF NOT EXISTS `iot_settings` ( `id` int NOT NULL AUTO_INCREMENT, `setting_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `setting_value` text COLLATE utf8mb4_unicode_ci, `description` text COLLATE utf8mb4_unicode_ci, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `wifi_ssid` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT 'YOUR_WIFI_NAME', `wifi_password` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT 'YOUR_WIFI_PASSWORD', `server_ip` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT 'localhost', PRIMARY KEY (`id`), UNIQUE KEY `setting_key` (`setting_key`) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: manifest_orders CREATE TABLE IF NOT EXISTS `manifest_orders` ( `id` int NOT NULL AUTO_INCREMENT, `manifest_id` int NOT NULL, `order_id` int NOT NULL, PRIMARY KEY (`id`), KEY `manifest_id` (`manifest_id`), KEY `order_id` (`order_id`), CONSTRAINT `manifest_orders_ibfk_1` FOREIGN KEY (`manifest_id`) REFERENCES `shipping_manifests` (`id`) ON DELETE CASCADE, CONSTRAINT `manifest_orders_ibfk_2` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: material_alerts CREATE TABLE IF NOT EXISTS `material_alerts` ( `id` int NOT NULL AUTO_INCREMENT, `material_type` enum('raw','packaging','wrapping') NOT NULL, `material_id` int NOT NULL, `alert_type` enum('low_stock','out_of_stock','expiring_soon','expired') NOT NULL, `current_quantity` decimal(10,3) NOT NULL, `threshold_quantity` decimal(10,3) DEFAULT NULL, `expiry_date` date DEFAULT NULL, `is_resolved` tinyint(1) DEFAULT '0', `resolved_at` timestamp NULL DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_material` (`material_type`,`material_id`), KEY `idx_is_resolved` (`is_resolved`), KEY `idx_alert_type` (`alert_type`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: material_movements CREATE TABLE IF NOT EXISTS `material_movements` ( `id` int NOT NULL AUTO_INCREMENT, `material_type` enum('raw','packaging','wrapping') NOT NULL, `material_id` int NOT NULL, `movement_type` enum('in','out','adjustment','production','return') NOT NULL, `quantity` decimal(10,3) NOT NULL, `previous_quantity` decimal(10,3) NOT NULL, `new_quantity` decimal(10,3) NOT NULL, `reference_type` varchar(50) DEFAULT NULL COMMENT 'purchase_order, production_batch, adjustment', `reference_id` int DEFAULT NULL, `notes` text, `created_by` int DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_material` (`material_type`,`material_id`), KEY `idx_movement_type` (`movement_type`), KEY `idx_created_at` (`created_at`), KEY `created_by` (`created_by`), CONSTRAINT `material_movements_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: messages CREATE TABLE IF NOT EXISTS `messages` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `phone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `message` text COLLATE utf8mb4_unicode_ci NOT NULL, `is_read` tinyint(1) DEFAULT '0', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: offers CREATE TABLE IF NOT EXISTS `offers` ( `id` int NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'عنوان العرض', `description` text COLLATE utf8mb4_unicode_ci COMMENT 'وصف العرض', `discount_type` enum('percentage','fixed') COLLATE utf8mb4_unicode_ci DEFAULT 'percentage' COMMENT 'نوع الخصم', `discount_value` decimal(10,2) NOT NULL COMMENT 'قيمة الخصم', `image` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'صورة العرض', `start_date` datetime NOT NULL COMMENT 'تاريخ البداية', `end_date` datetime NOT NULL COMMENT 'تاريخ النهاية', `is_active` tinyint(1) DEFAULT '1' COMMENT 'حالة العرض', `product_ids` text COLLATE utf8mb4_unicode_ci COMMENT 'معرفات المنتجات المشمولة (JSON)', `category_ids` text COLLATE utf8mb4_unicode_ci COMMENT 'معرفات الفئات المشمولة (JSON)', `min_purchase` decimal(10,2) DEFAULT '0.00' COMMENT 'الحد الأدنى للشراء', `max_discount` decimal(10,2) DEFAULT NULL COMMENT 'الحد الأقصى للخصم', `usage_limit` int DEFAULT '0' COMMENT 'عدد مرات الاستخدام (0 = غير محدود)', `used_count` int DEFAULT '0' COMMENT 'عدد مرات الاستخدام الفعلي', `priority` int DEFAULT '0' COMMENT 'الأولوية', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_active` (`is_active`), KEY `idx_dates` (`start_date`,`end_date`), KEY `idx_priority` (`priority`) ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='جدول العروض والخصومات'; -- Table: order_items CREATE TABLE IF NOT EXISTS `order_items` ( `id` int NOT NULL AUTO_INCREMENT, `order_id` int NOT NULL, `product_id` int NOT NULL, `product_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `price` decimal(10,2) NOT NULL, `quantity` int NOT NULL, `total` decimal(10,2) NOT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_order_id` (`order_id`), KEY `idx_product_id` (`product_id`), CONSTRAINT `order_items_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: orders CREATE TABLE IF NOT EXISTS `orders` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `order_number` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `first_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `last_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `phone` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, `email` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `address` text COLLATE utf8mb4_unicode_ci NOT NULL, `city` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `postal_code` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `notes` text COLLATE utf8mb4_unicode_ci, `payment_method` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'cod', `subtotal` decimal(10,2) NOT NULL DEFAULT '0.00', `shipping` decimal(10,2) NOT NULL DEFAULT '0.00', `tax` decimal(10,2) NOT NULL DEFAULT '0.00', `discount` decimal(10,2) NOT NULL DEFAULT '0.00', `total` decimal(10,2) NOT NULL DEFAULT '0.00', `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `order_number` (`order_number`), KEY `idx_user_id` (`user_id`), KEY `idx_order_number` (`order_number`), KEY `idx_status` (`status`), KEY `idx_created_at` (`created_at`) ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: packaging_materials CREATE TABLE IF NOT EXISTS `packaging_materials` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `type` enum('bottle','jar','cap','dropper','spray','pump','tube') NOT NULL, `size` varchar(50) DEFAULT NULL COMMENT '30ml, 50ml, 100ml', `material` varchar(50) DEFAULT NULL COMMENT 'زجاج، بلاستيك، ألومنيوم', `color` varchar(50) DEFAULT NULL, `quantity` int NOT NULL DEFAULT '0', `unit_cost` decimal(10,2) NOT NULL DEFAULT '0.00', `supplier_id` int DEFAULT NULL, `min_quantity` int DEFAULT '50', `notes` text, `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_type` (`type`), KEY `idx_supplier` (`supplier_id`), CONSTRAINT `packaging_materials_ibfk_1` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: payment_accounts CREATE TABLE IF NOT EXISTS `payment_accounts` ( `id` int NOT NULL AUTO_INCREMENT, `payment_method_id` int NOT NULL, `account_name` varchar(255) NOT NULL, `account_number` varchar(100) NOT NULL, `account_holder` varchar(255) DEFAULT NULL, `is_active` tinyint(1) DEFAULT '1', `daily_limit` decimal(10,2) DEFAULT '0.00', `current_daily_amount` decimal(10,2) DEFAULT '0.00', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `payment_method_id` (`payment_method_id`), CONSTRAINT `payment_accounts_ibfk_1` FOREIGN KEY (`payment_method_id`) REFERENCES `payment_methods` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: payment_methods CREATE TABLE IF NOT EXISTS `payment_methods` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `code` varchar(100) NOT NULL, `description` text, `is_active` tinyint(1) DEFAULT '1', `icon_class` varchar(100) DEFAULT NULL, `color_class` varchar(100) DEFAULT NULL, `integration_config` json DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: payment_settings CREATE TABLE IF NOT EXISTS `payment_settings` ( `id` int NOT NULL AUTO_INCREMENT, `cash_on_delivery` tinyint(1) DEFAULT '1', `bank_transfer` tinyint(1) DEFAULT '0', `fawry` tinyint(1) DEFAULT '0', `bank_name` varchar(255) DEFAULT '', `bank_account` varchar(255) DEFAULT '', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: pin_commands CREATE TABLE IF NOT EXISTS `pin_commands` ( `id` int NOT NULL AUTO_INCREMENT, `device_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `pin_gpio` tinyint NOT NULL, `action` enum('on','off','toggle','pulse') COLLATE utf8mb4_unicode_ci NOT NULL, `duration` int DEFAULT NULL, `status` enum('pending','sent','executed','failed') COLLATE utf8mb4_unicode_ci DEFAULT 'pending', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `executed_at` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `idx_pin_commands` (`device_id`,`pin_gpio`,`status`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: post_categories CREATE TABLE IF NOT EXISTS `post_categories` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `slug` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `description` text COLLATE utf8mb4_unicode_ci, `icon` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `color` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `posts_count` int DEFAULT '0', `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `slug` (`slug`) ) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: post_comments CREATE TABLE IF NOT EXISTS `post_comments` ( `id` int NOT NULL AUTO_INCREMENT, `post_id` int NOT NULL, `user_id` int NOT NULL, `comment` text NOT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `post_id` (`post_id`), KEY `user_id` (`user_id`), CONSTRAINT `post_comments_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE, CONSTRAINT `post_comments_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: post_likes CREATE TABLE IF NOT EXISTS `post_likes` ( `id` int NOT NULL AUTO_INCREMENT, `post_id` int NOT NULL, `user_id` int NOT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `unique_post_user_like` (`post_id`,`user_id`), KEY `user_id` (`user_id`), CONSTRAINT `post_likes_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE, CONSTRAINT `post_likes_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: posts CREATE TABLE IF NOT EXISTS `posts` ( `id` int NOT NULL AUTO_INCREMENT, `title` varchar(255) DEFAULT NULL, `slug` varchar(255) DEFAULT NULL, `excerpt` text, `content` longtext, `featured_image` varchar(255) DEFAULT NULL, `author_id` int DEFAULT NULL, `category` varchar(100) DEFAULT NULL, `tags` varchar(255) DEFAULT NULL, `status` enum('draft','published','scheduled') DEFAULT 'draft', `is_featured` tinyint(1) DEFAULT '0', `views_count` int DEFAULT '0', `likes_count` int DEFAULT '0', `comments_count` int DEFAULT '0', `published_at` datetime DEFAULT NULL, `caption` text, `image` varchar(255) DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: product_recipes CREATE TABLE IF NOT EXISTS `product_recipes` ( `id` int NOT NULL AUTO_INCREMENT, `product_id` int NOT NULL, `recipe_name` varchar(255) NOT NULL, `batch_size` int NOT NULL DEFAULT '1' COMMENT 'عدد القطع في الدفعة', `total_cost` decimal(10,2) DEFAULT '0.00' COMMENT 'التكلفة الإجمالية للدفعة', `cost_per_unit` decimal(10,2) DEFAULT '0.00' COMMENT 'تكلفة القطعة الواحدة', `notes` text, `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_product` (`product_id`), CONSTRAINT `product_recipes_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: production_batches CREATE TABLE IF NOT EXISTS `production_batches` ( `id` int NOT NULL AUTO_INCREMENT, `batch_number` varchar(50) NOT NULL, `recipe_id` int NOT NULL, `quantity_produced` int NOT NULL, `production_date` date NOT NULL, `total_cost` decimal(10,2) NOT NULL, `cost_per_unit` decimal(10,2) NOT NULL, `status` enum('pending','in_progress','completed','cancelled') DEFAULT 'pending', `produced_by` int DEFAULT NULL COMMENT 'المستخدم الذي أنتج', `notes` text, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `batch_number` (`batch_number`), KEY `idx_batch_number` (`batch_number`), KEY `idx_recipe` (`recipe_id`), KEY `idx_status` (`status`), KEY `idx_production_date` (`production_date`), KEY `produced_by` (`produced_by`), CONSTRAINT `production_batches_ibfk_1` FOREIGN KEY (`recipe_id`) REFERENCES `product_recipes` (`id`) ON DELETE RESTRICT, CONSTRAINT `production_batches_ibfk_2` FOREIGN KEY (`produced_by`) REFERENCES `users` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: products CREATE TABLE IF NOT EXISTS `products` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `description` text, `price` decimal(10,2) NOT NULL, `discount_price` decimal(10,2) DEFAULT NULL, `discount_percentage` int DEFAULT NULL, `status` varchar(20) DEFAULT 'active', `image` varchar(255) DEFAULT NULL, `category_id` int DEFAULT NULL, `stock_quantity` int DEFAULT '0', `low_stock_alert` int DEFAULT '5', `sku` varchar(100) DEFAULT NULL, `track_inventory` tinyint(1) DEFAULT '1', `is_limited_stock` tinyint(1) DEFAULT '0', `is_free_shipping` tinyint(1) DEFAULT '0', `is_medicinal` tinyint(1) DEFAULT '0', `medicinal_leaflet` text, `usage_instructions` text, `variations` json DEFAULT NULL, `additional_images` json DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `size` varchar(100) DEFAULT NULL COMMENT 'حجم المنتج', `certification` text COMMENT 'الاعتماد والترخيص', `short_description` text COMMENT 'وصف مختصر', `detailed_description` longtext COMMENT 'وصف تفصيلي', `how_to_use` text COMMENT 'طريقة الاستخدام', `additional_tips` text COMMENT 'نصائح إضافية', `gallery_images` json DEFAULT NULL COMMENT 'صور إضافية (معرض)', PRIMARY KEY (`id`), UNIQUE KEY `sku` (`sku`), KEY `category_id` (`category_id`), CONSTRAINT `products_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: purchase_order_items CREATE TABLE IF NOT EXISTS `purchase_order_items` ( `id` int NOT NULL AUTO_INCREMENT, `purchase_order_id` int NOT NULL, `product_id` int NOT NULL, `quantity` int NOT NULL, `unit_price` decimal(10,2) NOT NULL, `total_price` decimal(10,2) NOT NULL, `received_quantity` int DEFAULT '0', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_purchase_order_id` (`purchase_order_id`), KEY `idx_product_id` (`product_id`), CONSTRAINT `purchase_order_items_ibfk_1` FOREIGN KEY (`purchase_order_id`) REFERENCES `purchase_orders` (`id`) ON DELETE CASCADE, CONSTRAINT `purchase_order_items_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: purchase_orders CREATE TABLE IF NOT EXISTS `purchase_orders` ( `id` int NOT NULL AUTO_INCREMENT, `order_number` varchar(50) NOT NULL, `supplier_id` int DEFAULT NULL, `total_amount` decimal(10,2) NOT NULL, `status` enum('pending','approved','received','cancelled') DEFAULT 'pending', `notes` text, `created_by` int DEFAULT NULL, `received_at` timestamp NULL DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `order_number` (`order_number`), KEY `idx_order_number` (`order_number`), KEY `idx_supplier_id` (`supplier_id`), KEY `idx_status` (`status`), CONSTRAINT `purchase_orders_ibfk_1` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: raw_materials CREATE TABLE IF NOT EXISTS `raw_materials` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `category` varchar(100) DEFAULT NULL COMMENT 'زيوت، فيتامينات، عطور، مواد حافظة', `unit` enum('liter','ml','kg','gram','piece') NOT NULL DEFAULT 'ml', `quantity` decimal(10,3) NOT NULL DEFAULT '0.000', `unit_cost` decimal(10,2) NOT NULL DEFAULT '0.00', `supplier_id` int DEFAULT NULL, `min_quantity` decimal(10,3) DEFAULT '10.000', `expiry_date` date DEFAULT NULL, `notes` text, `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_category` (`category`), KEY `idx_supplier` (`supplier_id`), CONSTRAINT `raw_materials_ibfk_1` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: recipe_ingredients CREATE TABLE IF NOT EXISTS `recipe_ingredients` ( `id` int NOT NULL AUTO_INCREMENT, `recipe_id` int NOT NULL, `material_type` enum('raw','packaging','wrapping') NOT NULL, `material_id` int NOT NULL, `quantity_needed` decimal(10,3) NOT NULL COMMENT 'الكمية المطلوبة لدفعة واحدة', `unit` varchar(20) NOT NULL, `cost` decimal(10,2) DEFAULT '0.00' COMMENT 'التكلفة لهذا المكون', `notes` text, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_recipe` (`recipe_id`), KEY `idx_material` (`material_type`,`material_id`), CONSTRAINT `recipe_ingredients_ibfk_1` FOREIGN KEY (`recipe_id`) REFERENCES `product_recipes` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: reviews CREATE TABLE IF NOT EXISTS `reviews` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `product_id` int DEFAULT NULL, `service_id` int DEFAULT NULL, `rating` int NOT NULL, `comment` text, `status` enum('pending','approved','rejected') DEFAULT 'pending', `is_approved` tinyint(1) DEFAULT '0', `is_visible` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `unique_user_product_review` (`user_id`,`product_id`), UNIQUE KEY `unique_user_service_review` (`user_id`,`service_id`), KEY `product_id` (`product_id`), KEY `service_id` (`service_id`), CONSTRAINT `reviews_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE, CONSTRAINT `reviews_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE, CONSTRAINT `reviews_ibfk_3` FOREIGN KEY (`service_id`) REFERENCES `beauty_services` (`id`) ON DELETE CASCADE, CONSTRAINT `reviews_chk_1` CHECK (((`rating` >= 1) and (`rating` <= 5))) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: services CREATE TABLE IF NOT EXISTS `services` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `description` text COLLATE utf8mb4_unicode_ci, `price` decimal(10,2) NOT NULL, `discount_percentage` decimal(5,2) DEFAULT '0.00', `duration` int DEFAULT '60' COMMENT 'Duration in minutes', `category` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT 'skin_care', `image` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `additional_images` text COLLATE utf8mb4_unicode_ci, `variations` text COLLATE utf8mb4_unicode_ci, `available_branches` text COLLATE utf8mb4_unicode_ci, `is_limited_stock` tinyint(1) DEFAULT '0', `is_free_shipping` tinyint(1) DEFAULT '1', `is_medicinal` tinyint(1) DEFAULT '0', `medicinal_leaflet` text COLLATE utf8mb4_unicode_ci, `usage_instructions` text COLLATE utf8mb4_unicode_ci, `stock_quantity` int DEFAULT '0', `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: settings CREATE TABLE IF NOT EXISTS `settings` ( `id` int NOT NULL AUTO_INCREMENT, `setting_key` varchar(255) NOT NULL, `setting_value` text, `setting_type` enum('string','number','boolean','json') DEFAULT 'string', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `setting_key` (`setting_key`) ) ENGINE=InnoDB AUTO_INCREMENT=881 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: shipping_companies CREATE TABLE IF NOT EXISTS `shipping_companies` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `coverage` enum('all','internal_only','gov_only') COLLATE utf8mb4_unicode_ci DEFAULT 'all', `default_rate_internal` decimal(10,2) DEFAULT '0.00', `default_rate_gov` decimal(10,2) DEFAULT '0.00', `op_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `op_phone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: shipping_manifests CREATE TABLE IF NOT EXISTS `shipping_manifests` ( `id` int NOT NULL AUTO_INCREMENT, `manifest_number` varchar(50) NOT NULL, `shipping_company_id` int DEFAULT NULL, `delegate_name` varchar(255) DEFAULT NULL, `total_orders` int DEFAULT '0', `total_amount` decimal(10,2) DEFAULT '0.00', `shipping_cost` decimal(10,2) DEFAULT '0.00', `net_amount` decimal(10,2) DEFAULT '0.00', `notes` text, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `created_by` int DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `manifest_number` (`manifest_number`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: site_visits CREATE TABLE IF NOT EXISTS `site_visits` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int DEFAULT NULL, `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL, `user_agent` text COLLATE utf8mb4_unicode_ci, `page` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT 'index', `referrer` text COLLATE utf8mb4_unicode_ci, `device_type` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT 'Desktop', `browser` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT 'Unknown', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_user_id` (`user_id`), KEY `idx_created_at` (`created_at`), KEY `idx_ip` (`ip_address`) ) ENGINE=InnoDB AUTO_INCREMENT=557 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: skin_quiz_questions CREATE TABLE IF NOT EXISTS `skin_quiz_questions` ( `id` int NOT NULL AUTO_INCREMENT, `question_ar` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'نص السؤال بالعربية', `question_en` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT 'نص السؤال بالإنجليزية', `question_type` enum('single','multiple','scale','text') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 'single' COMMENT 'نوع السؤال', `options` json DEFAULT NULL COMMENT 'الخيارات المتاحة', `category` enum('skin_type','concerns','routine','lifestyle','goals') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'تصنيف السؤال', `weight` int DEFAULT '1' COMMENT 'وزن السؤال في الحساب', `order_position` int DEFAULT '0' COMMENT 'ترتيب السؤال', `is_active` tinyint(1) DEFAULT '1' COMMENT 'السؤال نشط؟', `icon` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'أيقونة السؤال', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_category` (`category`), KEY `idx_order` (`order_position`), KEY `idx_active` (`is_active`) ) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='أسئلة اختبار البشرة'; -- Table: skin_quiz_results CREATE TABLE IF NOT EXISTS `skin_quiz_results` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int DEFAULT NULL COMMENT 'معرف المستخدم (اختياري)', `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'اسم العميل', `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'البريد الإلكتروني', `phone` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'رقم الهاتف', `age` int NOT NULL COMMENT 'العمر', `gender` enum('female','male') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 'female' COMMENT 'الجنس', `quiz_answers` json NOT NULL COMMENT 'إجابات الاختبار كاملة', `skin_type` enum('oily','dry','combination','normal','sensitive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'نوع البشرة', `skin_concerns` json DEFAULT NULL COMMENT 'مشاكل البشرة الرئيسية', `recommended_products` json DEFAULT NULL COMMENT 'المنتجات المقترحة', `score` int DEFAULT '0' COMMENT 'النتيجة من 100', `analysis_text` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT 'التحليل النصي', `is_contacted` tinyint(1) DEFAULT '0' COMMENT 'تم التواصل مع العميل؟', `admin_notes` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT 'ملاحظات الأدمن', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_user_id` (`user_id`), KEY `idx_email` (`email`), KEY `idx_skin_type` (`skin_type`), KEY `idx_created_at` (`created_at`), KEY `idx_is_contacted` (`is_contacted`), CONSTRAINT `skin_quiz_results_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='نتائج اختبار روتين البشرة'; -- Table: social_assets CREATE TABLE IF NOT EXISTS `social_assets` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `type` enum('instagram_story','facebook_post','twitter_post','linkedin_post','pinterest_pin') NOT NULL, `image_path` varchar(500) NOT NULL, `created_by` int NOT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_type` (`type`), KEY `idx_created_by` (`created_by`), CONSTRAINT `social_assets_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: stories CREATE TABLE IF NOT EXISTS `stories` ( `id` int NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `image` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL, `link` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `duration` int DEFAULT '5', `is_active` tinyint(1) DEFAULT '1', `views_count` int DEFAULT '0', `order_position` int DEFAULT '0', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `expires_at` timestamp NULL DEFAULT NULL, `created_by` int DEFAULT NULL, PRIMARY KEY (`id`), KEY `created_by` (`created_by`), CONSTRAINT `stories_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: story_views CREATE TABLE IF NOT EXISTS `story_views` ( `id` int NOT NULL AUTO_INCREMENT, `story_id` int NOT NULL, `user_id` int DEFAULT NULL, `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `viewed_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `unique_view` (`story_id`,`user_id`,`ip_address`), KEY `user_id` (`user_id`), CONSTRAINT `story_views_ibfk_1` FOREIGN KEY (`story_id`) REFERENCES `stories` (`id`) ON DELETE CASCADE, CONSTRAINT `story_views_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Table: suppliers CREATE TABLE IF NOT EXISTS `suppliers` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `contact_person` varchar(255) DEFAULT NULL, `phone` varchar(20) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `address` text, `notes` text, `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_name` (`name`), KEY `idx_is_active` (`is_active`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: user_addresses CREATE TABLE IF NOT EXISTS `user_addresses` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `label` varchar(100) NOT NULL, `address` text NOT NULL, `location` varchar(255) DEFAULT NULL COMMENT 'الموقع الجغرافي (lat,lng)', `latitude` decimal(10,8) DEFAULT NULL, `longitude` decimal(11,8) DEFAULT NULL, `is_default` tinyint(1) DEFAULT '0', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), CONSTRAINT `user_addresses_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: users CREATE TABLE IF NOT EXISTS `users` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `phone` varchar(20) NOT NULL, `email` varchar(255) DEFAULT NULL, `password` varchar(255) NOT NULL, `address` text, `location` varchar(255) DEFAULT NULL COMMENT 'الموقع الجغرافي (lat,lng)', `latitude` decimal(10,8) DEFAULT NULL COMMENT 'خط العرض', `longitude` decimal(11,8) DEFAULT NULL COMMENT 'خط الطول', `age` int DEFAULT NULL, `profile_picture` varchar(255) DEFAULT NULL, `role` enum('user','admin') DEFAULT 'user', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `phone` (`phone`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: wishlist CREATE TABLE IF NOT EXISTS `wishlist` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `product_id` int NOT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `unique_wishlist_item` (`user_id`,`product_id`), KEY `product_id` (`product_id`), CONSTRAINT `wishlist_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE, CONSTRAINT `wishlist_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=93 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- Table: wrapping_materials CREATE TABLE IF NOT EXISTS `wrapping_materials` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `type` enum('bubble','box','flyer','sticker','bag','tape','tissue') NOT NULL, `unit` enum('roll','meter','piece','kg') NOT NULL DEFAULT 'piece', `quantity` decimal(10,2) NOT NULL DEFAULT '0.00', `unit_cost` decimal(10,2) NOT NULL DEFAULT '0.00', `supplier_id` int DEFAULT NULL, `min_quantity` decimal(10,2) DEFAULT '10.00', `notes` text, `is_active` tinyint(1) DEFAULT '1', `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_type` (`type`), KEY `idx_supplier` (`supplier_id`), CONSTRAINT `wrapping_materials_ibfk_1` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -- ======================================== -- Default Data / Sample Data -- ========================================