Spaces:
Running
Running
File size: 1,788 Bytes
cd357c6 b3b8847 cd357c6 b3b8847 cd357c6 b3b8847 cd357c6 b3b8847 cd357c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | -- Migration: Add pricing_levels JSON column to catalogue_ref table
-- Description: Adds pricing_levels column to store enhanced pricing data as JSON
-- Date: 2024-12-18
-- Add pricing_levels JSON column to trans.catalogue_ref
ALTER TABLE trans.catalogue_ref
ADD COLUMN IF NOT EXISTS pricing_levels JSON;
-- Create indexes for better query performance on pricing_levels
-- Index on currency field within JSON
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_catalogue_ref_pricing_levels_currency
ON trans.catalogue_ref USING GIN ((pricing_levels->>'currency'));
-- Index on MRP field within JSON (cast to numeric for range queries)
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_catalogue_ref_pricing_levels_mrp
ON trans.catalogue_ref USING BTREE (CAST(pricing_levels->>'mrp' AS NUMERIC));
-- Index on pricing levels structure (for queries on specific levels like 'retail', 'distributor')
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_catalogue_ref_pricing_levels_gin
ON trans.catalogue_ref USING GIN (pricing_levels);
-- Add comment to document the column purpose
COMMENT ON COLUMN trans.catalogue_ref.pricing_levels IS 'Enhanced pricing levels data stored as JSON with currency, MRP, and level-specific pricing (retail, distributor, etc.)';
-- Example of the JSON structure stored:
-- {
-- "currency": "INR",
-- "mrp": 399,
-- "levels": {
-- "retail": {
-- "purchase_price": 260,
-- "trade_margin": 20,
-- "selling_price": 299,
-- "retail_price": 349,
-- "retail_margin": 30,
-- "max_discount_pct": 15
-- },
-- "distributor": {
-- "purchase_price": 230,
-- "trade_margin": 25,
-- "selling_price": 279,
-- "retail_price": 349,
-- "retail_margin": 30,
-- "max_discount_pct": 20
-- }
-- }
-- } |