SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
PRINT N'Dropping index [NonClusteredIndex_LoadingInfoID_PrincipalMemberships] from [dbo].[PrincipalMemberships]'
GO
DROP INDEX [NonClusteredIndex_LoadingInfoID_PrincipalMemberships] ON [dbo].[PrincipalMemberships]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping index [NonClusteredIndex_LoadingInfoID_ScopeID] from [dbo].[RoleAssignments]'
GO
DROP INDEX [NonClusteredIndex_LoadingInfoID_ScopeID] ON [dbo].[RoleAssignments]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping index [NonClusteredIndex_LoadingInfoID_ScopeAssignments] from [dbo].[ScopeAssignments]'
GO
DROP INDEX [NonClusteredIndex_LoadingInfoID_ScopeAssignments] ON [dbo].[ScopeAssignments]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping index [NonClusteredIndex_LoadingInfoID_SharePointObjectMemberships] from [dbo].[SharePointObjectMemberships]'
GO
DROP INDEX [NonClusteredIndex_LoadingInfoID_SharePointObjectMemberships] ON [dbo].[SharePointObjectMemberships]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[ContentType]'
GO
CREATE TABLE [dbo].[ContentType]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[SharePointID] [nvarchar] (max) NOT NULL,
[ParentID] [int] NULL,
[ParentSiteID] [int] NULL,
[Name] [nvarchar] (max) NOT NULL,
[ContentTypeGroup] [nvarchar] (max) NULL,
[Description] [nvarchar] (max) NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_ContentType] on [dbo].[ContentType]'
GO
ALTER TABLE [dbo].[ContentType] ADD CONSTRAINT [PK_ContentType] PRIMARY KEY CLUSTERED  ([ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[PermissionScopeAlterations]'
GO
CREATE TABLE [dbo].[PermissionScopeAlterations]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[ScopeID] [int] NOT NULL,
[SharePointObjectTypeID] [int] NOT NULL,
[WebApplicationID] [int] NOT NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_PermissionScopeAlterations] on [dbo].[PermissionScopeAlterations]'
GO
ALTER TABLE [dbo].[PermissionScopeAlterations] ADD CONSTRAINT [PK_PermissionScopeAlterations] PRIMARY KEY CLUSTERED  ([ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[SharePointObjectContentType]'
GO
CREATE TABLE [dbo].[SharePointObjectContentType]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[SharePointObjectID] [int] NOT NULL,
[ContentTypeID] [int] NOT NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_SharePointObjectContentType] on [dbo].[SharePointObjectContentType]'
GO
ALTER TABLE [dbo].[SharePointObjectContentType] ADD CONSTRAINT [PK_SharePointObjectContentType] PRIMARY KEY CLUSTERED  ([ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[ContentDatabases]'
GO
CREATE TABLE [dbo].[ContentDatabases]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[SPGuid] [uniqueidentifier] NOT NULL,
[Name] [nvarchar] (255) NOT NULL,
[ServerName] [nvarchar] (255) NOT NULL,
[SiteCollectionCount] [int] NOT NULL,
[Size] [float] NOT NULL,
[PercentageUsed] [float] NOT NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_ContentDatabases] on [dbo].[ContentDatabases]'
GO
ALTER TABLE [dbo].[ContentDatabases] ADD CONSTRAINT [PK_ContentDatabases] PRIMARY KEY CLUSTERED  ([ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[SiteCollectionsContentDatabase]'
GO
CREATE TABLE [dbo].[SiteCollectionsContentDatabase]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[ContentDatabaseID] [int] NOT NULL,
[SiteCollectionID] [int] NOT NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_SiteCollectionsContentDatabase] on [dbo].[SiteCollectionsContentDatabase]'
GO
ALTER TABLE [dbo].[SiteCollectionsContentDatabase] ADD CONSTRAINT [PK_SiteCollectionsContentDatabase] PRIMARY KEY CLUSTERED  ([ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[DeliveryMethods]'
GO
CREATE TABLE [dbo].[DeliveryMethods]
(
[DeliveryMethodID] [int] NOT NULL,
[Name] [nvarchar] (100) NOT NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_DeliveryMethods] on [dbo].[DeliveryMethods]'
GO
ALTER TABLE [dbo].[DeliveryMethods] ADD CONSTRAINT [PK_DeliveryMethods] PRIMARY KEY CLUSTERED  ([DeliveryMethodID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[SubscriptionDeliveryMethods]'
GO
CREATE TABLE [dbo].[SubscriptionDeliveryMethods]
(
[SubscriptionID] [int] NOT NULL,
[DeliveryMethodID] [int] NOT NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_SubscriptionDeliveryMethods] on [dbo].[SubscriptionDeliveryMethods]'
GO
ALTER TABLE [dbo].[SubscriptionDeliveryMethods] ADD CONSTRAINT [PK_SubscriptionDeliveryMethods] PRIMARY KEY CLUSTERED  ([SubscriptionID], [DeliveryMethodID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[EmailSubscriptions]'
GO
ALTER TABLE [dbo].[EmailSubscriptions] ADD
[CreateZipFile] [bit] NOT NULL CONSTRAINT [DF_EmailSubscriptions_CreateZipFile] DEFAULT ((0)),
[CombinedOrZippedFileName] [nvarchar] (500) NOT NULL CONSTRAINT [DF_EmailSubscriptions_CombinedOrZippedFileName] DEFAULT ('')
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[RuleHistory]'
GO
ALTER TABLE [dbo].[RuleHistory] ADD
[SucceededCount] [int] NOT NULL CONSTRAINT [DF_RuleHistory_Succeeded] DEFAULT ((0)),
[FailedCount] [int] NOT NULL CONSTRAINT [DF_RuleHistory_Failed] DEFAULT ((0))
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[SharePointObjects]'
GO
ALTER TABLE [dbo].[SharePointObjects] ADD
[SiteSize] [bigint] NULL CONSTRAINT [DF_SharePointObjects_SiteSize] DEFAULT ((0)),
[MaxQuota] [bigint] NULL CONSTRAINT [DF_SharePointObjects_MaxQuota] DEFAULT ((0))
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [PrincipalMemberships_LoadingInfoID_GroupID] on [dbo].[PrincipalMemberships]'
GO
CREATE NONCLUSTERED INDEX [PrincipalMemberships_LoadingInfoID_GroupID] ON [dbo].[PrincipalMemberships] ([LoadingInfoID], [GroupID]) INCLUDE ([UserID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [PrincipalMemberships_LoadingInfoID_UserID] on [dbo].[PrincipalMemberships]'
GO
CREATE NONCLUSTERED INDEX [PrincipalMemberships_LoadingInfoID_UserID] ON [dbo].[PrincipalMemberships] ([LoadingInfoID], [UserID]) INCLUDE ([GroupID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [RoleAssignments_LoadingInfoID_PrincipalID] on [dbo].[RoleAssignments]'
GO
CREATE NONCLUSTERED INDEX [RoleAssignments_LoadingInfoID_PrincipalID] ON [dbo].[RoleAssignments] ([LoadingInfoID], [PrincipalID]) INCLUDE ([RoleID], [ScopeID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [RoleAssignments_LoadingInfoID_ScopeID] on [dbo].[RoleAssignments]'
GO
CREATE NONCLUSTERED INDEX [RoleAssignments_LoadingInfoID_ScopeID] ON [dbo].[RoleAssignments] ([LoadingInfoID], [ScopeID]) INCLUDE ([PrincipalID], [RoleID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [ScopeAssignments_LoadingInfoID_SPObjectID] on [dbo].[ScopeAssignments]'
GO
CREATE NONCLUSTERED INDEX [ScopeAssignments_LoadingInfoID_SPObjectID] ON [dbo].[ScopeAssignments] ([LoadingInfoID], [SPObjectID]) INCLUDE ([ScopeID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [SharePointObjectMemberships_LoadingInfoID_ChildID] on [dbo].[SharePointObjectMemberships]'
GO
CREATE NONCLUSTERED INDEX [SharePointObjectMemberships_LoadingInfoID_ChildID] ON [dbo].[SharePointObjectMemberships] ([LoadingInfoID], [ChildID]) INCLUDE ([ParentID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [SharePointObjectMemberships_LoadingInfoID_ParentID] on [dbo].[SharePointObjectMemberships]'
GO
CREATE NONCLUSTERED INDEX [SharePointObjectMemberships_LoadingInfoID_ParentID] ON [dbo].[SharePointObjectMemberships] ([LoadingInfoID], [ParentID]) INCLUDE ([ChildID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[SiteCollectionsContentDatabase]'
GO
ALTER TABLE [dbo].[SiteCollectionsContentDatabase] ADD CONSTRAINT [FK_SiteCollectionsContentDatabase_ContentDatabases] FOREIGN KEY ([ContentDatabaseID]) REFERENCES [dbo].[ContentDatabases] ([ID])
ALTER TABLE [dbo].[SiteCollectionsContentDatabase] ADD CONSTRAINT [FK_SiteCollectionsContentDatabase_SharePointObjects] FOREIGN KEY ([SiteCollectionID]) REFERENCES [dbo].[SharePointObjects] ([ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[ContentType]'
GO
ALTER TABLE [dbo].[ContentType] ADD CONSTRAINT [FK_ContentType_ContentType] FOREIGN KEY ([ParentID]) REFERENCES [dbo].[ContentType] ([ID])
ALTER TABLE [dbo].[ContentType] ADD CONSTRAINT [FK_ContentType_SharePointObjects] FOREIGN KEY ([ParentSiteID]) REFERENCES [dbo].[SharePointObjects] ([ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[SharePointObjectContentType]'
GO
ALTER TABLE [dbo].[SharePointObjectContentType] ADD CONSTRAINT [FK_SharePointObjectContentType_ContentType] FOREIGN KEY ([ContentTypeID]) REFERENCES [dbo].[ContentType] ([ID])
ALTER TABLE [dbo].[SharePointObjectContentType] ADD CONSTRAINT [FK_SharePointObjectContentType_SharePointObjects] FOREIGN KEY ([SharePointObjectID]) REFERENCES [dbo].[SharePointObjects] ([ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[SubscriptionDeliveryMethods]'
GO
ALTER TABLE [dbo].[SubscriptionDeliveryMethods] ADD CONSTRAINT [FK_SubscriptionDeliveryMethods_DeliveryMethods] FOREIGN KEY ([DeliveryMethodID]) REFERENCES [dbo].[DeliveryMethods] ([DeliveryMethodID])
ALTER TABLE [dbo].[SubscriptionDeliveryMethods] ADD CONSTRAINT [FK_SubscriptionDeliveryMethods_EmailSubscriptions] FOREIGN KEY ([SubscriptionID]) REFERENCES [dbo].[EmailSubscriptions] ([EmailSubscriptionID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[PermissionScopeAlterations]'
GO
ALTER TABLE [dbo].[PermissionScopeAlterations] ADD CONSTRAINT [FK_PermissionScopeAlterations_PermissionScopes] FOREIGN KEY ([ScopeID]) REFERENCES [dbo].[PermissionScopes] ([ID]) ON DELETE CASCADE
ALTER TABLE [dbo].[PermissionScopeAlterations] ADD CONSTRAINT [FK_PermissionScopeAlterations_SharePointObjectTypes] FOREIGN KEY ([SharePointObjectTypeID]) REFERENCES [dbo].[SharePointObjectTypes] ([ID])
ALTER TABLE [dbo].[PermissionScopeAlterations] ADD CONSTRAINT [FK_PermissionScopeAlterations_WebApplications] FOREIGN KEY ([WebApplicationID]) REFERENCES [dbo].[WebApplications] ([ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT 'The database update succeeded'
COMMIT TRANSACTION
END
ELSE PRINT 'The database update failed'
GO
DROP TABLE #tmpErrors
GO

INSERT INTO [RuleTypes] ([ID], [Name], [Description]) VALUES (4, 'Datasheet' , 'Specify whether the datasheet can be used to bulk edit data on this document library.')

INSERT INTO [RuleTypes] ([ID], [Name], [Description]) VALUES (5, 'Rating Settings' , 'Specify whether or not items in a list can be rated.')

INSERT INTO [RuleTypes] ([ID], [Name], [Description]) VALUES (6, 'Offline Client Availability' , 'Specify whether this document library should be available for offline clients.')

INSERT INTO [RuleTypes] ([ID], [Name], [Description]) VALUES (7, 'Item-level Permissions' , 'Specify which items users can read and edit.')

INSERT INTO [RuleTypes] ([ID], [Name], [Description]) VALUES (8, 'Dialogs' , 'Specify whether to launch the new, edit, and display forms in a dialog.')

INSERT INTO [RuleTypes] ([ID], [Name], [Description]) VALUES (9, 'Attachments' , 'Specify whether users can attach files to items in a list.')

INSERT INTO [RuleTypes] ([ID], [Name], [Description]) VALUES (10, 'Opening Documents in the Browser' , 'Specify whether browser-enabled documents should be opened in the client or browser by default when a user clicks on them.')

INSERT INTO [RuleTypes] ([ID], [Name], [Description]) VALUES (11, 'Folders' , 'Specify whether the "New Folder" command is available. Changing this setting does not affect existing folders.')

INSERT INTO [RuleTypes] ([ID], [Name], [Description]) VALUES (12, 'Search' , 'Specify whether a list should be visible in search results. Users who do not have permission to see these items will not see them in search results, no matter what this setting is.')



INSERT INTO [RuleTypes] ([ID], [Name], [Description]) VALUES (100, 'Query' , 'Dynamically query SharePoint for the state of List and List Item properties.')



INSERT INTO Rules VALUES(null, 'Queries', 1, 1, null, '2000-01-01 00:00:00.000', -1, 1, 0);



Declare @QueriesID INT
Select @QueriesID=ID FROM Rules Where Name LIKE 'Queries'
INSERT INTO Rules VALUES(null, 'Samples', 1, 1, NULL, '2000-01-01 00:00:00.000', @QueriesID, 1, 0)
Declare @SampleQueriesID INT
SET @SampleQueriesID=@@IDENTITY

INSERT INTO Rules VALUES(100, 'Checked Out Files', 0, 1, 
'<RuleConfiguration><RuleSchedule xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" p2:type="OneTimeSchedule"><StartTime>2014-09-11T00:00:00</StartTime></RuleSchedule><EmailRecipients /><QueryConfiguration><DataSource>ListItems</DataSource><FieldNames><string>Title</string><string>Url</string><string>CheckedOutByDisplayName</string><string>ListTitle</string><string>SubSiteTitle</string><string>SiteUrl</string></FieldNames><FieldSorting><string>N</string><string>N</string><string>N</string><string>N</string><string>N</string><string>N</string></FieldSorting></QueryConfiguration><GroupCondition><Enabled>True</Enabled><LogicalOperators>0</LogicalOperators><Conditions><GroupCondition><Enabled>True</Enabled><LogicalOperators>0</LogicalOperators><Conditions><SimpleCondition><Enabled>True</Enabled><FieldInfo><FieldName>CheckedOutByDisplayName</FieldName><FieldType>System.String</FieldType><Alias /></FieldInfo><Parameter /><ConditionApplies>0</ConditionApplies><ConditionTypeID>111</ConditionTypeID></SimpleCondition></Conditions></GroupCondition></Conditions></GroupCondition></RuleConfiguration>'
, '2000-01-01 00:00:00.000', @SampleQueriesID, 0, 0)

INSERT INTO Rules VALUES(100, 'Document Libraries Without Check Out', 0, 1, 
'<RuleConfiguration><RuleSchedule xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" p2:type="OneTimeSchedule"><StartTime>2014-10-02T00:00:00</StartTime></RuleSchedule><EmailRecipients /><QueryConfiguration><DataSource>Lists</DataSource><FieldNames><string>Title</string><string>Url</string></FieldNames><FieldSorting><string>N</string><string>N</string></FieldSorting></QueryConfiguration><GroupCondition><Enabled>True</Enabled><LogicalOperators>0,0</LogicalOperators><Conditions><GroupCondition><Enabled>True</Enabled><LogicalOperators>0</LogicalOperators><Conditions><SimpleCondition><Enabled>True</Enabled><FieldInfo><FieldName>ForceCheckout</FieldName><FieldType>System.Boolean</FieldType><Alias /></FieldInfo><Parameter /><ConditionApplies>0</ConditionApplies><ConditionTypeID>201</ConditionTypeID></SimpleCondition></Conditions></GroupCondition><GroupCondition><Enabled>True</Enabled><LogicalOperators>0</LogicalOperators><Conditions><SimpleCondition><Enabled>True</Enabled><FieldInfo><FieldName>ListTemplate</FieldName><FieldType>Acceleratio.SPDocKit.Business.Enums.BaseTemplateTypeEnum</FieldType><Alias /></FieldInfo><Parameter>101</Parameter><ConditionApplies>0</ConditionApplies><ConditionTypeID>400</ConditionTypeID></SimpleCondition></Conditions></GroupCondition></Conditions></GroupCondition></RuleConfiguration>'
, '2000-01-01 00:00:00.000', @SampleQueriesID, 0, 0)

INSERT INTO Rules VALUES(100, 'Document Libraries Without Versioning', 0, 1, 
'<RuleConfiguration><RuleSchedule xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" p2:type="OneTimeSchedule"><StartTime>2014-10-02T00:00:00</StartTime></RuleSchedule><EmailRecipients /><QueryConfiguration><DataSource>Lists</DataSource><FieldNames><string>Title</string><string>Url</string></FieldNames><FieldSorting><string>N</string><string>N</string></FieldSorting></QueryConfiguration><GroupCondition><Enabled>True</Enabled><LogicalOperators>0,0</LogicalOperators><Conditions><GroupCondition><Enabled>True</Enabled><LogicalOperators>0</LogicalOperators><Conditions><SimpleCondition><Enabled>True</Enabled><FieldInfo><FieldName>EnableVersioning</FieldName><FieldType>System.Boolean</FieldType><Alias /></FieldInfo><Parameter /><ConditionApplies>0</ConditionApplies><ConditionTypeID>201</ConditionTypeID></SimpleCondition></Conditions></GroupCondition><GroupCondition><Enabled>True</Enabled><LogicalOperators>0</LogicalOperators><Conditions><SimpleCondition><Enabled>True</Enabled><FieldInfo><FieldName>ListTemplate</FieldName><FieldType>Acceleratio.SPDocKit.Business.Enums.BaseTemplateTypeEnum</FieldType><Alias /></FieldInfo><Parameter>101</Parameter><ConditionApplies>0</ConditionApplies><ConditionTypeID>400</ConditionTypeID></SimpleCondition></Conditions></GroupCondition></Conditions></GroupCondition></RuleConfiguration>'
, '2000-01-01 00:00:00.000', @SampleQueriesID, 0, 0)


Declare @RulesID INT
Select @RulesID=ID FROM Rules Where Name LIKE 'Rules'
INSERT INTO Rules VALUES(null, 'Samples', 1, 1, NULL, '2000-01-01 00:00:00.000', @RulesID, 1, 0)
Declare @SampleRulesID INT
SET @SampleRulesID=@@IDENTITY

INSERT INTO Rules VALUES(2, 'Document Library Check Out Required', 0, 1, 
'<RuleConfiguration><RuleSchedule xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" p2:type="OneTimeSchedule"><StartTime>2014-10-02T00:00:00</StartTime></RuleSchedule><CustomConfiguration xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" p2:type="CheckOutRuleCustomConfiguration"><RequireCheckOut>true</RequireCheckOut></CustomConfiguration><GroupCondition><Enabled>True</Enabled><LogicalOperators>0</LogicalOperators><Conditions><GroupCondition><Enabled>True</Enabled><LogicalOperators>0</LogicalOperators><Conditions><SimpleCondition><Enabled>True</Enabled><FieldInfo><FieldName>ListTemplate</FieldName><FieldType>Acceleratio.SPDocKit.Business.Enums.BaseTemplateTypeEnum</FieldType><Alias /></FieldInfo><Parameter>101</Parameter><ConditionApplies>0</ConditionApplies><ConditionTypeID>400</ConditionTypeID></SimpleCondition></Conditions></GroupCondition></Conditions></GroupCondition></RuleConfiguration>'
, '2000-01-01 00:00:00.000', @SampleRulesID, 0, 0)

INSERT INTO Rules VALUES(1, 'Document Library Version History', 0, 1, 
'<RuleConfiguration><RuleSchedule xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" p2:type="OneTimeSchedule"><StartTime>2014-10-02T00:00:00</StartTime></RuleSchedule><CustomConfiguration xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" p2:type="VersioningRuleCustomConfiguration"><LimitNumberOfMajorVersions>false</LimitNumberOfMajorVersions><LimitNumberOfMinorVerions>false</LimitNumberOfMinorVerions><NumberOfMajorVersions>0</NumberOfMajorVersions><NumberOfMinorVersions>0</NumberOfMinorVersions><CreateVersions>1</CreateVersions><DraftItemVisibility>2</DraftItemVisibility><RequireContentApproval>false</RequireContentApproval></CustomConfiguration><GroupCondition><Enabled>True</Enabled><LogicalOperators>0</LogicalOperators><Conditions><GroupCondition><Enabled>True</Enabled><LogicalOperators>0</LogicalOperators><Conditions><SimpleCondition><Enabled>True</Enabled><FieldInfo><FieldName>ListTemplate</FieldName><FieldType>Acceleratio.SPDocKit.Business.Enums.BaseTemplateTypeEnum</FieldType><Alias /></FieldInfo><Parameter>101</Parameter><ConditionApplies>0</ConditionApplies><ConditionTypeID>400</ConditionTypeID></SimpleCondition></Conditions></GroupCondition></Conditions></GroupCondition></RuleConfiguration>'
, '2000-01-01 00:00:00.000', @SampleRulesID, 0, 0);

  



INSERT INTO DeliveryMethods(DeliveryMethodID, Name) VALUES(1, 'Email');

INSERT INTO DeliveryMethods(DeliveryMethodID, Name) VALUES(2, 'Network location');

INSERT INTO DeliveryMethods(DeliveryMethodID, Name) VALUES(3, 'SharePoint location');



UPDATE SystemJobs SET Name = 'Send Subscriptions' WHERE ID=1;



INSERT INTO SubscriptionDeliveryMethods SELECT EmailSubscriptionID,1 FROM EmailSubscriptions;



UPDATE [dbo].[Options] SET [OptionValue] = '5.0.0' WHERE [OptionID] = 14


