Răsfoiți Sursa

fix: add missing printer_hour_price and speed_coeff columns to orders table migration

unknown 2 luni în urmă
părinte
comite
ac12073dc6

+ 8 - 0
backend/check_orders_schema.py

@@ -0,0 +1,8 @@
+import db
+import json
+
+try:
+    cols = db.execute_query("DESCRIBE orders")
+    print(json.dumps(cols, indent=2))
+except Exception as e:
+    print(f"Error: {e}")

+ 5 - 0
backend/migrations/006_order_pricing_snapshot.sql

@@ -0,0 +1,5 @@
+-- Migration 006: Order Pricing Snapshot Columns
+-- Adding columns to store pricing parameters at the moment of order creation.
+
+ALTER TABLE `orders` ADD COLUMN `printer_hour_price` decimal(10,2) DEFAULT NULL;
+ALTER TABLE `orders` ADD COLUMN `speed_coeff` decimal(10,2) DEFAULT NULL;

+ 3 - 3
backend/routers/orders.py

@@ -120,10 +120,10 @@ async def create_order(
     })
 
     order_query = """
-    INSERT INTO orders (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, status, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, material_name, material_price, printer_hour_price, color_name, quantity, notes, original_params)
-    VALUES (%s, %s, %s, %s, %s, %s, %s, %s, 'pending', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
+    INSERT INTO orders (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, status, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, material_name, material_price, printer_hour_price, speed_coeff, color_name, quantity, notes, original_params)
+    VALUES (%s, %s, %s, %s, %s, %s, %s, %s, 'pending', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
     """
-    order_params = (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, mat_name, mat_price, hour_price, color_name, quantity, notes, original_params)
+    order_params = (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, mat_name, mat_price, hour_price, speed_coeff, color_name, quantity, notes, original_params)
     
     try:
         order_insert_id = db.execute_commit(order_query, order_params)