-- =============================================
-- Repsly API Integration - Remove Unused RepslyID Columns
-- Created: 2025-01-XX
-- Purpose: Remove RepslyProductID and RepslyPromotionID columns
--          These are not needed because:
--          1. We identify products/promotions by Code (strProdCode/ExternalID)
--          2. Bulk import API doesn't return individual IDs
--          3. We track imports via ImportJobID
--          4. If needed, we can query Repsly by Code to get the ID
-- =============================================

USE [Superbowl]
GO

-- =============================================
-- Remove RepslyProductID from sysCronJobProducts (if exists)
-- =============================================
IF EXISTS (SELECT * FROM sys.columns 
           WHERE object_id = OBJECT_ID(N'[dbo].[sysCronJobProducts]') 
           AND name = 'RepslyProductID')
BEGIN
    ALTER TABLE [dbo].[sysCronJobProducts]
    DROP COLUMN [RepslyProductID]
    
    PRINT 'Column RepslyProductID removed from sysCronJobProducts successfully'
END
ELSE
BEGIN
    PRINT 'Column RepslyProductID does not exist in sysCronJobProducts'
END
GO

-- =============================================
-- Remove RepslyPromotionID from sysCronJobPromotions (if exists)
-- =============================================
IF EXISTS (SELECT * FROM sys.columns 
           WHERE object_id = OBJECT_ID(N'[dbo].[sysCronJobPromotions]') 
           AND name = 'RepslyPromotionID')
BEGIN
    ALTER TABLE [dbo].[sysCronJobPromotions]
    DROP COLUMN [RepslyPromotionID]
    
    PRINT 'Column RepslyPromotionID removed from sysCronJobPromotions successfully'
END
ELSE
BEGIN
    PRINT 'Column RepslyPromotionID does not exist in sysCronJobPromotions'
END
GO

PRINT 'Unused RepslyID columns removal script completed'
GO

