-- Migration: 010_CreateOrgHierarchyTable
-- Source: OLD/Database/Tables/OrgHierarchy.sql
-- Changes: DATETIME -> DATETIME2(7)

IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'OrgHierarchy' AND schema_id = SCHEMA_ID('dbo'))
BEGIN
    CREATE TABLE [dbo].[OrgHierarchy]
    (
        [WorkCenterCode] VARCHAR(12) NOT NULL,
        [BranchCode] VARCHAR(12) NOT NULL,
        [ProfitCenterCode] VARCHAR(12) NOT NULL,
        [LastUpdateDT] DATETIME2(7) NOT NULL,
        CONSTRAINT [PK_OrgHierarchy] PRIMARY KEY CLUSTERED([WorkCenterCode], [BranchCode])
    );
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE name = 'IX_OrgHierarchy_ProfitCenterCode' AND object_id = OBJECT_ID('dbo.OrgHierarchy'))
BEGIN
    CREATE INDEX [IX_OrgHierarchy_ProfitCenterCode] ON [dbo].[OrgHierarchy] ([ProfitCenterCode]) INCLUDE([WorkCenterCode]);
END
GO
