IF EXISTS(SELECT * FROM sys.tables WHERE name = 'BA_SiteTypeMetadataDefinitions_DEPRECATED_6_15')
BEGIN	
	EXEC sp_rename 'BA_SiteTypeMetadataDefinitions_DEPRECATED_6_15', 'BA_SiteTypeMetadataDefinitions' 

	ALTER TABLE [dbo].[BA_SiteTypeMetadataDefinitions]
	ADD CONSTRAINT [FK_BA_SiteTypeBA_SiteTypeMetadataDefinition]
		FOREIGN KEY ([BA_SiteTypeId])
		REFERENCES [dbo].[BA_SiteType]
			([Id])
		ON DELETE NO ACTION ON UPDATE NO ACTION;

	ALTER TABLE [dbo].[BA_SiteTypeMetadataDefinitions]
	ADD CONSTRAINT [FK_BA_MetadataDefinitionBA_SiteTypeMetadataDefinition]
		FOREIGN KEY ([BA_MetadataDefinitionId])
		REFERENCES [dbo].[BA_MetadataDefinition]
			([Id])
		ON DELETE NO ACTION ON UPDATE NO ACTION
END

IF EXISTS(SELECT * FROM sys.tables WHERE name = 'BA_SiteTypeMetadataDefinition')
BEGIN	
	EXEC sp_rename 'BA_SiteTypeMetadataDefinition', 'BA_SiteTypeMetadataDefinition_DEPRECATED_6_15'; 
	IF OBJECT_ID(N'[dbo].[FK_SiteTypeMetadataDefinition_SiteType]', 'F') IS NOT NULL
		ALTER TABLE [dbo].BA_SiteTypeMetadataDefinition_DEPRECATED_6_15 DROP CONSTRAINT [FK_SiteTypeMetadataDefinition_SiteType];
	IF OBJECT_ID(N'[dbo].[FK_SiteTypeMetadataDefinition_MetadataDefinition]', 'F') IS NOT NULL
	    ALTER TABLE [dbo].BA_SiteTypeMetadataDefinition_DEPRECATED_6_15 DROP CONSTRAINT [FK_SiteTypeMetadataDefinition_MetadataDefinition];
END