IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'createdBy'
      AND Object_ID = Object_ID(N'pal_Report'))
BEGIN
    ALTER TABLE pal_Report
	ADD createdBy int NULL; 
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'updatedBy'
      AND Object_ID = Object_ID(N'pal_Report'))
BEGIN
    ALTER TABLE pal_Report
	ADD updatedBy int NULL; 
END


IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'dateSaved'
      AND Object_ID = Object_ID(N'pal_Report'))
BEGIN
    ALTER TABLE pal_Report
	ADD dateSaved datetime NULL; 
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'dateUpdated'
      AND Object_ID = Object_ID(N'pal_Report'))
BEGIN
    ALTER TABLE pal_Report
	ADD dateUpdated datetime NULL; 
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'isPublic'
      AND Object_ID = Object_ID(N'pal_Report'))
BEGIN
    ALTER TABLE pal_Report
	ADD isPublic bit NULL; 
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'isArchived'
      AND Object_ID = Object_ID(N'pal_Report'))
BEGIN
    ALTER TABLE pal_Report
	ADD isArchived bit NULL; 
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'parentSurfaceId'
      AND Object_ID = Object_ID(N'pal_ReportField'))
BEGIN
    ALTER TABLE pal_ReportField
	ADD parentSurfaceId int NULL; 
END


IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'isGrouped'
      AND Object_ID = Object_ID(N'pal_ReportField'))
BEGIN
    ALTER TABLE pal_ReportField
	ADD isGrouped bit NULL; 
END

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'isFilter'
      AND Object_ID = Object_ID(N'pal_ReportField'))
BEGIN
    ALTER TABLE pal_ReportField
	ADD isFilter bit NULL; 
END


Declare @AggCount AS Int = (SELECT Count (*) FROM [dbo].[pal_SurfaceGridAggregateType] WHERE aggregateType = 'count')
IF @AggCount = 0
BEGIN

	INSERT INTO [dbo].[pal_SurfaceGridAggregateType]
           ([aggregateType]
           ,[isActive])
     VALUES
           ('count'
           ,1)

END