-- Create Table
IF OBJECT_ID(N'[dbo].[Prj_T_Milestone]', N'U') IS NULL
BEGIN
    CREATE TABLE [dbo].[Prj_T_Milestone] (
        [Id]                   UNIQUEIDENTIFIER NOT NULL CONSTRAINT [PK_Prj_T_Milestone] PRIMARY KEY,
        [TenantId]             UNIQUEIDENTIFIER NULL,
        [Name]                 NVARCHAR(300)    NOT NULL,
        [TargetDate]           DATETIME2        NULL,
        [IsCompleted]          BIT              NOT NULL CONSTRAINT [DF_Prj_T_Milestone_IsCompleted] DEFAULT (0),
        [CreationTime]         DATETIME2        NOT NULL CONSTRAINT [DF_Prj_T_Milestone_CreationTime] DEFAULT (GETUTCDATE()),
        [CreatorId]            UNIQUEIDENTIFIER NULL,
        [LastModificationTime] DATETIME2        NULL,
        [LastModifierId]       UNIQUEIDENTIFIER NULL,
        [IsDeleted]            BIT              NOT NULL CONSTRAINT [DF_Prj_T_Milestone_IsDeleted] DEFAULT (0),
        [DeletionTime]         DATETIME2        NULL,
        [DeleterId]            UNIQUEIDENTIFIER NULL
    );
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'IX_Prj_T_Milestone_TenantId_Name' AND object_id = OBJECT_ID(N'[dbo].[Prj_T_Milestone]'))
    CREATE INDEX [IX_Prj_T_Milestone_TenantId_Name] ON [dbo].[Prj_T_Milestone] ([TenantId] ASC, [Name] ASC);
GO
