Subversion Repositories SmartDukaan

Rev

Go to most recent revision | 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.
-- Prerequisite: fofo.fofo_store.gst_number column already exists.

-- Step 1: Verify data before migration (dry run)
SELECT fs.id, fs.code, fs.gst_number AS current_fofo_gst, c.gstin AS counter_gst
FROM fofo.fofo_store fs
JOIN user.privatedealuser pdu ON pdu.id = fs.id
JOIN user.counter c ON c.id = pdu.counter_id
WHERE c.gstin IS NOT NULL
  AND TRIM(c.gstin) != ''
  AND LENGTH(TRIM(c.gstin)) = 15;

-- Step 2: Backfill valid GST numbers
UPDATE fofo.fofo_store fs
JOIN user.privatedealuser pdu ON pdu.id = fs.id
JOIN user.counter c ON c.id = pdu.counter_id
SET fs.gst_number = TRIM(c.gstin)
WHERE c.gstin IS NOT NULL
  AND TRIM(c.gstin) != ''
  AND LENGTH(TRIM(c.gstin)) = 15;

-- Step 3: Verify migration results
SELECT COUNT(*) AS migrated_count
FROM fofo.fofo_store
WHERE gst_number IS NOT NULL AND gst_number != '';