-- Update Products Table for Multi-Vendor Support
-- Uses "IF NOT EXISTS" to prevent errors if run multiple times (Supported in MariaDB 10.x / XAMPP)

ALTER TABLE `products` ADD COLUMN IF NOT EXISTS `vendor_id` INT(11) NOT NULL DEFAULT 0;
ALTER TABLE `products` ADD COLUMN IF NOT EXISTS `approval_status` ENUM('pending','approved','rejected') DEFAULT 'pending';
ALTER TABLE `products` ADD COLUMN IF NOT EXISTS `stock_quantity` INT(11) DEFAULT 0;
ALTER TABLE `products` ADD COLUMN IF NOT EXISTS `sku` VARCHAR(100) DEFAULT NULL;

-- Add index for performance
CREATE INDEX IF NOT EXISTS `idx_vendor_id` ON `products` (`vendor_id`);

-- Update Users table to ensure role column supports 'vendor' (if it's an ENUM) or exists
-- converting to varchar safely if needed, or just assuming it works if checking skipped.
-- For safety, we assume 'role' exists. If not:
ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `role` VARCHAR(50) DEFAULT 'user';
