Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
35896 amit 1
-- Migration: Backfill GST numbers from user.counter to fofo.fofo_store
2
-- Purpose: fofo_store.gst_number is now the canonical source for partner GST.
3
--          This script copies existing valid GST numbers from the counter table.
4
-- Safety: Non-destructive. Old counter data is NOT modified or deleted.
5
-- Prerequisite: fofo.fofo_store.gst_number column already exists.
6
 
7
-- Step 1: Verify data before migration (dry run)
8
SELECT fs.id, fs.code, fs.gst_number AS current_fofo_gst, c.gstin AS counter_gst
9
FROM fofo.fofo_store fs
10
JOIN user.privatedealuser pdu ON pdu.id = fs.id
11
JOIN user.counter c ON c.id = pdu.counter_id
12
WHERE c.gstin IS NOT NULL
13
  AND TRIM(c.gstin) != ''
14
  AND LENGTH(TRIM(c.gstin)) = 15;
15
 
16
-- Step 2: Backfill valid GST numbers
17
UPDATE fofo.fofo_store fs
18
JOIN user.privatedealuser pdu ON pdu.id = fs.id
19
JOIN user.counter c ON c.id = pdu.counter_id
20
SET fs.gst_number = TRIM(c.gstin)
21
WHERE c.gstin IS NOT NULL
22
  AND TRIM(c.gstin) != ''
23
  AND LENGTH(TRIM(c.gstin)) = 15;
24
 
25
-- Step 3: Verify migration results
26
SELECT COUNT(*) AS migrated_count
27
FROM fofo.fofo_store
28
WHERE gst_number IS NOT NULL AND gst_number != '';