
PRINT N'Altering [dbo].[pal_Note]...';

IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'pal_Note' AND COLUMN_NAME = 'caption')
	ALTER TABLE [dbo].[pal_Note] ALTER COLUMN [caption] TEXT NULL;


IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'pal_Note' AND COLUMN_NAME = 'customValue')
BEGIN
ALTER TABLE [dbo].[pal_Note]
    ADD [customValue] VARCHAR (200) NULL;
END


PRINT N'Altering [dbo].[pal_NoteType]...';
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'pal_NoteType' AND COLUMN_NAME = 'customItem')
BEGIN
ALTER TABLE [dbo].[pal_NoteType]
    ADD [customItem] VARCHAR (200) NULL;
END

PRINT N'Starting rebuilding table [dbo].[pal_TaskStatus]...';
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SET XACT_ABORT ON;

CREATE TABLE [dbo].[tmp_ms_xx_pal_TaskStatus] (
    [recId]      INT           IDENTITY (1, 1) NOT NULL,
    [taskStatus] VARCHAR (150) NULL,
    [isActive]   BIT           NULL,
    [sequence]   INT           NULL,
    CONSTRAINT [tmp_ms_xx_constraint_PK_pal_TaskStatus1] PRIMARY KEY CLUSTERED ([recId] ASC)
);

IF EXISTS (SELECT TOP 1 1 
           FROM   [dbo].[pal_TaskStatus])
    BEGIN
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_pal_TaskStatus] ON;
        INSERT INTO [dbo].[tmp_ms_xx_pal_TaskStatus] ([recId], [taskStatus], [isActive])
        SELECT   [recId],
                 [taskStatus],
                 [isActive]
        FROM     [dbo].[pal_TaskStatus]
        ORDER BY [recId] ASC;
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_pal_TaskStatus] OFF;
    END

DROP TABLE [dbo].[pal_TaskStatus];

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_pal_TaskStatus]', N'pal_TaskStatus';

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_constraint_PK_pal_TaskStatus1]', N'PK_pal_TaskStatus', N'OBJECT';


SET TRANSACTION ISOLATION LEVEL READ COMMITTED;



PRINT N'Refreshing [dbo].[sp_TaskNotes]...';

EXECUTE sp_refreshsqlmodule N'[dbo].[sp_TaskNotes]';

PRINT N'Refreshing [dbo].[sp_TaskActivityLog]...';

EXECUTE sp_refreshsqlmodule N'[dbo].[sp_TaskActivityLog]';

PRINT N'Refreshing [dbo].[sp_Tasks]...';

EXECUTE sp_refreshsqlmodule N'[dbo].[sp_Tasks]';

PRINT N'Update complete.';

GO

