USE [MiddlewareProxyDB]
GO

-- Migration script to add the Skill_Group column to existing StandardSurvey and
-- FailedRecord tables (PCS + UCCE integration - Bank Misr SOW).
-- Skill_Group holds Skill_Group.EnterpriseName resolved from the TCD
-- SkillGroupSkillTargetID via a LEFT JOIN, so the column is NULLABLE (a call may
-- have no matching skill group).
-- Run this script if the tables already exist in your database.

-- StandardSurvey: carries Skill_Group through to the survey_feedback update
IF NOT EXISTS (
    SELECT 1 FROM sys.columns
    WHERE object_id = OBJECT_ID(N'[dbo].[StandardSurvey]') AND name = N'Skill_Group')
BEGIN
    ALTER TABLE [dbo].[StandardSurvey]
    ADD [Skill_Group] [varchar](255) NULL
END
GO

-- FailedRecord: same column, kept in sync for callback/SMS records that failed ECM feeding
IF NOT EXISTS (
    SELECT 1 FROM sys.columns
    WHERE object_id = OBJECT_ID(N'[dbo].[FailedRecord]') AND name = N'Skill_Group')
BEGIN
    ALTER TABLE [dbo].[FailedRecord]
    ADD [Skill_Group] [varchar](255) NULL
END
GO
