Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
37601 amit 1
-- Drop dead stock-ageing columns (2026-09-12)
2
--
3
-- WHY THESE ARE DEAD
4
--   warehouse.inventoryItem.rootInvoiceDate
5
--     No writer exists anywhere in the codebase - nothing ever calls setRootInvoiceDate().
6
--     Its only reader was ScheduledTasks.refreshSnapshotAgeing(), which ran every 30 minutes
7
--     and whose UPDATE ... JOIN therefore matched zero rows on every run.
8
--     Verified on hadb1: 0 of 1,528,669 rows have a non-null value.
9
--
10
--   inventory.currentinventorysnapshot.oldest_invoice_date / newest_invoice_date
11
--     Written only by that same no-op task; read by nothing - the entity getters on
12
--     SaholicInventorySnapshot have no callers, and no Reportico report on static0
13
--     references either column (checked all XMLs under /var/www/html/reports/projects).
14
--     Verified on hadb1: 0 of 11,686 rows have a non-null value.
15
--
16
-- NOT AFFECTED
17
--   warehouse.inventoryItem.originalInventoryItemId is NOT dropped. It is populated on
18
--   157,020 rows and is the "original external supplier" tag used for internal-movement
19
--   pricing. Live stock is largely untagged only because the backfill call in
20
--   Application.java was commented out (restored in the same change as this script).
21
--
22
--   Stock ageing itself is unaffected: the ageing that is actually in use resolves the
23
--   original external supplier at query time by serialNumber + supplier.internal = false
24
--   (WarehouseInventoryItem named queries findStockAgeingBy*, and the Reportico report
25
--   FOCO/ImeiSupplierPricing.xml). Neither reads the columns dropped here.
26
--
27
-- ORDERING: deploy the code change first (it removes the entity fields), then run this.
28
-- Running it against an app that still maps these fields will break Hibernate on those
29
-- entities.
30
--
31
-- MySQL 5.7 note: DROP COLUMN rebuilds the table. ALGORITHM=INPLACE, LOCK=NONE is stated
32
-- explicitly so the statement fails loudly rather than silently taking a blocking copy.
33
-- inventoryItem is ~1.5M rows; expect a few minutes and free disk equal to table size.
34
 
35
ALTER TABLE warehouse.inventoryItem
36
    DROP COLUMN rootInvoiceDate,
37
    ALGORITHM = INPLACE, LOCK = NONE;
38
 
39
ALTER TABLE inventory.currentinventorysnapshot
40
    DROP COLUMN oldest_invoice_date,
41
    DROP COLUMN newest_invoice_date,
42
    ALGORITHM = INPLACE, LOCK = NONE;
43
 
44
-- Verification (expect 0 rows each):
45
-- SELECT COLUMN_NAME FROM information_schema.COLUMNS
46
--  WHERE TABLE_SCHEMA='warehouse' AND TABLE_NAME='inventoryItem'
47
--    AND COLUMN_NAME='rootInvoiceDate';
48
-- SELECT COLUMN_NAME FROM information_schema.COLUMNS
49
--  WHERE TABLE_SCHEMA='inventory' AND TABLE_NAME='currentinventorysnapshot'
50
--    AND COLUMN_NAME IN ('oldest_invoice_date','newest_invoice_date');
51
 
52
-- Rollback (columns were empty, so restoring them loses nothing):
53
-- ALTER TABLE warehouse.inventoryItem ADD COLUMN rootInvoiceDate DATE NULL;
54
-- ALTER TABLE inventory.currentinventorysnapshot ADD COLUMN oldest_invoice_date DATE NULL,
55
--                                                ADD COLUMN newest_invoice_date DATE NULL;