-- Migration: 021_CreateWorkOrderComponentCurrTable
-- Source: OLD/Database/Tables/WorkOrderComponent_Curr.sql
-- Changes: DATETIME -> DATETIME2(7)

IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'WorkOrderComponent_Curr' AND schema_id = SCHEMA_ID('dbo'))
BEGIN
    CREATE TABLE [dbo].[WorkOrderComponent_Curr]
    (
        [UniqueID] BIGINT NOT NULL,
        [WorkOrderNumber] BIGINT NOT NULL,
        [LotNumber] VARCHAR(30) NOT NULL,
        [BranchCode] VARCHAR(12) NULL,
        [ShortItemNumber] BIGINT NOT NULL,
        [Quantity] DECIMAL(15, 2) NOT NULL,
        [LastUpdateDT] DATETIME2(7) NOT NULL,
        CONSTRAINT [PK_WorkOrderComponent_Curr] PRIMARY KEY CLUSTERED([UniqueID])
    );
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE name = 'IX_WorkOrderComponent_Curr_WorkOrderNumber' AND object_id = OBJECT_ID('dbo.WorkOrderComponent_Curr'))
BEGIN
    CREATE INDEX [IX_WorkOrderComponent_Curr_WorkOrderNumber] ON [dbo].[WorkOrderComponent_Curr] ([WorkOrderNumber]);
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE name = 'IX_WorkOrderComponent_Curr_LotLookup' AND object_id = OBJECT_ID('dbo.WorkOrderComponent_Curr'))
BEGIN
    CREATE INDEX [IX_WorkOrderComponent_Curr_LotLookup] ON [dbo].[WorkOrderComponent_Curr] ([LotNumber], [ShortItemNumber], [BranchCode]);
END
GO
