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

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

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


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


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


IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'pal_Attachment' AND COLUMN_NAME = 'isPrimary')
BEGIN
	ALTER TABLE [dbo].[pal_Attachment]
		ADD isPrimary       BIT CONSTRAINT [DF_pal_Attachment_isPrimary] DEFAULT ((0)) NULL
END
