--{5.8.1.12}  
----------------------  
-- $Change: xxxxx $  
-- $DateTime: 2017/03/30 12:00:00 $  
-- $Author: rmevawala $  
----------------------  
-- Def<161176> - Template and Rosetta audit messages are failing to insert into the event_data_trail table 
-- Def<171030> - AA script run during 5.9/8.4 Beta installs runs for hours due to DROP COLUMN
                 

----------------------


IF EXISTS(SELECT 1 FROM sys.columns WHERE Name = N'old_value' AND Object_ID = Object_ID(N'[dbo].[event_data_trail]'))
	BEGIN
		DECLARE @oldValueColLength int = (Select CAST(COL_Length('event_data_trail', 'old_value') AS INT))
		if  ISNUMERIC (@oldValueColLength)=1 AND @oldValueColLength > -1 AND @oldValueColLength < 8000 
			BEGIN
				ALTER TABLE event_data_trail ALTER COLUMN old_value varchar(8000) NOT NULL
			END
	END
GO


IF EXISTS(SELECT 1 FROM sys.columns WHERE Name = N'new_value' AND Object_ID = Object_ID(N'[dbo].[event_data_trail]'))
	BEGIN
		DECLARE @newValueColLength int = (Select CAST(COL_Length('event_data_trail', 'new_value') AS INT))
		if  ISNUMERIC (@newValueColLength)=1 AND @newValueColLength > -1 AND @newValueColLength < 8000 
			BEGIN
				ALTER TABLE event_data_trail ALTER COLUMN new_value varchar(8000) NOT NULL
			END
	END
GO
