IF  NOT EXISTS (SELECT * FROM sys.objects 
WHERE object_id = OBJECT_ID(N'[dbo].[pal_CalendarStatus]') AND type in (N'U'))
BEGIN

	CREATE TABLE [dbo].[pal_CalendarStatus](
		[recId] [int] IDENTITY(1,1) NOT NULL,
		[status] [varchar](150) NULL,
		[icon] [varchar](150) NULL,
		[isActive] [bit] NULL,
	 CONSTRAINT [PK_pal_CalendarStatus] PRIMARY KEY CLUSTERED 
	(
		[recId] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	) ON [PRIMARY]

END

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

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

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


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

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

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

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


IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_GetSurfaceCalendarUsersByIDs]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_GetSurfaceCalendarUsersByIDs]
END


IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_GetSurfaceCalendarUsersBySearch]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_GetSurfaceCalendarUsersBySearch]
END

Update pal_Module SET isCalendar = '1' Where recId IN (10,3)


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


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