
--Migration_RCCP_20230817_114657.txt
CREATE TABLE [dbo].[DateCommentDetails] (
    [ID] [bigint] NOT NULL IDENTITY,
    [UserCommentId] [bigint] NOT NULL,
    [StartUtcDateTime] [datetime] NOT NULL,
    [EndUtcDateTime] [datetime] NOT NULL,
    CONSTRAINT [PK_dbo.DateCommentDetails] PRIMARY KEY ([ID])
)
CREATE TABLE [dbo].[EntityCommentDetails] (
    [ID] [bigint] NOT NULL IDENTITY,
    [UserCommentId] [bigint] NOT NULL,
    [EntityType] [int] NOT NULL,
    [EntityId] [nvarchar](max),
    CONSTRAINT [PK_dbo.EntityCommentDetails] PRIMARY KEY ([ID])
)
ALTER TABLE [dbo].[UserComments] ADD [CompanyId] [bigint] NOT NULL DEFAULT 0
ALTER TABLE [dbo].[UserComments] ADD [UserId] [bigint] NOT NULL DEFAULT 0
ALTER TABLE [dbo].[UserComments] ADD [CreatedUtcDateTime] [datetime] NOT NULL DEFAULT '1900-01-01T00:00:00.000'
DECLARE @var0 nvarchar(128)
SELECT @var0 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.UserComments')
AND col_name(parent_object_id, parent_column_id) = 'CreatedDateTime';
IF @var0 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[UserComments] DROP CONSTRAINT [' + @var0 + ']')
ALTER TABLE [dbo].[UserComments] DROP COLUMN [CreatedDateTime]
DECLARE @var1 nvarchar(128)
SELECT @var1 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.UserComments')
AND col_name(parent_object_id, parent_column_id) = 'EntityType';
IF @var1 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[UserComments] DROP CONSTRAINT [' + @var1 + ']')
ALTER TABLE [dbo].[UserComments] DROP COLUMN [EntityType]
DECLARE @var2 nvarchar(128)
SELECT @var2 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.UserComments')
AND col_name(parent_object_id, parent_column_id) = 'EntityId';
IF @var2 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[UserComments] DROP CONSTRAINT [' + @var2 + ']')
ALTER TABLE [dbo].[UserComments] DROP COLUMN [EntityId]
