Просмотр исходного кода

fix: adjust migration syntax for compatibility with older MySQL

unknown 2 месяцев назад
Родитель
Сommit
7822932642
1 измененных файлов с 8 добавлено и 12 удалено
  1. 8 12
      backend/migrations/005_advanced_pricing.sql

+ 8 - 12
backend/migrations/005_advanced_pricing.sql

@@ -15,20 +15,16 @@ CREATE TABLE IF NOT EXISTS `services` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
 
 -- 2. Add price_per_hour, speed_coeff and service_id to materials
 -- 2. Add price_per_hour, speed_coeff and service_id to materials
--- Using ALTER TABLE with multiple ADD COLUMN for efficiency
--- Note: IGNORE or existence check is handled by checking if column exists (manually or via script)
--- But here we just write the ALTER statements.
-
-ALTER TABLE `materials` 
-ADD COLUMN IF NOT EXISTS `price_per_hour` decimal(10,2) DEFAULT NULL,
-ADD COLUMN IF NOT EXISTS `speed_coeff` decimal(10,2) DEFAULT 1.00,
-ADD COLUMN IF NOT EXISTS `service_id` int(11) DEFAULT NULL;
+-- 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
 -- 3. Initial seed for services if empty
 INSERT INTO `services` (`name_en`, `name_ru`, `name_ua`, `tech_type`, `price_per_hour`)
 INSERT INTO `services` (`name_en`, `name_ru`, `name_ua`, `tech_type`, `price_per_hour`)
-SELECT 'FDM Printing', 'FDM Печать', 'FDM Друк', 'fdm', 2.00
-WHERE NOT EXISTS (SELECT 1 FROM `services` WHERE `tech_type` = 'fdm');
+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`)
 INSERT INTO `services` (`name_en`, `name_ru`, `name_ua`, `tech_type`, `price_per_hour`)
-SELECT 'SLA Printing', 'SLA Печать', 'SLA Друк', 'sla', 5.00
-WHERE NOT EXISTS (SELECT 1 FROM `services` WHERE `tech_type` = 'sla');
+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;