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

TRUNCATE TABLE pal_UserType
SET IDENTITY_INSERT [dbo].[pal_UserType] ON 
INSERT [dbo].[pal_UserType] ([recId], [userType], [isActive], [sequence]) VALUES (1, N'Website User', 1, 1)
INSERT [dbo].[pal_UserType] ([recId], [userType], [isActive], [sequence]) VALUES (2, N'Power User', 1, 2)
INSERT [dbo].[pal_UserType] ([recId], [userType], [isActive], [sequence]) VALUES (3, N'Super User', 1, 3)
INSERT [dbo].[pal_UserType] ([recId], [userType], [isActive], [sequence]) VALUES (4, N'Admin User', 1, 4)
INSERT [dbo].[pal_UserType] ([recId], [userType], [isActive], [sequence]) VALUES (5, N'Custom User', 1, 5)
SET IDENTITY_INSERT [dbo].[pal_UserType] OFF

IF NOT EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'customUsers'
      AND Object_ID = Object_ID(N'pal_Canvas'))
BEGIN
	ALTER TABLE [dbo].[pal_Canvas]
	ADD [customUsers] VARCHAR (250) NULL;
END

IF EXISTS (SELECT * FROM   sys.objects
           WHERE  object_id = OBJECT_ID(N'[dbo].[SplitAndRemoveDuplicates]')
                  AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
	DROP FUNCTION [dbo].[SplitAndRemoveDuplicates]

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

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

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

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

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

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

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





