CREATE TABLE selfaward_attach (id nvarchar(85) NOT NULL, file_name nvarchar(255) NOT NULL, display_name nvarchar(255) NOT NULL, path nvarchar(300) NOT NULL, url_path nvarchar(255), upload_date datetime, uploaded_by nvarchar(85))
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'selfaward_attach'; DECLARE @FullTableName SYSNAME; SET @FullTableName = @DynamicSchemaName + N'.selfaward_attach';DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Stores the attachments for the self-award certificate';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.name = N'MS_Description' AND ep.minor_id=0); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'selfaward_attach'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.selfaward_attach'; DECLARE @ColumnName SYSNAME set @ColumnName = N'id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'attachment id';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'selfaward_attach'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.selfaward_attach'; DECLARE @ColumnName SYSNAME set @ColumnName = N'file_name'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'file name of the attachement';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'selfaward_attach'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.selfaward_attach'; DECLARE @ColumnName SYSNAME set @ColumnName = N'display_name'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'file name of the attachement';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'selfaward_attach'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.selfaward_attach'; DECLARE @ColumnName SYSNAME set @ColumnName = N'path'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'path of the file in the directory';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'selfaward_attach'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.selfaward_attach'; DECLARE @ColumnName SYSNAME set @ColumnName = N'url_path'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'source of the file when using the API';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'selfaward_attach'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.selfaward_attach'; DECLARE @ColumnName SYSNAME set @ColumnName = N'upload_date'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'date the file is uploaded';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'selfaward_attach'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.selfaward_attach'; DECLARE @ColumnName SYSNAME set @ColumnName = N'uploaded_by'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'id of uploader';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE selfaward_attach ADD CONSTRAINT PK_SELFAWARD_ATTACH PRIMARY KEY (id)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160808-fr-1', 'francis.reforma', 'nschema/122.changeLog.xml', GETDATE(), 625, '8:075276975dbc7e3394c44ce6c2272d88', 'addColumn tableName=certusers; createTable tableName=certusers_selfaward; addPrimaryKey constraintName=PK_CERTUSERS_AWARD, tableName=certusers_selfaward; createIndex indexName=NUK_CERTUSERS_AWARD_USER_ID, tableName=certusers_selfaward; createIndex...', 'Support the functionality self-award certification', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160907-ps-1::paul.strugnell
-- [PD-4344] Saving Column Configurations
CREATE TABLE column_preset (preset_id nvarchar(85) NOT NULL, assignment_id nvarchar(85) NOT NULL, preset_type char(1) NOT NULL, preset_name nvarchar(255) NOT NULL, preset_data nvarchar (max) NOT NULL, created_date datetime NOT NULL, creator_uid nvarchar(85) NOT NULL, last_updated datetime NOT NULL, last_updater_uid nvarchar(85) NOT NULL, CONSTRAINT PK_COLUMN_PRESET PRIMARY KEY (preset_id))
GO

ALTER TABLE column_preset ADD CONSTRAINT UK_COLUMN_PRESET_ID_TYPE_NAME UNIQUE (assignment_id, preset_type, preset_name)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160907-ps-1', 'paul.strugnell', 'nschema/122.changeLog.xml', GETDATE(), 626, '8:4b47f4279c6134007ae89fa64a5aa633', 'createTable tableName=column_preset; addUniqueConstraint constraintName=UK_COLUMN_PRESET_ID_TYPE_NAME, tableName=column_preset', '[PD-4344] Saving Column Configurations', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160913-wp-1::william.puk
-- [PD-4844] Recovery of Competency-Related Tasks on Startup
ALTER TABLE background_task_log ADD nts_version nvarchar(15)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'background_task_log'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.background_task_log'; DECLARE @ColumnName SYSNAME set @ColumnName = N'nts_version'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'NTS version at the time the task is logged.';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

UPDATE background_task_log SET nts_version = '12.2.0.0'
GO

ALTER TABLE background_task_log ALTER COLUMN nts_version nvarchar(15) NOT NULL
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160913-wp-1', 'william.puk', 'nschema/122.changeLog.xml', GETDATE(), 627, '8:cd03bdb44ecd4eaacaf58da127c695cc', 'addColumn tableName=background_task_log; sql; addNotNullConstraint columnName=nts_version, tableName=background_task_log', '[PD-4844] Recovery of Competency-Related Tasks on Startup', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160913-wp-2::william.puk
DROP INDEX nuk_bg_task_log_end_time ON background_task_log
GO

CREATE NONCLUSTERED INDEX nuk_bg_task_log_unfinished ON background_task_log(end_time, node_id, nts_version)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160913-wp-2', 'william.puk', 'nschema/122.changeLog.xml', GETDATE(), 628, '8:154e7e276d0c42fd8aea8e4cbea2283b', 'dropIndex indexName=nuk_bg_task_log_end_time, tableName=background_task_log; createIndex indexName=nuk_bg_task_log_unfinished, tableName=background_task_log', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160913-sn-1::sam.ng
-- [PD-4733] Speed up the time to build learning object index
-- Create new columns - lucene_object_id and lucene_object_type
-- [PD-4733] Add index for preparing lucene documents
IF EXISTS (
			SELECT *
			FROM sys.objects
			WHERE type = 'TR' AND name =
			'i_resource_string'
			)
			DROP TRIGGER i_resource_string
GO

IF EXISTS (
			SELECT *
			FROM sys.objects
			WHERE type = 'TR' AND name =
			'u_resource_string'
			)
			DROP TRIGGER u_resource_string
GO

IF EXISTS (
			SELECT *
			FROM sys.objects
			WHERE type = 'TR' AND name =
			'd_resource_string'
			)
			DROP TRIGGER d_resource_string
GO

ALTER TABLE resource_string ADD lucene_object_id nvarchar(100)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'resource_string'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.resource_string'; DECLARE @ColumnName SYSNAME set @ColumnName = N'lucene_object_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Id of localiable object for lucene indexing';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

CREATE NONCLUSTERED INDEX NUK_RES_STRING_LUCENE ON resource_string(field, lucene_object_id)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160913-sn-1', 'sam.ng', 'nschema/122.changeLog.xml', GETDATE(), 629, '8:65248896facac40fb280102c195b76f9', 'sql; sql; sql; addColumn tableName=resource_string; createIndex indexName=NUK_RES_STRING_LUCENE, tableName=resource_string', '[PD-4733] Speed up the time to build learning object index
Create new columns - lucene_object_id and lucene_object_type
[PD-4733] Add index for preparing lucene documents', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160913-sn-2::sam.ng
DROP INDEX NUK_BUNDLE_ID_OBJECT_TYPE ON language_bundle
GO

CREATE NONCLUSTERED INDEX NUK_BUNDLE_ID_OBJECT_TYPE ON language_bundle(object_type, object_id)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160913-sn-2', 'sam.ng', 'nschema/122.changeLog.xml', GETDATE(), 630, '8:e22c048306923fdde4a0a4e5c59fefa5', 'dropIndex indexName=NUK_BUNDLE_ID_OBJECT_TYPE, tableName=language_bundle; createIndex indexName=NUK_BUNDLE_ID_OBJECT_TYPE, tableName=language_bundle', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160916-sn-1::sam.ng
DROP INDEX LOCOST_UN ON locosts
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160916-sn-1', 'sam.ng', 'nschema/122.changeLog.xml', GETDATE(), 631, '8:418ec973f915408ea144a00b5d7bf07c', 'dropIndex indexName=LOCOST_UN, tableName=locosts', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160916-sn-3::sam.ng
CREATE UNIQUE NONCLUSTERED INDEX LOCOST_UN ON locosts(payment_method, learningid, sessionid)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160916-sn-3', 'sam.ng', 'nschema/122.changeLog.xml', GETDATE(), 632, '8:459aba4811a9a19dc23008606238b805', 'createIndex indexName=LOCOST_UN, tableName=locosts', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160914-yu-1::yousri.usop
ALTER TABLE certusers ADD selfaward_attach_id nvarchar(85)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'certusers'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.certusers'; DECLARE @ColumnName SYSNAME set @ColumnName = N'selfaward_attach_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'self award certificate attachment id';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160914-yu-1', 'yousri.usop', 'nschema/122.changeLog.xml', GETDATE(), 633, '8:651b97433d62192afb3eb4ddc2d7af4a', 'addColumn tableName=certusers', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160915-fr-1::francis.reforma
-- Removed Unused Column
DECLARE @sql [nvarchar](MAX)
SELECT @sql = N'ALTER TABLE certusers_selfaward DROP CONSTRAINT ' + QUOTENAME([df].[name]) FROM [sys].[columns] AS [c] INNER JOIN [sys].[default_constraints] AS [df] ON [df].[object_id] = [c].[default_object_id] WHERE [c].[object_id] = OBJECT_ID(N'certusers_selfaward') AND [c].[name] = N'attachment_id'
EXEC sp_executesql @sql
GO

ALTER TABLE certusers_selfaward DROP COLUMN attachment_id
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160915-fr-1', 'francis.reforma', 'nschema/122.changeLog.xml', GETDATE(), 634, '8:7beef7c08b5f988c6149fb61a5b2b765', 'dropColumn columnName=attachment_id, tableName=certusers_selfaward', 'Removed Unused Column', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160919-wc-1::wilson.choi
ALTER TABLE schedule_task ADD schedule_type char(1) CONSTRAINT DF_schedule_task_schedule_type DEFAULT 'D' NOT NULL
GO

ALTER TABLE schedule_task ADD schedule_value smallint CONSTRAINT DF_schedule_task_schedule_value DEFAULT 0 NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'schedule_task'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.schedule_task'; DECLARE @ColumnName SYSNAME set @ColumnName = N'schedule_type'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'schedule type (D: Daily, W: Weekly, B: Bi-weekly, M: Monthly, Q:Quarterly, R: Run once), combine with schedule_value, replace the old column daily/weekly/monthly';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'schedule_task'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.schedule_task'; DECLARE @ColumnName SYSNAME set @ColumnName = N'schedule_value'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'schedule_value (base on schedule_type, Weekly/Bi-weekly: 1-7,  Monthly/Quarterly: 1-31, otherwise 0, combine with schedule_type replace the old column daily/weekly/monthly';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

Update schedule_task set schedule_type= case when daily='Y' then 'D' when weekly > 0 then 'W' when monthly > 0 then 'M' else 'R' end, 
				schedule_value=case when daily='Y' then 0 when weekly > 0 then weekly when monthly > 0 then monthly else 0 end
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160919-wc-1', 'wilson.choi', 'nschema/122.changeLog.xml', GETDATE(), 635, '8:69f6d35f2ef209ee10b1de7e059f12c3', 'addColumn tableName=schedule_task; sql', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160921-wc-1::wilson.choi
-- Removed Unused Column
DECLARE @sql [nvarchar](MAX)
SELECT @sql = N'ALTER TABLE schedule_task DROP CONSTRAINT ' + QUOTENAME([df].[name]) FROM [sys].[columns] AS [c] INNER JOIN [sys].[default_constraints] AS [df] ON [df].[object_id] = [c].[default_object_id] WHERE [c].[object_id] = OBJECT_ID(N'schedule_task') AND [c].[name] = N'daily'
EXEC sp_executesql @sql
GO

ALTER TABLE schedule_task DROP COLUMN daily
GO

DECLARE @sql [nvarchar](MAX)
SELECT @sql = N'ALTER TABLE schedule_task DROP CONSTRAINT ' + QUOTENAME([df].[name]) FROM [sys].[columns] AS [c] INNER JOIN [sys].[default_constraints] AS [df] ON [df].[object_id] = [c].[default_object_id] WHERE [c].[object_id] = OBJECT_ID(N'schedule_task') AND [c].[name] = N'weekly'
EXEC sp_executesql @sql
GO

ALTER TABLE schedule_task DROP COLUMN weekly
GO

DECLARE @sql [nvarchar](MAX)
SELECT @sql = N'ALTER TABLE schedule_task DROP CONSTRAINT ' + QUOTENAME([df].[name]) FROM [sys].[columns] AS [c] INNER JOIN [sys].[default_constraints] AS [df] ON [df].[object_id] = [c].[default_object_id] WHERE [c].[object_id] = OBJECT_ID(N'schedule_task') AND [c].[name] = N'monthly'
EXEC sp_executesql @sql
GO

ALTER TABLE schedule_task DROP COLUMN monthly
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160921-wc-1', 'wilson.choi', 'nschema/122.changeLog.xml', GETDATE(), 636, '8:261c9bc225453a71f424c077dc238801', 'dropColumn columnName=daily, tableName=schedule_task; dropColumn columnName=weekly, tableName=schedule_task; dropColumn columnName=monthly, tableName=schedule_task', 'Removed Unused Column', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160921-if-1::ivan.fung
-- [PD-5209] Extend Support Contact field length
ALTER TABLE learningObject ALTER COLUMN support_contact nvarchar(4000)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160921-if-1', 'ivan.fung', 'nschema/122.changeLog.xml', GETDATE(), 637, '8:32f308032909513db6592a7a7efd1be1', 'modifyDataType columnName=support_contact, tableName=learningObject', '[PD-5209] Extend Support Contact field length', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160923-sn-1::sam.ng
-- [PD-4733] Speed up the time to build learning object index
ALTER TABLE resource_string ADD lucene_should_use_ntext char(1) CONSTRAINT DF_resource_string_lucene_should_use_ntext DEFAULT 'N' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'resource_string'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.resource_string'; DECLARE @ColumnName SYSNAME set @ColumnName = N'lucene_should_use_ntext'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'should use ntext during lucene indexing? (Y/N)';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DROP INDEX NUK_RES_STRING_LUCENE ON resource_string
GO

CREATE NONCLUSTERED INDEX NUK_RES_STRING_LUCENE ON resource_string(field, lucene_should_use_ntext, lucene_object_id)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160923-sn-1', 'sam.ng', 'nschema/122.changeLog.xml', GETDATE(), 638, '8:23dbdb0ec7318a47b1988a5c20007247', 'addColumn tableName=resource_string; dropIndex indexName=NUK_RES_STRING_LUCENE, tableName=resource_string; createIndex indexName=NUK_RES_STRING_LUCENE, tableName=resource_string', '[PD-4733] Speed up the time to build learning object index', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160924-sn-1::sam.ng
if exists (
				SELECT  *
				FROM (SELECT CAST(serverproperty('ProductVersion') AS nvarchar) ver) as t
				where CAST(SUBSTRING(ver, 1, CHARINDEX('.', ver) - 1) as int) >= 11
			)
			DROP INDEX resource_string.NUK_RES_STRING_LUCENE
GO

if exists (
				SELECT  *
				FROM (SELECT CAST(serverproperty('ProductVersion') AS nvarchar) ver) as t
				where CAST(SUBSTRING(ver, 1, CHARINDEX('.', ver) - 1) as int) >= 11
			)
			create nonclustered index NUK_RES_STRING_LUCENE 
			on resource_string (field, lucene_should_use_ntext, lucene_object_id) 
			include (bundle_id, value_varchar, reference_id)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160924-sn-1', 'sam.ng', 'nschema/122.changeLog.xml', GETDATE(), 639, '8:63f4fa99fdb1a4cbbde6982a73f82e7b', 'sql; sql', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160924-sn-2::sam.ng
if exists (
				SELECT  *
				FROM (SELECT CAST(serverproperty('ProductVersion') AS nvarchar) ver) as t
				where CAST(SUBSTRING(ver, 1, CHARINDEX('.', ver) - 1) as int) >= 11
			)
			DROP INDEX language_bundle.NUK_BUNDLE_ID_OBJECT_TYPE
