Datapolis Process System
Migration of SharePoint 2010 Web Application
The steps below will show you how to move your Workbox 2010 workflows with one of web application from one SharePoint 2010 Farm to to another.
-- create temporary db
CREATE DATABASE <temporary_database_name>
GO
USE <temporary_database_name>
-- create tables
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE TABLE [dbo].[Associations](
[Id] [int] IDENTITY(1,1) NOT NULL,
[AssociationId] [uniqueidentifier] NULL,
[AppId] [uniqueidentifier] NULL,
[SiteId] [uniqueidentifier] NULL,
[WebId] [uniqueidentifier] NULL,
[ListId] [uniqueidentifier] NULL,
[AssociationType] [int] NULL,
[AssociationContent] [nvarchar](max) NULL,
[WBVersion] [nvarchar](20) NULL,
[AssociationReferenceId] [uniqueidentifier] NULL,
CONSTRAINT [PK_Associations] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
CREATE TABLE [dbo].[History](
[WorkflowInstanceId] [uniqueidentifier] NULL,
[TemplateId] [uniqueidentifier] NULL,
[ItemId] [int] NULL,
[UserId] [int] NULL,
[UserLogin] [nvarchar](100) NULL,
[Occured] [datetime2](7) NULL,
[EventType] [int] NULL,
[EventName] [nvarchar](100) NULL,
[EventTitle] [nvarchar](100) NULL,
[EventContent] [nvarchar](max) NULL,
CONSTRAINT [PK_History] PRIMARY KEY CLUSTERED
CREATE TABLE [dbo].[WBXml](
[BaseId] [uniqueidentifier] NULL,
[StateTitle] [nvarchar](100) NULL,
[ShowActions] [bit] NULL,
[WBXmlContent] [nvarchar](max) NULL,
CONSTRAINT [PK_WBXml] PRIMARY KEY CLUSTERED
CREATE TABLE [dbo].[SelfTimers](
[StartTime] [datetime2](7) NULL,
[ActionName] [nvarchar](100) NULL,
[StateInstanceId] [uniqueidentifier] NULL,
CONSTRAINT [PK_SelfTimers] PRIMARY KEY CLUSTERED
) ON [PRIMARY]
CREATE TABLE [dbo].[Tasks](
[TaskType] [int] NULL,
[CreatedBy] [nvarchar](100) NULL,
[Created] [datetime2](7) NULL,
[Started] [datetime2](7) NULL,
[Finished] [datetime2](7) NULL,
[TaskState] [int] NULL,
[Progress] [int] NULL,
[ItemIds] [nvarchar](max) NULL,
[WorkflowId] [uniqueidentifier] NULL,
[WorkflowIds] [nvarchar](max) NULL,
[TaskContent] [nvarchar](max) NULL,
[Result] [nvarchar](max) NULL,
CONSTRAINT [PK_Tasks] PRIMARY KEY CLUSTERED
--from
--SOURCE DB <source_DP_DB_2010_database_name>
--to
--TEMP DB <temporary_database_name>
-- remeber to replace database names in scrips !!!
SET STATISTICS TIME ON
DECLARE @TranName VARCHAR(50);
SET @TranName = 'CopyDPDBContentToTemp';
BEGIN TRANSACTION @TranName;
-- id of the web application that will be migrated
DECLARE @appId_SOURCE uniqueidentifier = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
SET IDENTITY_INSERT <temporary_database_name>.[dbo].[Associations] ON
INSERT INTO <temporary_database_name>.[dbo].[Associations]
([Id]
,[AssociationId]
,[AppId]
,[SiteId]
,[WebId]
,[ListId]
,[AssociationType]
,[AssociationContent]
,[WBVersion]
,[AssociationReferenceId])
SELECT [Id]
,[AssociationReferenceId] FROM <source_DP_DB_2010_database_name>.[dbo].[Associations] WHERE [AppId] = @appId_SOURCE
SET IDENTITY_INSERT <temporary_database_name>.[dbo].[Associations] OFF
SET IDENTITY_INSERT <temporary_database_name>.[dbo].[History] ON
INSERT INTO <temporary_database_name>.[dbo].[History]
,[WorkflowInstanceId]
,[TemplateId]
,[ItemId]
,[UserId]
,[UserLogin]
,[Occured]
,[EventType]
,[EventName]
,[EventTitle]
,[EventContent]
,[AssociationReferenceId] FROM <source_DP_DB_2010_database_name>.[dbo].[History] WHERE [AppId] = @appId_SOURCE
SET IDENTITY_INSERT <temporary_database_name>.[dbo].[History] OFF
SET IDENTITY_INSERT <temporary_database_name>.[dbo].[SelfTimers] ON
INSERT INTO <temporary_database_name>.[dbo].[SelfTimers]
,[StartTime]
,[ActionName]
,[StateInstanceId])
,[StateInstanceId] FROM <source_DP_DB_2010_database_name>.[dbo].[SelfTimers] WHERE [AppId] = @appId_SOURCE
SET IDENTITY_INSERT <temporary_database_name>.[dbo].[SelfTimers] OFF
SET IDENTITY_INSERT <temporary_database_name>.[dbo].[Tasks] ON
INSERT INTO <temporary_database_name>.[dbo].[Tasks]
,[TaskType]
,[CreatedBy]
,[Created]
,[Started]
,[Finished]
,[TaskState]
,[Progress]
,[ItemIds]
,[WorkflowId]
,[WorkflowIds]
,[TaskContent]
,[Result])
,[Result] FROM <source_DP_DB_2010_database_name>.[dbo].[Tasks] WHERE [AppId] = @appId_SOURCE
SET IDENTITY_INSERT <temporary_database_name>.[dbo].[Tasks] OFF
SET IDENTITY_INSERT <temporary_database_name>.[dbo].[WBXml] ON
INSERT INTO <temporary_database_name>.[dbo].[WBXml]
,[BaseId]
,[StateTitle]
,[ShowActions]
,[WBXmlContent]
,[WBVersion])
,[WBVersion] FROM <source_DP_DB_2010_database_name>.[dbo].[WBXml] WHERE [AppId] = @appId_SOURCE
SET IDENTITY_INSERT <temporary_database_name>.[dbo].[WBXml] OFF
COMMIT TRANSACTION @TranName
SET STATISTICS TIME OFF
--TEMPORARY DATABASE <temporary_database_name>
--DESTINATION DATABASE <destination_DP_DB_2010_database_name>
SET @TranName = 'CopyContentFromTemp';
-- ids of the web applications that will be migrated
DECLARE @appId_DEST uniqueidentifier = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
INSERT INTO <destination_DP_DB_2010_database_name>.[dbo].[Associations]
([AssociationId]
SELECT [AssociationId]
,@appId_DEST
,[AssociationReferenceId] FROM <temporary_database_name>.[dbo].[Associations] WHERE [AppId] = @appId_SOURCE
INSERT INTO <destination_DP_DB_2010_database_name>.[dbo].[History]
([WorkflowInstanceId]
SELECT [WorkflowInstanceId]
,[AssociationReferenceId] FROM <temporary_database_name>.[dbo].[History] WHERE [AppId] = @appId_SOURCE
INSERT INTO <destination_DP_DB_2010_database_name>.[dbo].[SelfTimers]
([AppId]
SELECT @appId_DEST
,[StateInstanceId] FROM <temporary_database_name>.[dbo].[SelfTimers] WHERE [AppId] = @appId_SOURCE
INSERT INTO <destination_DP_DB_2010_database_name>.[dbo].[Tasks]
([TaskType]
SELECT [TaskType]
,[Result] FROM <temporary_database_name>.[dbo].[Tasks] WHERE [AppId] = @appId_SOURCE
INSERT INTO <destination_DP_DB_2010_database_name>.[dbo].[WBXml]
,[WBVersion] FROM <temporary_database_name>.[dbo].[WBXml] WHERE [AppId] = @appId_SOURCE