-- Tables affected: lot
-- recovery.not-started: check first; ADD COLUMN fails if lot_category already exists
-- recovery.partial: DROP INDEX IF EXISTS idx_lot_category ON lot; ALTER TABLE lot DROP COLUMN lot_category;
-- recovery.completed: no action needed
-- verify: lot_category column missing | SELECT 1 FROM information_schema.COLUMNS WHERE table_schema=DATABASE() AND table_name='lot' AND column_name='lot_category' HAVING COUNT(*)=0

-- Migration: Add lot_category column to lot table
-- Run this migration manually on the database

-- Add lot_category column to lot table
ALTER TABLE lot ADD COLUMN lot_category VARCHAR(50) DEFAULT NULL;

-- Create index for faster lookups
CREATE INDEX idx_lot_category ON lot(lot_category);

-- Update existing lots: extract category from lot_name (first part before underscore)
UPDATE lot SET lot_category = SUBSTRING_INDEX(lot_name, '_', 1) WHERE lot_category IS NULL;
