IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[GiftTokenTypeDiscount]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[GiftTokenTypeDiscount]
  (
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [FK_GiftTokenTypeId] [int] NOT NULL,
    [AmountFrom] [money] NOT NULL,
    [AmountTo] [money] NOT NULL,
    [DiscountValue] [money] NOT NULL,
    [DiscountType] [tinyint] NOT NULL,
    CONSTRAINT [PK_GiftTokenTypeDiscount] PRIMARY KEY CLUSTERED 
    (
      [Id] ASC
    )
  ) ON [PRIMARY]

  ALTER TABLE [dbo].[GiftTokenTypeDiscount]  WITH CHECK ADD  CONSTRAINT [FK_GiftTokenTypeDiscount_GiftTokenType] FOREIGN KEY([FK_GiftTokenTypeId])
  REFERENCES [dbo].[GiftTokenType] ([Id])

  ALTER TABLE [dbo].[GiftTokenTypeDiscount] CHECK CONSTRAINT [FK_GiftTokenTypeDiscount_GiftTokenType]
END
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[GiftTokenTypePeriod]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[GiftTokenTypePeriod]
  (
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [FK_GiftTokenTypeId] [int] NOT NULL,
    [SalesPeriodFrom] [datetime] NOT NULL,
    [SalesPeriodTo] [datetime] NOT NULL,
    CONSTRAINT [PK_GiftTokenTypePeriod] PRIMARY KEY CLUSTERED 
    (
      [Id] ASC
    )
  ) ON [PRIMARY]

  ALTER TABLE [dbo].[GiftTokenTypePeriod]  WITH CHECK ADD  CONSTRAINT [FK_GiftTokenTypePeriod_GiftTokenType] FOREIGN KEY([FK_GiftTokenTypeId])
  REFERENCES [dbo].[GiftTokenType] ([Id])

  ALTER TABLE [dbo].[GiftTokenTypePeriod] CHECK CONSTRAINT [FK_GiftTokenTypePeriod_GiftTokenType]
END
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'FK_CampaignCodeNumber'
    WHERE SysObjects.Name = 'GiftTokenType'
)
BEGIN
  ALTER TABLE GiftTokenType ADD FK_CampaignCodeNumber SMALLINT NULL 
END
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OnlineDescription'
    WHERE SysObjects.Name = 'GiftTokenType'
)
BEGIN
  ALTER TABLE GiftTokenType ADD OnlineDescription VARCHAR(MAX) NULL 
END
GO