GO

if exists (
				SELECT  *
				FROM (SELECT CAST(serverproperty('ProductVersion') AS nvarchar) ver) as t
				where CAST(SUBSTRING(ver, 1, CHARINDEX('.', ver) - 1) as int) >= 11
			)
			create nonclustered index NUK_BUNDLE_ID_OBJECT_TYPE 
			on language_bundle (object_type, object_id) 
			include (bundle_id, locale, ilangid, is_primary)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160924-sn-2', 'sam.ng', 'nschema/122.changeLog.xml', GETDATE(), 640, '8:88c9512c396d5045a9bda9f2943a2741', 'sql; sql', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160924-sn-3::sam.ng
if exists (
				SELECT  *
				FROM (SELECT CAST(serverproperty('ProductVersion') AS nvarchar) ver) as t
				where CAST(SUBSTRING(ver, 1, CHARINDEX('.', ver) - 1) as int) >= 11
			)
			DROP INDEX locosts.LOCOST_UN
GO

if exists (
				SELECT  *
				FROM (SELECT CAST(serverproperty('ProductVersion') AS nvarchar) ver) as t
				where CAST(SUBSTRING(ver, 1, CHARINDEX('.', ver) - 1) as int) >= 11
			)
			create UNIQUE nonclustered index LOCOST_UN 
			on locosts (payment_method, learningid, sessionid) 
			include (cost, currency)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160924-sn-3', 'sam.ng', 'nschema/122.changeLog.xml', GETDATE(), 641, '8:2662f373bf4ef9fb7ee0a6afd2ac674e', 'sql; sql', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160924-sn-4::sam.ng
IF EXISTS(SELECT * FROM sys.indexes WHERE object_id = object_id('lo_attribute') AND NAME ='UK_LO_ATTRIBUTE')
    			DROP INDEX UK_LO_ATTRIBUTE ON lo_attribute
GO

if exists (
				SELECT  *
				FROM (SELECT CAST(serverproperty('ProductVersion') AS nvarchar) ver) as t
				where CAST(SUBSTRING(ver, 1, CHARINDEX('.', ver) - 1) as int) >= 11
			)
			create UNIQUE nonclustered index UK_LO_ATTRIBUTE 
			on lo_attribute (attribute_id, learningid) 
			include (attribute_value_data)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160924-sn-4', 'sam.ng', 'nschema/122.changeLog.xml', GETDATE(), 642, '8:fe185ec101e4a3bbc9ab42a2368ce9f7', 'sql; sql', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160922-wl-1::winnie.li
-- [PD-5210]extend the field so that there is enough space to store chinese character
ALTER TABLE dataloaderfiles ALTER COLUMN description nvarchar(4000)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160922-wl-1', 'winnie.li', 'nschema/122.changeLog.xml', GETDATE(), 643, '8:dc2e94c6ec0801016b559f7a2deae492', 'modifyDataType columnName=description, tableName=dataloaderfiles', '[PD-5210]extend the field so that there is enough space to store chinese character', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160922-wl-2::winnie.li
-- modifyDataType would remove nullable constraint for mssql and mysql in the current version of liquibase
ALTER TABLE dataloaderfiles ALTER COLUMN description nvarchar(4000) NOT NULL
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160922-wl-2', 'winnie.li', 'nschema/122.changeLog.xml', GETDATE(), 644, '8:121a7873f13ad344d94f83e264b45e4c', 'addNotNullConstraint columnName=description, tableName=dataloaderfiles', 'modifyDataType would remove nullable constraint for mssql and mysql in the current version of liquibase', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20161909-kk-1::kumar.khiani
-- [PD-5339] Introduce a minimum and maximum numbers of goals within an appraisal section
ALTER TABLE appraisal_s_goal_plan ADD min_number_of_goals smallint CONSTRAINT DF_appraisal_s_goal_plan_min_number_of_goals DEFAULT 0 NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'appraisal_s_goal_plan'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.appraisal_s_goal_plan'; DECLARE @ColumnName SYSNAME set @ColumnName = N'min_number_of_goals'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Minimum number of goals within an appraisal goal plan. 0 represents no limit.';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE appraisal_s_goal_plan ADD max_number_of_goals smallint CONSTRAINT DF_appraisal_s_goal_plan_max_number_of_goals DEFAULT 0 NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'appraisal_s_goal_plan'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.appraisal_s_goal_plan'; DECLARE @ColumnName SYSNAME set @ColumnName = N'max_number_of_goals'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Maximum number of goals within an appraisal goal plan. 0 represents no limit.';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE appraisal_s_goal_result ADD min_number_of_goals smallint CONSTRAINT DF_appraisal_s_goal_result_min_number_of_goals DEFAULT 0 NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'appraisal_s_goal_result'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.appraisal_s_goal_result'; DECLARE @ColumnName SYSNAME set @ColumnName = N'min_number_of_goals'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Minimum number of goals within an appraisal goal result. 0 represents no limit';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE appraisal_s_goal_result ADD max_number_of_goals smallint CONSTRAINT DF_appraisal_s_goal_result_max_number_of_goals DEFAULT 0 NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'appraisal_s_goal_result'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.appraisal_s_goal_result'; DECLARE @ColumnName SYSNAME set @ColumnName = N'max_number_of_goals'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Maximum number of goals within an appraisal goal result. 0 represents no limit';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161909-kk-1', 'kumar.khiani', 'nschema/122.changeLog.xml', GETDATE(), 645, '8:fb7e7fd91ec1ea66096471290fff8bc1', 'addColumn tableName=appraisal_s_goal_plan; addColumn tableName=appraisal_s_goal_plan; addColumn tableName=appraisal_s_goal_result; addColumn tableName=appraisal_s_goal_result', '[PD-5339] Introduce a minimum and maximum numbers of goals within an appraisal section', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160923-jw-1::joe.wong
-- [PD-5208] Lengthen default question prefix field to 50 characters
ALTER TABLE code_pool ALTER COLUMN defaultPrefix nvarchar(15) NULL
GO

ALTER TABLE code_pool ALTER COLUMN defaultPrefix nvarchar(50)
GO

ALTER TABLE code_pool ALTER COLUMN defaultPrefix nvarchar(50) NOT NULL
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160923-jw-1', 'joe.wong', 'nschema/122.changeLog.xml', GETDATE(), 646, '8:6325b48190c87fd4391a8592d66aa141', 'dropNotNullConstraint columnName=defaultPrefix, tableName=code_pool; modifyDataType columnName=defaultPrefix, tableName=code_pool; addNotNullConstraint columnName=defaultPrefix, tableName=code_pool', '[PD-5208] Lengthen default question prefix field to 50 characters', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160927-fr-1::francis.reforma
-- Flag to Disable self-enrollment when pending requests exceed seats limit
ALTER TABLE learningObject ADD disable_selfenroll_maxlimit char(1) CONSTRAINT DF_learningObject_disable_selfenroll_maxlimit DEFAULT 'N' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'learningObject'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.learningObject'; DECLARE @ColumnName SYSNAME set @ColumnName = N'disable_selfenroll_maxlimit'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Flag to Disable of self-enrollment when pending requests exceed seats limit';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160927-fr-1', 'francis.reforma', 'nschema/122.changeLog.xml', GETDATE(), 647, '8:1f5f2b1089b78a0bee4e03e6bc5603e7', 'addColumn tableName=learningObject', 'Flag to Disable self-enrollment when pending requests exceed seats limit', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160928-nl-1::nick.lee
-- [PD-5242] Tin Can API: Activity Profile API
CREATE TABLE tincan_profile (id nvarchar(85) NOT NULL, activity_id nvarchar(2000) NOT NULL, activity_id_hash_sha256 char(64) NOT NULL, profile_id nvarchar(2000) NOT NULL, profile_id_hash_sha256 char(64) NOT NULL, document_id nvarchar(85) NOT NULL, CONSTRAINT pk_tincan_profile PRIMARY KEY (id))
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_profile'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_profile'; DECLARE @ColumnName SYSNAME set @ColumnName = N'id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'primary key';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_profile'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_profile'; DECLARE @ColumnName SYSNAME set @ColumnName = N'activity_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'activityId';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_profile'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_profile'; DECLARE @ColumnName SYSNAME set @ColumnName = N'activity_id_hash_sha256'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'sha-256 hash of activityId';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_profile'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_profile'; DECLARE @ColumnName SYSNAME set @ColumnName = N'profile_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'profileId';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_profile'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_profile'; DECLARE @ColumnName SYSNAME set @ColumnName = N'profile_id_hash_sha256'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'sha-256 hash of profileId';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_profile'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_profile'; DECLARE @ColumnName SYSNAME set @ColumnName = N'document_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'foreign key to tincan_document.id';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE tincan_profile ADD CONSTRAINT fk_tincan_profile_document FOREIGN KEY (document_id) REFERENCES tincan_document (id)
GO

CREATE UNIQUE NONCLUSTERED INDEX nuk_tincan_profile ON tincan_profile(activity_id_hash_sha256, profile_id_hash_sha256)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160928-nl-1', 'nick.lee', 'nschema/122.changeLog.xml', GETDATE(), 648, '8:861b8e67d4d391b4c874663a42b35d90', 'createTable tableName=tincan_profile; addForeignKeyConstraint baseTableName=tincan_profile, constraintName=fk_tincan_profile_document, referencedTableName=tincan_document; createIndex indexName=nuk_tincan_profile, tableName=tincan_profile', '[PD-5242] Tin Can API: Activity Profile API', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20160929-wp-1::william.puk
-- [PD-4844] Recovery of Competency-Related Tasks on Startup
CREATE TABLE background_task_progress (id nvarchar(85) NOT NULL, task_log_id nvarchar(85) NOT NULL, progress_data_order int NOT NULL, progress_data nvarchar (max), CONSTRAINT PK_BG_TASK_PROGRESS PRIMARY KEY (id))
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'background_task_progress'; DECLARE @FullTableName SYSNAME; SET @FullTableName = @DynamicSchemaName + N'.background_task_progress';DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'This table stores the progress data of a background task, for the use of task recovery.';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.name = N'MS_Description' AND ep.minor_id=0); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'background_task_progress'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.background_task_progress'; DECLARE @ColumnName SYSNAME set @ColumnName = N'id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Unqiue ID as primary key.';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'background_task_progress'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.background_task_progress'; DECLARE @ColumnName SYSNAME set @ColumnName = N'task_log_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'The foreign key mapped to background_task_log';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'background_task_progress'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.background_task_progress'; DECLARE @ColumnName SYSNAME set @ColumnName = N'progress_data_order'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'The order of the progress data.';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'background_task_progress'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.background_task_progress'; DECLARE @ColumnName SYSNAME set @ColumnName = N'progress_data'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'The progress data.';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE background_task_progress ADD CONSTRAINT FK_BG_TASK_PROG_TASK_LOG_ID FOREIGN KEY (task_log_id) REFERENCES background_task_log (id)
GO

ALTER TABLE background_task_progress ADD CONSTRAINT UK_TASK_LOG_ID_DATA_ORDER UNIQUE (task_log_id, progress_data_order)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20160929-wp-1', 'william.puk', 'nschema/122.changeLog.xml', GETDATE(), 649, '8:a6ef348dbc6b44dea4e2bcfd287aba6b', 'createTable tableName=background_task_progress; addForeignKeyConstraint baseTableName=background_task_progress, constraintName=FK_BG_TASK_PROG_TASK_LOG_ID, referencedTableName=background_task_log; addUniqueConstraint constraintName=UK_TASK_LOG_ID_...', '[PD-4844] Recovery of Competency-Related Tasks on Startup', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20161005-ps-1::paul.strugnell
-- [PD-5246] Tin Can API: concurrency control for Activity Profile API
ALTER TABLE tincan_document ADD content_hash_sha1 char(40) NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_document'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_document'; DECLARE @ColumnName SYSNAME set @ColumnName = N'content_hash_sha1'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'sha-1 hash of original (non-gzipped) content';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161005-ps-1', 'paul.strugnell', 'nschema/122.changeLog.xml', GETDATE(), 650, '8:fbc9702d1b0d63c499b9ed91adeec1ae', 'addColumn tableName=tincan_document', '[PD-5246] Tin Can API: concurrency control for Activity Profile API', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20161005-nl-1::nick.lee
-- [PD-5237] Appraisal Rating Summary in Report Wizard
ALTER TABLE appraisal_u_sign_off ADD overall_rating_weighted float(53)
GO

ALTER TABLE appraisal_u_sign_off ADD overall_rating_percent float(53)
GO

DROP VIEW user_appraisal_vw
GO

