-- Drop Sprocs
DROP PROCEDURE [dbo].[ToSIC_EAV_LogToTimeline]
GO

DROP PROCEDURE [dbo].[ToSIC_EAV_DeleteApp]
GO

DROP PROCEDURE [dbo].[ToSIC_EAV_ChangeLogSet]
GO

DROP PROCEDURE [dbo].[ToSIC_EAV_ChangeLogGet]
GO

DROP PROCEDURE [dbo].[ToSIC_EAV_ChangeLogAdd]
GO

-- Drop Constraints
ALTER TABLE [dbo].[ToSIC_EAV_ValuesDimensions] DROP CONSTRAINT [FK_ToSIC_EAV_ValuesDimensions_ToSIC_EAV_Values]
GO

ALTER TABLE [dbo].[ToSIC_EAV_ValuesDimensions] DROP CONSTRAINT [FK_ToSIC_EAV_ValuesDimensions_ToSIC_EAV_Dimensions]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Values] DROP CONSTRAINT [FK_ToSIC_EAV_Values_ToSIC_EAV_Entities]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Values] DROP CONSTRAINT [FK_ToSIC_EAV_Values_ToSIC_EAV_ChangeLogModified]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Values] DROP CONSTRAINT [FK_ToSIC_EAV_Values_ToSIC_EAV_ChangeLogDeleted]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Values] DROP CONSTRAINT [FK_ToSIC_EAV_Values_ToSIC_EAV_ChangeLogCreated]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Values] DROP CONSTRAINT [FK_ToSIC_EAV_Values_ToSIC_EAV_Attributes]
GO

ALTER TABLE [dbo].[ToSIC_EAV_EntityRelationships] DROP CONSTRAINT [FK_ToSIC_EAV_EntityRelationships_ToSIC_EAV_ParentEntities]
GO

ALTER TABLE [dbo].[ToSIC_EAV_EntityRelationships] DROP CONSTRAINT [FK_ToSIC_EAV_EntityRelationships_ToSIC_EAV_ChildEntities]
GO

ALTER TABLE [dbo].[ToSIC_EAV_EntityRelationships] DROP CONSTRAINT [FK_ToSIC_EAV_EntityRelationships_ToSIC_EAV_Attributes]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Entities] DROP CONSTRAINT [FK_ToSIC_EAV_Entities_ToSIC_EAV_Entities]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Entities] DROP CONSTRAINT [FK_ToSIC_EAV_Entities_ToSIC_EAV_ChangeLogDeleted]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Entities] DROP CONSTRAINT [FK_ToSIC_EAV_Entities_ToSIC_EAV_ChangeLogCreated]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Entities] DROP CONSTRAINT [FK_ToSIC_EAV_Entities_ToSIC_EAV_ChangeLog_Modified]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Entities] DROP CONSTRAINT [FK_ToSIC_EAV_Entities_ToSIC_EAV_AttributeSets]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Entities] DROP CONSTRAINT [FK_ToSIC_EAV_Entities_ToSIC_EAV_AssignmentObjectTypes]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Entities] DROP CONSTRAINT [FK_ToSIC_EAV_Entities_ToSIC_EAV_Apps]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Dimensions] DROP CONSTRAINT [FK_ToSIC_EAV_Dimensions_ToSIC_EAV_Zones]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Dimensions] DROP CONSTRAINT [FK_ToSIC_EAV_Dimensions_ToSIC_EAV_Dimensions1]
GO

ALTER TABLE [dbo].[ToSIC_EAV_AttributesInSets] DROP CONSTRAINT [FK_ToSIC_EAV_AttributesInSets_ToSIC_EAV_AttributeSets]
GO

ALTER TABLE [dbo].[ToSIC_EAV_AttributesInSets] DROP CONSTRAINT [FK_ToSIC_EAV_AttributesInSets_ToSIC_EAV_Attributes]
GO

ALTER TABLE [dbo].[ToSIC_EAV_AttributesInSets] DROP CONSTRAINT [FK_ToSIC_EAV_AttributesInSets_ToSIC_EAV_AttributeGroups]
GO

ALTER TABLE [dbo].[ToSIC_EAV_AttributeSets] DROP CONSTRAINT [FK_ToSIC_EAV_AttributeSets_ToSIC_EAV_ChangeLogDeleted]
GO

ALTER TABLE [dbo].[ToSIC_EAV_AttributeSets] DROP CONSTRAINT [FK_ToSIC_EAV_AttributeSets_ToSIC_EAV_ChangeLogCreated]
GO

ALTER TABLE [dbo].[ToSIC_EAV_AttributeSets] DROP CONSTRAINT [FK_ToSIC_EAV_AttributeSets_ToSIC_EAV_AttributeSets]
GO

ALTER TABLE [dbo].[ToSIC_EAV_AttributeSets] DROP CONSTRAINT [FK_ToSIC_EAV_AttributeSets_ToSIC_EAV_Apps]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Attributes] DROP CONSTRAINT [FK_ToSIC_EAV_Attributes_ToSIC_EAV_Types]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Attributes] DROP CONSTRAINT [FK_ToSIC_EAV_Attributes_ToSIC_EAV_ChangeLogDeleted]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Attributes] DROP CONSTRAINT [FK_ToSIC_EAV_Attributes_ToSIC_EAV_ChangeLogCreated]
GO

ALTER TABLE [dbo].[ToSIC_EAV_AttributeGroups] DROP CONSTRAINT [FK_ToSIC_EAV_AttributeGroups_ToSIC_EAV_AttributeSets]
GO

ALTER TABLE [dbo].[ToSIC_EAV_Apps] DROP CONSTRAINT [FK_ToSIC_EAV_Apps_ToSIC_EAV_Zones]
GO

ALTER TABLE [dbo].[ToSIC_EAV_ChangeLog] DROP CONSTRAINT [DF_ToSIC_EAV_ChangeLog_Timestamp]
GO

-- Drop Tables
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_Zones]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_Zones]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_ValuesDimensions]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_ValuesDimensions]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_Values]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_Values]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_EntityRelationships]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_EntityRelationships]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_Entities]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_Entities]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_Dimensions]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_Dimensions]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_DataTimeline]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_DataTimeline]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_ContextInfo]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_ContextInfo]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_AttributeTypes]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_AttributeTypes]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_AttributesInSets]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_AttributesInSets]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_AttributeSets]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_AttributeSets]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_Attributes]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_Attributes]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_AttributeGroups]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_AttributeGroups]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_AssignmentObjectTypes]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_AssignmentObjectTypes]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_Apps]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_Apps]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_Attachments]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_Attachments]
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_SexyContent_ContentGroupItems]') AND TYPE IN (N'U'))
DROP TABLE [dbo].[ToSIC_SexyContent_ContentGroupItems]
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_SexyContent_Templates]') AND TYPE IN (N'U'))
DROP TABLE [dbo].[ToSIC_SexyContent_Templates]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToSIC_EAV_ChangeLog]') AND type in (N'U'))
DROP TABLE [dbo].[ToSIC_EAV_ChangeLog]
GO

-- Remove PortalSettings
DELETE FROM PortalSettings
WHERE (SettingName = N'ToSIC_SexyContent_ZoneID')