
--Migration_RCCP_20250609_130215.txt
CREATE TABLE [dbo].[SessionEntityLinks] (
    [Id] [bigint] NOT NULL IDENTITY,
    [SessionId] [bigint] NOT NULL,
    [EntityType] [nvarchar](max),
    [EntityId] [nvarchar](max),
    CONSTRAINT [PK_dbo.SessionEntityLinks] PRIMARY KEY ([Id])
)
ALTER TABLE [dbo].[Sessions] ADD [Type] [nvarchar](max)
ALTER TABLE [dbo].[Sessions] ADD [EntityType] [nvarchar](max)
ALTER TABLE [dbo].[Sessions] ADD [StartTime] [datetime]
ALTER TABLE [dbo].[Sessions] ADD [EndTime] [datetime]
ALTER TABLE [dbo].[Sessions] ADD [StartDate] [datetime] NOT NULL DEFAULT '1900-01-01T00:00:00.000'
ALTER TABLE [dbo].[Sessions] ADD [EndDate] [datetime] NOT NULL DEFAULT '1900-01-01T00:00:00.000'
ALTER TABLE [dbo].[Sessions] ADD [CompanyId] [bigint] NOT NULL DEFAULT 0
ALTER TABLE [dbo].[Sessions] ADD [CreatedByUserId] [bigint] NOT NULL DEFAULT 0
ALTER TABLE [dbo].[Sessions] ADD [CreatedUtcDateTime] [datetime] NOT NULL DEFAULT '1900-01-01T00:00:00.000'
ALTER TABLE [dbo].[Sessions] ADD [LastUpdatedUtcDateTime] [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.Sessions')
AND col_name(parent_object_id, parent_column_id) = 'BranchId';
IF @var0 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[Sessions] DROP CONSTRAINT [' + @var0 + ']')
ALTER TABLE [dbo].[Sessions] DROP COLUMN [BranchId]
DECLARE @var1 nvarchar(128)
SELECT @var1 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.Sessions')
AND col_name(parent_object_id, parent_column_id) = 'AreaId';
IF @var1 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[Sessions] DROP CONSTRAINT [' + @var1 + ']')
ALTER TABLE [dbo].[Sessions] DROP COLUMN [AreaId]
DECLARE @var2 nvarchar(128)
SELECT @var2 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.Sessions')
AND col_name(parent_object_id, parent_column_id) = 'StartDateTime';
IF @var2 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[Sessions] DROP CONSTRAINT [' + @var2 + ']')
ALTER TABLE [dbo].[Sessions] DROP COLUMN [StartDateTime]
DECLARE @var3 nvarchar(128)
SELECT @var3 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.Sessions')
AND col_name(parent_object_id, parent_column_id) = 'EndDateTime';
IF @var3 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[Sessions] DROP CONSTRAINT [' + @var3 + ']')
ALTER TABLE [dbo].[Sessions] DROP COLUMN [EndDateTime]
DECLARE @var4 nvarchar(128)
SELECT @var4 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.SessionInstances')
AND col_name(parent_object_id, parent_column_id) = 'Name';
IF @var4 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[SessionInstances] DROP CONSTRAINT [' + @var4 + ']')
ALTER TABLE [dbo].[SessionInstances] DROP COLUMN [Name]
DECLARE @var5 nvarchar(128)
SELECT @var5 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.SessionInstances')
AND col_name(parent_object_id, parent_column_id) = 'AreaId';
IF @var5 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[SessionInstances] DROP CONSTRAINT [' + @var5 + ']')
ALTER TABLE [dbo].[SessionInstances] DROP COLUMN [AreaId]