CREATE VIEW user_appraisal_vw AS select ua.id as appraisal_id, ua.appraisal_template_id, atp.template_name, ua.appraisee_id, da.currentPID as appraiser_id, da.givenname as appraiser_first_name, da.familyname as appraiser_last_name,
		   		sda.currentPID as super_appraiser_id, sda.givenname as super_appraiser_first_name, sda.familyname as super_appraiser_last_name, ast.code as status_code,
		   		ast.category_id as status_category_id, ac.code as status_category_code, ua.created_date, ua.completed_date, aso.appraisee_comments, aso.appraiser_comments,
		   		aso.compliance_attitude, aso.appraisee_acceptance, aso.appraiser_acceptance, aso.career_dev_dialogue,
		   		aso.average_goal_rating, aso.average_objective_rating, aso.average_competency_rating, aso.average_dimensions_rating, aso.overall_rating, aso.overall_rating_weighted, aso.overall_rating_percent,
		   		atp.start_date as template_start_date, atp.end_date as template_end_date, aso.s_appraiser_acceptance, aso.s_appraiser_comments, aso.appraisee_reply 
			from user_appraisal ua
			inner join appraisal_template atp on atp.id = ua.appraisal_template_id
			left join valid_users_vw da on da.userid = ua.appraiser_id
			left join valid_users_vw sda on sda.userid = ua.super_appraiser_id
			inner join appraisal_status ast on ast.id = ua.status_id
			left join appraisal_status_category ac on ac.id = ast.category_id
			left join appraisal_u_sign_off aso on aso.appraisal_id = ua.id
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161005-nl-1', 'nick.lee', 'nschema/122.changeLog.xml', GETDATE(), 651, '8:6a82e9db149bc5304d713b71ffc2b990', 'addColumn tableName=appraisal_u_sign_off; dropView viewName=user_appraisal_vw; createView viewName=user_appraisal_vw', '[PD-5237] Appraisal Rating Summary in Report Wizard', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20161007-yu-1::yousri.usop
ALTER TABLE learningObject ADD learning_validity int CONSTRAINT DF_learningObject_learning_validity DEFAULT 0 NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'learningObject'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.learningObject'; DECLARE @ColumnName SYSNAME set @ColumnName = N'learning_validity'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'validity of learning for shared credit program';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161007-yu-1', 'yousri.usop', 'nschema/122.changeLog.xml', GETDATE(), 652, '8:d8c73932333d0e79be12e883880436da', 'addColumn tableName=learningObject', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20161007-fr-1::francis.reforma
-- Add option for Elapse time type
ALTER TABLE mastertest ADD remaining_time_type char(1) CONSTRAINT DF_mastertest_remaining_time_type DEFAULT '1' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'mastertest'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.mastertest'; DECLARE @ColumnName SYSNAME set @ColumnName = N'remaining_time_type'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'type of the Computation for Remaining time: 1- Exam Time or 2 - Elapsed Time';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE testquestion ADD teststart datetime
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'testquestion'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.testquestion'; DECLARE @ColumnName SYSNAME set @ColumnName = N'teststart'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'startdate of the question for Elapsed Time Computation';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161007-fr-1', 'francis.reforma', 'nschema/122.changeLog.xml', GETDATE(), 653, '8:4de419a149235ea686cc62c983852278', 'addColumn tableName=mastertest; addColumn tableName=testquestion', 'Add option for Elapse time type', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20161015-rr-1::ray.ruff
-- Course relevance - used for user LO recommendation calculations
CREATE TABLE lo_relationship (id nvarchar(15) NOT NULL, source_learningid nvarchar(85) NOT NULL, related_learningid nvarchar(85) NOT NULL, rating float(53) NOT NULL, CONSTRAINT PK_LO_REC_ID PRIMARY KEY (id))
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'lo_relationship'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.lo_relationship'; DECLARE @ColumnName SYSNAME set @ColumnName = N'id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Internal pseudo primary key';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'lo_relationship'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.lo_relationship'; DECLARE @ColumnName SYSNAME set @ColumnName = N'source_learningid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Source learning object';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'lo_relationship'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.lo_relationship'; DECLARE @ColumnName SYSNAME set @ColumnName = N'related_learningid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'LO to which the source is related.';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'lo_relationship'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.lo_relationship'; DECLARE @ColumnName SYSNAME set @ColumnName = N'rating'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'relationship relevance (from 0 to 1.0)';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE lo_relationship ADD CONSTRAINT UK_LO_REL_SOURCE_RELATION UNIQUE (source_learningid, related_learningid)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161015-rr-1', 'ray.ruff', 'nschema/122.changeLog.xml', GETDATE(), 654, '8:13538f425638b315335fc6b02f71a8c9', 'createTable tableName=lo_relationship; addUniqueConstraint constraintName=UK_LO_REL_SOURCE_RELATION, tableName=lo_relationship', 'Course relevance - used for user LO recommendation calculations', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20161015-rr-2::ray.ruff
-- User course recommendations
CREATE TABLE lo_recomendations (id nvarchar(15) NOT NULL, userid nvarchar(85) NOT NULL, learningid nvarchar(85) NOT NULL, recommendation_type char(1) NOT NULL, rating float(53) NOT NULL, CONSTRAINT PK_LO_RECOM_ID PRIMARY KEY (id))
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'lo_recomendations'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.lo_recomendations'; DECLARE @ColumnName SYSNAME set @ColumnName = N'id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Internal pseudo primary key';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'lo_recomendations'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.lo_recomendations'; DECLARE @ColumnName SYSNAME set @ColumnName = N'userid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'User identifier';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'lo_recomendations'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.lo_recomendations'; DECLARE @ColumnName SYSNAME set @ColumnName = N'learningid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Recommended learning object';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'lo_recomendations'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.lo_recomendations'; DECLARE @ColumnName SYSNAME set @ColumnName = N'recommendation_type'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Type: Self, Job-related, Mixed';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'lo_recomendations'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.lo_recomendations'; DECLARE @ColumnName SYSNAME set @ColumnName = N'rating'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Recommendation relevance (from 0 to 1.0)';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

CREATE NONCLUSTERED INDEX nuk_lo_recomendations_user ON lo_recomendations(userid, recommendation_type)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161015-rr-2', 'ray.ruff', 'nschema/122.changeLog.xml', GETDATE(), 655, '8:71ec5e452fb10cf41b9b88657de7f04c', 'createTable tableName=lo_recomendations; createIndex indexName=nuk_lo_recomendations_user, tableName=lo_recomendations', 'User course recommendations', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20161107-sn-1::sam.ng
-- [PD-5604] fix irregular performance issues in 12.2
DROP INDEX NUK_RES_STRING_LUCENE ON resource_string
GO

CREATE NONCLUSTERED INDEX NUK_RES_STRING_LUCENE ON resource_string(lucene_should_use_ntext, field, lucene_object_id)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161107-sn-1', 'sam.ng', 'nschema/122.changeLog.xml', GETDATE(), 656, '8:40820a35887f6507a57bf41221d4db3e', 'dropIndex indexName=NUK_RES_STRING_LUCENE, tableName=resource_string; createIndex indexName=NUK_RES_STRING_LUCENE, tableName=resource_string', '[PD-5604] fix irregular performance issues in 12.2', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/122.changeLog.xml::20161107-sn-2::sam.ng
if exists (
				SELECT  *
				FROM (SELECT CAST(serverproperty('ProductVersion') AS nvarchar) ver) as t
				where CAST(SUBSTRING(ver, 1, CHARINDEX('.', ver) - 1) as int) >= 11
			)
			DROP INDEX resource_string.NUK_RES_STRING_LUCENE
GO

if exists (
				SELECT  *
				FROM (SELECT CAST(serverproperty('ProductVersion') AS nvarchar) ver) as t
				where CAST(SUBSTRING(ver, 1, CHARINDEX('.', ver) - 1) as int) >= 11
			)
			create nonclustered index NUK_RES_STRING_LUCENE 
			on resource_string (lucene_should_use_ntext, field, lucene_object_id) 
			include (bundle_id, value_varchar, reference_id)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161107-sn-2', 'sam.ng', 'nschema/122.changeLog.xml', GETDATE(), 657, '8:f55d7a7d74baf2f3ee4941387ff791c7', 'sql; sql', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::17Oct2016-sg-1::shravan.gurrala
