IF OBJECT_ID(N'[dbo].[NEXORA_ITEMSHOP_REWARD_DELIVERIES]', N'U') IS NULL
BEGIN
    CREATE TABLE [dbo].[NEXORA_ITEMSHOP_REWARD_DELIVERIES](
        [id] bigint IDENTITY(1,1) NOT NULL PRIMARY KEY,[reference_key] varchar(120) NOT NULL,[source] varchar(30) NOT NULL,
        [user_id] int NOT NULL,[account_username] varchar(50) NOT NULL,[item_id] int NOT NULL,[item_name] nvarchar(100) NOT NULL,
        [status] varchar(20) NOT NULL,[warehouse_slot] smallint NULL,[item_serial] bigint NULL,[created_at] datetime2 NOT NULL DEFAULT(SYSUTCDATETIME()),
        [delivered_at] datetime2 NULL,CONSTRAINT [UX_NISRD_reference] UNIQUE([reference_key])
    );
    CREATE INDEX [IX_NISRD_account] ON [dbo].[NEXORA_ITEMSHOP_REWARD_DELIVERIES]([account_username],[created_at] DESC);
END;
