005_advanced_pricing.sql 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. -- Migration 005: Advanced Pricing (Services and Speed Coefficients)
  2. -- 1. Create services table
  3. CREATE TABLE IF NOT EXISTS `services` (
  4. `id` int(11) NOT NULL AUTO_INCREMENT,
  5. `name_en` varchar(255) NOT NULL,
  6. `name_ru` varchar(255) DEFAULT NULL,
  7. `name_ua` varchar(255) DEFAULT NULL,
  8. `desc_en` text DEFAULT NULL,
  9. `tech_type` varchar(50) DEFAULT 'fdm',
  10. `price_per_hour` decimal(10,2) DEFAULT 0.00,
  11. `is_active` tinyint(1) DEFAULT 1,
  12. `created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
  13. PRIMARY KEY (`id`)
  14. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  15. -- 2. Add price_per_hour, speed_coeff and service_id to materials
  16. -- Using ALTER TABLE with multiple ADD COLUMN for efficiency
  17. -- Note: IGNORE or existence check is handled by checking if column exists (manually or via script)
  18. -- But here we just write the ALTER statements.
  19. ALTER TABLE `materials`
  20. ADD COLUMN IF NOT EXISTS `price_per_hour` decimal(10,2) DEFAULT NULL,
  21. ADD COLUMN IF NOT EXISTS `speed_coeff` decimal(10,2) DEFAULT 1.00,
  22. ADD COLUMN IF NOT EXISTS `service_id` int(11) DEFAULT NULL;
  23. -- 3. Initial seed for services if empty
  24. INSERT INTO `services` (`name_en`, `name_ru`, `name_ua`, `tech_type`, `price_per_hour`)
  25. SELECT 'FDM Printing', 'FDM Печать', 'FDM Друк', 'fdm', 2.00
  26. WHERE NOT EXISTS (SELECT 1 FROM `services` WHERE `tech_type` = 'fdm');
  27. INSERT INTO `services` (`name_en`, `name_ru`, `name_ua`, `tech_type`, `price_per_hour`)
  28. SELECT 'SLA Printing', 'SLA Печать', 'SLA Друк', 'sla', 5.00
  29. WHERE NOT EXISTS (SELECT 1 FROM `services` WHERE `tech_type` = 'sla');