UPDATE ekpversion SET dblevel = 130, splevel = 0
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('17Oct2016-sg-1', 'shravan.gurrala', 'nschema/130.changeLog.xml', GETDATE(), 658, '8:1a2cd3e9614236f01d567c1072be3883', 'update tableName=ekpversion', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161018-wl-1::winnie.li
-- [PD-4059] Relative deadlines for checklist items
ALTER TABLE checklist_item ADD relative_days int
GO

ALTER TABLE checklist_item ADD relative_days_option char(1)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'checklist_item'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.checklist_item'; DECLARE @ColumnName SYSNAME set @ColumnName = N'relative_days'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Relative days for deadline';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'checklist_item'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.checklist_item'; DECLARE @ColumnName SYSNAME set @ColumnName = N'relative_days_option'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Relative days option';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161018-wl-1', 'winnie.li', 'nschema/130.changeLog.xml', GETDATE(), 659, '8:f763c42a08a460f3ada200504d1be77b', 'addColumn tableName=checklist_item', '[PD-4059] Relative deadlines for checklist items', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161019-jw-1::joe.wong
-- [PD-4778] Module Level Checklist
ALTER TABLE checklist_item ALTER COLUMN sessionid nvarchar(15) NULL
GO

ALTER TABLE checklist_item ADD checklist_type char(1) CONSTRAINT DF_checklist_item_checklist_type DEFAULT 'S' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'checklist_item'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.checklist_item'; DECLARE @ColumnName SYSNAME set @ColumnName = N'checklist_type'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Checklist type: Module(M) or session(S) level';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161019-jw-1', 'joe.wong', 'nschema/130.changeLog.xml', GETDATE(), 660, '8:cfa69207a1cfa30150ac6fccdc3cac37', 'dropNotNullConstraint columnName=sessionid, tableName=checklist_item; addColumn tableName=checklist_item', '[PD-4778] Module Level Checklist', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161018-kl-1::kam.lee
-- Facility Reservation for Ad-hoc Booking
CREATE TABLE facility_reservation (reservationid nvarchar(85) NOT NULL, facilityid nvarchar(15) NOT NULL, userid nvarchar(85) NOT NULL, startdate datetime NOT NULL, finishdate datetime NOT NULL, comments nvarchar(1000), CONSTRAINT PK_FACILITY_RESERVATION PRIMARY KEY (reservationid))
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'facility_reservation'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.facility_reservation'; DECLARE @ColumnName SYSNAME set @ColumnName = N'reservationid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Facility Reservation primary key';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'facility_reservation'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.facility_reservation'; DECLARE @ColumnName SYSNAME set @ColumnName = N'facilityid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Facilities Primary Key';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

CREATE NONCLUSTERED INDEX NUK_STARTDATE ON facility_reservation(startdate)
GO

CREATE NONCLUSTERED INDEX NUK_FINISHDATE ON facility_reservation(finishdate)
GO

ALTER TABLE facility_reservation ADD CONSTRAINT fk_facilityid FOREIGN KEY (facilityid) REFERENCES facilities (facilityid)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161018-kl-1', 'kam.lee', 'nschema/130.changeLog.xml', GETDATE(), 661, '8:2b16665f4f150b9bf96d2e34e3f68389', 'createTable tableName=facility_reservation; createIndex indexName=NUK_STARTDATE, tableName=facility_reservation; createIndex indexName=NUK_FINISHDATE, tableName=facility_reservation; addForeignKeyConstraint baseTableName=facility_reservation, cons...', 'Facility Reservation for Ad-hoc Booking', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161024-kl-1::kam.lee
-- Title for Ad Hoc booking of Facilities
ALTER TABLE facility_reservation ADD title nvarchar(85) NOT NULL
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161024-kl-1', 'kam.lee', 'nschema/130.changeLog.xml', GETDATE(), 662, '8:2493f46c4957a6685ac307dad66c720d', 'addColumn tableName=facility_reservation', 'Title for Ad Hoc booking of Facilities', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161025-wp-1::william.puk
-- [PD-5554] Background Task Execution Statistics - Part II
ALTER TABLE background_task_log ADD request_source nvarchar(85)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'background_task_log'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.background_task_log'; DECLARE @ColumnName SYSNAME set @ColumnName = N'request_source'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Request source of this task, recorded for statistics report.';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161025-wp-1', 'william.puk', 'nschema/130.changeLog.xml', GETDATE(), 663, '8:0e5aacb2aee4c975a2496070b4a5de1d', 'addColumn tableName=background_task_log', '[PD-5554] Background Task Execution Statistics - Part II', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161103-dc-1::dennis.chenung
-- Synchronize table schema for liquibase upgrade
INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161103-dc-1', 'dennis.chenung', 'nschema/130.changeLog.xml', GETDATE(), 664, '8:f972597f399c2b334ddb58ce47ccabce', 'dropPrimaryKey tableName=DATABASECHANGELOG; sql; sql; sql', 'Synchronize table schema for liquibase upgrade', 'MARK_RAN', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161031-nl-1::nick.lee
-- [PD-4789] Make Checklist Item Owner optional
ALTER TABLE checklist_item ALTER COLUMN owner_id nvarchar(85) NULL
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161031-nl-1', 'nick.lee', 'nschema/130.changeLog.xml', GETDATE(), 665, '8:4e880409fd2f87e38a2900a490c8ece2', 'dropNotNullConstraint columnName=owner_id, tableName=checklist_item', '[PD-4789] Make Checklist Item Owner optional', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161115-gg-1::gary.gan
-- [PD-4062] Option to define checklist item settings already in template
ALTER TABLE checklist_template_item ADD important char(1) CONSTRAINT DF_checklist_template_item_important DEFAULT 'N' NOT NULL
GO

ALTER TABLE checklist_template_item ADD owner_id nvarchar(85)
GO

ALTER TABLE checklist_template_item ADD deadline datetime
GO

ALTER TABLE checklist_template_item ADD relative_days int
GO

ALTER TABLE checklist_template_item ADD relative_days_option char(1)
GO

ALTER TABLE checklist_template_item ADD reminder_days int
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'checklist_template_item'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.checklist_template_item'; DECLARE @ColumnName SYSNAME set @ColumnName = N'relative_days'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Relative days for deadline';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'checklist_template_item'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.checklist_template_item'; DECLARE @ColumnName SYSNAME set @ColumnName = N'relative_days_option'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Relative days option';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161115-gg-1', 'gary.gan', 'nschema/130.changeLog.xml', GETDATE(), 666, '8:6dc82f393e7bef3c1525408d768113ef', 'addColumn tableName=checklist_template_item', '[PD-4062] Option to define checklist item settings already in template', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161117-jw-1::joe.wong
-- [PD-4063] Option to mark a checklist item as completed in Catalog Editor
IF EXISTS (
			SELECT *
			FROM sys.objects
			WHERE type = 'TR' AND name =
			'i_checklist_item'
			)
			DROP TRIGGER i_checklist_item
GO

IF EXISTS (
			SELECT *
			FROM sys.objects
			WHERE type = 'TR' AND name =
			'u_checklist_item'
			)
			DROP TRIGGER u_checklist_item
GO

IF EXISTS (
			SELECT *
			FROM sys.objects
			WHERE type = 'TR' AND name =
			'd_checklist_item'
			)
			DROP TRIGGER d_checklist_item
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161117-jw-1', 'joe.wong', 'nschema/130.changeLog.xml', GETDATE(), 667, '8:e17c14c1651329df03173968b0cdb339', 'sql; sql; sql', '[PD-4063] Option to mark a checklist item as completed in Catalog Editor', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161117-jw-2::joe.wong
-- [PD-4063] Option to mark a checklist item as completed in Catalog Editor
ALTER TABLE checklist_item ADD completed_by nvarchar(85)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'checklist_item'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.checklist_item'; DECLARE @ColumnName SYSNAME set @ColumnName = N'completed_by'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'User assignment who mark this item complete';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161117-jw-2', 'joe.wong', 'nschema/130.changeLog.xml', GETDATE(), 668, '8:9e256ffa119c8e206a6f29c036f4cb35', 'addColumn tableName=checklist_item', '[PD-4063] Option to mark a checklist item as completed in Catalog Editor', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161117-jw-3::joe.wong
-- [PD-4063] Option to mark a checklist item as completed in Catalog Editor
update checklist_item set completed_by = owner_id where completion_status = 'C'
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161117-jw-3', 'joe.wong', 'nschema/130.changeLog.xml', GETDATE(), 669, '8:db2aa6e69f2d6c817d52589d1e7353d8', 'sql', '[PD-4063] Option to mark a checklist item as completed in Catalog Editor', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161117-wc-1::wilson.choi
-- Title for Ad Hoc booking of Training Resource
ALTER TABLE training_resource_reservation ADD title nvarchar(85)
GO

Update training_resource_reservation set title= 'Ad-hoc Booking' where eventid is NULL
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161117-wc-1', 'wilson.choi', 'nschema/130.changeLog.xml', GETDATE(), 670, '8:b9ff372a3666cd87e63273bfb24666b6', 'addColumn tableName=training_resource_reservation; sql', 'Title for Ad Hoc booking of Training Resource', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161122-sc-1::shu.cui
-- [PD-4065] Migration task: grant read/write permissions to checklist template creator
INSERT INTO permissions (objectid, objecttype, identityid, permissioncode, identitytype, operator, is_pts_objecttype) 
            SELECT template_id, 'CKT', creator_uid, 1, 'U', 'OR', 'N' FROM checklist_template
GO

INSERT INTO permission_mapping (objectid, objecttype, permissioncode, resolved_objectid, is_pts_objecttype) 
			SELECT template_id, 'CKT', 1, template_id, 'N' FROM checklist_template
GO

INSERT INTO permissions (objectid, objecttype, identityid, permissioncode, identitytype, operator, is_pts_objecttype) 
            SELECT template_id, 'CKT', creator_uid, 2, 'U', 'OR', 'N' FROM checklist_template
GO

INSERT INTO permission_mapping (objectid, objecttype, permissioncode, resolved_objectid, is_pts_objecttype) 
			SELECT template_id, 'CKT', 2, template_id, 'N' FROM checklist_template
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161122-sc-1', 'shu.cui', 'nschema/130.changeLog.xml', GETDATE(), 671, '8:32f03ac3e470e1040639a5d40ff610f6', 'sql; sql; sql; sql', '[PD-4065] Migration task: grant read/write permissions to checklist template creator', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161130-jw-1::joe.wong
-- [PD-5261] Tin Can API: basic support for GET Statements
ALTER TABLE tincan_statement ADD object_type char(1)
GO

ALTER TABLE tincan_statement ADD context_registration char(36)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement'; DECLARE @ColumnName SYSNAME set @ColumnName = N'object_type'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Object type';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement'; DECLARE @ColumnName SYSNAME set @ColumnName = N'context_registration'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'The registration that the Statement is associated with.';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161130-jw-1', 'joe.wong', 'nschema/130.changeLog.xml', GETDATE(), 672, '8:15b1bf8dd10a39c2fcb26d5895b73dd6', 'addColumn tableName=tincan_statement', '[PD-5261] Tin Can API: basic support for GET Statements', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161130-nl-1::nick.lee
-- New Runtime Environment for Tin Can API
ALTER TABLE AICC_core ADD launch_password char(40)
GO

ALTER TABLE ContentObject ADD tincan_activity_id nvarchar(2000)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161130-nl-1', 'nick.lee', 'nschema/130.changeLog.xml', GETDATE(), 673, '8:b56b045df6307a6329334e774d22add8', 'addColumn tableName=AICC_core; addColumn tableName=ContentObject', 'New Runtime Environment for Tin Can API', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161123-hf-1::hubert.fajarit
CREATE TABLE exchange_server_login (exchange_server_id nvarchar(15) NOT NULL, exchange_server_name nvarchar(85) NOT NULL, version nvarchar(85) NOT NULL, email nvarchar(85) NOT NULL, password nvarchar(255) NOT NULL, endpoint_url nvarchar(100) NOT NULL, watermark nvarchar(100), creator_uid nvarchar(85), datecreated datetime, last_updater_uid nvarchar(85), last_updated datetime)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'exchange_server_login'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.exchange_server_login'; DECLARE @ColumnName SYSNAME set @ColumnName = N'exchange_server_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Unique Identifier';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'exchange_server_login'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.exchange_server_login'; DECLARE @ColumnName SYSNAME set @ColumnName = N'exchange_server_name'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Name of Exchange Server';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'exchange_server_login'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.exchange_server_login'; DECLARE @ColumnName SYSNAME set @ColumnName = N'version'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Version of Exchange Server';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'exchange_server_login'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.exchange_server_login'; DECLARE @ColumnName SYSNAME set @ColumnName = N'email'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Exchange Server email account';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'exchange_server_login'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.exchange_server_login'; DECLARE @ColumnName SYSNAME set @ColumnName = N'password'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Exchange Server account password';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'exchange_server_login'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.exchange_server_login'; DECLARE @ColumnName SYSNAME set @ColumnName = N'endpoint_url'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'URL of Exchange Web Service';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'exchange_server_login'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.exchange_server_login'; DECLARE @ColumnName SYSNAME set @ColumnName = N'watermark'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Bookmark for Server Pull Notification';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'exchange_server_login'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.exchange_server_login'; DECLARE @ColumnName SYSNAME set @ColumnName = N'creator_uid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Creator UID';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'exchange_server_login'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.exchange_server_login'; DECLARE @ColumnName SYSNAME set @ColumnName = N'datecreated'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Date created';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'exchange_server_login'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.exchange_server_login'; DECLARE @ColumnName SYSNAME set @ColumnName = N'last_updater_uid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Last updater UID';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'exchange_server_login'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.exchange_server_login'; DECLARE @ColumnName SYSNAME set @ColumnName = N'last_updated'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Date last updated';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE exchange_server_login ADD PRIMARY KEY (exchange_server_id)
GO

ALTER TABLE code_training_center ADD exchange_server_id nvarchar(15)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'code_training_center'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.code_training_center'; DECLARE @ColumnName SYSNAME set @ColumnName = N'exchange_server_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Reference Id for assigned Exchange Server';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE users_meta ADD exchange_server_id nvarchar(15)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'users_meta'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.users_meta'; DECLARE @ColumnName SYSNAME set @ColumnName = N'exchange_server_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Reference Id for assigned Exchange Server';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DROP VIEW users
GO

CREATE VIEW users AS select ua.userid, ua.dappraiser, ua.level1id, ua.level2id, ua.level3id, ua.level4id, ua.level5id,
    		       ua.costcenter, ua.joindate, um.userattr1, um.userattr2, um.userattr3, um.userattr4, ua.userrole,
    		       ua.datecreated, ua.jobtitle, ua.UserOption1, ua.UserOption2, ua.UserOption3, ua.profile, ua.managername,
    		       ua.manageremail, ua.departmentname, ua.locationcode, ua.hrmanagername, ua.hrmanageremail,
    		       ua.line_of_business, ua.skills_assessment_enabled, um.userattr5, um.userattr6, um.userattr7,
    		       um.userattr8, ua.leaf_orgid, ua.creditbalance, ua.hr_tag, ua.departmentid, ua.costcentername,
    		       ua.creator_uid, ua.last_updated, ua.last_updater_uid, ua.offline_player_eval_days, ua.offline_player_eval_start_date,
    		       ua.token_account_id, ua.domain_id, ua.user_meta_id, ua.assignment_ref_code, ua.dappraiserid,
    		       um.password, um.currentstatus, um.currentPID, um.familyname,
           		   um.givenname, um.othername, um.personaltitle, um.email, um.employeeno,
           		   um.externalAuthentication, um.autoDelete, um.deleteDate, um.dateofbirth,
           		   um.gender, um.expirationdate, um.nationality, um.dietary_constraints,
           		   um.middlename, um.skype_name, um.date_closed, ua.assignment_end_date, ua.super_appraiser, um.b_city, um.b_country,
           		   um.exchange_server_id
			from users_assignment ua, users_meta um
			where ua.user_meta_id = um.user_meta_id
GO

DROP VIEW valid_users_vw
GO

CREATE VIEW valid_users_vw AS select *
		  	from users
		  	where currentstatus NOT IN (3, 6)
GO

ALTER TABLE cschedule ADD exchange_server_id nvarchar(15)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'cschedule'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.cschedule'; DECLARE @ColumnName SYSNAME set @ColumnName = N'exchange_server_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Reference Id for assigned Exchange Server';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE module_session_schedule ADD exchange_item_id nvarchar(200)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'module_session_schedule'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.module_session_schedule'; DECLARE @ColumnName SYSNAME set @ColumnName = N'exchange_item_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Reference Id for corresponding Exchange Server Appointment';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE facility_reservation ADD exchange_item_id nvarchar(200)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'facility_reservation'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.facility_reservation'; DECLARE @ColumnName SYSNAME set @ColumnName = N'exchange_item_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Reference Id for corresponding Exchange Server Appointment';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE personal_event ADD exchange_item_id nvarchar(200)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'personal_event'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.personal_event'; DECLARE @ColumnName SYSNAME set @ColumnName = N'exchange_item_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Reference Id for corresponding Exchange Server Appointment';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE training_resource_reservation ADD exchange_item_id nvarchar(200)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'training_resource_reservation'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.training_resource_reservation'; DECLARE @ColumnName SYSNAME set @ColumnName = N'exchange_item_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Reference Id for corresponding Exchange Server Appointment';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161123-hf-1', 'hubert.fajarit', 'nschema/130.changeLog.xml', GETDATE(), 674, '8:42c70a3d6d147ad7cdbbef09e912145b', 'createTable tableName=exchange_server_login; addPrimaryKey tableName=exchange_server_login; addColumn tableName=code_training_center; addColumn tableName=users_meta; dropView viewName=users; createView viewName=users; dropView viewName=valid_users...', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161228-hf-2::hubert.fajarit
DROP VIEW cschedule_vw
GO

CREATE VIEW cschedule_vw AS SELECT
			    cschedule.*,
			    (select
			    count(*)
			     from transcript
			     where transcript.eventid = cschedule.eventid and studentstatus in (2, 3, 18)) nregistered
			FROM cschedule
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161228-hf-2', 'hubert.fajarit', 'nschema/130.changeLog.xml', GETDATE(), 675, '8:1f0ebbed93b0311ce49c71e77f0127dc', 'dropView viewName=cschedule_vw; createView viewName=cschedule_vw', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161202-ps-1::paul.strugnell
-- [PD-5421] Reusable HTML Widgets
CREATE TABLE template_widget_html_preset (preset_id nvarchar(85) NOT NULL, name nvarchar(255) NOT NULL, title nvarchar(255), content nvarchar (max), created_date datetime NOT NULL, creator_uid nvarchar(85) NOT NULL, last_updated datetime NOT NULL, last_updater_uid nvarchar(85) NOT NULL, CONSTRAINT PK_HTML_WIDGET PRIMARY KEY (preset_id))
GO

ALTER TABLE template_widget_html_config ADD preset_id nvarchar(85)
GO

ALTER TABLE template_widget_html_config ADD CONSTRAINT fk_html_widget_preset_id FOREIGN KEY (preset_id) REFERENCES template_widget_html_preset (preset_id)
GO

ALTER TABLE template_widget_html_preset ADD CONSTRAINT uk_html_widget_preset_name UNIQUE (name)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161202-ps-1', 'paul.strugnell', 'nschema/130.changeLog.xml', GETDATE(), 676, '8:beee1324f8cad28c27f4df734fa6941e', 'createTable tableName=template_widget_html_preset; addColumn tableName=template_widget_html_config; addForeignKeyConstraint baseTableName=template_widget_html_config, constraintName=fk_html_widget_preset_id, referencedTableName=template_widget_htm...', '[PD-5421] Reusable HTML Widgets', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161215-jw-1::joe.wong
-- [PD-5666] Tin Can API: launch (part 2)
ALTER TABLE AICC_core ADD registration char(36)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'AICC_core'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.AICC_core'; DECLARE @ColumnName SYSNAME set @ColumnName = N'registration'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'UUID of item attempt';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE tincan_statement ADD session_id nvarchar(15)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement'; DECLARE @ColumnName SYSNAME set @ColumnName = N'session_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'AICC session ID';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161215-jw-1', 'joe.wong', 'nschema/130.changeLog.xml', GETDATE(), 677, '8:26fe1a43b57085ba43d5c8e70363aace', 'addColumn tableName=AICC_core; addColumn tableName=tincan_statement', '[PD-5666] Tin Can API: launch (part 2)', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161216-sc-1::shu.cui
-- [PD-5813] Tin Can API: agent and verb for GET Statements
ALTER TABLE tincan_statement ADD home_page nvarchar(2000)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement'; DECLARE @ColumnName SYSNAME set @ColumnName = N'home_page'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Home page of actor';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161216-sc-1', 'shu.cui', 'nschema/130.changeLog.xml', GETDATE(), 678, '8:63bf921201261c5a8d5913a31fd6cf24', 'addColumn tableName=tincan_statement', '[PD-5813] Tin Can API: agent and verb for GET Statements', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161220-dc-1::dennis.cheung
-- [PD-5836] Printcert slow - Add index to certusers sub-tables by awardid
CREATE NONCLUSTERED INDEX NUK_CERTUSERS_ATTR_AWARDID ON certusers_attribute(certusers_awardid)
GO

CREATE NONCLUSTERED INDEX NUK_CERTUSERS_OBJ_AWARDID ON certusers_course_objectives(certusers_awardid)
GO

CREATE NONCLUSTERED INDEX NUK_CERTUSERS_INSTR_AWARDID ON certusers_instructor(certusers_awardid)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161220-dc-1', 'dennis.cheung', 'nschema/130.changeLog.xml', GETDATE(), 679, '8:7871d2b1282d9b3850de49181cfad5c1', 'createIndex indexName=NUK_CERTUSERS_ATTR_AWARDID, tableName=certusers_attribute; createIndex indexName=NUK_CERTUSERS_OBJ_AWARDID, tableName=certusers_course_objectives; createIndex indexName=NUK_CERTUSERS_INSTR_AWARDID, tableName=certusers_instructor', '[PD-5836] Printcert slow - Add index to certusers sub-tables by awardid', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161229-mm-1::marco.mate
-- Refer to CSS024
CREATE TABLE cschedule_hotel_list (eventid nvarchar(15) NOT NULL, courseid nvarchar(85) NOT NULL, resource_id nvarchar(15) NOT NULL, training_center_id nvarchar(15) NOT NULL)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'cschedule_hotel_list'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.cschedule_hotel_list'; DECLARE @ColumnName SYSNAME set @ColumnName = N'eventid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Refer to CSS024';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'cschedule_hotel_list'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.cschedule_hotel_list'; DECLARE @ColumnName SYSNAME set @ColumnName = N'courseid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Refer to CSS024';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'cschedule_hotel_list'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.cschedule_hotel_list'; DECLARE @ColumnName SYSNAME set @ColumnName = N'resource_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Refer to CSS024';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'cschedule_hotel_list'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.cschedule_hotel_list'; DECLARE @ColumnName SYSNAME set @ColumnName = N'training_center_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Refer to CSS024';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE cschedule_hotel_list ADD CONSTRAINT PK_CSCHED_HOTEL_LIST PRIMARY KEY (eventid, courseid, resource_id)
GO

ALTER TABLE cschedule_hotel_list ADD CONSTRAINT FK_CSCHED_HLIST_EVENTID FOREIGN KEY (eventid) REFERENCES cschedule (eventid)
GO

ALTER TABLE cschedule_hotel_list ADD CONSTRAINT FK_CSCHED_HLIST_COURSEID FOREIGN KEY (courseid) REFERENCES learningObject (learningid)
GO

ALTER TABLE cschedule_hotel_list ADD CONSTRAINT FK_CSCHED_HLIST_RSCID FOREIGN KEY (resource_id) REFERENCES code_training_resource (resource_id)
GO

ALTER TABLE cschedule_hotel_list ADD CONSTRAINT FK_CSCHED_HLIST_TCID FOREIGN KEY (training_center_id) REFERENCES code_training_center (training_center_id)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161229-mm-1', 'marco.mate', 'nschema/130.changeLog.xml', GETDATE(), 680, '8:fd0bbd1bc6283190fb5bdcb42171dba2', 'createTable tableName=cschedule_hotel_list; addPrimaryKey constraintName=PK_CSCHED_HOTEL_LIST, tableName=cschedule_hotel_list; addForeignKeyConstraint baseTableName=cschedule_hotel_list, constraintName=FK_CSCHED_HLIST_EVENTID, referencedTableName=...', 'Refer to CSS024', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20161229-mm-2::marco.mate
-- Refer to CSS024
CREATE TABLE sessiondetail_hotel_list (sessionid nvarchar(15) NOT NULL, currid nvarchar(85) NOT NULL, resource_id nvarchar(15) NOT NULL, training_center_id nvarchar(15) NOT NULL)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'sessiondetail_hotel_list'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.sessiondetail_hotel_list'; DECLARE @ColumnName SYSNAME set @ColumnName = N'sessionid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Refer to CSS024';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'sessiondetail_hotel_list'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.sessiondetail_hotel_list'; DECLARE @ColumnName SYSNAME set @ColumnName = N'currid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Refer to CSS024';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'sessiondetail_hotel_list'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.sessiondetail_hotel_list'; DECLARE @ColumnName SYSNAME set @ColumnName = N'resource_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Refer to CSS024';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'sessiondetail_hotel_list'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.sessiondetail_hotel_list'; DECLARE @ColumnName SYSNAME set @ColumnName = N'training_center_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Refer to CSS024';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE sessiondetail_hotel_list ADD CONSTRAINT PK_SESSDET_HOTEL_LIST PRIMARY KEY (sessionid, currid, resource_id)
GO

ALTER TABLE sessiondetail_hotel_list ADD CONSTRAINT FK_SESSDET_HLIST_SESSIONID FOREIGN KEY (currid, sessionid) REFERENCES sessiondetail (currid, sessionid)
GO

ALTER TABLE sessiondetail_hotel_list ADD CONSTRAINT FK_SESSDET_HLIST_RSCID FOREIGN KEY (resource_id) REFERENCES code_training_resource (resource_id)
GO

ALTER TABLE sessiondetail_hotel_list ADD CONSTRAINT FK_SESSDET_HLIST_TCID FOREIGN KEY (training_center_id) REFERENCES code_training_center (training_center_id)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20161229-mm-2', 'marco.mate', 'nschema/130.changeLog.xml', GETDATE(), 681, '8:7a4f5d280fced16b4370564e36a31099', 'createTable tableName=sessiondetail_hotel_list; addPrimaryKey constraintName=PK_SESSDET_HOTEL_LIST, tableName=sessiondetail_hotel_list; addForeignKeyConstraint baseTableName=sessiondetail_hotel_list, constraintName=FK_SESSDET_HLIST_SESSIONID, refe...', 'Refer to CSS024', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170104-wc-1::wilson.choi
-- [PD-5717] Add new column is_latest
ALTER TABLE certusers ADD is_latest char(1) CONSTRAINT DF_certusers_is_latest DEFAULT 'N' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'certusers'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.certusers'; DECLARE @ColumnName SYSNAME set @ColumnName = N'is_latest'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Flag to indicate whether this is latest certificate for user';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170104-wc-1', 'wilson.choi', 'nschema/130.changeLog.xml', GETDATE(), 682, '8:35cfdb57473972f1065f03c76751f8e9', 'addColumn tableName=certusers', '[PD-5717] Add new column is_latest', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170106-dc-1::dennis.cheung
ALTER TABLE tincan_statement ADD object_id_hash_sha256 char(64) CONSTRAINT DF_tincan_statement_object_id_hash_sha256 DEFAULT 'migrate130' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement'; DECLARE @ColumnName SYSNAME set @ColumnName = N'object_id_hash_sha256'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'sha-256 hash for Tin Can Object ID';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

CREATE NONCLUSTERED INDEX NUK_OBJECT_ID_HASH_SHA256 ON tincan_statement(object_id_hash_sha256)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170106-dc-1', 'dennis.cheung', 'nschema/130.changeLog.xml', GETDATE(), 683, '8:833d8793a48ba57c8762541197093485', 'addColumn tableName=tincan_statement; createIndex indexName=NUK_OBJECT_ID_HASH_SHA256, tableName=tincan_statement', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170106-dc-2::dennis.cheung
ALTER TABLE tincan_context_activity ADD activity_id_hash_sha256 char(64) CONSTRAINT DF_tincan_context_activity_activity_id_hash_sha256 DEFAULT 'migrate130' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_context_activity'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_context_activity'; DECLARE @ColumnName SYSNAME set @ColumnName = N'activity_id_hash_sha256'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'sha-256 hash for Activity ID';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

CREATE NONCLUSTERED INDEX NUK_ACTIVIY_ID_HASH_SHA256 ON tincan_context_activity(activity_id_hash_sha256)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170106-dc-2', 'dennis.cheung', 'nschema/130.changeLog.xml', GETDATE(), 684, '8:c9e5ad0493d907ea54d4a8b0b3c1057a', 'addColumn tableName=tincan_context_activity; createIndex indexName=NUK_ACTIVIY_ID_HASH_SHA256, tableName=tincan_context_activity', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170106-dc-3::dennis.cheung
DROP INDEX TINCAN_LO_ACTIVITY_HASH ON tincan_lo_activity
GO

DECLARE @sql [nvarchar](MAX)
SELECT @sql = N'ALTER TABLE tincan_lo_activity DROP CONSTRAINT ' + QUOTENAME([df].[name]) FROM [sys].[columns] AS [c] INNER JOIN [sys].[default_constraints] AS [df] ON [df].[object_id] = [c].[default_object_id] WHERE [c].[object_id] = OBJECT_ID(N'tincan_lo_activity') AND [c].[name] = N'tincan_activity_id_hash'
EXEC sp_executesql @sql
GO

ALTER TABLE tincan_lo_activity DROP COLUMN tincan_activity_id_hash
GO

ALTER TABLE tincan_lo_activity ADD tincan_activity_id_hash_sha256 char(64) CONSTRAINT DF_tincan_lo_activity_tincan_activity_id_hash_sha256 DEFAULT 'migrate130' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_lo_activity'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_lo_activity'; DECLARE @ColumnName SYSNAME set @ColumnName = N'tincan_activity_id_hash_sha256'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'sha-256 hash for Activity ID';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

CREATE NONCLUSTERED INDEX UNK_TINCAN_LO_ACTIVITY_HASH ON tincan_lo_activity(tincan_activity_id_hash_sha256)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170106-dc-3', 'dennis.cheung', 'nschema/130.changeLog.xml', GETDATE(), 685, '8:151c0570a92c4dfd09cca887a56f3676', 'dropIndex indexName=TINCAN_LO_ACTIVITY_HASH, tableName=tincan_lo_activity; dropColumn columnName=tincan_activity_id_hash, tableName=tincan_lo_activity; addColumn tableName=tincan_lo_activity; createIndex indexName=UNK_TINCAN_LO_ACTIVITY_HASH, tabl...', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170113-sc-1::shu.cui
-- [PD-5857] Migration task: grant read/write permissions of existing forums to All organizations
INSERT INTO permissions (objectid, objecttype, identityid, permissioncode, identitytype, operator, is_pts_objecttype) 
            SELECT forumid, 'FM', '*ROOT*', 1, 'O', 'OR', 'N' FROM forum where topicid = 0
GO

INSERT INTO permission_mapping (objectid, objecttype, permissioncode, resolved_objectid, is_pts_objecttype) 
			SELECT forumid, 'FM', 1, forumid, 'N' FROM forum where topicid = 0
GO

INSERT INTO permissions (objectid, objecttype, identityid, permissioncode, identitytype, operator, is_pts_objecttype) 
            SELECT forumid, 'FM', '*ROOT*', 2, 'O', 'OR', 'N' FROM forum where topicid = 0
GO

INSERT INTO permission_mapping (objectid, objecttype, permissioncode, resolved_objectid, is_pts_objecttype) 
			SELECT forumid, 'FM', 2, forumid, 'N' FROM forum where topicid = 0
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170113-sc-1', 'shu.cui', 'nschema/130.changeLog.xml', GETDATE(), 686, '8:39eda4c4b012942de67a74dda186efc0', 'sql; sql; sql; sql', '[PD-5857] Migration task: grant read/write permissions of existing forums to All organizations', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170117-js-1::janice.sung
-- Defaults for Resource Planner Calendar
CREATE TABLE resource_planner_defaults (userid nvarchar(85) NOT NULL, display_view char(1) CONSTRAINT DF_resource_planner_defaults_display_view DEFAULT 'W' NOT NULL, working_period nvarchar (max), display_fields nvarchar (max), CONSTRAINT PK_RESOURCE_PLANNER_DEFAULTS PRIMARY KEY (userid))
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'resource_planner_defaults'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.resource_planner_defaults'; DECLARE @ColumnName SYSNAME set @ColumnName = N'userid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Primary key - User ID';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'resource_planner_defaults'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.resource_planner_defaults'; DECLARE @ColumnName SYSNAME set @ColumnName = N'display_view'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Display view of the calendar';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'resource_planner_defaults'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.resource_planner_defaults'; DECLARE @ColumnName SYSNAME set @ColumnName = N'working_period'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Json of the working period';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'resource_planner_defaults'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.resource_planner_defaults'; DECLARE @ColumnName SYSNAME set @ColumnName = N'display_fields'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Json of the display fields';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE resource_planner_defaults ADD CONSTRAINT FK_PLANNER_DEFAULTS_USERID FOREIGN KEY (userid) REFERENCES users_assignment (userid)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170117-js-1', 'janice.sung', 'nschema/130.changeLog.xml', GETDATE(), 687, '8:ef50006dd9791cbb616bae28a8dcddcb', 'createTable tableName=resource_planner_defaults; addForeignKeyConstraint baseTableName=resource_planner_defaults, constraintName=FK_PLANNER_DEFAULTS_USERID, referencedTableName=users_assignment', 'Defaults for Resource Planner Calendar', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170118-if-1::ivan.fung
-- [PD-5885] Add child table for storing agent information of statements
CREATE TABLE tincan_statement_agent (id nvarchar(85) NOT NULL, statement_id char(36) NOT NULL, context_type char(1) NOT NULL, agent_type char(1) NOT NULL, agent_name nvarchar(2000) NOT NULL, agent_name_hash_sha256 char(64) NOT NULL, home_page nvarchar(2000), CONSTRAINT PK_STATE_AGENT PRIMARY KEY (id))
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement_agent'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement_agent'; DECLARE @ColumnName SYSNAME set @ColumnName = N'id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'primary key';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement_agent'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement_agent'; DECLARE @ColumnName SYSNAME set @ColumnName = N'statement_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Statement ID';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement_agent'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement_agent'; DECLARE @ColumnName SYSNAME set @ColumnName = N'context_type'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Which context of the agent is in the statement';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement_agent'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement_agent'; DECLARE @ColumnName SYSNAME set @ColumnName = N'agent_type'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Type of Agent (mbox, mbox_sha1sum, openid, account)';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement_agent'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement_agent'; DECLARE @ColumnName SYSNAME set @ColumnName = N'agent_name'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'account.name or mbox or mbox_sha1sum or openid';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement_agent'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement_agent'; DECLARE @ColumnName SYSNAME set @ColumnName = N'agent_name_hash_sha256'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'sha-256 hash for agent_name';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'tincan_statement_agent'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.tincan_statement_agent'; DECLARE @ColumnName SYSNAME set @ColumnName = N'home_page'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'account.homePage';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE tincan_statement_agent ADD CONSTRAINT FK_STATE_AGENT FOREIGN KEY (statement_id) REFERENCES tincan_statement (id)
GO

CREATE NONCLUSTERED INDEX NUK_STATE_AGENT_ID ON tincan_statement_agent(statement_id)
GO

CREATE NONCLUSTERED INDEX NUK_STATE_AGENT_NAME ON tincan_statement_agent(agent_name_hash_sha256)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170118-if-1', 'ivan.fung', 'nschema/130.changeLog.xml', GETDATE(), 688, '8:c10b8b9675eb1169df726b4a051755a5', 'createTable tableName=tincan_statement_agent; addForeignKeyConstraint baseTableName=tincan_statement_agent, constraintName=FK_STATE_AGENT, referencedTableName=tincan_statement; createIndex indexName=NUK_STATE_AGENT_ID, tableName=tincan_statement_a...', '[PD-5885] Add child table for storing agent information of statements', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170123-hf-3::hubert.fajarit
ALTER TABLE code_training_resource ADD exchange_ref_email nvarchar(85)
GO

UPDATE code_training_resource SET exchange_ref_email = '>'
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'code_training_resource'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.code_training_resource'; DECLARE @ColumnName SYSNAME set @ColumnName = N'exchange_ref_email'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Exchange Server Resource Reference Email';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170123-hf-3', 'hubert.fajarit', 'nschema/130.changeLog.xml', GETDATE(), 689, '8:f836b3e2640e308275b0a7d0745653d5', 'addColumn tableName=code_training_resource', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170125-hf-4::hubert.fajarit
ALTER TABLE facilities ADD exchange_ref_email nvarchar(85)
GO

UPDATE facilities SET exchange_ref_email = '>'
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'facilities'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.facilities'; DECLARE @ColumnName SYSNAME set @ColumnName = N'exchange_ref_email'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Exchange Server Resource Reference Email';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170125-hf-4', 'hubert.fajarit', 'nschema/130.changeLog.xml', GETDATE(), 690, '8:7b4e08ad3c2cd7b01984046507aed94d', 'addColumn tableName=facilities', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170126-wc-1::wilson.choi
DECLARE @sql [nvarchar](MAX)
SELECT @sql = N'ALTER TABLE tincan_statement DROP CONSTRAINT ' + QUOTENAME([df].[name]) FROM [sys].[columns] AS [c] INNER JOIN [sys].[default_constraints] AS [df] ON [df].[object_id] = [c].[default_object_id] WHERE [c].[object_id] = OBJECT_ID(N'tincan_statement') AND [c].[name] = N'actor_type'
EXEC sp_executesql @sql
GO

DECLARE @sql [nvarchar](MAX)
SELECT @sql = N'ALTER TABLE tincan_statement DROP CONSTRAINT ' + QUOTENAME([df].[name]) FROM [sys].[columns] AS [c] INNER JOIN [sys].[default_constraints] AS [df] ON [df].[object_id] = [c].[default_object_id] WHERE [c].[object_id] = OBJECT_ID(N'tincan_statement') AND [c].[name] = N'actor_type'
EXEC sp_executesql @sql
GO

ALTER TABLE tincan_statement DROP COLUMN actor_type
GO

DECLARE @sql [nvarchar](MAX)
SELECT @sql = N'ALTER TABLE tincan_statement DROP CONSTRAINT ' + QUOTENAME([df].[name]) FROM [sys].[columns] AS [c] INNER JOIN [sys].[default_constraints] AS [df] ON [df].[object_id] = [c].[default_object_id] WHERE [c].[object_id] = OBJECT_ID(N'tincan_statement') AND [c].[name] = N'actor_name'
EXEC sp_executesql @sql
GO

ALTER TABLE tincan_statement DROP COLUMN actor_name
GO

DECLARE @sql [nvarchar](MAX)
SELECT @sql = N'ALTER TABLE tincan_statement DROP CONSTRAINT ' + QUOTENAME([df].[name]) FROM [sys].[columns] AS [c] INNER JOIN [sys].[default_constraints] AS [df] ON [df].[object_id] = [c].[default_object_id] WHERE [c].[object_id] = OBJECT_ID(N'tincan_statement') AND [c].[name] = N'home_page'
EXEC sp_executesql @sql
GO

ALTER TABLE tincan_statement DROP COLUMN home_page
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170126-wc-1', 'wilson.choi', 'nschema/130.changeLog.xml', GETDATE(), 691, '8:de3743a27ff7e6bf6a99110d833e6bd7', 'dropDefaultValue columnName=actor_type, tableName=tincan_statement; dropColumn columnName=actor_type, tableName=tincan_statement; dropColumn columnName=actor_name, tableName=tincan_statement; dropColumn columnName=home_page, tableName=tincan_state...', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170117-kk-1::kumar.khiani
-- [PD-5858] Migration task: set target audience to All Organizations for public forum categories
INSERT INTO permissions (objectid, objecttype, identityid, permissioncode, identitytype, operator, is_pts_objecttype) 
            SELECT boardid, 'FCT', '*ROOT*', 1, 'O', 'OR', 'N' FROM code_forumBoard where isPublic ='Y'
GO

INSERT INTO permission_mapping (objectid, objecttype, permissioncode, resolved_objectid, is_pts_objecttype) 
			SELECT boardid, 'FCT', 1, boardid, 'N' FROM code_forumBoard where isPublic ='Y'
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170117-kk-1', 'kumar.khiani', 'nschema/130.changeLog.xml', GETDATE(), 692, '8:563c4684040fc3e6a1c52ca072c1b9a3', 'sql; sql', '[PD-5858] Migration task: set target audience to All Organizations for public forum categories', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/130.changeLog.xml::20170201-wc-1::wilson.choi
DECLARE @sql [nvarchar](MAX)
SELECT @sql = N'ALTER TABLE code_forumBoard DROP CONSTRAINT ' + QUOTENAME([df].[name]) FROM [sys].[columns] AS [c] INNER JOIN [sys].[default_constraints] AS [df] ON [df].[object_id] = [c].[default_object_id] WHERE [c].[object_id] = OBJECT_ID(N'code_forumBoard') AND [c].[name] = N'isPublic'
EXEC sp_executesql @sql
GO

DECLARE @sql [nvarchar](MAX)
SELECT @sql = N'ALTER TABLE code_forumBoard DROP CONSTRAINT ' + QUOTENAME([df].[name]) FROM [sys].[columns] AS [c] INNER JOIN [sys].[default_constraints] AS [df] ON [df].[object_id] = [c].[default_object_id] WHERE [c].[object_id] = OBJECT_ID(N'code_forumBoard') AND [c].[name] = N'isPublic'
EXEC sp_executesql @sql
GO

ALTER TABLE code_forumBoard DROP COLUMN isPublic
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170201-wc-1', 'wilson.choi', 'nschema/130.changeLog.xml', GETDATE(), 693, '8:8f9c72b06fb8e4dfdd1858e8ad2b6ad4', 'dropDefaultValue columnName=isPublic, tableName=code_forumBoard; dropColumn columnName=isPublic, tableName=code_forumBoard', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::1Feb2017-sg-1::shravan.gurrala
UPDATE ekpversion SET dblevel = 131, splevel = 0
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('1Feb2017-sg-1', 'shravan.gurrala', 'nschema/131.changeLog.xml', GETDATE(), 694, '8:1838e05edf31a738a341c5deaf63d691', 'update tableName=ekpversion', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170201-ps-1::paul.strugnell
-- [PD-5776] Rename column transcript.usage_expiration_date to correct column name in 13.1
exec sp_rename 'transcript.usage_expiration_date', 'settings_as_of_date'
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170201-ps-1', 'paul.strugnell', 'nschema/131.changeLog.xml', GETDATE(), 695, '8:6bb84fa4781bd68e4b8413c56211f152', 'renameColumn newColumnName=settings_as_of_date, oldColumnName=usage_expiration_date, tableName=transcript', '[PD-5776] Rename column transcript.usage_expiration_date to correct column name in 13.1', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170201-ps-2::paul.strugnell
DROP VIEW aggregated_transcript_vw
GO

CREATE VIEW aggregated_transcript_vw AS SELECT
		    t1.transcriptid,
		    a2.userid,
			t1.learningid,
		    t1.currid,
		    t1.learningType,
		    t1.eventid,
		    t1.startdate,
		    t1.finishdate,
		    t1.finalgrade,
		    t1.studentstatus,
		    tsub.substatus_code,
		    tsub.substatus_name,
		    t1.progress,
		    t1.assessDate,
		    t1.attendance,
		    t1.perfGradeid,
		    t1.sessionid,
		    t1.creditTranscriptLink,
		    t1.curriculumTranscriptLink,
		    t1.assessmentscore,
		    t1.requestSource,
		    t1.contentSessionID,
		    t1.certSessionID,
		    t1.enrollmentDate,
		    t1.remindercount,
		    t1.costcenter,
		    t1.confirmation_status,
		    t1.reopen,
		    t1.isOpen,
		    t1.pre_assess_score,
		    t1.post_assess_score,
		    t1.settings_as_of_date,
		    t1.quick_eval,
		    t1.notifyemail,
		    t1.completion_deadline,
		    t1.deadline_expired,
		    t1.revision_number,
		    t1.ntraininghours,
		    t1.allowDappraiserAssess,
		    t1.offline_key,
		    t1.mekp_sync,
		    t1.send_notif_ew,
		    t1.update_meaning,
		    t1.last_updated,
		    t1.updater_legal_name,
		    t1.update_meaning_text,
		    t1.last_updater_uid,
		    t1.creator_uid,
		    t1.datecreated,
		    t1.curr_total_time,
		    t1.attempts_allowed,
		    t1.grading_method,
		    t1.attempts_count,
		    t1.completion_method,
		    t1.final_score,
		    t1.weighting,
		    t1.weightedscore,
			case when EXISTS(SELECT * FROM submod_tran_subt WHERE program_tran_id = t1.transcriptid) then 'Y' else 'N' end as sub_learning,
			case when a2.userid = t1.userid then 'Y' else 'N' end belongsToLearnerAssignment,
			t1.is_reqd_custom_attr_complete,
			t1.bundle_id,
		    t1.allowBundleSwitch,
			case when lang.ilangid is null then lang.locale else cast(lang.ilangid as char) end language_tag,
			t1.transcriptid as resolved_transcriptid
		  FROM transcript t1
			  inner join users_assignment a1 on a1.userid = t1.userid
			  inner join users_assignment a2 on a2.user_meta_id = a1.user_meta_id
			  left join transcript_substatus tsub on t1.student_substatus = tsub.id
			  inner join language_bundle lang on lang.bundle_id = t1.bundle_id
		  WHERE t1.studentstatus NOT IN (8, 9, 10)
		  UNION ALL
		  SELECT
		    a.transcriptid,
		    a2.userid,
		    a.learningid,
		    a.currid,
		    a.learningType,
		    a.eventid,
		    b.startdate,
		    b.finishdate,
		    b.finalgrade,
		    b.studentstatus,
		    tsub.substatus_code,
		    tsub.substatus_name,
		    b.progress,
		    b.assessDate,
		    b.attendance,
		    b.perfGradeid,
		    a.sessionid,
		    CASE WHEN 1=1 THEN NULL ELSE '' END as creditTranscriptLink,
		    a.curriculumTranscriptLink,
		    b.assessmentscore,
		    a.requestSource,
		    b.contentSessionID,
		    b.certSessionID,
		    a.enrollmentDate,
		    b.remindercount,
		    b.costcenter,
		    b.confirmation_status,
		    b.reopen,
		    a.isOpen,
		    b.pre_assess_score,
		    b.post_assess_score,
		    b.settings_as_of_date,
		    b.quick_eval,
		    b.notifyemail,
		    b.completion_deadline,
		    b.deadline_expired,
		    b.revision_number,
		    b.ntraininghours,
		    b.allowDappraiserAssess,
		    b.offline_key,
		    b.mekp_sync,
		    b.send_notif_ew,
		    b.update_meaning,
		    b.last_updated,
		    b.updater_legal_name,
		    a.update_meaning_text,
		    a.last_updater_uid,
		    a.creator_uid,
		    a.datecreated,
		    b.curr_total_time,
		    b.attempts_allowed,
		    b.grading_method,
		    b.attempts_count,
		    b.completion_method,
		    b.final_score,
		    b.weighting,
		    b.weightedscore,
		    case when EXISTS(SELECT * FROM submod_tran_subt WHERE program_tran_id = b.transcriptid) then 'Y' else 'N' end as sub_learning,
			case when a2.userid = a.userid then 'Y' else 'N' end belongsToLearnerAssignment,
			b.is_reqd_custom_attr_complete,
			b.bundle_id,
		    b.allowBundleSwitch,
			case when lang.ilangid is null then lang.locale else cast(lang.ilangid as char) end language_tag,
			a.creditTranscriptLink as resolved_transcriptid
		  FROM transcript a
			  inner join transcript b on b.transcriptid = a.creditTranscriptLink
			  inner join users_assignment a1 on a1.userid = a.userid
			  inner join users_assignment a2 on a2.user_meta_id = a1.user_meta_id
			  left join transcript_substatus tsub on a.student_substatus = tsub.id
			  inner join language_bundle lang on b.bundle_id = lang.bundle_id
		  WHERE a.studentstatus = 8 AND b.transcriptid = a.creditTranscriptLink AND b.studentstatus NOT IN (8, 9, 10)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170201-ps-2', 'paul.strugnell', 'nschema/131.changeLog.xml', GETDATE(), 696, '8:00076b5f5e6062b00b2892bcd43d58d8', 'dropView viewName=aggregated_transcript_vw; createView viewName=aggregated_transcript_vw', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170201-ps-3::paul.strugnell
DROP VIEW valid_transcript_vw
GO

CREATE VIEW valid_transcript_vw AS SELECT
		    transcriptid,
		    userid,
		    learningid,
		    currid,
		    learningType,
		    eventid,
		    startdate,
		    finishdate,
		    finalgrade,
		    studentstatus,
		    progress,
		    assessDate,
		    attendance,
		    perfGradeid,
		    sessionid,
		    creditTranscriptLink,
		    curriculumTranscriptLink,
		    assessmentscore,
		    requestSource,
		    contentSessionID,
		    certSessionID,
		    enrollmentDate,
		    remindercount,
		    costcenter,
		    confirmation_status,
		    reopen,
		    isOpen,
		    pre_assess_score,
		    post_assess_score,
		    settings_as_of_date,
		    quick_eval,
		    notifyemail,
		    completion_deadline,
		    deadline_expired,
		    revision_number,
		    ntraininghours,
		    allowDappraiserAssess,
		    offline_key,
		    mekp_sync,
		    send_notif_ew,
		    update_meaning,
		    a.last_updated,
		    a.updater_legal_name,
		    a.update_meaning_text,
		    a.last_updater_uid,
		    creator_uid,
		    datecreated,
		    curr_total_time,
		    attempts_allowed,
		    grading_method,
		    attempts_count,
		    completion_method,
		    final_score,
		    weighting,
		    weightedscore,
		    sub_learning,
		    actual_training_time_sec,
		    student_substatus,
		    is_reqd_custom_attr_complete,
		    a.bundle_id,
		    a.allowBundleSwitch,
			lang.ilangid,
			lang.locale
		  FROM transcript a, language_bundle lang
		  WHERE studentstatus NOT IN (8, 9, 10)
		  and a.bundle_id = lang.bundle_id
		  UNION ALL
		  SELECT
		    a.transcriptid,
		    a.userid,
		    a.learningid,
		    a.currid,
		    a.learningType,
		    a.eventid,
		    b.startdate,
		    b.finishdate,
		    b.finalgrade,
		    b.studentstatus,
		    b.progress,
		    b.assessDate,
		    b.attendance,
		    b.perfGradeid,
		    a.sessionid,
		    CASE WHEN 1=1 THEN NULL ELSE '' END as creditTranscriptLink,
		    a.curriculumTranscriptLink,
		    b.assessmentscore,
		    a.requestSource,
		    b.contentSessionID,
		    b.certSessionID,
		    a.enrollmentDate,
		    b.remindercount,
		    b.costcenter,
		    b.confirmation_status,
		    b.reopen,
		    a.isOpen,
		    b.pre_assess_score,
		    b.post_assess_score,
		    b.settings_as_of_date,
		    b.quick_eval,
		    b.notifyemail,
		    b.completion_deadline,
		    b.deadline_expired,
		    b.revision_number,
		    b.ntraininghours,
		    b.allowDappraiserAssess,
		    b.offline_key,
		    b.mekp_sync,
		    b.send_notif_ew,
		    b.update_meaning,
		    b.last_updated,
		    b.updater_legal_name,
		    a.update_meaning_text,
		    a.last_updater_uid,
		    a.creator_uid,
		    a.datecreated,
		    b.curr_total_time,
		    b.attempts_allowed,
		    b.grading_method,
		    b.attempts_count,
		    b.completion_method,
		    b.final_score,
		    b.weighting,
		    b.weightedscore,
		    b.sub_learning,
		    b.actual_training_time_sec,
		    b.student_substatus,
		    b.is_reqd_custom_attr_complete,
		    b.bundle_id,
		    b.allowBundleSwitch,
			lang.ilangid,
			lang.locale
		  FROM transcript a, transcript b, language_bundle lang
		  WHERE a.studentstatus = 8 AND b.transcriptid = a.creditTranscriptLink AND b.studentstatus NOT IN (8, 9, 10)
		  and b.bundle_id = lang.bundle_id
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170201-ps-3', 'paul.strugnell', 'nschema/131.changeLog.xml', GETDATE(), 697, '8:94def8dcc0e945970343bedb72ea5e1b', 'dropView viewName=valid_transcript_vw; createView viewName=valid_transcript_vw', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170207-vn-1::vincent.ni
-- ADD Additional Roles View
CREATE VIEW user_additional_roles_vw AS
				Select distinct ST2.userid, 
				    substring(
				        (
				            Select '|'+ST1.roleid  AS [text()]
				            From user_additional_roles ST1
				            Where ST1.userid = ST2.userid
				            ORDER BY ST1.userid
				            For XML PATH ('')
				        ), 2, 1000) additionalroles
				From user_additional_roles ST2
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170207-vn-1', 'vincent.ni', 'nschema/131.changeLog.xml', GETDATE(), 698, '8:5819e10784e25b38956850d66f55ed83', 'sql; sql; sql', 'ADD Additional Roles View', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170207-vn-3::vincent.ni
-- add user roles view
CREATE VIEW user_roles_vw AS SELECT users_assignment.userid 
				,users_assignment.userrole code
				,code_role.name name
				,1 type
			FROM users_assignment
			JOIN code_role ON code_role.roleid = users_assignment.userrole
			UNION ALL
			SELECT user_additional_roles.userid
				,user_additional_roles.roleid
				,code_role.name
				,2
			FROM user_additional_roles
			JOIN code_role ON code_role.roleid = user_additional_roles.roleid
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170207-vn-3', 'vincent.ni', 'nschema/131.changeLog.xml', GETDATE(), 699, '8:5e410b780184e2b7ade73e9ef7c2bdc0', 'createView viewName=user_roles_vw', 'add user roles view', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170214-gg-1::gary.gan
-- add dynamic attribute view
create view dynamic_attribute_vw as 
				SELECT        attribute_id, code, display_areas, label_key, type, sum_total, attr_order, is_mandatory, category, domain_id
					FROM            dynamic_attribute
				UNION ALL
				SELECT        CONVERT(varchar(11), extension_no), 'UAE-' + CAST(extension_no AS VARCHAR), display_areas, label, 'D', 'N', extension_no, 'N', 'UE', domain_id
					FROM            user_extension_label
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170214-gg-1', 'gary.gan', 'nschema/131.changeLog.xml', GETDATE(), 700, '8:393c778b7f54cd8a637213657203e0f9', 'sql; sql; sql', 'add dynamic attribute view', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170214-gg-2::gary.gan
-- add dynamic attribute drop down value view
create view dynamic_attribute_dd_val_vw as 
				SELECT     attribute_key,   attribute_id, attribute_value_data, label_key, attribute_description
				FROM            dynamic_attribute_dropdown_val
				UNION
				SELECT     extension_key,   CONVERT(varchar(11), extension_no), code, display_name, display_name
				FROM            code_user_extension
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170214-gg-2', 'gary.gan', 'nschema/131.changeLog.xml', GETDATE(), 701, '8:2b9f83dffa7b133b3f29de4107e5244c', 'sql; sql; sql', 'add dynamic attribute drop down value view', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170214-gg-3::gary.gan
-- add added user extension value view
CREATE VIEW user_extension_vw AS SELECT     users_assignment.userid, user_extension_meta.extension_no attribute_id, user_extension_meta.extension_value_data attribute_value_data
				FROM       user_extension_meta INNER JOIN
				users_assignment ON user_extension_meta.user_meta_id = users_assignment.user_meta_id
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170214-gg-3', 'gary.gan', 'nschema/131.changeLog.xml', GETDATE(), 702, '8:20070fb87bbe5d87e9a2186c1c327a4c', 'createView viewName=user_extension_vw', 'add added user extension value view', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170221-kk-1::kumar.khiani
ALTER TABLE forum ADD description nvarchar(1000)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'forum'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.forum'; DECLARE @ColumnName SYSNAME set @ColumnName = N'description'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Description column for forum';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170221-kk-1', 'kumar.khiani', 'nschema/131.changeLog.xml', GETDATE(), 703, '8:710a90e7d433b8db7d24d6956441cc4e', 'addColumn tableName=forum', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170306-js-1::janice.sung
-- [PD-5875] Add table for storing forum subscription information
CREATE TABLE forum_subscription (id nvarchar(85) NOT NULL, boardid int NOT NULL, forumid int NOT NULL, userid nvarchar(85) NOT NULL, CONSTRAINT PK_FORUM_SUBSCRIPTION PRIMARY KEY (id))
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'forum_subscription'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.forum_subscription'; DECLARE @ColumnName SYSNAME set @ColumnName = N'id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Primary key';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'forum_subscription'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.forum_subscription'; DECLARE @ColumnName SYSNAME set @ColumnName = N'boardid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Forum board Id';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'forum_subscription'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.forum_subscription'; DECLARE @ColumnName SYSNAME set @ColumnName = N'forumid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Forum Id';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'forum_subscription'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.forum_subscription'; DECLARE @ColumnName SYSNAME set @ColumnName = N'userid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'User who subscribed to the forum';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE forum_subscription ADD CONSTRAINT FK_FORUM_SUBSCRIPT_USERID FOREIGN KEY (userid) REFERENCES users_assignment (userid)
GO

CREATE NONCLUSTERED INDEX NUK_FORUM_SUBSCRIPT_FORUMID ON forum_subscription(boardid, forumid)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170306-js-1', 'janice.sung', 'nschema/131.changeLog.xml', GETDATE(), 704, '8:9eceefd750681ef5f30de18f75b0a161', 'createTable tableName=forum_subscription; addForeignKeyConstraint baseTableName=forum_subscription, constraintName=FK_FORUM_SUBSCRIPT_USERID, referencedTableName=users_assignment; createIndex indexName=NUK_FORUM_SUBSCRIPT_FORUMID, tableName=forum_...', '[PD-5875] Add table for storing forum subscription information', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170306-vn-1::vincent.ni
-- [PD-6097] New Criteria for User Groups
ALTER TABLE user_group_mem_otherdetail ADD user_account_status nvarchar(2000)
GO

ALTER TABLE user_group_mem_otherdetail ADD country nvarchar(3)
GO

ALTER TABLE user_group_mem_otherdetail ADD employment_country nvarchar(3)
GO

ALTER TABLE user_group_mem_otherdetail ADD province_state nvarchar(50)
GO

ALTER TABLE user_group_mem_otherdetail ADD city nvarchar(50)
GO

ALTER TABLE user_group_mem_otherdetail ADD super_appraiser nvarchar(85)
GO

ALTER TABLE user_group_mem_otherdetail ADD birth_date_start datetime
GO

ALTER TABLE user_group_mem_otherdetail ADD birth_date_end datetime
GO

ALTER TABLE user_group_mem_otherdetail ADD expiration_date_start datetime
GO

ALTER TABLE user_group_mem_otherdetail ADD expiration_date_end datetime
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'user_group_mem_otherdetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.user_group_mem_otherdetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'user_account_status'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'User Account Status';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'user_group_mem_otherdetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.user_group_mem_otherdetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'country'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Country';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'user_group_mem_otherdetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.user_group_mem_otherdetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'employment_country'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Employment Country';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'user_group_mem_otherdetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.user_group_mem_otherdetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'province_state'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Province/State';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'user_group_mem_otherdetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.user_group_mem_otherdetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'city'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'City';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'user_group_mem_otherdetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.user_group_mem_otherdetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'super_appraiser'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Super Appraiser';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'user_group_mem_otherdetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.user_group_mem_otherdetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'birth_date_start'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Start Date of Birth';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'user_group_mem_otherdetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.user_group_mem_otherdetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'birth_date_end'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'End Date of Birth';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'user_group_mem_otherdetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.user_group_mem_otherdetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'expiration_date_start'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Expiration Start Date';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'user_group_mem_otherdetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.user_group_mem_otherdetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'expiration_date_end'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Expiration End Date';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170306-vn-1', 'vincent.ni', 'nschema/131.changeLog.xml', GETDATE(), 705, '8:72272e08ddb36cb771fcf2d1148bf8d6', 'addColumn tableName=user_group_mem_otherdetail', '[PD-6097] New Criteria for User Groups', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170306-vn-2::vincent.ni
-- [PD-5874] Extend forum and topic title length, varchar length is 255*4
ALTER TABLE forum ALTER COLUMN topic nvarchar(1020)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170306-vn-2', 'vincent.ni', 'nschema/131.changeLog.xml', GETDATE(), 706, '8:71577feb49f28c82a841860cb6165c6e', 'modifyDataType columnName=topic, tableName=forum', '[PD-5874] Extend forum and topic title length, varchar length is 255*4', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170316-ec-1::edwin.chan
ALTER TABLE course_competency ADD assign_date datetime
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'course_competency'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.course_competency'; DECLARE @ColumnName SYSNAME set @ColumnName = N'assign_date'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Last timestamp of assigning courses to a competency for counting grace period';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170316-ec-1', 'edwin.chan', 'nschema/131.changeLog.xml', GETDATE(), 707, '8:b4820126b8f005b9d3999990e0e87ba1', 'addColumn tableName=course_competency', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170313-kk-1::kumar.khiani
-- PD-5861 Move permission to create topic or post to a forum setting
ALTER TABLE forum ADD forum_type char(1)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'forum'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.forum'; DECLARE @ColumnName SYSNAME set @ColumnName = N'forum_type'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Forum Type: V–View Only, R–Read Only, C–Reply and Create Topic';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170313-kk-1', 'kumar.khiani', 'nschema/131.changeLog.xml', GETDATE(), 708, '8:f633391c37d13a207ef8d72d7964650b', 'addColumn tableName=forum', 'PD-5861 Move permission to create topic or post to a forum setting', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170313-kk-2::kumar.khiani
-- PD-5861 Move permission to create topic or post to a forum setting - set forum type as 'C' (Reply And Create Topic) for all the existing forums
update forum set forum_type = 'C' where topicid = 0
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170313-kk-2', 'kumar.khiani', 'nschema/131.changeLog.xml', GETDATE(), 709, '8:c4bd5989b7e6a1c8a23c5c0755b0ebb5', 'sql', 'PD-5861 Move permission to create topic or post to a forum setting - set forum type as ''C'' (Reply And Create Topic) for all the existing forums', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170323-ca-1::chris.au
-- add dynamic attribute view
DROP VIEW dynamic_attribute_vw
GO

create view dynamic_attribute_vw as 
				SELECT        attribute_id, code, display_areas, label_key, type, sum_total, attr_order, is_mandatory, category, domain_id
					FROM            dynamic_attribute
				UNION ALL
				SELECT        distinct CONVERT(varchar(11), uel.extension_no), 'UAE-' + CAST(uel.extension_no AS VARCHAR), uel.display_areas, uel.label, case when cue.extension_no is not null then 'D' else 'F' end as type, 'N', uel.extension_no, 'N', 'UE', uel.domain_id
					FROM            user_extension_label uel
					left join code_user_extension  cue on uel.extension_no = cue.extension_no
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170323-ca-1', 'chris.au', 'nschema/131.changeLog.xml', GETDATE(), 710, '8:70273a2b9952287bbafabf62c6e75292', 'dropView viewName=dynamic_attribute_vw; sql; sql; sql', 'add dynamic attribute view', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170327-vn-1::vincent.ni
-- Certificate Award Attributes in Report Wizard
ALTER TABLE certusers_attribute ADD attribute_id nvarchar(15)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'certusers_attribute'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.certusers_attribute'; DECLARE @ColumnName SYSNAME set @ColumnName = N'attribute_id'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'attribute_id from dynamic_attribute';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

CREATE VIEW certusers_attribute_vw AS SELECT certusers_awardid, attribute_id, certusers_attribute.attribute_value attribute_value_data
			FROM certusers_attribute WHERE certusers_attribute.attribute_type = 'CT'
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170327-vn-1', 'vincent.ni', 'nschema/131.changeLog.xml', GETDATE(), 711, '8:6166e40fab7422a19c7359f436011db9', 'addColumn tableName=certusers_attribute; createView viewName=certusers_attribute_vw', 'Certificate Award Attributes in Report Wizard', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170406-vn-1::vincent.ni
-- PD-5860 Assign forum instead of complete forum category to module
ALTER TABLE learningObject ADD assignedForumType char(1) CONSTRAINT DF_learningObject_assignedForumType DEFAULT 'C' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'learningObject'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.learningObject'; DECLARE @ColumnName SYSNAME set @ColumnName = N'assignedForumType'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'assigned forum type, C:category, F:forum';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170406-vn-1', 'vincent.ni', 'nschema/131.changeLog.xml', GETDATE(), 712, '8:15f68bd38d2d3eca0bac54362ee71977', 'addColumn tableName=learningObject', 'PD-5860 Assign forum instead of complete forum category to module', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170406-gg-1::gary.gan
INSERT INTO permissions (objectid, objecttype, permissioncode, identityid, identitytype, operator, is_pts_objecttype) VALUES ('R603', 'RT', 1, '*ROOT*', 'O', 'OR', 'N')
GO

INSERT INTO permission_mapping (objectid, objecttype, permissioncode, resolved_objectid, is_pts_objecttype) VALUES ('R603', 'RT', 1, 'R603', 'N')
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170406-gg-1', 'gary.gan', 'nschema/131.changeLog.xml', GETDATE(), 713, '8:0059b08a8f5f4efa3de77534e52da7a8', 'insert tableName=permissions; insert tableName=permission_mapping', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170406-gg-2::gary.gan
INSERT INTO permissions (objectid, objecttype, permissioncode, identityid, identitytype, operator, is_pts_objecttype) VALUES ('R604', 'RT', 1, '*ROOT*', 'O', 'OR', 'N')
GO

INSERT INTO permission_mapping (objectid, objecttype, permissioncode, resolved_objectid, is_pts_objecttype) VALUES ('R604', 'RT', 1, 'R604', 'N')
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170406-gg-2', 'gary.gan', 'nschema/131.changeLog.xml', GETDATE(), 714, '8:df687c9c53731b6dcf5fe9acdf97eb1d', 'insert tableName=permissions; insert tableName=permission_mapping', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170407-js-1::janice.sung
-- [PD#5954] Certification Columns at Report Wizard
DROP VIEW localized_certusers_vw
GO

CREATE VIEW certifications_vw AS SELECT c.certid, c.certification_code, c.title, c.description, c.certtype, c.certstatus, c.issuedby, c.poolid, lb.locale AS language 
			FROM certifications c 
			LEFT JOIN language_bundle lb on lb.object_id = c.certid and lb.object_type = 'CR' and lb.is_primary = 'Y'
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170407-js-1', 'janice.sung', 'nschema/131.changeLog.xml', GETDATE(), 715, '8:3953217c15e854d8bdb54f1817b38f34', 'dropView viewName=localized_certusers_vw; createView viewName=certifications_vw', '[PD#5954] Certification Columns at Report Wizard', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170421-vn-1::vincent.ni
-- PD-5860 Assign forum instead of complete forum category to module
exec sp_rename 'learningObject.assignedForumType', 'assigned_forum_type'
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170421-vn-1', 'vincent.ni', 'nschema/131.changeLog.xml', GETDATE(), 716, '8:9fd258cca3af56c386a2216c095aec18', 'renameColumn newColumnName=assigned_forum_type, oldColumnName=assignedForumType, tableName=learningObject', 'PD-5860 Assign forum instead of complete forum category to module', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170502-js-1::janice.sung
-- [PD-6641] Extend forum description field length, varchar length is 1000*4
ALTER TABLE forum ALTER COLUMN description nvarchar(4000)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170502-js-1', 'janice.sung', 'nschema/131.changeLog.xml', GETDATE(), 717, '8:7b50ca901ddfcfaf71e4449a3a3ca88d', 'modifyDataType columnName=description, tableName=forum', '[PD-6641] Extend forum description field length, varchar length is 1000*4', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170512-yc-1::yanfang.cui
-- [PD-6336] Improve forum update notification daily task handling
ALTER TABLE forum_subscription ADD subscription_time datetime NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'forum_subscription'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.forum_subscription'; DECLARE @ColumnName SYSNAME set @ColumnName = N'subscription_time'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Subscribe forum time';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170512-yc-1', 'yanfang.cui', 'nschema/131.changeLog.xml', GETDATE(), 718, '8:a8d433bd8040442d02b473bf396cf689', 'addColumn tableName=forum_subscription', '[PD-6336] Improve forum update notification daily task handling', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170519-kl-1::kam.lee
-- [PD-5896] Allow file attachments to forum posts
CREATE TABLE forum_attachment (attachmentid nvarchar(85) NOT NULL, msgid numeric(16, 0) NOT NULL, original_filename nvarchar(255) NOT NULL, filename nvarchar(255) NOT NULL, CONSTRAINT PK_FORUM_ATTACHMENT PRIMARY KEY (attachmentid))
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'forum_attachment'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.forum_attachment'; DECLARE @ColumnName SYSNAME set @ColumnName = N'attachmentid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Primary key';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'forum_attachment'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.forum_attachment'; DECLARE @ColumnName SYSNAME set @ColumnName = N'msgid'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Foreign Key of Forum Message Id';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'forum_attachment'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.forum_attachment'; DECLARE @ColumnName SYSNAME set @ColumnName = N'original_filename'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Original File Name';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'forum_attachment'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.forum_attachment'; DECLARE @ColumnName SYSNAME set @ColumnName = N'filename'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'File Name';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

CREATE NONCLUSTERED INDEX NUK_FORUM_ATTTACHMENT_MSGID ON forum_attachment(msgid)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170519-kl-1', 'kam.lee', 'nschema/131.changeLog.xml', GETDATE(), 719, '8:b199f3b89c147590de292339ec3d7a39', 'createTable tableName=forum_attachment; createIndex indexName=NUK_FORUM_ATTTACHMENT_MSGID, tableName=forum_attachment', '[PD-5896] Allow file attachments to forum posts', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/131.changeLog.xml::20170525-yc-1::yanfang.cui
-- [PD-6130] Allow unsubscription by e-mail link
ALTER TABLE ekpversion ADD private_key nvarchar(100)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'ekpversion'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.ekpversion'; DECLARE @ColumnName SYSNAME set @ColumnName = N'private_key'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Private key';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170525-yc-1', 'yanfang.cui', 'nschema/131.changeLog.xml', GETDATE(), 720, '8:fd944b0a7f904c23e19f66c4a9dd58c3', 'addColumn tableName=ekpversion', '[PD-6130] Allow unsubscription by e-mail link', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::29May2017-sg-1::shravan.gurrala
UPDATE ekpversion SET dblevel = 132, splevel = 0
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('29May2017-sg-1', 'shravan.gurrala', 'nschema/132.changeLog.xml', GETDATE(), 721, '8:5b35678ed1a343e8ae0da44c534098d4', 'update tableName=ekpversion', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170713-ny::nelson.yip
-- [PD-6974] Count Pending Approval Records in Total Current Enrollments
CREATE TABLE code_enroll_cnt_method (method nvarchar(1) NOT NULL, studentstatus int NOT NULL)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'code_enroll_cnt_method'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.code_enroll_cnt_method'; DECLARE @ColumnName SYSNAME set @ColumnName = N'method'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Method to count total current enrollments; A = Active Only; P = Active and Pending Approval';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'code_enroll_cnt_method'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.code_enroll_cnt_method'; DECLARE @ColumnName SYSNAME set @ColumnName = N'studentstatus'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Student status to include when counting current enrollments';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO code_enroll_cnt_method (method, studentstatus) VALUES ('A', 2)
GO

INSERT INTO code_enroll_cnt_method (method, studentstatus) VALUES ('A', 3)
GO

INSERT INTO code_enroll_cnt_method (method, studentstatus) VALUES ('A', 18)
GO

INSERT INTO code_enroll_cnt_method (method, studentstatus) VALUES ('P', 2)
GO

INSERT INTO code_enroll_cnt_method (method, studentstatus) VALUES ('P', 3)
GO

INSERT INTO code_enroll_cnt_method (method, studentstatus) VALUES ('P', 7)
GO

INSERT INTO code_enroll_cnt_method (method, studentstatus) VALUES ('P', 18)
GO

ALTER TABLE cschedule ADD enroll_cnt_method nvarchar(1) CONSTRAINT DF_cschedule_enroll_cnt_method DEFAULT 'A' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'cschedule'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.cschedule'; DECLARE @ColumnName SYSNAME set @ColumnName = N'enroll_cnt_method'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Flag to indicate whether to count pending approval records in total current enrollments';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DROP VIEW cschedule_vw
GO

CREATE VIEW cschedule_vw AS SELECT
				cschedule.*,      	
				(select count(*)
				 from transcript 
				 where transcript.eventid = cschedule.eventid 
				 and transcript.studentstatus in (select studentstatus from code_enroll_cnt_method where method = cschedule.enroll_cnt_method)) nregistered	
			FROM cschedule
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170713-ny', 'nelson.yip', 'nschema/132.changeLog.xml', GETDATE(), 722, '8:53b1d77e23abf02d42f045478611f300', 'createTable tableName=code_enroll_cnt_method; insert tableName=code_enroll_cnt_method; insert tableName=code_enroll_cnt_method; insert tableName=code_enroll_cnt_method; insert tableName=code_enroll_cnt_method; insert tableName=code_enroll_cnt_meth...', '[PD-6974] Count Pending Approval Records in Total Current Enrollments', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170801-if-1::ivan.fung
-- [PD-7367] WebEx Training History update for not attended participants
ALTER TABLE vc_launcher_session ADD overall_status_absent int
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'vc_launcher_session'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.vc_launcher_session'; DECLARE @ColumnName SYSNAME set @ColumnName = N'overall_status_absent'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Overall status for not attended participants';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170801-if-1', 'ivan.fung', 'nschema/132.changeLog.xml', GETDATE(), 723, '8:8cffaf2dd8d0aeff8d05dc6c299c230c', 'addColumn tableName=vc_launcher_session', '[PD-7367] WebEx Training History update for not attended participants', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170803-ny::nelson.yip
-- [PD-7289] Allow a User to choose which of their assignments is displayed on login
ALTER TABLE userstats_assignment ADD lastswitchdate datetime
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'userstats_assignment'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.userstats_assignment'; DECLARE @ColumnName SYSNAME set @ColumnName = N'lastswitchdate'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'The latest time when this assignment is siwtched to';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DROP VIEW userstats
GO

CREATE VIEW userstats AS select userstats_assignment.userid, 
	               users_meta.lastlogon,
	               users_meta.lastpwchange, 
	               users_meta.nlogons,
	               users_meta.nattempts,
	               userstats_assignment.nmsgspending,
	               users_meta.elapsedloginseconds,
	               users_meta.nlogouts,
	               userstats_assignment.lastAutoEnrollUpdate,
	               users_meta.first_login,
	               users_meta.firstlogonfailure, 
	               users_meta.lastlogonfailure, 
	               users_meta.nlogonfailure, 
	               userstats_assignment.last_catalog_id,
	               users_meta.requirepwchange, 
	               users_meta.lastactivedate, 
	               users_meta.mekp_activation, 
	               users_meta.mekp_last_sync,
	               userstats_assignment.last_job_auto_assign_update,
	               userstats_assignment.last_crs_offline_auto_enroll, 
	               userstats_assignment.last_job_offline_auto_assign, 
	               users_meta.terms_of_use_accept_date,
	               userstats_assignment.lastswitchdate
	        from userstats_assignment
	        JOIN users_assignment on userstats_assignment.userid = users_assignment.userid
	        JOIN users_meta on users_assignment.user_meta_id = users_meta.user_meta_id
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170803-ny', 'nelson.yip', 'nschema/132.changeLog.xml', GETDATE(), 724, '8:527f4cd2d7679680448a590b1866e649', 'addColumn tableName=userstats_assignment; dropView viewName=userstats; createView viewName=userstats', '[PD-7289] Allow a User to choose which of their assignments is displayed on login', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170808-ny::nelson.yip
-- [PD-7385] Allow self-enrollment in Prompt User to Select session
ALTER TABLE cschedule ADD allow_self_enroll_to_prompt nvarchar(1) CONSTRAINT DF_cschedule_allow_self_enroll_to_prompt DEFAULT 'N' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'cschedule'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.cschedule'; DECLARE @ColumnName SYSNAME set @ColumnName = N'allow_self_enroll_to_prompt'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Flag to indicate self-enrollment to prompt session is allowed';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DROP VIEW cschedule_vw
GO

CREATE VIEW cschedule_vw AS SELECT
				cschedule.*,      	
				(select count(*)
				 from transcript 
				 where transcript.eventid = cschedule.eventid 
				 and transcript.studentstatus in (select studentstatus from code_enroll_cnt_method where method = cschedule.enroll_cnt_method)) nregistered	
			FROM cschedule
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170808-ny', 'nelson.yip', 'nschema/132.changeLog.xml', GETDATE(), 725, '8:f15d0c2016156c0a5176996850356d23', 'addColumn tableName=cschedule; dropView viewName=cschedule_vw; createView viewName=cschedule_vw', '[PD-7385] Allow self-enrollment in Prompt User to Select session', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170814-ny::nelson.yip
-- [PD-5873] Session related forum
ALTER TABLE cschedule ADD assigned_forum numeric(16, 0)
GO

ALTER TABLE cschedule ADD assigned_forum_type nvarchar(1) CONSTRAINT DF_cschedule_assigned_forum_type DEFAULT 'C' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'cschedule'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.cschedule'; DECLARE @ColumnName SYSNAME set @ColumnName = N'assigned_forum'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Assigned forum or category Id';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'cschedule'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.cschedule'; DECLARE @ColumnName SYSNAME set @ColumnName = N'assigned_forum_type'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'assigned forum type, C:category, F:forum';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

ALTER TABLE sessiondetail ADD assigned_forum numeric(16, 0)
GO

ALTER TABLE sessiondetail ADD assigned_forum_type nvarchar(1) CONSTRAINT DF_sessiondetail_assigned_forum_type DEFAULT 'C' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'sessiondetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.sessiondetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'assigned_forum'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Assigned forum or category Id';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'sessiondetail'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.sessiondetail'; DECLARE @ColumnName SYSNAME set @ColumnName = N'assigned_forum_type'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'assigned forum type, C:category, F:forum';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DROP VIEW cschedule_vw
GO

CREATE VIEW cschedule_vw AS SELECT
				cschedule.*,      	
				(select count(*)
				 from transcript 
				 where transcript.eventid = cschedule.eventid 
				 and transcript.studentstatus in (select studentstatus from code_enroll_cnt_method where method = cschedule.enroll_cnt_method)) nregistered	
			FROM cschedule
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170814-ny', 'nelson.yip', 'nschema/132.changeLog.xml', GETDATE(), 726, '8:b1da3279b20998c279d322f4c2612b1e', 'addColumn tableName=cschedule; addColumn tableName=sessiondetail; dropView viewName=cschedule_vw; createView viewName=cschedule_vw', '[PD-5873] Session related forum', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170822-if-1::ivan.fung
-- [PD-6133] Class Resource Code
ALTER TABLE code_training_resource ADD resource_code nvarchar(255)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'code_training_resource'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.code_training_resource'; DECLARE @ColumnName SYSNAME set @ColumnName = N'resource_code'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Class Resource Code';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170822-if-1', 'ivan.fung', 'nschema/132.changeLog.xml', GETDATE(), 727, '8:5d2b573f01f1e09016480ce9a14cd6fd', 'addColumn tableName=code_training_resource', '[PD-6133] Class Resource Code', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170822-if-2::ivan.fung
-- [PD-7539] Class Resource Picture
ALTER TABLE code_training_resource ADD resource_picture nvarchar(15)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'code_training_resource'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.code_training_resource'; DECLARE @ColumnName SYSNAME set @ColumnName = N'resource_picture'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'File repository ID for the class resource picture';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170822-if-2', 'ivan.fung', 'nschema/132.changeLog.xml', GETDATE(), 728, '8:c60da47af8615ff87d11c092f001fe89', 'addColumn tableName=code_training_resource', '[PD-7539] Class Resource Picture', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170825-yc-1::yanfang.cui
DECLARE @counter INT
				SET @counter = 0
				UPDATE code_training_resource 
				SET resource_code = 'MCR-' + (CASE WHEN LEN(@counter) > 3 THEN CAST(@counter AS VARCHAR) ELSE RIGHT('0000'+CAST(@counter AS VARCHAR(4)),4) END), @counter = @counter + 1
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170825-yc-1', 'yanfang.cui', 'nschema/132.changeLog.xml', GETDATE(), 729, '8:7c770e0fcd4111cea1cc10dad80be6dd', 'sql', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170823-tc::tommy.chu
-- [PD-7419] Option to block Session Selection reminder
ALTER TABLE cschedule ADD show_session_sel_rmdr nvarchar(1) CONSTRAINT DF_cschedule_show_session_sel_rmdr DEFAULT 'Y' NOT NULL
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'cschedule'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.cschedule'; DECLARE @ColumnName SYSNAME set @ColumnName = N'show_session_sel_rmdr'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Flag to control session selection reminder in login notification';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

DROP VIEW cschedule_vw
GO

CREATE VIEW cschedule_vw AS SELECT
				cschedule.*,      	
				(select count(*)
				 from transcript 
				 where transcript.eventid = cschedule.eventid 
				 and transcript.studentstatus in (select studentstatus from code_enroll_cnt_method where method = cschedule.enroll_cnt_method)) nregistered	
			FROM cschedule
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170823-tc', 'tommy.chu', 'nschema/132.changeLog.xml', GETDATE(), 730, '8:477c9e0a1458d380203d97a3568100e8', 'addColumn tableName=cschedule; dropView viewName=cschedule_vw; createView viewName=cschedule_vw', '[PD-7419] Option to block Session Selection reminder', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170825-yc-2::yanfang.cui
ALTER TABLE code_training_resource ALTER COLUMN resource_code nvarchar(255) NOT NULL
GO

ALTER TABLE code_training_resource ADD CONSTRAINT uk_resource_code UNIQUE (resource_code)
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170825-yc-2', 'yanfang.cui', 'nschema/132.changeLog.xml', GETDATE(), 731, '8:5a24b89ea89c60d2333bdb334202a67b', 'addNotNullConstraint columnName=resource_code, tableName=code_training_resource; addUniqueConstraint constraintName=uk_resource_code, tableName=code_training_resource', '', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170825-if-1::ivan.fung
-- [PD-7536] Class Resource Attribute Types
ALTER TABLE dynamic_attribute ADD visibility nvarchar(15)
GO

DECLARE @DynamicSchemaName SYSNAME set @DynamicSchemaName = SCHEMA_NAME();
DECLARE @TableName SYSNAME set @TableName = N'dynamic_attribute'; DECLARE @FullTableName SYSNAME set @FullTableName = @DynamicSchemaName + N'.dynamic_attribute'; DECLARE @ColumnName SYSNAME set @ColumnName = N'visibility'; DECLARE @MS_DescriptionValue NVARCHAR(3749); SET @MS_DescriptionValue = N'Visibility for dynamic attribute';DECLARE @MS_Description NVARCHAR(3749) set @MS_Description = NULL; SET @MS_Description = (SELECT CAST(Value AS NVARCHAR(3749)) AS [MS_Description] FROM sys.extended_properties AS ep WHERE ep.major_id = OBJECT_ID(@FullTableName) AND ep.minor_id=COLUMNPROPERTY(ep.major_id, @ColumnName, 'ColumnId') AND ep.name = N'MS_Description'); IF @MS_Description IS NULL BEGIN EXEC sys.sp_addextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END ELSE BEGIN EXEC sys.sp_updateextendedproperty @name  = N'MS_Description', @value = @MS_DescriptionValue, @level0type = N'SCHEMA', @level0name = @DynamicSchemaName, @level1type = N'TABLE', @level1name = @TableName, @level2type = N'COLUMN', @level2name = @ColumnName; END
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170825-if-1', 'ivan.fung', 'nschema/132.changeLog.xml', GETDATE(), 732, '8:6657af693603ca294545d82b835b3808', 'addColumn tableName=dynamic_attribute', '[PD-7536] Class Resource Attribute Types', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170825-if-2::ivan.fung
-- [PD-7536] Recreate view for dynamic_attribute
DROP VIEW dynamic_attribute_vw
GO

create view dynamic_attribute_vw as 
				SELECT        attribute_id, code, display_areas, label_key, type, sum_total, attr_order, is_mandatory, category, domain_id, visibility
					FROM            dynamic_attribute
				UNION ALL
				SELECT        distinct CONVERT(varchar(11), uel.extension_no), 'UAE-' + CAST(uel.extension_no AS VARCHAR), uel.display_areas, uel.label, case when cue.extension_no is not null then 'D' else 'F' end as type, 'N', uel.extension_no, 'N', 'UE', uel.domain_id, ''
					FROM            user_extension_label uel
					left join code_user_extension  cue on uel.extension_no = cue.extension_no
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170825-if-2', 'ivan.fung', 'nschema/132.changeLog.xml', GETDATE(), 733, '8:bbf417e39435cf23ea22a5a0954f26dc', 'dropView viewName=dynamic_attribute_vw; sql; sql; sql', '[PD-7536] Recreate view for dynamic_attribute', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170825-if-3::ivan.fung
-- [PD-7536] Migration for class resource attribute to dynamic attribute
INSERT INTO dynamic_attribute (attribute_id, code, label_key, visibility, type, display_areas, sum_total, attr_order, is_mandatory, category, domain_id) 
			SELECT 
				attribute_id, 
				code, 
				label_key, 
				visibility, 
				CASE type WHEN 'T' THEN 'F' ELSE 'S' END, 
				'',
				'N',
				0,
				'N',
				'CR',
				'DEFAULT' 
			FROM dynamic_resource_attribute
GO

INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('20170825-if-3', 'ivan.fung', 'nschema/132.changeLog.xml', GETDATE(), 734, '8:2ca1261d3eed41240f66fb903eb6ae29', 'sql', '[PD-7536] Migration for class resource attribute to dynamic attribute', 'EXECUTED', NULL, NULL, '4.8.0', '0912889689')
GO

-- Changeset nschema/132.changeLog.xml::20170904-ny-1::nelson.yip
-- [PD-7678] Introduce a Transcript History/Audit Trail
