-- Migration: Make PO optional in GRN tables
-- This allows creating GRNs without requiring a Purchase Order

-- Step 1: Make po_id nullable in scm_grn table
ALTER TABLE scm_grn 
ALTER COLUMN po_id DROP NOT NULL;

-- Step 2: Make po_item_id nullable in scm_grn_item table  
ALTER TABLE scm_grn_item 
ALTER COLUMN po_item_id DROP NOT NULL;

-- Step 3: Make batch_no nullable in scm_grn_item table
ALTER TABLE scm_grn_item 
ALTER COLUMN batch_no DROP NOT NULL;

-- Verify the changes
SELECT 
    table_name,
    column_name,
    is_nullable,
    data_type
FROM information_schema.columns 
WHERE table_name IN ('scm_grn', 'scm_grn_item') 
  AND column_name IN ('po_id', 'po_item_id', 'batch_no')
ORDER BY table_name, column_name;