# location_id Field Presence Analysis **Query Date:** January 28, 2026 --- ## 📊 Summary | File | scanfg_orders Table | location_id Field | box_id Field | Status | |------|-------------------|------------------|--------------|--------| | **init_db.py** | ❌ NOT DEFINED | ❌ NO | ❌ NO | ⚠️ Missing | | **initialize_db.py** | ✅ DEFINED | ✅ YES | ✅ YES | ✅ Complete | | **Database** | ✅ EXISTS | ✅ YES | ✅ YES | ✅ Deployed | --- ## 🔍 Detailed Analysis ### ❌ init_db.py **File Path:** `/srv/quality_app-v2/init_db.py` **Status:** Does NOT include scanfg_orders table at all **Tables Defined (9 total):** 1. users 2. user_credentials 3. quality_inspections 4. application_settings 5. roles 6. user_modules 7. user_permissions 8. worker_manager_bindings 9. **(No scanfg_orders table)** **Conclusion:** ❌ Neither `location_id` nor `box_id` are present --- ### ✅ initialize_db.py **File Path:** `/srv/quality_app-v2/initialize_db.py` (Lines 357-379) **Status:** INCLUDES scanfg_orders table WITH location_id and box_id **scanfg_orders Table Definition:** ```python CREATE TABLE IF NOT EXISTS scanfg_orders ( id INT AUTO_INCREMENT PRIMARY KEY, operator_code VARCHAR(50), CP_full_code VARCHAR(50), OC1_code VARCHAR(50), OC2_code VARCHAR(50), quality_code VARCHAR(10), date DATE, time TIME, approved_quantity INT DEFAULT 0, rejected_quantity INT DEFAULT 0, box_id BIGINT, # ✅ NEW BOX FIELD location_id BIGINT, # ✅ NEW LOCATION FIELD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (box_id) REFERENCES boxes_crates(id) ON DELETE SET NULL, FOREIGN KEY (location_id) REFERENCES warehouse_locations(id) ON DELETE SET NULL, INDEX idx_cp_code (CP_full_code), INDEX idx_operator (operator_code), INDEX idx_date (date), INDEX idx_box_id (box_id), # ✅ INDEX ON LOCATION INDEX idx_location_id (location_id) # ✅ INDEX ON BOX ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ``` **Conclusion:** ✅ Both `location_id` AND `box_id` are present with: - Proper foreign key constraints - Indexes for query performance - NULL-safe delete behavior --- ### ✅ Actual Database **Database:** quality_db **Table:** scanfg_orders **Current Status:** Both fields are deployed and active ``` Field Type Null Key Default ───────────────────────────────────────────────────── id INT(11) NO PRI auto_increment operator_code VARCHAR(50) YES MUL NULL CP_full_code VARCHAR(50) YES MUL NULL OC1_code VARCHAR(50) YES NULL OC2_code VARCHAR(50) YES NULL quality_code VARCHAR(10) YES NULL date DATE YES MUL NULL time TIME YES NULL approved_quantity INT(11) YES 0 rejected_quantity INT(11) YES 0 box_id BIGINT(20) YES MUL NULL ✅ location_id BIGINT(20) YES MUL NULL ✅ created_at TIMESTAMP YES CURRENT_TIMESTAMP ``` --- ## 🎯 Key Differences Between Files | Feature | init_db.py | initialize_db.py | Database | |---------|-----------|------------------|----------| | Has scanfg_orders | ❌ NO | ✅ YES | ✅ YES | | Has location_id | ❌ NO | ✅ YES | ✅ YES | | Has box_id | ❌ NO | ✅ YES | ✅ YES | | Foreign key constraints | - | ✅ YES | ✅ YES | | Indexes | - | ✅ YES (5 indexes) | ✅ YES | | Total tables created | 9 | 18+ | 19 | | Warehouse support | ❌ Minimal | ✅ Full | ✅ Full | | Box tracking | ❌ NO | ✅ YES | ✅ YES | --- ## 📝 Recommendation ### **USE: initialize_db.py** ✅ - Contains complete scanfg_orders table - Includes location_id field - Includes box_id field - Has all warehouse-related tables - Proper foreign key constraints ### **AVOID: init_db.py** ❌ - Missing scanfg_orders table entirely - Missing location_id field - Missing box_id field - Only basic tables - Not suitable for box tracking features --- ## 🔧 Action Items If database was initialized with `init_db.py`, you need to: 1. **Add scanfg_orders table** using initialize_db.py definition 2. **Or run this ALTER statement:** ```sql ALTER TABLE scanfg_orders ADD COLUMN location_id BIGINT AFTER box_id, ADD FOREIGN KEY (location_id) REFERENCES warehouse_locations(id) ON DELETE SET NULL, ADD INDEX idx_location_id (location_id); ``` 3. **Verify with:** ```sql DESCRIBE scanfg_orders; ``` --- ## ✅ Current Status Your database ✅ **ALREADY HAS** location_id field (as verified on 2026-01-28) ``` Total Records: 0 Records with location_id: 0 ``` The field is ready for data insertion as scans are performed.