File manager - Edit - /home/webapp69.cm.in.th/u69319090033/Shop/schema.sql
Back
SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for users -- ---------------------------- DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `full_name` varchar(100) NOT NULL, `email` varchar(100) NOT NULL, `password` varchar(255) NOT NULL, `phone` varchar(20) DEFAULT NULL, `role` enum('user','buyer','seller','admin','page_editor') NOT NULL DEFAULT 'user', `seller_status` enum('none','pending','approved','rejected') NOT NULL DEFAULT 'none', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), `approved_at` timestamp NULL DEFAULT NULL, `approved_by` int(11) DEFAULT NULL, PRIMARY KEY (`user_id`), UNIQUE KEY `email` (`email`), KEY `fk_users_approved_by` (`approved_by`), CONSTRAINT `fk_users_approved_by` FOREIGN KEY (`approved_by`) REFERENCES `users` (`user_id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- ---------------------------- -- Table structure for categories -- ---------------------------- DROP TABLE IF EXISTS `categories`; CREATE TABLE `categories` ( `category_id` varchar(50) NOT NULL, `category_name` varchar(100) NOT NULL, `icon` varchar(255) DEFAULT NULL, PRIMARY KEY (`category_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- ---------------------------- -- Table structure for products -- ---------------------------- DROP TABLE IF EXISTS `products`; CREATE TABLE `products` ( `product_id` int(11) NOT NULL AUTO_INCREMENT, `seller_id` int(11) NOT NULL, `category_id` varchar(50) NOT NULL, `product_name` varchar(255) NOT NULL, `description` text DEFAULT NULL, `price` decimal(10,2) NOT NULL, `original_price` decimal(10,2) DEFAULT NULL, `stock` int(11) NOT NULL DEFAULT 0, `image_url` varchar(255) DEFAULT NULL, `badge` varchar(50) DEFAULT NULL, `badge_text` varchar(50) DEFAULT NULL, `is_active` tinyint(1) NOT NULL DEFAULT 1, `approval_status` enum('pending','approved','rejected') NOT NULL DEFAULT 'pending', `rating_avg` decimal(3,2) DEFAULT 0.00, `sold_count` int(11) DEFAULT 0, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`product_id`), KEY `fk_product_seller` (`seller_id`), KEY `fk_product_category` (`category_id`), CONSTRAINT `fk_product_category` FOREIGN KEY (`category_id`) REFERENCES `categories` (`category_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_product_seller` FOREIGN KEY (`seller_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- ---------------------------- -- Table structure for cart -- ---------------------------- DROP TABLE IF EXISTS `cart`; CREATE TABLE `cart` ( `cart_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `product_id` int(11) NOT NULL, `quantity` int(11) NOT NULL DEFAULT 1, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`cart_id`), KEY `fk_cart_user` (`user_id`), KEY `fk_cart_product` (`product_id`), CONSTRAINT `fk_cart_product` FOREIGN KEY (`product_id`) REFERENCES `products` (`product_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_cart_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- ---------------------------- -- Table structure for orders -- ---------------------------- DROP TABLE IF EXISTS `orders`; CREATE TABLE `orders` ( `order_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `total_amount` decimal(10,2) NOT NULL, `status` enum('pending','shipping','delivered','cancelled') NOT NULL DEFAULT 'pending', `shipping_address` text NOT NULL, `payment_method` varchar(50) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`order_id`), KEY `fk_order_user` (`user_id`), CONSTRAINT `fk_order_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- ---------------------------- -- Table structure for order_items -- ---------------------------- DROP TABLE IF EXISTS `order_items`; CREATE TABLE `order_items` ( `order_item_id` int(11) NOT NULL AUTO_INCREMENT, `order_id` int(11) NOT NULL, `product_id` int(11) DEFAULT NULL, `quantity` int(11) NOT NULL, `price_at_purchase` decimal(10,2) NOT NULL, PRIMARY KEY (`order_item_id`), KEY `fk_order_item_order` (`order_id`), KEY `fk_order_item_product` (`product_id`), CONSTRAINT `fk_order_item_order` FOREIGN KEY (`order_id`) REFERENCES `orders` (`order_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_order_item_product` FOREIGN KEY (`product_id`) REFERENCES `products` (`product_id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- ---------------------------- -- Table structure for reviews -- ---------------------------- DROP TABLE IF EXISTS `reviews`; CREATE TABLE `reviews` ( `review_id` int(11) NOT NULL AUTO_INCREMENT, `product_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `rating` tinyint(4) NOT NULL, `comment` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`review_id`), KEY `fk_review_product` (`product_id`), KEY `fk_review_user` (`user_id`), CONSTRAINT `fk_review_product` FOREIGN KEY (`product_id`) REFERENCES `products` (`product_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_review_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- ---------------------------- -- Table structure for seller_applications -- ---------------------------- DROP TABLE IF EXISTS `seller_applications`; CREATE TABLE `seller_applications` ( `application_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `shop_name` varchar(100) NOT NULL, `status` enum('pending','approved','rejected') NOT NULL DEFAULT 'pending', `applied_at` timestamp NOT NULL DEFAULT current_timestamp(), `reviewed_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`application_id`), KEY `fk_app_user` (`user_id`), CONSTRAINT `fk_app_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- ---------------------------- -- Seed Data -- ---------------------------- -- SEED: Users (Password is '123' for admin, 'password123' for others, hashed with BCRYPT) -- NOTE: hashes below are REAL bcrypt hashes generated via PHP password_hash(). -- admin@goodboyshop.com -> password: 123 -- seller@goodboy.test -> password: password123 -- buyer@goodboy.test -> password: password123 INSERT INTO `users` (`user_id`, `full_name`, `email`, `password`, `phone`, `role`, `seller_status`) VALUES (1, 'Admin Good boy Shop', 'admin@goodboyshop.com', '$2b$10$pRzQaRQAElC4SeO12g6dreRA.XjcdgCSep8Vl1jP37qAKnSKPFYRC', '0812345678', 'admin', 'none'), (2, 'Seller Shop 1', 'seller@goodboy.test', '$2b$10$C82vlrgtd1IaD6BKOn1H7.zNpVyQZbwKITs04BDdAocx5sUCs5N7y', '0898765432', 'seller', 'approved'), (3, 'Buyer User', 'buyer@goodboy.test', '$2b$10$C82vlrgtd1IaD6BKOn1H7.zNpVyQZbwKITs04BDdAocx5sUCs5N7y', '0822223333', 'user', 'none'); -- SEED: Categories INSERT INTO `categories` (`category_id`, `category_name`, `icon`) VALUES ('electronics', 'อิเล็กทรอนิกส์', 'laptop'), ('fashion', 'แฟชั่น', 'shirt'), ('cosmetics', 'เครื่องสำอาง', 'sparkles'), ('home', 'ของใช้ในบ้าน', 'home'), ('food', 'อาหาร', 'coffee'), ('sports', 'กีฬา', 'dumbbell'); -- SEED: Products INSERT INTO `products` (`seller_id`, `category_id`, `product_name`, `description`, `price`, `original_price`, `stock`, `image_url`, `badge`, `badge_text`, `is_active`, `approval_status`, `rating_avg`, `sold_count`) VALUES (2, 'electronics', 'หูฟังบลูทูธไร้สาย Noise Cancelling', 'สัมผัสประสบการณ์เสียงที่เหนือชั้น', 1290.00, 2590.00, 50, 'https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=800&auto=format&fit=crop&q=80', 'sale', 'ลด 50%', 1, 'approved', 4.90, 450), (2, 'electronics', 'นาฬิกา Smartwatch สุขภาพ', 'ติดตามสุขภาพของคุณตลอด 24 ชั่วโมง', 1850.00, 2990.00, 30, 'https://images.unsplash.com/photo-1523275335684-37898b6baf30?w=800&auto=format&fit=crop&q=80', 'hot', 'ขายดี', 1, 'approved', 4.80, 320), (2, 'electronics', 'คีย์บอร์ด Mechanical ไร้สาย', 'สัมผัสการพิมพ์ที่ลื่นไหล พร้อมไฟ RGB', 2150.00, 3500.00, 20, 'https://images.unsplash.com/photo-1595225476474-87563907a212?w=800&auto=format&fit=crop&q=80', NULL, NULL, 1, 'approved', 4.70, 120), (2, 'fashion', 'เสื้อแจ็คเก็ตแฟชั่นสไตล์เกาหลี', 'ผ้านุ่มใส่สบาย ดีไซน์ทันสมัย', 690.00, 1200.00, 100, 'https://images.unsplash.com/photo-1551028719-00167b16eac5?w=800&auto=format&fit=crop&q=80', 'new', 'มาใหม่', 1, 'approved', 4.70, 210), (2, 'fashion', 'แว่นตากันแดด Vintage Classic', 'ปกป้องดวงตาของคุณจากแสงแดด', 390.00, 790.00, 80, 'https://images.unsplash.com/photo-1511499767150-a48a237f0083?w=800&auto=format&fit=crop&q=80', NULL, NULL, 1, 'approved', 4.50, 150), (2, 'fashion', 'กระเป๋าสะพายข้างสไตล์มินิมอล', 'หนังสังเคราะห์พรีเมียม จุของได้เยอะ', 590.00, 990.00, 40, 'https://images.unsplash.com/photo-1548036328-c9fa89d128fa?w=800&auto=format&fit=crop&q=80', 'hot', 'ขายดี', 1, 'approved', 4.80, 340), (2, 'cosmetics', 'เซรั่มบำรุงผิวหน้าไฮยาลูรอน 100ml', 'คืนความชุ่มชื้นให้ผิวหน้า ลดเลือนริ้วรอย', 490.00, 990.00, 200, 'https://images.unsplash.com/photo-1620916566398-39f1143ab7be?w=800&auto=format&fit=crop&q=80', 'sale', 'ลด 50%', 1, 'approved', 4.90, 890), (2, 'cosmetics', 'ลิปสติกเนื้อแมท ติดทนนาน', 'สีสดชัด ไม่ตกร่อง เติมเต็มริมฝีปาก', 290.00, 490.00, 150, 'https://images.unsplash.com/photo-1586495777744-4413f21062fa?w=800&auto=format&fit=crop&q=80', 'new', 'สีใหม่', 1, 'approved', 4.60, 200), (2, 'cosmetics', 'ชุดแปรงแต่งหน้าพรีเมียม 12 ชิ้น', 'ขนแปรงนุ่มพิเศษ ไม่บาดผิว', 890.00, 1590.00, 50, 'https://images.unsplash.com/photo-1596462502278-27bfdc403348?w=800&auto=format&fit=crop&q=80', NULL, NULL, 1, 'approved', 4.70, 180), (2, 'home', 'หม้อทอดไร้น้ำมันอัจฉริยะ 5.5 ลิตร', 'ทำอาหารสุขภาพได้ง่ายๆ', 1590.00, 3200.00, 40, 'https://images.unsplash.com/photo-1585515320310-259814833e62?w=800&auto=format&fit=crop&q=80', 'hot', 'ฮิต', 1, 'approved', 4.80, 410), (2, 'home', 'โคมไฟตั้งโต๊ะ LED ปรับแสงได้', 'ถนอมสายตา ปรับความสว่างได้ 3 ระดับ', 350.00, 690.00, 120, 'https://images.unsplash.com/photo-1507473885765-e6ed057f782c?w=800&auto=format&fit=crop&q=80', 'sale', 'ลด 50%', 1, 'approved', 4.60, 250), (2, 'home', 'เครื่องพ่นอโรมา สร้างบรรยากาศ', 'เปลี่ยนบ้านให้เป็นสปา พร้อมไฟ LED', 450.00, 890.00, 70, 'https://images.unsplash.com/photo-1602928321679-560bb453f190?w=800&auto=format&fit=crop&q=80', NULL, NULL, 1, 'approved', 4.50, 190), (2, 'food', 'กาแฟดริปออร์แกนิค คั่วบดละเอียด 250g', 'เมล็ดกาแฟแท้ 100% หอมเข้มข้น', 250.00, 350.00, 300, 'https://images.unsplash.com/photo-1559056199-641a0ac8b55e?w=800&auto=format&fit=crop&q=80', NULL, NULL, 1, 'approved', 4.90, 530), (2, 'food', 'ชาเขียวมัทฉะ พรีเมียม 100g', 'ชงง่าย หอมกลิ่นชาแท้จากญี่ปุ่น', 390.00, 590.00, 100, 'https://images.unsplash.com/photo-1582793988951-9aed5509eb97?w=800&auto=format&fit=crop&q=80', 'new', 'มาใหม่', 1, 'approved', 4.80, 150), (2, 'food', 'คุ้กกี้ธัญพืช ไร้แป้งน้ำตาล 200g', 'อร่อย สุขภาพดี เหมาะสำหรับสายคลีน', 150.00, 220.00, 250, 'https://images.unsplash.com/photo-1499636136210-6f4ee915583e?w=800&auto=format&fit=crop&q=80', 'hot', 'ขายดี', 1, 'approved', 4.70, 310), (2, 'sports', 'รองเท้าวิ่งเพื่อสุขภาพ ซับแรงกระแทก', 'ลดอาการปวดเข่า วิ่งได้ไกลขึ้น', 1390.00, 2490.00, 80, 'https://images.unsplash.com/photo-1542291026-7eec264c27ff?w=800&auto=format&fit=crop&q=80', 'hot', 'ขายดี', 1, 'approved', 4.80, 280), (2, 'sports', 'เสื่อโยคะ กันลื่น 10mm', 'หนานุ่ม ยึดเกาะดีเยี่ยม', 290.00, 590.00, 150, 'https://images.unsplash.com/photo-1601925260368-ae2f83cf8b7f?w=800&auto=format&fit=crop&q=80', 'sale', 'ลด 50%', 1, 'approved', 4.60, 420), (2, 'sports', 'ดัมเบลปรับน้ำหนักได้ 20kg', 'ชุดดัมเบลพร้อมกล่อง ครบจบในเซ็ตเดียว', 1290.00, 1990.00, 30, 'https://images.unsplash.com/photo-1586401700818-2831b730fdf1?w=800&auto=format&fit=crop&q=80', NULL, NULL, 1, 'approved', 4.70, 95); SET FOREIGN_KEY_CHECKS = 1;
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.22 |
proxy
|
phpinfo
|
Settings