-- Migration 005: Advanced Pricing (Services and Speed Coefficients) -- 1. Create services table CREATE TABLE IF NOT EXISTS `services` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name_en` varchar(255) NOT NULL, `name_ru` varchar(255) DEFAULT NULL, `name_ua` varchar(255) DEFAULT NULL, `desc_en` text DEFAULT NULL, `tech_type` varchar(50) DEFAULT 'fdm', `price_per_hour` decimal(10,2) DEFAULT 0.00, `is_active` tinyint(1) DEFAULT 1, `created_at` timestamp DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- 2. Add price_per_hour, speed_coeff and service_id to materials -- Plain ALTER TABLE for compatibility with older MySQL versions ALTER TABLE `materials` ADD COLUMN `price_per_hour` decimal(10,2) DEFAULT NULL; ALTER TABLE `materials` ADD COLUMN `speed_coeff` decimal(10,2) DEFAULT 1.00; ALTER TABLE `materials` ADD COLUMN `service_id` int(11) DEFAULT NULL; -- 3. Initial seed for services if empty INSERT INTO `services` (`name_en`, `name_ru`, `name_ua`, `tech_type`, `price_per_hour`) SELECT * FROM (SELECT 'FDM Printing', 'FDM Печать', 'FDM Друк', 'fdm', 2.00) AS tmp WHERE NOT EXISTS (SELECT 1 FROM `services` WHERE `tech_type` = 'fdm') LIMIT 1; INSERT INTO `services` (`name_en`, `name_ru`, `name_ua`, `tech_type`, `price_per_hour`) SELECT * FROM (SELECT 'SLA Printing', 'SLA Печать', 'SLA Друк', 'sla', 5.00) AS tmp WHERE NOT EXISTS (SELECT 1 FROM `services` WHERE `tech_type` = 'sla') LIMIT 1;