Rev 35896 | Blame | Compare with Previous | Last modification | View Log | RSS feed
-- Migration: Backfill GST numbers from user.counter to fofo.fofo_store-- Purpose: fofo_store.gst_number is now the canonical source for partner GST.-- This script copies existing valid GST numbers from the counter table.-- Safety: Non-destructive. Old counter data is NOT modified or deleted.-- Step 0: Add gst_number column if it doesn't existALTER TABLE fofo.fofo_store ADD COLUMN IF NOT EXISTS gst_number VARCHAR(15) DEFAULT NULL;-- Step 1: Verify data before migration (dry run)SELECT fs.id, fs.code, fs.gst_number AS current_fofo_gst, c.gstin AS counter_gstFROM fofo.fofo_store fsJOIN user.privatedealuser pdu ON pdu.id = fs.idJOIN user.counter c ON c.id = pdu.counter_idWHERE c.gstin IS NOT NULLAND TRIM(c.gstin) != ''AND LENGTH(TRIM(c.gstin)) = 15;-- Step 2: Backfill valid GST numbersUPDATE fofo.fofo_store fsJOIN user.privatedealuser pdu ON pdu.id = fs.idJOIN user.counter c ON c.id = pdu.counter_idSET fs.gst_number = TRIM(c.gstin)WHERE c.gstin IS NOT NULLAND TRIM(c.gstin) != ''AND LENGTH(TRIM(c.gstin)) = 15;-- Step 3: Verify migration resultsSELECT COUNT(*) AS migrated_countFROM fofo.fofo_storeWHERE gst_number IS NOT NULL AND gst_number != '';