CREATE UNIQUE INDEX [IX_Name_CatalogId] ON [dbo].[Property]([Name], [CatalogId])
ALTER TABLE [dbo].[Property] ADD [TargetType] [nvarchar](128)
ALTER TABLE [dbo].[EditorialReview] ADD [Locale] [nvarchar](64)
GO
                ALTER TRIGGER [TR_CategoryDeleteTrigger] ON [dbo].[Category]
                FOR DELETE
                AS
                BEGIN

                IF(EXISTS((SELECT CategoryId FROM [deleted])))
	                BEGIN

		                DECLARE @TempParentCategoryId TABLE
		                (
		                   CategoryId nvarchar(128)
		                );

		                INSERT INTO @TempParentCategoryId 
		                SELECT CategoryId FROM [dbo].[CategoryBase] 
		                WHERE ParentCategoryId IN (SELECT CategoryId FROM [deleted])

		                DELETE FROM [dbo].[Category] WHERE CategoryId IN (SELECT CategoryId FROM @TempParentCategoryId)
		                DELETE FROM [dbo].[LinkedCategory] WHERE LinkedCategoryId IN (SELECT CategoryId FROM [deleted])
		                DELETE FROM [dbo].[LinkedCategory] WHERE CategoryId IN (SELECT CategoryId FROM @TempParentCategoryId)
		                DELETE FROM [dbo].[CategoryItemRelation] WHERE CategoryId IN (SELECT CategoryId FROM [deleted])
		                DELETE FROM [dbo].[CategoryItemRelation] WHERE CategoryId IN (SELECT CategoryId FROM @TempParentCategoryId)
		                DELETE FROM [dbo].[CategoryBase] WHERE ParentCategoryId IN (SELECT CategoryId FROM [deleted])
                        IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'SeoUrlKeyword'))
	                    BEGIN
		                    DELETE FROM [dbo].[SeoUrlKeyword] WHERE KeywordType = 0 AND KeywordValue IN (SELECT CategoryId FROM [deleted])
	                    END
	                END
                END
GO
                CREATE TRIGGER [dbo].[TR_ItemDeleteTrigger] ON [dbo].[Item] 
                FOR DELETE AS
                BEGIN
	                IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'SeoUrlKeyword'))
	                BEGIN
		                DELETE FROM [dbo].[SeoUrlKeyword] WHERE KeywordType = 1 AND KeywordValue IN (SELECT ItemId FROM [deleted])
	                END
                END
GO

INSERT [dbo].[__MigrationHistory]([MigrationId], [ContextKey], [Model], [ProductVersion])
VALUES (N'201409031214424_EditorialReviewLocale_SeoTriggers', N'VCF.Catalogs',  0x[encoded data, 19922 characters] , N'6.0.2-21211')
