USE [REPLACE Cloud Assert Billing DB Name Here!!!]
GO

DECLARE @var0 nvarchar(128)
SELECT @var0 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.BillingInvoices')
AND col_name(parent_object_id, parent_column_id) = 'SubscriptionName';
IF @var0 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[BillingInvoices] DROP CONSTRAINT [' + @var0 + ']')
ALTER TABLE [dbo].[BillingInvoices] DROP COLUMN [SubscriptionName]
DELETE [dbo].[__MigrationHistory]
WHERE (([MigrationId] = N'201711231145116_AddSubscriptionNameColumnForInvoice') AND ([ContextKey] = N'CloudAssert.WAP.Billing.Persistence.Sql.Migrations.Configuration'))
DECLARE @var1 nvarchar(128)
SELECT @var1 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.BillingInvoiceLineItems')
AND col_name(parent_object_id, parent_column_id) = 'ServiceType';
IF @var1 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[BillingInvoiceLineItems] DROP CONSTRAINT [' + @var1 + ']')
ALTER TABLE [dbo].[BillingInvoiceLineItems] DROP COLUMN [ServiceType]
DECLARE @var2 nvarchar(128)
SELECT @var2 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.BillingInvoiceLineItems')
AND col_name(parent_object_id, parent_column_id) = 'Provider';
IF @var2 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[BillingInvoiceLineItems] DROP CONSTRAINT [' + @var2 + ']')
ALTER TABLE [dbo].[BillingInvoiceLineItems] DROP COLUMN [Provider]
DECLARE @var3 nvarchar(128)
SELECT @var3 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.BillingUserInvoiceLineItems')
AND col_name(parent_object_id, parent_column_id) = 'ServiceType';
IF @var3 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[BillingUserInvoiceLineItems] DROP CONSTRAINT [' + @var3 + ']')
ALTER TABLE [dbo].[BillingUserInvoiceLineItems] DROP COLUMN [ServiceType]
DECLARE @var4 nvarchar(128)
SELECT @var4 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.BillingUserInvoiceLineItems')
AND col_name(parent_object_id, parent_column_id) = 'Provider';
IF @var4 IS NOT NULL
    EXECUTE('ALTER TABLE [dbo].[BillingUserInvoiceLineItems] DROP CONSTRAINT [' + @var4 + ']')
ALTER TABLE [dbo].[BillingUserInvoiceLineItems] DROP COLUMN [Provider]
DELETE [dbo].[__MigrationHistory]
WHERE (([MigrationId] = N'201711231019595_AddServiceTypeAndProviderColumnsInLineItemTables') AND ([ContextKey] = N'CloudAssert.WAP.Billing.Persistence.Sql.Migrations.Configuration'))
