· 9 years ago · Nov 21, 2016, 06:34 PM
1USE [master]
2GO
3/****** Object: Database [iConIRNet] Script Date: 21/11/2016 12:32:20 ******/
4CREATE DATABASE [iConIRNet]
5 CONTAINMENT = NONE
6 ON PRIMARY
7( NAME = N'iConIRNet', FILENAME = N'W:\data\iConIRNet.mdf' , SIZE = 31793152KB , MAXSIZE = UNLIMITED, FILEGROWTH = 512000KB )
8 LOG ON
9( NAME = N'iConIRNet_log', FILENAME = N'W:\logs\iConIRNet_log.ldf' , SIZE = 1048576KB , MAXSIZE = 2048GB , FILEGROWTH = 204800KB )
10GO
11ALTER DATABASE [iConIRNet] SET COMPATIBILITY_LEVEL = 110
12GO
13IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
14begin
15EXEC [iConIRNet].[dbo].[sp_fulltext_database] @action = 'enable'
16end
17GO
18ALTER DATABASE [iConIRNet] SET ANSI_NULL_DEFAULT OFF
19GO
20ALTER DATABASE [iConIRNet] SET ANSI_NULLS OFF
21GO
22ALTER DATABASE [iConIRNet] SET ANSI_PADDING OFF
23GO
24ALTER DATABASE [iConIRNet] SET ANSI_WARNINGS OFF
25GO
26ALTER DATABASE [iConIRNet] SET ARITHABORT OFF
27GO
28ALTER DATABASE [iConIRNet] SET AUTO_CLOSE OFF
29GO
30ALTER DATABASE [iConIRNet] SET AUTO_SHRINK OFF
31GO
32ALTER DATABASE [iConIRNet] SET AUTO_UPDATE_STATISTICS ON
33GO
34ALTER DATABASE [iConIRNet] SET CURSOR_CLOSE_ON_COMMIT OFF
35GO
36ALTER DATABASE [iConIRNet] SET CURSOR_DEFAULT GLOBAL
37GO
38ALTER DATABASE [iConIRNet] SET CONCAT_NULL_YIELDS_NULL OFF
39GO
40ALTER DATABASE [iConIRNet] SET NUMERIC_ROUNDABORT OFF
41GO
42ALTER DATABASE [iConIRNet] SET QUOTED_IDENTIFIER OFF
43GO
44ALTER DATABASE [iConIRNet] SET RECURSIVE_TRIGGERS OFF
45GO
46ALTER DATABASE [iConIRNet] SET DISABLE_BROKER
47GO
48ALTER DATABASE [iConIRNet] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
49GO
50ALTER DATABASE [iConIRNet] SET DATE_CORRELATION_OPTIMIZATION OFF
51GO
52ALTER DATABASE [iConIRNet] SET TRUSTWORTHY OFF
53GO
54ALTER DATABASE [iConIRNet] SET ALLOW_SNAPSHOT_ISOLATION ON
55GO
56ALTER DATABASE [iConIRNet] SET PARAMETERIZATION SIMPLE
57GO
58ALTER DATABASE [iConIRNet] SET READ_COMMITTED_SNAPSHOT ON
59GO
60ALTER DATABASE [iConIRNet] SET HONOR_BROKER_PRIORITY OFF
61GO
62ALTER DATABASE [iConIRNet] SET RECOVERY SIMPLE
63GO
64ALTER DATABASE [iConIRNet] SET MULTI_USER
65GO
66ALTER DATABASE [iConIRNet] SET PAGE_VERIFY CHECKSUM
67GO
68ALTER DATABASE [iConIRNet] SET DB_CHAINING OFF
69GO
70ALTER DATABASE [iConIRNet] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
71GO
72ALTER DATABASE [iConIRNet] SET TARGET_RECOVERY_TIME = 0 SECONDS
73GO
74ALTER DATABASE [iConIRNet] SET DELAYED_DURABILITY = DISABLED
75GO
76USE [iConIRNet]
77GO
78/****** Object: UserDefinedFunction [dbo].[FolderPath] Script Date: 21/11/2016 12:32:20 ******/
79SET ANSI_NULLS ON
80GO
81SET QUOTED_IDENTIFIER ON
82GO
83create function [dbo].[FolderPath] (@folderid int)
84returns varchar(2000)
85as
86begin
87 if (@folderid is null)
88 return null
89
90 declare @folderpath varchar(2000), @parentid int
91
92 select @folderpath = FolderType, @parentid = Parentid
93 from SnapshotFolder where folderid = @folderid
94
95 if (@parentid is not null)
96 select @folderpath = dbo.folderpath(@parentid) + '\\' + @folderpath
97
98 return @folderpath
99end
100
101GO
102/****** Object: UserDefinedFunction [dbo].[FolderPathFull] Script Date: 21/11/2016 12:32:20 ******/
103SET ANSI_NULLS ON
104GO
105SET QUOTED_IDENTIFIER ON
106GO
107create function [dbo].[FolderPathFull] (@folderid int)
108returns varchar(4000)
109as
110begin
111 if (@folderid is null)
112 return null
113
114 declare @folderpath varchar(4000), @parentid int, @folderdesc varchar(255)
115
116 select @folderpath = FolderType,
117 @parentid = Parentid,
118 @folderdesc = Description
119 from SnapshotFolder where folderid = @folderid
120
121 declare @attributeStr varchar(1000)
122 select @attributestr = substring(
123 (
124 select ';' + AttributeName + '=' + replace(replace(AttributeValue,'&','&'),';',':')
125 from SnapshotAttribute where objectid = @folderid
126 for XML Path('')
127 ),2,1000)
128
129 if (len(ltrim(@folderdesc)) > 0)
130 select @folderpath = @folderpath + ';Description=' + replace(replace(@folderdesc,'&','&'),';',':') + ';MigrationDesc=' + replace(replace(@folderdesc,'&','&'),';',':')
131 if (len(ltrim(@attributeStr)) > 0)
132 select @folderpath = @folderpath + ';' + replace(@attributeStr,'&','&')
133
134 if (@parentid is not null)
135 select @folderpath = dbo.FolderPathFull(@parentid) + '\\' + @folderpath
136
137 return @folderpath
138end
139
140GO
141/****** Object: UserDefinedFunction [dbo].[isFolderDeleted] Script Date: 21/11/2016 12:32:20 ******/
142SET ANSI_NULLS ON
143GO
144SET QUOTED_IDENTIFIER ON
145GO
146create function [dbo].[isFolderDeleted] (@folderid int)
147returns bit
148as
149begin
150 if (@folderid is null)
151 return 0
152
153 declare @isdeleted bit, @parentid int
154
155 select @isdeleted = cast(isdeleted as bit), @parentid = Parentid
156 from SnapshotFolder where folderid = @folderid
157
158 if (@parentid is not null)
159 select @isdeleted = @isdeleted | dbo.isFolderDeleted(@parentid)
160
161 return @isdeleted
162end
163
164GO
165/****** Object: UserDefinedFunction [dbo].[map] Script Date: 21/11/2016 12:32:20 ******/
166SET ANSI_NULLS ON
167GO
168SET QUOTED_IDENTIFIER ON
169GO
170create function [dbo].[map] (@SrcFolderPathFull varchar(4000),@mapping varchar(2000))
171 returns varchar(4000)
172as
173begin
174 if (right(@mapping,1) <> '|') set @mapping = @mapping + '|'
175
176 declare @mapStmt varchar(1000), @pos int
177 set @pos = charIndex('|',@mapping)
178 while (@pos > 0)
179 begin
180 set @mapStmt = substring(@mapping,1,@pos-1)
181
182 select @SrcFolderPathFull =
183 replace(@SrcFolderPathFull,
184 substring(@mapStmt,1,patIndex('%->%',@mapStmt)-1),
185 substring(@mapStmt,patIndex('%->%',@mapStmt)+2,len(@mapStmt)-patIndex('%->%',@mapStmt)-1))
186
187
188 set @mapping = substring(@mapping,@pos+1,2000)
189 set @pos = charIndex('|',@mapping)
190
191 end
192 return @SrcFolderPathFull
193
194end
195
196GO
197/****** Object: UserDefinedFunction [dbo].[StringAfterChar] Script Date: 21/11/2016 12:32:20 ******/
198SET ANSI_NULLS ON
199GO
200SET QUOTED_IDENTIFIER ON
201GO
202create function [dbo].[StringAfterChar]
203(
204 @string varchar(1000),
205 @char varchar(50)
206)
207returns varchar(1000)
208begin
209 return
210 case
211 when @string like '%'+@char+'%'
212 then ltrim(rtrim(reverse(left(reverse(@string),charindex(@char,reverse(@string))-1))))
213 else ''
214 end
215end
216
217GO
218/****** Object: UserDefinedFunction [dbo].[StringBeforeChar] Script Date: 21/11/2016 12:32:20 ******/
219SET ANSI_NULLS ON
220GO
221SET QUOTED_IDENTIFIER ON
222GO
223create function [dbo].[StringBeforeChar]
224(
225 @string varchar(1000),
226 @char varchar(50)
227)
228returns varchar(1000)
229begin
230 return
231 case charindex(@char,@string)
232 when 0 then ''
233 when 1 then ''
234 else left(ltrim(@string),charindex(@char,ltrim(@string))-1)
235 end
236end
237
238GO
239/****** Object: Table [dbo].[AFUP] Script Date: 21/11/2016 12:32:20 ******/
240SET ANSI_NULLS ON
241GO
242SET QUOTED_IDENTIFIER ON
243GO
244SET ANSI_PADDING ON
245GO
246CREATE TABLE [dbo].[AFUP](
247 [tofileid] [int] NOT NULL,
248 [fromfileid] [int] NOT NULL,
249 [tofilenumber] [varchar](255) NOT NULL,
250 [fromfilenumber] [varchar](255) NOT NULL,
251 [ToFiletype] [varchar](50) NOT NULL,
252 [fromFileType] [varchar](50) NOT NULL
253) ON [PRIMARY]
254
255GO
256SET ANSI_PADDING OFF
257GO
258/****** Object: Table [dbo].[BackupMigrationPath] Script Date: 21/11/2016 12:32:20 ******/
259SET ANSI_NULLS ON
260GO
261SET QUOTED_IDENTIFIER ON
262GO
263SET ANSI_PADDING ON
264GO
265CREATE TABLE [dbo].[BackupMigrationPath](
266 [System] [varchar](40) NOT NULL,
267 [storage] [varchar](20) NOT NULL,
268 [ID] [varchar](20) NOT NULL,
269 [Path] [varchar](400) NOT NULL
270) ON [PRIMARY]
271
272GO
273SET ANSI_PADDING OFF
274GO
275/****** Object: Table [dbo].[ConfigDeviceList] Script Date: 21/11/2016 12:32:20 ******/
276SET ANSI_NULLS ON
277GO
278SET QUOTED_IDENTIFIER ON
279GO
280SET ANSI_PADDING ON
281GO
282CREATE TABLE [dbo].[ConfigDeviceList](
283 [System] [varchar](50) NOT NULL,
284 [OldDevicePath] [varchar](200) NOT NULL,
285 [NewDevicePath] [varchar](200) NULL,
286PRIMARY KEY CLUSTERED
287(
288 [System] ASC,
289 [OldDevicePath] ASC
290)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
291) ON [PRIMARY]
292
293GO
294SET ANSI_PADDING OFF
295GO
296/****** Object: Table [dbo].[ConfigDrawerList] Script Date: 21/11/2016 12:32:20 ******/
297SET ANSI_NULLS ON
298GO
299SET QUOTED_IDENTIFIER ON
300GO
301SET ANSI_PADDING ON
302GO
303CREATE TABLE [dbo].[ConfigDrawerList](
304 [system] [varchar](50) NOT NULL,
305 [drawer] [varchar](100) NOT NULL,
306 [purge] [varchar](10) NOT NULL,
307 [purgedate] [datetime] NULL,
308 CONSTRAINT [PK_ConfigDrawer] PRIMARY KEY CLUSTERED
309(
310 [system] ASC,
311 [drawer] ASC,
312 [purge] ASC
313)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
314) ON [PRIMARY]
315
316GO
317SET ANSI_PADDING OFF
318GO
319/****** Object: Table [dbo].[ConfigMigration] Script Date: 21/11/2016 12:32:20 ******/
320SET ANSI_NULLS ON
321GO
322SET QUOTED_IDENTIFIER ON
323GO
324SET ANSI_PADDING ON
325GO
326CREATE TABLE [dbo].[ConfigMigration](
327 [ConfigKey] [varchar](500) NULL,
328 [ConfigValue] [varchar](500) NULL,
329 [ConfigDescription] [varchar](max) NULL,
330 [ConfigValueDefault] [varchar](500) NULL
331) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
332
333GO
334SET ANSI_PADDING OFF
335GO
336/****** Object: Table [dbo].[ConfigPageCorrection] Script Date: 21/11/2016 12:32:20 ******/
337SET ANSI_NULLS ON
338GO
339SET QUOTED_IDENTIFIER ON
340GO
341SET ANSI_PADDING ON
342GO
343CREATE TABLE [dbo].[ConfigPageCorrection](
344 [fileid] [varchar](100) NOT NULL,
345 [OldFilePath] [varchar](255) NOT NULL,
346 [NewFilePath] [varchar](255) NULL,
347 CONSTRAINT [PK_ConfigPageCorrection] PRIMARY KEY CLUSTERED
348(
349 [fileid] ASC,
350 [OldFilePath] ASC
351)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
352) ON [PRIMARY]
353
354GO
355SET ANSI_PADDING OFF
356GO
357/****** Object: Table [dbo].[ConfigPriority] Script Date: 21/11/2016 12:32:20 ******/
358SET ANSI_NULLS ON
359GO
360SET QUOTED_IDENTIFIER ON
361GO
362SET ANSI_PADDING ON
363GO
364CREATE TABLE [dbo].[ConfigPriority](
365 [System] [varchar](20) NOT NULL,
366 [Priority] [int] NOT NULL,
367 [Rule] [varchar](10) NOT NULL,
368 [Description] [varchar](200) NOT NULL,
369 [SrcDrawer] [varchar](4) NULL,
370 [SrcFileNumber] [varchar](50) NULL,
371 [filedate] [datetime] NULL
372) ON [PRIMARY]
373
374GO
375SET ANSI_PADDING OFF
376GO
377/****** Object: Table [dbo].[ConfigPurgeList] Script Date: 21/11/2016 12:32:20 ******/
378SET ANSI_NULLS ON
379GO
380SET QUOTED_IDENTIFIER ON
381GO
382SET ANSI_PADDING ON
383GO
384CREATE TABLE [dbo].[ConfigPurgeList](
385 [System] [varchar](20) NOT NULL,
386 [SrcDrawer] [varchar](4) NOT NULL,
387 [SrcFileNumber] [varchar](50) NOT NULL,
388 CONSTRAINT [PK_ConfigPurgeList] PRIMARY KEY CLUSTERED
389(
390 [System] ASC,
391 [SrcDrawer] ASC,
392 [SrcFileNumber] ASC
393)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
394) ON [PRIMARY]
395
396GO
397SET ANSI_PADDING OFF
398GO
399/****** Object: Table [dbo].[ConfigStatus] Script Date: 21/11/2016 12:32:20 ******/
400SET ANSI_NULLS ON
401GO
402SET QUOTED_IDENTIFIER ON
403GO
404SET ANSI_PADDING ON
405GO
406CREATE TABLE [dbo].[ConfigStatus](
407 [Status] [int] NOT NULL,
408 [Description] [varchar](255) NOT NULL,
409 CONSTRAINT [PK_ConfigStatus] PRIMARY KEY CLUSTERED
410(
411 [Status] ASC
412)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
413) ON [PRIMARY]
414
415GO
416SET ANSI_PADDING OFF
417GO
418/****** Object: Table [dbo].[Filemarks] Script Date: 21/11/2016 12:32:20 ******/
419SET ANSI_NULLS ON
420GO
421SET QUOTED_IDENTIFIER ON
422GO
423SET ANSI_PADDING ON
424GO
425CREATE TABLE [dbo].[Filemarks](
426 [DRAWER] [varchar](9) NOT NULL,
427 [NAME] [varchar](255) NULL,
428 [filenumber] [varchar](255) NULL,
429 [fileid] [int] NOT NULL,
430 [filemarkid] [int] NOT NULL,
431 [programmaticname] [varchar](255) NULL
432) ON [PRIMARY]
433
434GO
435SET ANSI_PADDING OFF
436GO
437/****** Object: Table [dbo].[LogMessage] Script Date: 21/11/2016 12:32:20 ******/
438SET ANSI_NULLS ON
439GO
440SET QUOTED_IDENTIFIER ON
441GO
442SET ANSI_PADDING ON
443GO
444CREATE TABLE [dbo].[LogMessage](
445 [ID] [int] IDENTITY(1,1) NOT NULL,
446 [messagecode] [int] NOT NULL,
447 [datetimeoccurance] [datetime] NOT NULL,
448 [MachineName] [varchar](100) NULL,
449 CONSTRAINT [pk_LogMessage] PRIMARY KEY CLUSTERED
450(
451 [ID] ASC
452)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
453) ON [PRIMARY]
454
455GO
456SET ANSI_PADDING OFF
457GO
458/****** Object: Table [dbo].[LogProcess] Script Date: 21/11/2016 12:32:20 ******/
459SET ANSI_NULLS ON
460GO
461SET QUOTED_IDENTIFIER ON
462GO
463SET ANSI_PADDING ON
464GO
465CREATE TABLE [dbo].[LogProcess](
466 [ID] [int] IDENTITY(1,1) NOT NULL,
467 [Name] [varchar](100) NOT NULL,
468 [System] [varchar](50) NULL,
469 [Drawer] [varchar](4) NULL,
470 [OtherParam1] [varchar](50) NULL,
471 [OtherParam2] [varchar](50) NULL,
472 [OtherParam3] [varchar](50) NULL,
473 [StartTime] [datetime] NOT NULL,
474 [EndTime] [datetime] NULL,
475 [Duration] [int] NULL,
476 [isPhase] [bit] NULL,
477 CONSTRAINT [PK_LogProcess] PRIMARY KEY CLUSTERED
478(
479 [ID] ASC
480)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
481) ON [PRIMARY]
482
483GO
484SET ANSI_PADDING OFF
485GO
486/****** Object: Table [dbo].[LogProcessHistory] Script Date: 21/11/2016 12:32:20 ******/
487SET ANSI_NULLS ON
488GO
489SET QUOTED_IDENTIFIER ON
490GO
491SET ANSI_PADDING ON
492GO
493CREATE TABLE [dbo].[LogProcessHistory](
494 [ArchiveDate] [datetime] NOT NULL,
495 [ID] [int] NOT NULL,
496 [Name] [varchar](100) NOT NULL,
497 [System] [varchar](50) NULL,
498 [Drawer] [varchar](4) NULL,
499 [OtherParam1] [varchar](50) NULL,
500 [OtherParam2] [varchar](50) NULL,
501 [OtherParam3] [varchar](50) NULL,
502 [StartTime] [datetime] NOT NULL,
503 [EndTime] [datetime] NULL,
504 [Duration] [int] NULL,
505 [isPhase] [bit] NULL
506) ON [PRIMARY]
507
508GO
509SET ANSI_PADDING OFF
510GO
511/****** Object: Table [dbo].[LogProgress] Script Date: 21/11/2016 12:32:20 ******/
512SET ANSI_NULLS ON
513GO
514SET QUOTED_IDENTIFIER ON
515GO
516SET ANSI_PADDING ON
517GO
518CREATE TABLE [dbo].[LogProgress](
519 [ID] [int] IDENTITY(1,1) NOT NULL,
520 [DocumentID] [varchar](100) NOT NULL,
521 [doccount] [int] NULL,
522 [pagecount] [int] NULL,
523 [duration] [int] NULL,
524 [success] [int] NULL,
525 [status] [varchar](max) NULL,
526 [errormessage] [varchar](max) NULL,
527 [MachineName] [varchar](100) NULL,
528 [TimeStamp] [datetime] NULL,
529 CONSTRAINT [PK_LogProgress] PRIMARY KEY CLUSTERED
530(
531 [ID] ASC
532)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
533) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
534
535GO
536SET ANSI_PADDING OFF
537GO
538/****** Object: Table [dbo].[LogProgressHistory] Script Date: 21/11/2016 12:32:21 ******/
539SET ANSI_NULLS ON
540GO
541SET QUOTED_IDENTIFIER ON
542GO
543SET ANSI_PADDING ON
544GO
545CREATE TABLE [dbo].[LogProgressHistory](
546 [ArchiveDate] [datetime] NOT NULL,
547 [ID] [int] NOT NULL,
548 [DocumentID] [varchar](100) NULL,
549 [doccount] [int] NULL,
550 [pagecount] [int] NULL,
551 [duration] [int] NULL,
552 [success] [int] NULL,
553 [status] [varchar](max) NULL,
554 [errormessage] [varchar](max) NULL,
555 [MachineName] [varchar](100) NULL,
556 [TimeStamp] [datetime] NULL
557) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
558
559GO
560SET ANSI_PADDING OFF
561GO
562/****** Object: Table [dbo].[LogQueueCounts] Script Date: 21/11/2016 12:32:21 ******/
563SET ANSI_NULLS ON
564GO
565SET QUOTED_IDENTIFIER ON
566GO
567CREATE TABLE [dbo].[LogQueueCounts](
568 [status] [int] NULL,
569 [count] [int] NULL
570) ON [PRIMARY]
571
572GO
573/****** Object: Table [dbo].[MapDocument] Script Date: 21/11/2016 12:32:21 ******/
574SET ANSI_NULLS ON
575GO
576SET QUOTED_IDENTIFIER ON
577GO
578SET ANSI_PADDING ON
579GO
580CREATE TABLE [dbo].[MapDocument](
581 [System] [varchar](50) NOT NULL,
582 [SrcDrawer] [varchar](100) NOT NULL,
583 [SrcFileType] [varchar](255) NOT NULL,
584 [SrcDrawerDesc] [varchar](255) NOT NULL,
585 [SrcDrawerOwner] [varchar](50) NOT NULL,
586 [SrcDocType] [varchar](50) NOT NULL,
587 [SrcDocName] [varchar](100) NOT NULL,
588 [SrcFolderPath] [varchar](2000) NOT NULL,
589 [SrcFolderDesc] [varchar](255) NOT NULL,
590 [DestDrawer] [varchar](50) NOT NULL,
591 [DestFileType] [varchar](50) NOT NULL,
592 [DestDocType] [varchar](50) NOT NULL,
593 [DestFolderPath] [varchar](4000) NOT NULL
594) ON [PRIMARY]
595
596GO
597SET ANSI_PADDING OFF
598GO
599/****** Object: Table [dbo].[MapMark] Script Date: 21/11/2016 12:32:21 ******/
600SET ANSI_NULLS ON
601GO
602SET QUOTED_IDENTIFIER ON
603GO
604SET ANSI_PADDING ON
605GO
606CREATE TABLE [dbo].[MapMark](
607 [System] [varchar](50) NOT NULL,
608 [SrcDrawer] [varchar](255) NOT NULL,
609 [MarkType] [varchar](50) NOT NULL,
610 [SrcMarkID] [varchar](255) NOT NULL,
611 [SrcMarkDesc] [varchar](255) NOT NULL,
612 [DestMarkID] [int] NULL,
613 [DestMarkDesc] [varchar](255) NULL,
614 [DestMarkProgrammaticName] [varchar](255) NULL,
615 [DestFileType] [varchar](255) NULL,
616 CONSTRAINT [UNIQUE_MapMark_SrcColumns] UNIQUE NONCLUSTERED
617(
618 [System] ASC,
619 [SrcDrawer] ASC,
620 [MarkType] ASC,
621 [SrcMarkID] ASC
622)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
623) ON [PRIMARY]
624
625GO
626SET ANSI_PADDING OFF
627GO
628/****** Object: Table [dbo].[MapTask] Script Date: 21/11/2016 12:32:21 ******/
629SET ANSI_NULLS ON
630GO
631SET QUOTED_IDENTIFIER ON
632GO
633SET ANSI_PADDING ON
634GO
635CREATE TABLE [dbo].[MapTask](
636 [System] [varchar](20) NOT NULL,
637 [srcFlowid] [varchar](255) NOT NULL,
638 [srcFlowName] [varchar](255) NOT NULL,
639 [srcStepid] [varchar](255) NOT NULL,
640 [srcStepName] [varchar](255) NOT NULL,
641 [DestFlowProgName] [varchar](50) NOT NULL,
642 [DestStepProgName] [varchar](50) NOT NULL
643) ON [PRIMARY]
644
645GO
646SET ANSI_PADDING OFF
647GO
648/****** Object: Table [dbo].[MapTaskAttribute] Script Date: 21/11/2016 12:32:21 ******/
649SET ANSI_NULLS ON
650GO
651SET QUOTED_IDENTIFIER ON
652GO
653SET ANSI_PADDING ON
654GO
655CREATE TABLE [dbo].[MapTaskAttribute](
656 [SourceSystem] [varchar](50) NOT NULL,
657 [Sourcev3Prompt] [varchar](50) NOT NULL,
658 [Sourcev3RecordNo] [varchar](50) NOT NULL,
659 [Sourcev3FieldNo] [varchar](50) NOT NULL,
660 [Sourcev3AttributeValue] [varchar](50) NOT NULL,
661 [DestAttributeName] [varchar](50) NOT NULL,
662 [DestAttributeProgrammaticName] [varchar](50) NOT NULL,
663 [DestAttributeValue] [varchar](50) NOT NULL
664) ON [PRIMARY]
665
666GO
667SET ANSI_PADDING OFF
668GO
669/****** Object: Table [dbo].[MapUser] Script Date: 21/11/2016 12:32:21 ******/
670SET ANSI_NULLS ON
671GO
672SET QUOTED_IDENTIFIER ON
673GO
674SET ANSI_PADDING ON
675GO
676CREATE TABLE [dbo].[MapUser](
677 [System] [varchar](50) NOT NULL,
678 [SrcUserID] [varchar](50) NOT NULL,
679 [SrcUserName] [varchar](50) NOT NULL,
680 [DestAccountID] [varchar](50) NOT NULL,
681 [DestUserName] [varchar](50) NOT NULL
682) ON [PRIMARY]
683
684GO
685SET ANSI_PADDING OFF
686GO
687/****** Object: Table [dbo].[MigrationDocument] Script Date: 21/11/2016 12:32:21 ******/
688SET ANSI_NULLS ON
689GO
690SET QUOTED_IDENTIFIER ON
691GO
692SET ANSI_PADDING ON
693GO
694CREATE TABLE [dbo].[MigrationDocument](
695 [ID] [varchar](300) NOT NULL,
696 [FileID] [varchar](300) NOT NULL,
697 [Status] [int] NOT NULL,
698 [MachineName] [varchar](100) NULL,
699 [Priority] [int] NULL,
700 [bookmark] [uniqueidentifier] NULL,
701 [Timestamp] [datetime] NULL,
702 [System] [varchar](50) NOT NULL,
703 [SrcDrawerID] [int] NULL,
704 [SrcDrawer] [varchar](100) NOT NULL,
705 [SrcFileID] [int] NULL,
706 [SrcFileNumber] [varchar](300) NOT NULL,
707 [SrcFileName] [varchar](255) NULL,
708 [SrcFileType] [varchar](255) NULL,
709 [SrcDocID] [int] NULL,
710 [SrcDocType] [varchar](255) NULL,
711 [SrcDocDate] [datetime] NULL,
712 [SrcCreateDate] [datetime] NULL,
713 [SrcAttributes] [varchar](4000) NULL,
714 [PageCount] [int] NOT NULL,
715 [ExtCount] [int] NOT NULL,
716 [HoldReason] [varchar](500) NULL,
717 CONSTRAINT [PK_MigrationDocument] PRIMARY KEY CLUSTERED
718(
719 [ID] ASC
720)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
721) ON [PRIMARY]
722
723GO
724SET ANSI_PADDING OFF
725GO
726/****** Object: Table [dbo].[MigrationFile] Script Date: 21/11/2016 12:32:21 ******/
727SET ANSI_NULLS ON
728GO
729SET QUOTED_IDENTIFIER ON
730GO
731SET ANSI_PADDING ON
732GO
733CREATE TABLE [dbo].[MigrationFile](
734 [ID] [varchar](300) NOT NULL,
735 [Status] [int] NULL,
736 [Priority] [int] NULL,
737 [PageCount] [int] NULL,
738 [DocumentCount] [int] NULL,
739 [TaskCount] [int] NULL,
740 [System] [varchar](50) NULL,
741 [SrcDrawerID] [int] NULL,
742 [SrcDrawer] [varchar](50) NULL,
743 [SrcFileID] [int] NULL,
744 [SrcFileNumber] [varchar](255) NULL,
745 [SrcFileName] [varchar](255) NULL,
746 [SrcUserData1] [varchar](50) NULL,
747 [SrcUserData2] [varchar](50) NULL,
748 [SrcUserData3] [varchar](50) NULL,
749 [SrcUserData4] [varchar](50) NULL,
750 [SrcUserData5] [varchar](50) NULL,
751 [SrcFileType] [varchar](255) NULL,
752 [SrcFileOwner] [varchar](10) NULL,
753 [SrcFileMark1] [int] NULL,
754 [SrcFileMark2] [int] NULL,
755 [SrcFileMark3] [int] NULL,
756 [CreateDate] [datetime] NULL,
757 [MostRecentDocDate] [datetime] NULL,
758 [Attributes] [varchar](5000) NULL,
759 CONSTRAINT [PK_MigrationFile] PRIMARY KEY CLUSTERED
760(
761 [ID] ASC
762)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
763) ON [PRIMARY]
764
765GO
766SET ANSI_PADDING OFF
767GO
768/****** Object: Table [dbo].[MigrationPage] Script Date: 21/11/2016 12:32:21 ******/
769SET ANSI_NULLS ON
770GO
771SET QUOTED_IDENTIFIER ON
772GO
773SET ANSI_PADDING ON
774GO
775CREATE TABLE [dbo].[MigrationPage](
776 [ID] [bigint] IDENTITY(1,1) NOT NULL,
777 [DocumentID] [varchar](300) NOT NULL,
778 [FileID] [varchar](300) NOT NULL,
779 [FilePath] [varchar](500) NULL,
780 [AnnotationsPath] [varchar](500) NULL,
781 [IRDrawer] [varchar](100) NULL,
782 [IRFileType] [varchar](100) NULL,
783 [IRFileNumber] [varchar](255) NULL,
784 [IRFileName] [varchar](255) NULL,
785 [IRFolderPath] [varchar](4000) NULL,
786 [IRDocType] [varchar](100) NULL,
787 [IRPageMark] [int] NULL,
788 [IRDocDate] [datetime] NULL,
789 [IRDocDescription] [varchar](255) NULL,
790 [IRPageDescription] [varchar](255) NULL,
791 [IRAttribute1] [varchar](200) NULL,
792 [IRAttribute2] [varchar](200) NULL,
793 [IRAttribute3] [varchar](200) NULL,
794 [IRAttribute4] [varchar](200) NULL,
795 [IRAttribute5] [varchar](200) NULL,
796 [IRAttribute6] [varchar](200) NULL,
797 [IRAttribute7] [varchar](200) NULL,
798 [IRAttribute8] [varchar](200) NULL,
799 [IRAttribute9] [varchar](200) NULL,
800 [IRAttribute10] [varchar](200) NULL,
801 [IRAttribute11] [varchar](200) NULL,
802 [IRAttribute12] [varchar](200) NULL,
803 [IRAttribute13] [varchar](200) NULL,
804 [IRAttribute14] [varchar](200) NULL,
805 [IRAttribute15] [varchar](200) NULL,
806 [Orientation] [int] NOT NULL,
807 [PageNumber] [int] NULL,
808 [System] [varchar](50) NOT NULL,
809 [SrcDrawerID] [int] NOT NULL,
810 [SrcDrawer] [varchar](100) NOT NULL,
811 [SrcFileNumber] [varchar](255) NOT NULL,
812 [SrcFileName] [varchar](255) NOT NULL,
813 [SrcFileID] [int] NOT NULL,
814 [SrcFileType] [varchar](50) NOT NULL,
815 [SrcFolderPath] [varchar](2000) NULL,
816 [SrcFolderPathFull] [varchar](4000) NULL,
817 [SrcFolderTypeDesc] [varchar](255) NULL,
818 [SrcFolderID] [int] NULL,
819 [SrcNoteID] [int] NULL,
820 [SrcDocType] [varchar](50) NOT NULL,
821 [SrcDocDescription] [varchar](255) NULL,
822 [SrcDocDate] [datetime] NULL,
823 [SrcReceivedDate] [datetime] NULL,
824 [SrcDocID] [int] NULL,
825 [SrcDocLastModified] [datetime] NULL,
826 [SrcDocCreated] [datetime] NULL,
827 [SrcPageID] [int] NULL,
828 [SrcPageDescription] [varchar](255) NULL,
829 [SrcPageLastModified] [datetime] NULL,
830 [SrcPageCreated] [datetime] NULL,
831 [SrcPageMark] [varchar](255) NULL,
832 [SrcImageSetID] [int] NULL,
833 [SrcImageID] [int] NULL,
834 [SrcImageVersion] [int] NULL,
835 [SrcCritical] [int] NULL,
836 [SrcPathDate] [int] NULL,
837 [SrcDivisionNumber] [int] NULL,
838 [SrcImageExt] [varchar](50) NULL,
839 [SrcImageType] [int] NULL,
840 [SrcPlatterID] [int] NULL,
841 [SrcPlatterNearlineDeviceID] [int] NULL,
842 [SrcImageVersionNearlineDeviceID] [int] NULL,
843 [SrcImageVersionOnlineDeviceID] [int] NULL,
844 [SrcImageMap3xPath] [varchar](120) NULL,
845 [SrcImageMap3xPlatter] [varchar](20) NULL,
846 [SrcPlatterMap3xNearLineDeviceID] [int] NULL,
847 [SrcImageMap3xDeviceId] [int] NULL,
848 [SrcAnnImageSetID] [int] NULL,
849 [SrcAnnImageID] [int] NULL,
850 [SrcAnnImageVersion] [int] NULL,
851 [SrcAnnCritical] [int] NULL,
852 [SrcAnnPathDate] [int] NULL,
853 [SrcAnnDivisionNumber] [int] NULL,
854 [SrcAnnImageExt] [varchar](50) NULL,
855 [SrcAnnImageType] [int] NULL,
856 [SrcAnnPlatterID] [int] NULL,
857 [SrcAnnPlatterNearlineDeviceID] [int] NULL,
858 [SrcAnnImageVersionNearlineDeviceID] [int] NULL,
859 [SrcAnnImageVersionOnlineDeviceID] [int] NULL,
860 [SrcAnnImageMap3xPath] [varchar](120) NULL,
861 [SrcAnnImageMap3xPlatter] [varchar](20) NULL,
862 [SrcAnnPlatterMap3xNearLineDeviceID] [int] NULL,
863 [SrcAnnImageMap3xDeviceId] [int] NULL,
864 [MissImageExt] [varchar](50) NULL,
865 CONSTRAINT [PK_MigrationPage] PRIMARY KEY CLUSTERED
866(
867 [ID] ASC
868)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
869) ON [PRIMARY]
870
871GO
872SET ANSI_PADDING OFF
873GO
874/****** Object: Table [dbo].[MigrationPath] Script Date: 21/11/2016 12:32:21 ******/
875SET ANSI_NULLS ON
876GO
877SET QUOTED_IDENTIFIER ON
878GO
879SET ANSI_PADDING ON
880GO
881CREATE TABLE [dbo].[MigrationPath](
882 [System] [varchar](40) NOT NULL,
883 [storage] [varchar](20) NOT NULL,
884 [ID] [varchar](20) NOT NULL,
885 [Path] [varchar](400) NOT NULL,
886 CONSTRAINT [PK_MigrationPath] PRIMARY KEY CLUSTERED
887(
888 [System] ASC,
889 [storage] ASC,
890 [ID] ASC
891)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
892) ON [PRIMARY]
893
894GO
895SET ANSI_PADDING OFF
896GO
897/****** Object: Table [dbo].[MigrationSecurity] Script Date: 21/11/2016 12:32:21 ******/
898SET ANSI_NULLS ON
899GO
900SET QUOTED_IDENTIFIER ON
901GO
902SET ANSI_PADDING ON
903GO
904CREATE TABLE [dbo].[MigrationSecurity](
905 [System] [varchar](40) NOT NULL,
906 [AccountID] [int] NOT NULL,
907 [ExternalID] [varchar](255) NULL,
908 [Name] [varchar](255) NULL,
909 [Description] [varchar](255) NULL,
910 [AccountType] [int] NULL,
911 CONSTRAINT [PK_MigrationSecurity] PRIMARY KEY CLUSTERED
912(
913 [System] ASC,
914 [AccountID] ASC
915)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
916) ON [PRIMARY]
917
918GO
919SET ANSI_PADDING OFF
920GO
921/****** Object: Table [dbo].[MigrationTask] Script Date: 21/11/2016 12:32:21 ******/
922SET ANSI_NULLS ON
923GO
924SET QUOTED_IDENTIFIER ON
925GO
926SET ANSI_PADDING ON
927GO
928CREATE TABLE [dbo].[MigrationTask](
929 [ID] [bigint] IDENTITY(1,1) NOT NULL,
930 [FileID] [varchar](300) NOT NULL,
931 [DocumentID] [varchar](300) NOT NULL,
932 [PageID] [bigint] NOT NULL,
933 [FlowID] [varchar](255) NULL,
934 [StepID] [varchar](255) NULL,
935 [Description] [varchar](255) NULL,
936 [AssignedToUserID] [varchar](50) NULL,
937 [Priority] [int] NOT NULL,
938 [AvailableDate] [datetime] NOT NULL,
939 [System] [varchar](50) NOT NULL,
940 [SrcDrawer] [varchar](255) NOT NULL,
941 [SrcTaskID] [varchar](50) NOT NULL,
942 [SrcFlowID] [varchar](255) NOT NULL,
943 [SrcStepID] [varchar](255) NOT NULL,
944 [SrcExtraKey] [varchar](255) NULL,
945 [SrcAssignedToUserID] [varchar](50) NULL,
946 CONSTRAINT [PK_MigrationTask] PRIMARY KEY CLUSTERED
947(
948 [ID] ASC
949)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
950) ON [PRIMARY]
951
952GO
953SET ANSI_PADDING OFF
954GO
955/****** Object: Table [dbo].[MigrationType] Script Date: 21/11/2016 12:32:21 ******/
956SET ANSI_NULLS ON
957GO
958SET QUOTED_IDENTIFIER ON
959GO
960SET ANSI_PADDING ON
961GO
962CREATE TABLE [dbo].[MigrationType](
963 [System] [varchar](40) NOT NULL,
964 [Kind] [varchar](10) NOT NULL,
965 [Drawer] [varchar](50) NOT NULL CONSTRAINT [MigrationType_Drawer_Default] DEFAULT (''),
966 [ItemType] [varchar](255) NOT NULL,
967 [Description] [varchar](255) NOT NULL,
968 CONSTRAINT [PK_MigrationType] PRIMARY KEY CLUSTERED
969(
970 [System] ASC,
971 [Kind] ASC,
972 [Drawer] ASC,
973 [ItemType] ASC
974)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
975) ON [PRIMARY]
976
977GO
978SET ANSI_PADDING OFF
979GO
980/****** Object: Table [dbo].[newfilemarks] Script Date: 21/11/2016 12:32:21 ******/
981SET ANSI_NULLS ON
982GO
983SET QUOTED_IDENTIFIER ON
984GO
985SET ANSI_PADDING ON
986GO
987CREATE TABLE [dbo].[newfilemarks](
988 [filemarkid] [int] NOT NULL,
989 [description] [varchar](255) NULL,
990 [color] [int] NOT NULL,
991 [bindata] [image] NULL,
992 [programmaticname] [varchar](255) NULL
993) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
994
995GO
996SET ANSI_PADDING OFF
997GO
998/****** Object: Table [dbo].[newtasks] Script Date: 21/11/2016 12:32:21 ******/
999SET ANSI_NULLS ON
1000GO
1001SET QUOTED_IDENTIFIER ON
1002GO
1003SET ANSI_PADDING ON
1004GO
1005CREATE TABLE [dbo].[newtasks](
1006 [MigrationID] [varchar](255) NULL
1007) ON [PRIMARY]
1008
1009GO
1010SET ANSI_PADDING OFF
1011GO
1012/****** Object: Table [dbo].[PageMarkz] Script Date: 21/11/2016 12:32:21 ******/
1013SET ANSI_NULLS ON
1014GO
1015SET QUOTED_IDENTIFIER ON
1016GO
1017SET ANSI_PADDING ON
1018GO
1019CREATE TABLE [dbo].[PageMarkz](
1020 [fileid] [int] NOT NULL,
1021 [pageid] [int] NOT NULL,
1022 [pagemarkid] [int] NOT NULL,
1023 [filenumber] [varchar](255) NOT NULL,
1024 [name] [varchar](50) NOT NULL
1025) ON [PRIMARY]
1026
1027GO
1028SET ANSI_PADDING OFF
1029GO
1030/****** Object: Table [dbo].[PRFolderDesc] Script Date: 21/11/2016 12:32:21 ******/
1031SET ANSI_NULLS ON
1032GO
1033SET QUOTED_IDENTIFIER ON
1034GO
1035SET ANSI_PADDING ON
1036GO
1037CREATE TABLE [dbo].[PRFolderDesc](
1038 [docfolderid] [int] NOT NULL,
1039 [description] [varchar](255) NULL,
1040 [fileid] [int] NOT NULL,
1041 [filename] [varchar](255) NULL,
1042 [filenumber] [varchar](255) NULL
1043) ON [PRIMARY]
1044
1045GO
1046SET ANSI_PADDING OFF
1047GO
1048/****** Object: Table [dbo].[ProcMapping] Script Date: 21/11/2016 12:32:21 ******/
1049SET ANSI_NULLS ON
1050GO
1051SET QUOTED_IDENTIFIER ON
1052GO
1053SET ANSI_PADDING ON
1054GO
1055CREATE TABLE [dbo].[ProcMapping](
1056 [ID] [int] IDENTITY(1,1) NOT NULL,
1057 [filenumber] [varchar](50) NULL,
1058 [ProcessorName] [varchar](max) NULL,
1059PRIMARY KEY CLUSTERED
1060(
1061 [ID] ASC
1062)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1063) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
1064
1065GO
1066SET ANSI_PADDING OFF
1067GO
1068/****** Object: Table [dbo].[rep] Script Date: 21/11/2016 12:32:21 ******/
1069SET ANSI_NULLS ON
1070GO
1071SET QUOTED_IDENTIFIER ON
1072GO
1073SET ANSI_PADDING ON
1074GO
1075CREATE TABLE [dbo].[rep](
1076 [DocumentID] [varchar](300) NOT NULL
1077) ON [PRIMARY]
1078
1079GO
1080SET ANSI_PADDING OFF
1081GO
1082/****** Object: Table [dbo].[SnapshotAttribute] Script Date: 21/11/2016 12:32:21 ******/
1083SET ANSI_NULLS ON
1084GO
1085SET QUOTED_IDENTIFIER ON
1086GO
1087SET ANSI_PADDING ON
1088GO
1089CREATE TABLE [dbo].[SnapshotAttribute](
1090 [SnapShot] [datetime] NOT NULL,
1091 [OBJECTID] [int] NOT NULL,
1092 [OBJECTNAME] [varchar](255) NULL,
1093 [OBJECTTYPE] [varchar](255) NULL,
1094 [ATTRIBUTEID] [int] NOT NULL,
1095 [ATTRIBUTENAME] [varchar](255) NULL,
1096 [ATTRIBUTEVALUE] [varchar](255) NULL
1097) ON [PRIMARY]
1098
1099GO
1100SET ANSI_PADDING OFF
1101GO
1102/****** Object: Table [dbo].[SnapshotDevice] Script Date: 21/11/2016 12:32:21 ******/
1103SET ANSI_NULLS ON
1104GO
1105SET QUOTED_IDENTIFIER ON
1106GO
1107SET ANSI_PADDING ON
1108GO
1109CREATE TABLE [dbo].[SnapshotDevice](
1110 [SnapShot] [datetime] NOT NULL,
1111 [deviceid] [int] NOT NULL,
1112 [uncpath] [varchar](255) NULL,
1113 [devicetype] [int] NOT NULL,
1114 [isdefault] [int] NOT NULL,
1115 [filesperdirectory] [int] NOT NULL,
1116 [cacheceiling] [float] NOT NULL,
1117 [cachefloor] [float] NOT NULL,
1118 [disabled] [int] NOT NULL,
1119 [deviceproperties] [varchar](255) NULL
1120) ON [PRIMARY]
1121
1122GO
1123SET ANSI_PADDING OFF
1124GO
1125/****** Object: Table [dbo].[SnapshotDocument] Script Date: 21/11/2016 12:32:21 ******/
1126SET ANSI_NULLS ON
1127GO
1128SET QUOTED_IDENTIFIER ON
1129GO
1130SET ANSI_PADDING ON
1131GO
1132CREATE TABLE [dbo].[SnapshotDocument](
1133 [SnapShot] [datetime] NOT NULL,
1134 [DOCUMENTID] [int] NOT NULL,
1135 [FOLDERID] [int] NULL,
1136 [DESCRIPTION] [varchar](255) NULL,
1137 [LASTMODIFIED] [datetime] NOT NULL,
1138 [FILEID] [int] NOT NULL,
1139 [CREATED] [datetime] NOT NULL,
1140 [ISDELETED] [int] NOT NULL,
1141 [DOCUMENTDATE] [datetime] NOT NULL,
1142 [RECEIVEDDATE] [datetime] NOT NULL,
1143 [DOCTYPE] [varchar](255) NULL,
1144 [DOCTYPEDESC] [varchar](255) NULL
1145) ON [PRIMARY]
1146
1147GO
1148SET ANSI_PADDING OFF
1149GO
1150/****** Object: Table [dbo].[SnapshotFile] Script Date: 21/11/2016 12:32:21 ******/
1151SET ANSI_NULLS ON
1152GO
1153SET QUOTED_IDENTIFIER ON
1154GO
1155SET ANSI_PADDING ON
1156GO
1157CREATE TABLE [dbo].[SnapshotFile](
1158 [SnapShot] [datetime] NOT NULL,
1159 [FILENUMBER] [varchar](255) NULL,
1160 [FILENAME] [varchar](255) NULL,
1161 [LOCATIONID] [int] NOT NULL,
1162 [FILEID] [int] NOT NULL,
1163 [LASTMODIFIED] [datetime] NULL,
1164 [CREATED] [datetime] NOT NULL,
1165 [DATELASTOPENED] [datetime] NULL,
1166 [ISTEMPORARY] [int] NOT NULL,
1167 [ISDELETED] [int] NOT NULL,
1168 [FILETYPE] [varchar](255) NULL,
1169 [FILETYPEDESC] [varchar](255) NULL
1170) ON [PRIMARY]
1171
1172GO
1173SET ANSI_PADDING OFF
1174GO
1175/****** Object: Table [dbo].[SnapshotFolder] Script Date: 21/11/2016 12:32:21 ******/
1176SET ANSI_NULLS ON
1177GO
1178SET QUOTED_IDENTIFIER ON
1179GO
1180SET ANSI_PADDING ON
1181GO
1182CREATE TABLE [dbo].[SnapshotFolder](
1183 [SnapShot] [datetime] NOT NULL,
1184 [FOLDERID] [int] NOT NULL,
1185 [PARENTID] [int] NULL,
1186 [DESCRIPTION] [varchar](255) NULL,
1187 [LASTMODIFIED] [datetime] NOT NULL,
1188 [FILEID] [int] NOT NULL,
1189 [CREATED] [datetime] NOT NULL,
1190 [ISDELETED] [int] NOT NULL,
1191 [FOLDERTYPE] [varchar](255) NULL,
1192 [FOLDERTYPEDESC] [varchar](255) NULL
1193) ON [PRIMARY]
1194
1195GO
1196SET ANSI_PADDING OFF
1197GO
1198/****** Object: Table [dbo].[SnapshotImage] Script Date: 21/11/2016 12:32:21 ******/
1199SET ANSI_NULLS ON
1200GO
1201SET QUOTED_IDENTIFIER ON
1202GO
1203SET ANSI_PADDING ON
1204GO
1205CREATE TABLE [dbo].[SnapshotImage](
1206 [SnapShot] [datetime] NOT NULL,
1207 [IMAGESETID] [int] NOT NULL,
1208 [IMAGEID] [int] NOT NULL,
1209 [IMAGEVERSION] [int] NOT NULL,
1210 [CRITICAL] [int] NOT NULL,
1211 [PATHDATE] [int] NOT NULL,
1212 [DIVISIONNUMBER] [int] NOT NULL,
1213 [ORIENTATION] [int] NOT NULL,
1214 [IMAGEEXT] [varchar](255) NULL,
1215 [IMAGETYPE] [int] NOT NULL,
1216 [PLATTERID] [int] NULL,
1217 [PLATTERNEARLINEDEVICEID] [int] NULL,
1218 [IMAGEVERSIONNEARLINEDEVICEID] [int] NULL,
1219 [IMAGEVERSIONONLINEDEVICEID] [int] NULL
1220) ON [PRIMARY]
1221
1222GO
1223SET ANSI_PADDING OFF
1224GO
1225/****** Object: Table [dbo].[SnapshotLocation] Script Date: 21/11/2016 12:32:21 ******/
1226SET ANSI_NULLS ON
1227GO
1228SET QUOTED_IDENTIFIER ON
1229GO
1230SET ANSI_PADDING ON
1231GO
1232CREATE TABLE [dbo].[SnapshotLocation](
1233 [SnapShot] [datetime] NOT NULL,
1234 [LOCATIONID] [int] NOT NULL,
1235 [PARENTID] [int] NULL,
1236 [NAME] [varchar](255) NULL,
1237 [DESCRIPTION] [varchar](255) NULL,
1238 [LOCATIONTYPE] [varchar](255) NULL,
1239 [LOCATIONTYPEDESC] [varchar](255) NULL
1240) ON [PRIMARY]
1241
1242GO
1243SET ANSI_PADDING OFF
1244GO
1245/****** Object: Table [dbo].[SnapshotNote] Script Date: 21/11/2016 12:32:21 ******/
1246SET ANSI_NULLS ON
1247GO
1248SET QUOTED_IDENTIFIER ON
1249GO
1250CREATE TABLE [dbo].[SnapshotNote](
1251 [SnapShot] [datetime] NOT NULL,
1252 [NOTEID] [int] NOT NULL,
1253 [OBJECTID] [int] NOT NULL,
1254 [ISDELETED] [int] NOT NULL,
1255 [HIDDEN] [int] NOT NULL,
1256 [NOTETYPEID] [int] NOT NULL,
1257 [DEFAULTNOTE] [int] NULL,
1258 [IMAGESETID] [int] NOT NULL
1259) ON [PRIMARY]
1260
1261GO
1262/****** Object: Table [dbo].[SnapshotPage] Script Date: 21/11/2016 12:32:21 ******/
1263SET ANSI_NULLS ON
1264GO
1265SET QUOTED_IDENTIFIER ON
1266GO
1267SET ANSI_PADDING ON
1268GO
1269CREATE TABLE [dbo].[SnapshotPage](
1270 [SnapShot] [datetime] NOT NULL,
1271 [PAGEID] [int] NOT NULL,
1272 [DESCRIPTION] [varchar](255) NULL,
1273 [PAGENUMBER] [int] NOT NULL,
1274 [IMAGESETID] [int] NOT NULL,
1275 [LASTMODIFIED] [datetime] NOT NULL,
1276 [CREATED] [datetime] NOT NULL,
1277 [DOCUMENTID] [int] NOT NULL,
1278 [ISDELETED] [int] NOT NULL,
1279 [PAGEMARK] [varchar](255) NULL,
1280 [PAGEMARKDESC] [varchar](255) NULL
1281) ON [PRIMARY]
1282
1283GO
1284SET ANSI_PADDING OFF
1285GO
1286/****** Object: Table [dbo].[SnapshotSecurity] Script Date: 21/11/2016 12:32:21 ******/
1287SET ANSI_NULLS ON
1288GO
1289SET QUOTED_IDENTIFIER ON
1290GO
1291SET ANSI_PADDING ON
1292GO
1293CREATE TABLE [dbo].[SnapshotSecurity](
1294 [SnapShot] [datetime] NOT NULL,
1295 [ACCOUNTID] [int] NOT NULL,
1296 [EXTERNALID] [varchar](255) NULL,
1297 [NAME] [varchar](255) NULL,
1298 [DESCRIPTION] [varchar](255) NULL,
1299 [ACCOUNTTYPE] [int] NOT NULL
1300) ON [PRIMARY]
1301
1302GO
1303SET ANSI_PADDING OFF
1304GO
1305/****** Object: Table [dbo].[SnapshotTask] Script Date: 21/11/2016 12:32:21 ******/
1306SET ANSI_NULLS ON
1307GO
1308SET QUOTED_IDENTIFIER ON
1309GO
1310SET ANSI_PADDING ON
1311GO
1312CREATE TABLE [dbo].[SnapshotTask](
1313 [SnapShot] [datetime] NOT NULL,
1314 [TASKID] [int] NOT NULL,
1315 [FILEID] [int] NOT NULL,
1316 [ATTACHEDTO] [varchar](255) NULL,
1317 [FLOWNAME] [varchar](255) NULL,
1318 [FLOWDESC] [varchar](255) NULL,
1319 [STEPNAME] [varchar](255) NULL,
1320 [STEPDESC] [text] NULL,
1321 [ASSIGNEDTO] [varchar](255) NULL,
1322 [OBJECTID] [int] NOT NULL,
1323 [PAGEID] [int] NULL,
1324 [NOTEID] [int] NULL,
1325 [PRIORITY] [int] NOT NULL,
1326 [STATUS] [int] NOT NULL,
1327 [DESCRIPTION] [varchar](255) NULL,
1328 [DATEAVAILABLE] [datetime] NOT NULL
1329) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
1330
1331GO
1332SET ANSI_PADDING OFF
1333GO
1334/****** Object: View [dbo].[LogProcessTime] Script Date: 21/11/2016 12:32:21 ******/
1335SET ANSI_NULLS ON
1336GO
1337SET QUOTED_IDENTIFIER ON
1338GO
1339create view [dbo].[LogProcessTime]
1340as
1341select *,
1342 LogProcess.Duration as Durationms,
1343 LogProcess.Duration/86400000 as DurationDayPart,
1344 CONVERT(varchar,dateadd(ms,LogProcess.Duration,0),114) as DurationTimePart
1345from LogProcess
1346
1347GO
1348SET ANSI_PADDING ON
1349
1350GO
1351/****** Object: Index [IX_LogProgress_DocumentID] Script Date: 21/11/2016 12:32:21 ******/
1352CREATE NONCLUSTERED INDEX [IX_LogProgress_DocumentID] ON [dbo].[LogProgress]
1353(
1354 [DocumentID] ASC
1355)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1356GO
1357SET ANSI_PADDING ON
1358
1359GO
1360/****** Object: Index [IX_MigrationDocument_Bookmark] Script Date: 21/11/2016 12:32:21 ******/
1361CREATE NONCLUSTERED INDEX [IX_MigrationDocument_Bookmark] ON [dbo].[MigrationDocument]
1362(
1363 [bookmark] ASC
1364)
1365INCLUDE ( [ID]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1366GO
1367SET ANSI_PADDING ON
1368
1369GO
1370/****** Object: Index [IX_MigrationDocument_FileID] Script Date: 21/11/2016 12:32:21 ******/
1371CREATE NONCLUSTERED INDEX [IX_MigrationDocument_FileID] ON [dbo].[MigrationDocument]
1372(
1373 [FileID] ASC
1374)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1375GO
1376/****** Object: Index [IX_MigrationDocument_Priority] Script Date: 21/11/2016 12:32:21 ******/
1377CREATE NONCLUSTERED INDEX [IX_MigrationDocument_Priority] ON [dbo].[MigrationDocument]
1378(
1379 [Priority] ASC
1380)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1381GO
1382/****** Object: Index [IX_MigrationDocument_StatusPriority] Script Date: 21/11/2016 12:32:21 ******/
1383CREATE NONCLUSTERED INDEX [IX_MigrationDocument_StatusPriority] ON [dbo].[MigrationDocument]
1384(
1385 [Status] ASC,
1386 [Priority] ASC
1387)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1388GO
1389/****** Object: Index [IX_MigrationFile_PriorityStatus] Script Date: 21/11/2016 12:32:21 ******/
1390CREATE NONCLUSTERED INDEX [IX_MigrationFile_PriorityStatus] ON [dbo].[MigrationFile]
1391(
1392 [Priority] ASC,
1393 [Status] ASC
1394)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1395GO
1396SET ANSI_PADDING ON
1397
1398GO
1399/****** Object: Index [IX_MigrationFile_SystemDrawerFile] Script Date: 21/11/2016 12:32:21 ******/
1400CREATE NONCLUSTERED INDEX [IX_MigrationFile_SystemDrawerFile] ON [dbo].[MigrationFile]
1401(
1402 [System] ASC,
1403 [SrcDrawer] ASC,
1404 [SrcFileNumber] ASC
1405)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1406GO
1407SET ANSI_PADDING ON
1408
1409GO
1410/****** Object: Index [IX_MigrationPage_DocumentID] Script Date: 21/11/2016 12:32:21 ******/
1411CREATE NONCLUSTERED INDEX [IX_MigrationPage_DocumentID] ON [dbo].[MigrationPage]
1412(
1413 [DocumentID] ASC,
1414 [PageNumber] ASC
1415)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1416GO
1417SET ANSI_PADDING ON
1418
1419GO
1420/****** Object: Index [IX_MigrationPage_FileID] Script Date: 21/11/2016 12:32:21 ******/
1421CREATE NONCLUSTERED INDEX [IX_MigrationPage_FileID] ON [dbo].[MigrationPage]
1422(
1423 [FileID] ASC
1424)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1425GO
1426SET ANSI_PADDING ON
1427
1428GO
1429/****** Object: Index [IX_MigrationPage_MappingSample] Script Date: 21/11/2016 12:32:21 ******/
1430CREATE NONCLUSTERED INDEX [IX_MigrationPage_MappingSample] ON [dbo].[MigrationPage]
1431(
1432 [System] ASC,
1433 [SrcDrawer] ASC,
1434 [SrcFileNumber] ASC,
1435 [SrcFolderID] ASC,
1436 [SrcDocType] ASC
1437)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1438GO
1439SET ANSI_PADDING ON
1440
1441GO
1442/****** Object: Index [IX_MigrationTask_DocumentID] Script Date: 21/11/2016 12:32:21 ******/
1443CREATE NONCLUSTERED INDEX [IX_MigrationTask_DocumentID] ON [dbo].[MigrationTask]
1444(
1445 [DocumentID] ASC
1446)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1447GO
1448SET ANSI_PADDING ON
1449
1450GO
1451/****** Object: Index [IX_MigrationTask_FileID] Script Date: 21/11/2016 12:32:21 ******/
1452CREATE NONCLUSTERED INDEX [IX_MigrationTask_FileID] ON [dbo].[MigrationTask]
1453(
1454 [FileID] ASC
1455)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1456GO
1457/****** Object: Index [IX_MigrationTask_PageID] Script Date: 21/11/2016 12:32:21 ******/
1458CREATE NONCLUSTERED INDEX [IX_MigrationTask_PageID] ON [dbo].[MigrationTask]
1459(
1460 [PageID] ASC
1461)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1462GO
1463SET ANSI_PADDING ON
1464
1465GO
1466/****** Object: Index [IDX_SnapshotAttributeObject] Script Date: 21/11/2016 12:32:21 ******/
1467CREATE NONCLUSTERED INDEX [IDX_SnapshotAttributeObject] ON [dbo].[SnapshotAttribute]
1468(
1469 [OBJECTID] ASC
1470)
1471INCLUDE ( [ATTRIBUTENAME],
1472 [ATTRIBUTEVALUE]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1473GO
1474/****** Object: Index [IDX_SnapshotDocument_DocumentID] Script Date: 21/11/2016 12:32:21 ******/
1475CREATE NONCLUSTERED INDEX [IDX_SnapshotDocument_DocumentID] ON [dbo].[SnapshotDocument]
1476(
1477 [DOCUMENTID] ASC
1478)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1479GO
1480/****** Object: Index [IDX_SnapshotDocument_FileID] Script Date: 21/11/2016 12:32:21 ******/
1481CREATE NONCLUSTERED INDEX [IDX_SnapshotDocument_FileID] ON [dbo].[SnapshotDocument]
1482(
1483 [FILEID] ASC
1484)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1485GO
1486/****** Object: Index [IDX_SnapshotFile_FileID] Script Date: 21/11/2016 12:32:21 ******/
1487CREATE NONCLUSTERED INDEX [IDX_SnapshotFile_FileID] ON [dbo].[SnapshotFile]
1488(
1489 [FILEID] ASC
1490)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1491GO
1492/****** Object: Index [IDX_SnapshotFile_LocationID] Script Date: 21/11/2016 12:32:21 ******/
1493CREATE NONCLUSTERED INDEX [IDX_SnapshotFile_LocationID] ON [dbo].[SnapshotFile]
1494(
1495 [LOCATIONID] ASC
1496)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1497GO
1498SET ANSI_PADDING ON
1499
1500GO
1501/****** Object: Index [IDX_SnapshotFolder_FolderID] Script Date: 21/11/2016 12:32:21 ******/
1502CREATE NONCLUSTERED INDEX [IDX_SnapshotFolder_FolderID] ON [dbo].[SnapshotFolder]
1503(
1504 [FOLDERID] ASC
1505)
1506INCLUDE ( [PARENTID],
1507 [DESCRIPTION],
1508 [FOLDERTYPE],
1509 [ISDELETED]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1510GO
1511/****** Object: Index [IDX_SnapshotImage_ImageSetID] Script Date: 21/11/2016 12:32:21 ******/
1512CREATE NONCLUSTERED INDEX [IDX_SnapshotImage_ImageSetID] ON [dbo].[SnapshotImage]
1513(
1514 [IMAGESETID] ASC
1515)
1516INCLUDE ( [IMAGETYPE]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1517GO
1518/****** Object: Index [IDX_SnapshotNote_ObjectID] Script Date: 21/11/2016 12:32:21 ******/
1519CREATE NONCLUSTERED INDEX [IDX_SnapshotNote_ObjectID] ON [dbo].[SnapshotNote]
1520(
1521 [OBJECTID] ASC
1522)
1523INCLUDE ( [HIDDEN],
1524 [ISDELETED]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1525GO
1526/****** Object: Index [IDX_SnapshotPage_DocumentID] Script Date: 21/11/2016 12:32:21 ******/
1527CREATE NONCLUSTERED INDEX [IDX_SnapshotPage_DocumentID] ON [dbo].[SnapshotPage]
1528(
1529 [DOCUMENTID] ASC
1530)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1531GO
1532/****** Object: Index [IDX_SnapshotPage_ImageSetID] Script Date: 21/11/2016 12:32:21 ******/
1533CREATE NONCLUSTERED INDEX [IDX_SnapshotPage_ImageSetID] ON [dbo].[SnapshotPage]
1534(
1535 [IMAGESETID] ASC
1536)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1537GO
1538ALTER TABLE [dbo].[MapMark] ADD CONSTRAINT [DEFAULT_MapMark_MarkType_page] DEFAULT ('page') FOR [MarkType]
1539GO
1540ALTER TABLE [dbo].[ConfigDrawerList] WITH CHECK ADD CONSTRAINT [chkPurge] CHECK (([purge]='Date' OR [purge]='Files' OR [purge]='None' OR [purge]='All'))
1541GO
1542ALTER TABLE [dbo].[ConfigDrawerList] CHECK CONSTRAINT [chkPurge]
1543GO
1544ALTER TABLE [dbo].[ConfigPriority] WITH CHECK ADD CONSTRAINT [chkConfigPriority_Rule] CHECK (([rule]='Sample' OR [rule]='File' OR [rule]='TaskFiles' OR [rule]='TaskDocs' OR [rule]='DocDate' OR [rule]='Drawer'))
1545GO
1546ALTER TABLE [dbo].[ConfigPriority] CHECK CONSTRAINT [chkConfigPriority_Rule]
1547GO
1548ALTER TABLE [dbo].[MapMark] WITH CHECK ADD CONSTRAINT [chk_MapMark_MarkType] CHECK (([MarkType]='file' OR [MarkType]='page'))
1549GO
1550ALTER TABLE [dbo].[MapMark] CHECK CONSTRAINT [chk_MapMark_MarkType]
1551GO
1552/****** Object: StoredProcedure [dbo].[analyzeMigrationFileStatuses] Script Date: 21/11/2016 12:32:21 ******/
1553SET ANSI_NULLS ON
1554GO
1555SET QUOTED_IDENTIFIER ON
1556GO
1557create procedure [dbo].[analyzeMigrationFileStatuses]
1558 @migrationFileID varchar(300) = null,
1559 @fileNumber varchar(255) = null
1560as
1561begin
1562 set nocount on;
1563
1564 if @migrationFileID is null and @filenumber is null
1565 begin
1566 exec raiseMessage @message='analyzeMigrationFileStatuses requires that a value must be provided for either @migrationFileID or @fileNumber', @severity=15, @state=1;
1567 return
1568 end
1569
1570 --General Migration File Summary
1571 if object_id('tempdb..#File') is not null drop table #File
1572 select System, SrcDrawer, SrcFileNumber, ID as FileID, Status, Priority, PageCount, DocumentCount, TaskCount
1573 into #File
1574 from MigrationFile
1575 where SrcFileNumber=@filenumber
1576 or ID=@migrationFileID;
1577
1578 --Base File Analsysis table
1579 if object_id('tempdb..#FileAnalysis') is not null drop table #FileAnalysis
1580 ;with Tasks as(
1581 select FileID, DocumentID, SrcTaskID
1582 from MigrationTask
1583 where FileID in(select FileID from #File)
1584 ),
1585 ActiveTasks as(
1586 select DocumentID, count(*) as Tasks
1587 from MigrationTask
1588 where FlowID<>'Do Not Migrate'
1589 group by DocumentID
1590 ),
1591 PurgeTasks as(
1592 select DocumentID, count(*) as Tasks
1593 from MigrationTask
1594 where FlowID='Do Not Migrate'
1595 group by DocumentID
1596 )
1597 select MigrationDocument.System,
1598 MigrationDocument.SrcDrawer,
1599 MigrationDocument.SrcFileNumber,
1600 MigrationDocument.ID as DocumentID,
1601 MigrationDocument.FileID,
1602 MigrationDocument.Status,
1603 MigrationDocument.Priority,
1604 MigrationDocument.TimeStamp as DocMigrationStatusDate,
1605 SrcDocDate,
1606 MigrationDocument.PageCount,
1607 isnull(ActiveTasks.Tasks,0) as ActiveTasks,
1608 isnull(PurgeTasks.Tasks,0) as PurgeTasks,
1609 MigrationDocument.HoldReason,
1610 LogProgress.errormessage
1611 into #FileAnalysis
1612 from MigrationDocument
1613 left join ActiveTasks on MigrationDocument.ID=ActiveTasks.DocumentID
1614 left join PurgeTasks on MigrationDocument.ID=PurgeTasks.DocumentID
1615 join MigrationFile on MigrationDocument.FileID=MigrationFile.ID
1616 left join LogProgress on MigrationDocument.ID=LogProgress.DocumentID
1617 where MigrationFile.ID in(
1618 select FileID
1619 from #File
1620 )
1621
1622 -- Display results
1623 select * from #File
1624 select *
1625 from #FileAnalysis
1626 order by
1627 case status
1628 when -1 then 0
1629 when -5 then 1
1630 when 2 then 2
1631 when 0 then 3
1632 when 1 then 4
1633 when -9 then 100
1634 else 5
1635 end ASC, -- Enumerated so that errors and holds come first followed by Migrating, Pending, Migrated(Success), everything else but Purge, and Purge last
1636 errormessage,
1637 HoldReason,
1638 DocMigrationStatusDate desc
1639
1640 --
1641 if object_id('tempdb..#ErroredDocs') is not null drop table #ErroredDocs
1642 SELECT id,
1643 documentid,
1644 filepath,
1645 annotationspath,
1646 irdrawer,
1647 irfiletype,
1648 irfilenumber,
1649 irfilename,
1650 irfoldertype,
1651 irdoctype,
1652 irdocdate,
1653 irpagedescription,
1654 irpagemark,
1655 pagenumber
1656 Orientation,
1657 SrcDrawer,
1658 SrcFolderPath,
1659 SrcDocType
1660 into #ErroredDocs
1661 FROM MigrationPage (nolock)
1662 WHERE documentid in(select DocumentID from #FileAnalysis where Status=-1)
1663 ORDER BY documentid,pagenumber
1664
1665 if exists(select * from #ErroredDocs)
1666 select * from #ErroredDocs
1667 else
1668 exec raiseMessage 'There were no errored documents in the specified file.';
1669
1670 if exists(select * from #FileAnalysis where Status=-1 and (ActiveTasks>0 or PurgeTasks>0))
1671 begin
1672 if object_id('tempdb..#ErroredTasks') is not null drop table #ErroredTasks
1673 SELECT
1674 #FileAnalysis.FileID,
1675 #FileAnalysis.DocumentID,
1676 #FileAnalysis.Status as DocMigStatus,
1677 MigrationTask.flowid,
1678 MigrationTask.stepid,
1679 MigrationTask.description,
1680 MigrationTask.assignedtouserid as userid,
1681 MigrationTask.priority,
1682 MigrationTask.availabledate,
1683 MigrationTask.SrcTaskID,
1684 MigrationTask.SrcFlowID,
1685 MigrationTask.SrcStepID,
1686 #FileAnalysis.HoldReason,
1687 #FileAnalysis.errormessage
1688 into #ErroredTasks
1689 FROM MigrationTask (nolock)
1690 join #FileAnalysis on MigrationTask.DocumentID=#FileAnalysis.DocumentID
1691 WHERE MigrationTask.DocumentID in(select DocumentID from #FileAnalysis where Status=-1)
1692 --and flowid <> 'Do Not Migrate'
1693
1694 select *
1695 from #ErroredTasks
1696 end
1697 else
1698 exec raiseMessage 'There were no errored tasks in the specified file.';
1699end
1700
1701GO
1702/****** Object: StoredProcedure [dbo].[archiveSnapshot] Script Date: 21/11/2016 12:32:21 ******/
1703SET ANSI_NULLS ON
1704GO
1705SET QUOTED_IDENTIFIER ON
1706GO
1707create procedure [dbo].[archiveSnapshot]
1708 @system varchar(50)
1709as
1710begin
1711 if not exists(select * from sys.tables where name like 'Snapshot%')
1712 begin
1713 Raiserror('No current Snapshot exists!',16,1)
1714 return
1715 end
1716
1717 if exists(select * from sys.tables where name like 'z' + @system + '_Snapshot%')
1718 begin
1719 Raiserror('There is already an archived version of that Snapshot',16,1)
1720 return
1721 end
1722
1723 declare @archiveName varchar(100)
1724 declare @tablename varchar(100)
1725 declare tCursor cursor local static for
1726 select name from sys.tables where name like 'Snapshot%'
1727 open tCursor
1728 fetch from tCursor into @tablename
1729 while (@@FETCH_STATUS = 0)
1730 begin
1731 set @archiveName = 'z' + @system + '_' + @tablename
1732 exec sp_rename @tablename, @archiveName
1733 fetch from tCursor into @tablename
1734 end
1735 close tCursor
1736 deallocate tCursor
1737
1738end
1739
1740GO
1741/****** Object: StoredProcedure [dbo].[configureDefaults] Script Date: 21/11/2016 12:32:21 ******/
1742SET ANSI_NULLS ON
1743GO
1744SET QUOTED_IDENTIFIER ON
1745GO
1746CREATE Procedure [dbo].[configureDefaults]
1747 @system varchar(50),
1748 @estMigrationDate datetime
1749as
1750begin
1751 set nocount on
1752 Set Transaction Isolation Level Read Uncommitted
1753
1754 declare @logid int, @ProcName varchar(50)
1755 set @ProcName = Object_Name(@@PROCID)
1756 exec logStart @procname, @system, @ID = @logid output
1757
1758 if exists(select * from ConfigDrawerList where system = @system)
1759 or exists(select * from ConfigPriority where System = @system)
1760 begin
1761 raiserror(' System: %s already has some configuration.',1,18,@system)
1762 return
1763 end
1764
1765 if (db_name() in ('IconIRNet','ExtractIRNet'))
1766 begin
1767 insert into ConfigDrawerList
1768 select distinct system = @system, Name, 'None', null from SnapshotLocation
1769 end
1770 if (db_name() = 'IconIR3x')
1771 begin
1772 insert into ConfigDrawerList
1773 select distinct system = @system, drawer, 'None', null from SnapshotDocument3x
1774 where drawer <> 'DEL*'
1775 end
1776
1777 insert into ConfigPriority
1778 (Priority, [Rule], Description, System)
1779 values (2,'Sample','Sample of each Mapping Combination',@system)
1780
1781 insert into ConfigPriority
1782 (Priority, [Rule], Description, System)
1783 values (3,'TaskFiles','All Files with Active Tasks',@system)
1784
1785 declare @date datetime
1786
1787 set @date = dateAdd(Month,-6,@estMigrationDate)
1788 insert into ConfigPriority
1789 (Priority, [Rule], Description, System, filedate)
1790 values (4,'DocDate','All Files Modified in the last 6 months',@system,@date)
1791
1792 set @date = dateAdd(Year,-1,@estMigrationDate)
1793 insert into ConfigPriority
1794 (Priority, [Rule], Description, System, filedate)
1795 values (5,'DocDate','All Remaining Files Modified in the last year',@system,@date)
1796
1797 set @date = dateAdd(YEAR,-2,@estMigrationDate)
1798 insert into ConfigPriority
1799 (Priority, [Rule], Description, System, filedate)
1800 values (6,'DocDate','All Remaining Files Modified in the last 2 years',@system,@date)
1801
1802 set @date = dateAdd(YEAR,-3,@estMigrationDate)
1803 insert into ConfigPriority
1804 (Priority, [Rule], Description, System, filedate)
1805 values (7,'DocDate','All Remaining Files Modified in the last 3 years',@system,@date)
1806
1807 set @date = dateAdd(YEAR,-5,@estMigrationDate)
1808 insert into ConfigPriority
1809 (Priority, [Rule], Description, System, filedate)
1810 values (8,'DocDate','All Remaining Files Modified in the last 5 years',@system,@date)
1811
1812 if (db_name() = 'MigrationIRNet')
1813 begin
1814 insert into ConfigDeviceList
1815 select distinct system = @system, uncpath, null from SnapshotDevice
1816 end
1817
1818 exec logEnd @logid
1819
1820end
1821
1822GO
1823/****** Object: StoredProcedure [dbo].[dropData] Script Date: 21/11/2016 12:32:21 ******/
1824SET ANSI_NULLS ON
1825GO
1826SET QUOTED_IDENTIFIER ON
1827GO
1828Create Procedure [dbo].[dropData]
1829 @system varchar(20) = null,
1830 @drawer varchar(4) = null,
1831 @override varchar(8) = null
1832as
1833begin
1834 set nocount on
1835 declare @logid int, @ProcName varchar(50)
1836 set @ProcName = Object_Name(@@PROCID)
1837 exec logStart @procname, @system, @drawer, @ID = @logid output
1838
1839 if (@system is null and @drawer is null)
1840 begin
1841 RAISERROR (' Clearing out all document and task data', 10, 1) WITH NOWAIT
1842 if exists(select * from MigrationDocument where status >= 0) and @override <> 'override'
1843 begin
1844 RAISERROR (' Migration is Underway! You must Override to delete all content in the system!', 10, 1) WITH NOWAIT
1845 return
1846 end
1847 exec dropIndexes
1848 if (object_id('MigrationPage') is not null)
1849 truncate table MigrationPage
1850 if (object_id('MigrationDocument') is not null)
1851 truncate table MigrationDocument
1852 if (object_id('MigrationFile') is not null)
1853 truncate table MigrationFile
1854 if (object_id('MigrationTask') is not null)
1855 truncate table MigrationTask
1856 if (object_id('MigrationPath') is not null)
1857 truncate table MigrationPath
1858 if (object_id('MigrationType') is not null)
1859 truncate table MigrationType
1860 insert into LogProgressHistory select getDate(), * from LogProgress
1861 truncate table LogProgress
1862 insert into LogProcessHistory select getDate(), * from LogProcess
1863 truncate table LogProcess
1864 truncate table LogMessage
1865 end
1866 else if (@system is not null and @drawer is null)
1867 begin
1868 RAISERROR (' Clearing out all Data from System: %s', 10, 1, @system) WITH NOWAIT
1869 if (object_id('MigrationTask') is not null)
1870 delete from MigrationTask where System = @system
1871 if (object_id('MigrationFile') is not null)
1872 delete from MigrationFile where System = @system
1873 if (object_id('MigrationDocument') is not null)
1874 delete from MigrationDocument where System = @system
1875 if (object_id('MigrationPage') is not null)
1876 delete from MigrationPage where System = @system
1877 if (object_id('MigrationPath') is not null)
1878 delete from MigrationPath where System = @system
1879 if (object_id('MigrationType') is not null)
1880 delete from MigrationType where System = @system
1881 end
1882 else
1883 begin
1884 RAISERROR (' Clearing out Data from System: %s Drawer: %s', 10, 1, @system, @drawer) WITH NOWAIT
1885 if (object_id('MigrationTask') is not null)
1886 delete from MigrationTask where System = @system and SrcDrawer = @drawer
1887 if (object_id('MigrationFile') is not null)
1888 delete from MigrationFile where System = @system and SrcDrawer = @drawer
1889 if (object_id('MigrationDocument') is not null)
1890 delete from MigrationDocument where System = @system and SrcDrawer = @drawer
1891 if (object_id('MigrationPage') is not null)
1892 delete from MigrationPage where System = @system and SrcDrawer = @drawer
1893 end
1894 exec logEnd @logid
1895end
1896
1897GO
1898/****** Object: StoredProcedure [dbo].[dropIndexes] Script Date: 21/11/2016 12:32:21 ******/
1899SET ANSI_NULLS ON
1900GO
1901SET QUOTED_IDENTIFIER ON
1902GO
1903create procedure [dbo].[dropIndexes]
1904as
1905begin
1906 RAISERROR ('Dropping all Migration Data Table Indexes', 10, 1) WITH NOWAIT
1907 declare @logid int, @ProcName varchar(50)
1908 set @ProcName = Object_Name(@@PROCID)
1909 exec logStart @procname, null, null, @ID = @logid output
1910
1911 declare @sql nvarchar(1000)
1912 declare @tablename nvarchar(100), @indexname nvarchar(200)
1913 declare iCursor cursor local static for
1914 select ind.name, tab.name
1915 from sys.indexes as ind inner join sys.tables as tab
1916 on ind.object_id = tab.object_id
1917 where tab.name like 'Migration%'
1918 and tab.type = 'U'
1919 and ind.is_primary_key = 0
1920 open iCursor
1921 fetch from iCursor into @indexname, @tablename
1922 while (@@fetch_status = 0)
1923 begin
1924 set @sql = 'DROP INDEX [' + @indexname + '] ON [dbo].[' + @tablename + ']'
1925 exec (@sql)
1926 fetch from iCursor into @indexname, @tablename
1927 end
1928 close iCursor
1929 deallocate iCursor
1930
1931 exec logEnd @logid
1932end
1933
1934
1935
1936GO
1937/****** Object: StoredProcedure [dbo].[dropSnapshot] Script Date: 21/11/2016 12:32:21 ******/
1938SET ANSI_NULLS ON
1939GO
1940SET QUOTED_IDENTIFIER ON
1941GO
1942create Procedure [dbo].[dropSnapshot]
1943 @system varchar(50) = null -- null be default so that the active snapshot will be dropped by default.
1944as
1945begin
1946 -- Check to see if there is a current snapshot to drop. This is just for notification.
1947 if not exists(
1948 select *
1949 from sys.tables
1950 where name like isnull('z' + @system + '_','') + 'Snapshot%' -- If @system is null, then the expression inside the isnull function will evaluate to null which will trigger the isnull function to return the empty string which in turn causes the query to return the records of the active snapshot.
1951 )
1952 begin
1953 if @system is null Raiserror('No current active Snapshot exists!',16,1)
1954 else Raiserror('No archived "%s" Snapshot exists!',16,1,@system)
1955 return
1956 end
1957 else
1958 begin
1959 declare @tablename varchar(100)
1960 declare @sql varchar(5000)
1961 declare tCursor cursor local static for
1962 select '['+name+']'
1963 from sys.tables
1964 where name like isnull('z' + @system + '_','') + 'Snapshot%' -- If @system is null, then the expression inside the isnull function will evaluate to null which will trigger the isnull function to return the empty string which in turn causes the query to return the records of the active snapshot.
1965 open tCursor
1966 fetch from tCursor into @tablename
1967 while (@@FETCH_STATUS = 0)
1968 begin
1969 set @sql = 'drop table ' + @tablename
1970 exec (@sql)
1971 fetch from tCursor into @tablename
1972 end
1973 close tCursor
1974 deallocate tCursor
1975 end
1976end
1977
1978GO
1979/****** Object: StoredProcedure [dbo].[indexSnapshot] Script Date: 21/11/2016 12:32:21 ******/
1980SET ANSI_NULLS ON
1981GO
1982SET QUOTED_IDENTIFIER ON
1983GO
1984create procedure [dbo].[indexSnapshot]
1985as
1986begin
1987
1988IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[SnapshotAttribute]') AND name = N'IDX_SnapshotAttributeObject')
1989 begin
1990 raiserror ('Building Index IDX_SnapshotAttributeObject on SnapshotAttribute',10,1) with nowait
1991 CREATE NONCLUSTERED INDEX [IDX_SnapshotAttributeObject] ON [dbo].[SnapshotAttribute]
1992 (
1993 [OBJECTID] ASC
1994 )
1995 INCLUDE (
1996 [ATTRIBUTENAME],
1997 [ATTRIBUTEVALUE]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
1998 end
1999
2000IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[SnapshotFolder]') AND name = N'IDX_SnapshotFolder_FolderID')
2001 begin
2002 raiserror ('Building Index IDX_SnapshotFolder_FolderID on SnapshotFolder',10,1) with nowait
2003 CREATE NONCLUSTERED INDEX [IDX_SnapshotFolder_FolderID] ON [dbo].[SnapshotFolder]
2004 (
2005 [FOLDERID] ASC
2006 )
2007 INCLUDE (
2008 [PARENTID],
2009 [DESCRIPTION],
2010 [FOLDERTYPE],
2011 [ISDELETED]
2012 ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
2013 end
2014
2015IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[SnapshotFile]') AND name = N'IDX_SnapshotFile_LocationID')
2016 begin
2017 raiserror ('Building Index IDX_SnapshotFile_LocationID on SnapshotFile',10,1) with nowait
2018 CREATE NONCLUSTERED INDEX [IDX_SnapshotFile_LocationID] ON [dbo].[SnapshotFile]
2019 (
2020 [LocationID] ASC
2021 )
2022 WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
2023 end
2024
2025IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[SnapshotFile]') AND name = N'IDX_SnapshotFile_FileID')
2026 begin
2027 raiserror ('Building Index IDX_SnapshotFile_FileID on SnapshotFile',10,1) with nowait
2028 CREATE NONCLUSTERED INDEX [IDX_SnapshotFile_FileID] ON [dbo].[SnapshotFile]
2029 (
2030 [FileID] ASC
2031 )
2032 WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
2033 end
2034
2035IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[SnapshotDocument]') AND name = N'IDX_SnapshotDocument_FileID')
2036 begin
2037 raiserror ('Building Index IDX_SnapshotDocument_FileID on SnapshotDocument',10,1) with nowait
2038 CREATE NONCLUSTERED INDEX [IDX_SnapshotDocument_FileID] ON [dbo].[SnapshotDocument]
2039 (
2040 [FileID] ASC
2041 )
2042 WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
2043 end
2044
2045IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[SnapshotDocument]') AND name = N'IDX_SnapshotDocument_DocumentID')
2046 begin
2047 raiserror ('Building Index IDX_SnapshotDocument_DocumentID on SnapshotDocument',10,1) with nowait
2048 CREATE NONCLUSTERED INDEX [IDX_SnapshotDocument_DocumentID] ON [dbo].[SnapshotDocument]
2049 (
2050 [DocumentID] ASC
2051 )
2052 WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
2053 end
2054
2055IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[SnapshotPage]') AND name = N'IDX_SnapshotPage_DocumentID')
2056 begin
2057 raiserror ('Building Index IDX_SnapshotPage_DocumentID on SnapshotPage',10,1) with nowait
2058 CREATE NONCLUSTERED INDEX [IDX_SnapshotPage_DocumentID] ON [dbo].[SnapshotPage]
2059 (
2060 [DocumentID] ASC
2061 )
2062 WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
2063 end
2064
2065IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[SnapshotPage]') AND name = N'IDX_SnapshotPage_ImageSetID')
2066 begin
2067 raiserror ('Building Index IDX_SnapshotPage_ImageSetID on SnapshotPage',10,1) with nowait
2068 CREATE NONCLUSTERED INDEX [IDX_SnapshotPage_ImageSetID] ON [dbo].[SnapshotPage]
2069 (
2070 [ImageSetID] ASC
2071 )
2072 WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
2073 end
2074
2075
2076IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[SnapshotImage]') AND name = N'IDX_SnapshotImage_ImageSetID')
2077 begin
2078 raiserror ('Building Index IDX_SnapshotImage_ImageSetID on SnapshotImage',10,1) with nowait
2079 CREATE NONCLUSTERED INDEX [IDX_SnapshotImage_ImageSetID] ON [dbo].[SnapshotImage]
2080 (
2081 [ImageSetID] ASC
2082 )
2083 INCLUDE (
2084 [ImageType]
2085 )
2086 WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
2087 end
2088
2089IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[SnapshotNote]') AND name = N'IDX_SnapshotNote_ObjectID')
2090 begin
2091 raiserror ('Building Index IDX_SnapshotNote_ObjectID on SnapshotNote',10,1) with nowait
2092 CREATE NONCLUSTERED INDEX [IDX_SnapshotNote_ObjectID] ON [dbo].[SnapshotNote]
2093 (
2094 [ObjectID] ASC
2095 )
2096 INCLUDE (
2097 [Hidden],
2098 [IsDeleted]
2099 )
2100 WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
2101 end
2102
2103end
2104
2105GO
2106/****** Object: StoredProcedure [dbo].[load] Script Date: 21/11/2016 12:32:21 ******/
2107SET ANSI_NULLS ON
2108GO
2109SET QUOTED_IDENTIFIER ON
2110GO
2111Create Procedure [dbo].[load]
2112 @system varchar(50)
2113as
2114begin
2115 set nocount on
2116 Set Transaction Isolation Level Read Uncommitted
2117
2118 declare @logid int, @ProcName varchar(50)
2119 set @ProcName = Object_Name(@@PROCID)
2120 exec logStart @procname, @system, @ID = @logid output
2121
2122 exec indexSnapshot
2123
2124 exec loadPages @system
2125 exec loadNotes @system
2126 exec loadDocuments @system
2127 exec loadFiles @system
2128 exec loadTasks @system
2129 exec loadPaths @system
2130 exec loadTypes @system
2131 exec loadSecurity @system
2132
2133 exec logEnd @logid
2134end
2135
2136GO
2137/****** Object: StoredProcedure [dbo].[loadDocuments] Script Date: 21/11/2016 12:32:21 ******/
2138SET ANSI_NULLS ON
2139GO
2140SET QUOTED_IDENTIFIER ON
2141GO
2142create Procedure [dbo].[loadDocuments]
2143 @system varchar(50)
2144as
2145begin
2146 set nocount on
2147 Set Transaction Isolation Level Read Uncommitted
2148
2149 declare @logid int, @ProcName varchar(50)
2150 set @ProcName = Object_Name(@@PROCID)
2151 exec logStart @procname, @system, @ID = @logid output
2152
2153 Raiserror ('Loading All Documents for System: %s',10,1,@system) with nowait
2154
2155 insert into MigrationDocument with (tablock)
2156 (ID, FileID, Status, Priority, PageCount, ExtCount, System,
2157 SrcDrawerID, SrcDrawer,
2158 SrcFileID, SrcFileNumber, SrcFileName, SrcFileType,
2159 SrcDocID, SrcDocType, SrcDocDate, SrcCreateDate,
2160 SrcAttributes)
2161 select
2162 ID = DocumentID,
2163 FileID,
2164 Status = -2,
2165 Priority = 9,
2166 PageCount = count(ID),
2167 ExtCount = count(distinct SrcImageExt),
2168 System = @system,
2169 SrcDrawerID, SrcDrawer,
2170 SrcFileID, SrcFileNumber, SrcFileName, SrcFileType,
2171 SrcDocID, SrcDocType, SrcDocDate,
2172 SrcCreateDate = SrcDocCreated,
2173 SrcAttributes = isNull(substring(
2174 (
2175 select '^' + AttributeName + '=' + replace(AttributeValue,'&','&')
2176 from SnapshotAttribute where objectid = SrcDocID
2177 for XML Path('')
2178 ),2,4000),'')
2179 from MigrationPage
2180 where System = @system
2181 group by DocumentID, FileID, SrcDocID, System,
2182 SrcDrawerID, SrcDrawer,
2183 SrcFileID, SrcFileNumber, SrcFileName, SrcFileType,
2184 SrcDocID, SrcDocType, SrcDocDate, SrcDocCreated
2185
2186 exec logEnd @logid
2187end
2188
2189GO
2190/****** Object: StoredProcedure [dbo].[loadFiles] Script Date: 21/11/2016 12:32:21 ******/
2191SET ANSI_NULLS ON
2192GO
2193SET QUOTED_IDENTIFIER ON
2194GO
2195create Procedure [dbo].[loadFiles]
2196 @system varchar(50)
2197as
2198begin
2199 set nocount on
2200 Set Transaction Isolation Level Read Uncommitted
2201
2202 declare @logid int, @ProcName varchar(50)
2203 set @ProcName = Object_Name(@@PROCID)
2204 exec logStart @procname, @system, @ID = @logid output
2205
2206 --exec prepareIndexes @table = 'SnapshotFolder3x', @index = 'ndx_Folder'
2207
2208 raiserror ('Loading Files for all Drawers in the ConfigDrawerList from System: %s',10,1,@system) with nowait
2209 insert into MigrationFile
2210 (ID, Status, Priority, PageCount, DocumentCount, TaskCount, System,
2211 SrcDrawerID, SrcDrawer,
2212 SrcFileID, SrcFileNumber, SrcFileName, SrcFileType,
2213 CreateDate, MostRecentDocDate,
2214 Attributes)
2215 select
2216 FileID, Status = -2, Priority = 9,
2217 PageCount = sum(pagecount), DocumentCount = count(ID), TaskCount = 0, System,
2218 SrcDrawerID, SrcDrawer,
2219 SrcFileID, SrcFileNumber, SrcFileName, SrcFileType,
2220 CreateDate = min(SrcCreateDate),
2221 MostRecentDocDate = max(SrcDocDate),
2222 SrcAttributes = isNull(substring(
2223 (
2224 select '^' + AttributeName + '=' + replace(AttributeValue,'&','&')
2225 from SnapshotAttribute where objectid = SrcFileID
2226 for XML Path('')
2227 ),2,4000),'')
2228 from MigrationDocument where System = @system
2229 group by FileID, System, SrcDrawerID, SrcDrawer,
2230 SrcFileID, SrcFileNumber, SrcFileName, SrcFileType
2231
2232 exec logEnd @logid
2233end
2234
2235GO
2236/****** Object: StoredProcedure [dbo].[loadNotes] Script Date: 21/11/2016 12:32:21 ******/
2237SET ANSI_NULLS ON
2238GO
2239SET QUOTED_IDENTIFIER ON
2240GO
2241create Procedure [dbo].[loadNotes]
2242 @system varchar(50),
2243 @drawer varchar(255)=null
2244as
2245begin
2246 set nocount on
2247 Set Transaction Isolation Level Read Uncommitted
2248
2249 declare @logid int, @ProcName varchar(50)
2250 set @ProcName = Object_Name(@@PROCID)
2251 exec logStart @procname, @system, @ID = @logid output
2252
2253 --exec prepareIndexes @table = 'SnapshotDocument3x', @index = 'ndx_Document'
2254 --exec prepareIndexes @table = 'SnapshotFolder3x', @index = 'ndx_Folder'
2255
2256 if (@drawer is null)
2257 begin
2258 raiserror ('Loading Notes for all Drawers in the ConfigDrawerList from System: %s',10,1,@system) with nowait
2259 -- Do the File Notes First
2260 insert into dbo.MigrationPage with(tablock)
2261 (DocumentID,
2262 FileID,
2263 IRFileNumber,
2264 IRFileName,
2265 IRDocDate,
2266 Orientation,
2267 PageNumber,
2268 System,
2269 SrcDrawerID,
2270 SrcDrawer,
2271 SrcFileNumber,
2272 SrcFileName,
2273 SrcFileID,
2274 SrcFileType,
2275 SrcFolderPath,
2276 SrcFolderPathFull,
2277 SrcFolderTypeDesc,
2278 SrcFolderID,
2279 SrcNoteID,
2280 SrcDocType,
2281 SrcImageSetID,
2282 SrcImageID,
2283 SrcImageVersion,
2284 SrcCritical,
2285 SrcPathDate,
2286 SrcDivisionNumber,
2287 SrcImageExt,
2288 SrcImageType,
2289 SrcPlatterID,
2290 SrcPlatterNearlineDeviceID,
2291 SrcImageVersionNearlineDeviceID,
2292 SrcImageVersionOnlineDeviceID
2293 )
2294 select
2295 DocumentID = @system + '_' + cast(SnapshotFile.FileID as varchar) + '_' + cast(SnapshotNote.NoteID as varchar) + '_Note',
2296 FileID = @system + '_' + cast(SnapshotFile.FileID as varchar),
2297 IRFileNumber = SnapshotFile.FileNumber,
2298 IRFileName = SnapshotFile.FileName,
2299 IRDocDate = null,
2300 Orientation = SnapshotImage.Orientation,
2301 PageNumber = 1,
2302 System = @system,
2303 SrcDrawerID = SnapshotLocation.LocationID,
2304 SrcDrawer = SnapshotLocation.Name,
2305 SrcFileNumber = SnapshotFile.FileNumber,
2306 SrcFileName = SnapshotFile.FileName,
2307 SrcFileID = SnapshotFile.FileID,
2308 SrcFileType = SnapshotFile.FileType,
2309 SrcFolderPath = '',
2310 SrcFolderPathFull = '',
2311 SrcFolderTypeDesc = 'Note at File Level',
2312 SrcFolderID = 0,
2313 SrcNoteID = SnapshotNote.Noteid,
2314 SrcDocType = 'ImportedFileNote',
2315 SrcImageSetID = SnapshotImage.imagesetid,
2316 SrcImageID = SnapshotImage.imageid,
2317 SrcImageVersion = SnapshotImage.ImageVersion,
2318 SrcCritical = SnapshotImage.critical,
2319 SrcPathDate = SnapshotImage.PathDate,
2320 SrcDivisionNumber = SnapshotImage.DivisionNumber,
2321 SrcImageExt = SnapshotImage.ImageExt,
2322 SrcImageType = SnapshotImage.ImageType,
2323 SrcPlatterID = SnapshotImage.PlatterID,
2324 SrcPlatterNearlineDeviceID = SnapshotImage.PlatterNearlineDeviceID,
2325 SrcImageVersionNearlineDeviceID = SnapshotImage.ImageVersionNearlineDeviceID,
2326 SrcImageVersionOnlineDeviceID = SnapshotImage.ImageVersionOnlineDeviceID
2327 from SnapshotLocation
2328 join SnapshotFile on SnapshotFile.locationid = SnapshotLocation.locationid
2329 join SnapshotNote on SnapshotFile.fileid = SnapshotNote.objectid -- Join on the File Directly
2330 join SnapshotImage on SnapshotNote.imagesetid = SnapshotImage.imagesetid
2331 join ConfigDrawerList
2332 on ConfigDrawerList.drawer = SnapshotLocation.Name
2333 where SnapshotImage.ImageType <> 1 and purge <> 'All'
2334 and SnapshotNote.isDeleted = 0
2335 and SnapshotNote.hidden = 0 and SnapshotFile.isDeleted = 0
2336 and ConfigDrawerList.system = @system
2337
2338 insert into dbo.MigrationPage with(tablock)
2339 (DocumentID,
2340 FileID,
2341 IRFileNumber,
2342 IRFileName,
2343 IRDocDate,
2344 Orientation,
2345 PageNumber,
2346 System,
2347 SrcDrawerID,
2348 SrcDrawer,
2349 SrcFileNumber,
2350 SrcFileName,
2351 SrcFileID,
2352 SrcFileType,
2353 SrcFolderPath,
2354 SrcFolderPathFull,
2355 SrcFolderTypeDesc,
2356 SrcFolderID,
2357 SrcNoteID,
2358 SrcDocType,
2359 SrcImageSetID,
2360 SrcImageID,
2361 SrcImageVersion,
2362 SrcCritical,
2363 SrcPathDate,
2364 SrcDivisionNumber,
2365 SrcImageExt,
2366 SrcImageType,
2367 SrcPlatterID,
2368 SrcPlatterNearlineDeviceID,
2369 SrcImageVersionNearlineDeviceID,
2370 SrcImageVersionOnlineDeviceID
2371 )
2372 select
2373 DocumentID = @system + '_' + cast(SnapshotFile.FileID as varchar) + '_' + cast(SnapshotNote.NoteID as varchar) + '_Note',
2374 FileID = @system + '_' + cast(SnapshotFile.FileID as varchar),
2375 IRFileNumber = SnapshotFile.FileNumber,
2376 IRFileName = SnapshotFile.FileName,
2377 IRDocDate = null,
2378 Orientation = SnapshotImage.Orientation,
2379 PageNumber = 1,
2380 System = @system,
2381 SrcDrawerID = SnapshotLocation.LocationID,
2382 SrcDrawer = SnapshotLocation.Name,
2383 SrcFileNumber = SnapshotFile.FileNumber,
2384 SrcFileName = SnapshotFile.FileName,
2385 SrcFileID = SnapshotFile.FileID,
2386 SrcFileType = SnapshotFile.FileType,
2387 SrcFolderPath = dbo.FolderPath(folder1.FolderID),
2388 SrcFolderPathFull = dbo.FolderPathFull(folder1.FolderID),
2389 SrcFolderTypeDesc = folder1.FolderTypeDesc,
2390 SrcFolderID = folder1.FolderID,
2391 SrcNoteID = SnapshotNote.Noteid,
2392 SrcDocType = 'ImportedFolderNote',
2393 SrcImageSetID = SnapshotImage.imagesetid,
2394 SrcImageID = SnapshotImage.imageid,
2395 SrcImageVersion = SnapshotImage.ImageVersion,
2396 SrcCritical = SnapshotImage.critical,
2397 SrcPathDate = SnapshotImage.PathDate,
2398 SrcDivisionNumber = SnapshotImage.DivisionNumber,
2399 SrcImageExt = SnapshotImage.ImageExt,
2400 SrcImageType = SnapshotImage.ImageType,
2401 SrcPlatterID = SnapshotImage.PlatterID,
2402 SrcPlatterNearlineDeviceID = SnapshotImage.PlatterNearlineDeviceID,
2403 SrcImageVersionNearlineDeviceID = SnapshotImage.ImageVersionNearlineDeviceID,
2404 SrcImageVersionOnlineDeviceID = SnapshotImage.ImageVersionOnlineDeviceID
2405 from SnapshotNote
2406 join SnapshotFolder as folder1 on folder1.folderid = SnapshotNote.objectid -- Join on Folder here.
2407 join SnapshotFile on folder1.fileid = SnapshotFile.fileid -- Get the file through the folder
2408 join SnapshotLocation on SnapshotFile.locationid = SnapshotLocation.locationid
2409 join SnapshotImage on SnapshotNote.imagesetid = SnapshotImage.imagesetid
2410 left join SnapshotFolder as folder2 on folder2.folderid = folder1.parentid -- Join parent folder is necessary
2411 left join SnapshotFolder as folder3 on folder3.folderid = folder2.parentid
2412 left join SnapshotFolder as folder4 on folder4.folderid = folder3.parentid
2413 left join SnapshotFolder as folder5 on folder5.folderid = folder4.parentid
2414 left join SnapshotFolder as folder6 on folder6.folderid = folder5.parentid
2415 left join SnapshotFolder as folder7 on folder7.folderid = folder6.parentid
2416 left join SnapshotFolder as folder8 on folder8.folderid = folder7.parentid
2417 left join SnapshotFolder as folder9 on folder9.folderid = folder8.parentid
2418 left join SnapshotFolder as folder10 on folder10.folderid = folder9.parentid
2419 join ConfigDrawerList
2420 on ConfigDrawerList.drawer = SnapshotLocation.Name
2421 where SnapshotImage.ImageType > 1 and purge <> 'All'
2422 and SnapshotNote.isDeleted = 0
2423 and SnapshotNote.hidden = 0 and SnapshotFile.isDeleted = 0
2424 and isNull(folder1.isDeleted,0) = 0 and isNull(folder2.isDeleted,0) = 0
2425 and isNull(folder3.isDeleted,0) = 0 and isNull(folder4.isDeleted,0) = 0
2426 and isNull(folder5.isDeleted,0) = 0 and isNull(folder6.isDeleted,0) = 0
2427 and isNull(folder7.isDeleted,0) = 0 and isNull(folder8.isDeleted,0) = 0
2428 and isNull(folder9.isDeleted,0) = 0 and isNull(folder10.isDeleted,0) = 0
2429 and ConfigDrawerList.system = @system
2430
2431
2432 end
2433 else
2434 begin
2435 raiserror ('Loading Notes for Drawer: %s from System: %s',10,1,@drawer,@system) with nowait
2436 if not exists(select * from ConfigDrawerList where system = @system and drawer = @drawer)
2437 begin
2438 raiserror (' Drawer is not in the ConfigDrawerList',16,1) with nowait
2439 return
2440 end
2441 if (@drawer is null)
2442 -- Do the File Notes First
2443 insert into dbo.MigrationPage with(tablock)
2444 (DocumentID,
2445 FileID,
2446 IRFileNumber,
2447 IRFileName,
2448 IRDocDate,
2449 Orientation,
2450 PageNumber,
2451 System,
2452 SrcDrawerID,
2453 SrcDrawer,
2454 SrcFileNumber,
2455 SrcFileName,
2456 SrcFileID,
2457 SrcFileType,
2458 SrcFolderPath,
2459 SrcFolderPathFull,
2460 SrcFolderTypeDesc,
2461 SrcFolderID,
2462 SrcNoteID,
2463 SrcDocType,
2464 SrcImageSetID,
2465 SrcImageID,
2466 SrcImageVersion,
2467 SrcCritical,
2468 SrcPathDate,
2469 SrcDivisionNumber,
2470 SrcImageExt,
2471 SrcImageType,
2472 SrcPlatterID,
2473 SrcPlatterNearlineDeviceID,
2474 SrcImageVersionNearlineDeviceID,
2475 SrcImageVersionOnlineDeviceID
2476 )
2477 select
2478 DocumentID = @system + '_' + cast(SnapshotFile.FileID as varchar) + '_' + cast(SnapshotNote.NoteID as varchar) + '_Note',
2479 FileID = @system + '_' + cast(SnapshotFile.FileID as varchar),
2480 IRFileNumber = SnapshotFile.FileNumber,
2481 IRFileName = SnapshotFile.FileName,
2482 IRDocDate = null,
2483 Orientation = SnapshotImage.Orientation,
2484 PageNumber = 1,
2485 System = @system,
2486 SrcDrawerID = SnapshotLocation.LocationID,
2487 SrcDrawer = SnapshotLocation.Name,
2488 SrcFileNumber = SnapshotFile.FileNumber,
2489 SrcFileName = SnapshotFile.FileName,
2490 SrcFileID = SnapshotFile.FileID,
2491 SrcFileType = SnapshotFile.FileType,
2492 SrcFolderPath = '',
2493 SrcFolderPathFull = '',
2494 SrcFolderTypeDesc = 'Note at File Level',
2495 SrcFolderID = 0,
2496 SrcNoteID = SnapshotNote.Noteid,
2497 SrcDocType = 'ImportedFileNote',
2498 SrcImageSetID = SnapshotImage.imagesetid,
2499 SrcImageID = SnapshotImage.imageid,
2500 SrcImageVersion = SnapshotImage.ImageVersion,
2501 SrcCritical = SnapshotImage.critical,
2502 SrcPathDate = SnapshotImage.PathDate,
2503 SrcDivisionNumber = SnapshotImage.DivisionNumber,
2504 SrcImageExt = SnapshotImage.ImageExt,
2505 SrcImageType = SnapshotImage.ImageType,
2506 SrcPlatterID = SnapshotImage.PlatterID,
2507 SrcPlatterNearlineDeviceID = SnapshotImage.PlatterNearlineDeviceID,
2508 SrcImageVersionNearlineDeviceID = SnapshotImage.ImageVersionNearlineDeviceID,
2509 SrcImageVersionOnlineDeviceID = SnapshotImage.ImageVersionOnlineDeviceID
2510 from SnapshotLocation
2511 join SnapshotFile on SnapshotFile.locationid = SnapshotLocation.locationid
2512 join SnapshotNote on SnapshotFile.fileid = SnapshotNote.objectid
2513 join SnapshotImage on SnapshotNote.imagesetid = SnapshotImage.imagesetid
2514 join ConfigDrawerList
2515 on ConfigDrawerList.drawer = SnapshotLocation.Name
2516 where SnapshotImage.ImageType <> 1 and purge <> 'All'
2517 and SnapshotNote.isDeleted = 0
2518 and SnapshotNote.hidden = 0 and SnapshotFile.isDeleted = 0
2519 and ConfigDrawerList.system = @system and SnapshotLocation.name = @drawer
2520
2521 insert into dbo.MigrationPage with(tablock)
2522 (DocumentID,
2523 FileID,
2524 IRFileNumber,
2525 IRFileName,
2526 IRDocDate,
2527 Orientation,
2528 PageNumber,
2529 System,
2530 SrcDrawerID,
2531 SrcDrawer,
2532 SrcFileNumber,
2533 SrcFileName,
2534 SrcFileID,
2535 SrcFileType,
2536 SrcFolderPath,
2537 SrcFolderPathFull,
2538 SrcFolderTypeDesc,
2539 SrcFolderID,
2540 SrcNoteID,
2541 SrcDocType,
2542 SrcImageSetID,
2543 SrcImageID,
2544 SrcImageVersion,
2545 SrcCritical,
2546 SrcPathDate,
2547 SrcDivisionNumber,
2548 SrcImageExt,
2549 SrcImageType,
2550 SrcPlatterID,
2551 SrcPlatterNearlineDeviceID,
2552 SrcImageVersionNearlineDeviceID,
2553 SrcImageVersionOnlineDeviceID
2554 )
2555 select
2556 DocumentID = @system + '_' + cast(SnapshotFile.FileID as varchar) + '_' + cast(SnapshotNote.NoteID as varchar) + '_Note',
2557 FileID = @system + '_' + cast(SnapshotFile.FileID as varchar),
2558 IRFileNumber = SnapshotFile.FileNumber,
2559 IRFileName = SnapshotFile.FileName,
2560 IRDocDate = null,
2561 Orientation = SnapshotImage.Orientation,
2562 PageNumber = 1,
2563 System = @system,
2564 SrcDrawerID = SnapshotLocation.LocationID,
2565 SrcDrawer = SnapshotLocation.Name,
2566 SrcFileNumber = SnapshotFile.FileNumber,
2567 SrcFileName = SnapshotFile.FileName,
2568 SrcFileID = SnapshotFile.FileID,
2569 SrcFileType = SnapshotFile.FileType,
2570 SrcFolderPath = dbo.FolderPath(folder1.FolderID),
2571 SrcFolderPathFull = dbo.FolderPathFull(folder1.FolderID),
2572 SrcFolderTypeDesc = folder1.FolderTypeDesc,
2573 SrcFolderID = folder1.FolderID,
2574 SrcNoteID = SnapshotNote.Noteid,
2575 SrcDocType = 'ImportedFolderNote',
2576 SrcImageSetID = SnapshotImage.imagesetid,
2577 SrcImageID = SnapshotImage.imageid,
2578 SrcImageVersion = SnapshotImage.ImageVersion,
2579 SrcCritical = SnapshotImage.critical,
2580 SrcPathDate = SnapshotImage.PathDate,
2581 SrcDivisionNumber = SnapshotImage.DivisionNumber,
2582 SrcImageExt = SnapshotImage.ImageExt,
2583 SrcImageType = SnapshotImage.ImageType,
2584 SrcPlatterID = SnapshotImage.PlatterID,
2585 SrcPlatterNearlineDeviceID = SnapshotImage.PlatterNearlineDeviceID,
2586 SrcImageVersionNearlineDeviceID = SnapshotImage.ImageVersionNearlineDeviceID,
2587 SrcImageVersionOnlineDeviceID = SnapshotImage.ImageVersionOnlineDeviceID
2588 from SnapshotNote
2589 join SnapshotFolder as folder1 on folder1.folderid = SnapshotNote.objectid -- Join on Folder here.
2590 join SnapshotFile on folder1.fileid = SnapshotFile.fileid -- Get the file through the folder
2591 join SnapshotLocation on SnapshotFile.locationid = SnapshotLocation.locationid
2592 join SnapshotImage on SnapshotNote.imagesetid = SnapshotImage.imagesetid
2593 left join SnapshotFolder as folder2 on folder2.folderid = folder1.parentid -- Join parent folder is necessary
2594 left join SnapshotFolder as folder3 on folder3.folderid = folder2.parentid
2595 left join SnapshotFolder as folder4 on folder4.folderid = folder3.parentid
2596 left join SnapshotFolder as folder5 on folder5.folderid = folder4.parentid
2597 left join SnapshotFolder as folder6 on folder6.folderid = folder5.parentid
2598 left join SnapshotFolder as folder7 on folder7.folderid = folder6.parentid
2599 left join SnapshotFolder as folder8 on folder8.folderid = folder7.parentid
2600 left join SnapshotFolder as folder9 on folder9.folderid = folder8.parentid
2601 left join SnapshotFolder as folder10 on folder10.folderid = folder9.parentid
2602 join ConfigDrawerList
2603 on ConfigDrawerList.drawer = SnapshotLocation.Name
2604 where SnapshotImage.ImageType > 1 and purge <> 'All'
2605 and SnapshotNote.isDeleted = 0
2606 and SnapshotNote.hidden = 0 and SnapshotFile.isDeleted = 0
2607 and isNull(folder1.isDeleted,0) = 0 and isNull(folder2.isDeleted,0) = 0
2608 and isNull(folder3.isDeleted,0) = 0 and isNull(folder4.isDeleted,0) = 0
2609 and isNull(folder5.isDeleted,0) = 0 and isNull(folder6.isDeleted,0) = 0
2610 and isNull(folder7.isDeleted,0) = 0 and isNull(folder8.isDeleted,0) = 0
2611 and isNull(folder9.isDeleted,0) = 0 and isNull(folder10.isDeleted,0) = 0
2612 and ConfigDrawerList.system = @system and SnapshotLocation.name = @drawer
2613 end
2614 exec logEnd @logid
2615end
2616
2617GO
2618/****** Object: StoredProcedure [dbo].[loadPages] Script Date: 21/11/2016 12:32:21 ******/
2619SET ANSI_NULLS ON
2620GO
2621SET QUOTED_IDENTIFIER ON
2622GO
2623create Procedure [dbo].[loadPages]
2624 @system varchar(50)
2625as
2626begin
2627 set nocount on
2628 Set Transaction Isolation Level Read Uncommitted
2629
2630 declare @logid int, @ProcName varchar(50)
2631 set @ProcName = Object_Name(@@PROCID)
2632 exec logStart @procname, @system, @ID = @logid output
2633
2634 exec indexSnapshot
2635
2636 if (object_id('MigrationDocument') is not null)
2637 begin
2638 if (not exists(select ID from MigrationDocument where System = @system and Status = 1))
2639 begin
2640 if (not exists(select ID from MigrationDocument where Status = 0))
2641 begin
2642 exec dbo.dropIndexes
2643 end
2644 exec dropData @system
2645 end
2646 else
2647 begin
2648 RAISERROR(' Can not reload System since migration already in Progress!',16,1)
2649 RETURN
2650 end
2651 end
2652
2653 raiserror ('Loading Pages for all Drawers in the ConfigDrawerList from System: %s',10,1,@system) with nowait
2654
2655 -- Load the Standard Pages
2656 insert into dbo.MigrationPage with(tablock)
2657 (DocumentID,
2658 FileID,
2659 IRFileNumber,
2660 IRFileName,
2661 IRDocDate,
2662 Orientation,
2663 PageNumber,
2664 System,
2665 SrcDrawerID,
2666 SrcDrawer,
2667 SrcFileNumber,
2668 SrcFileName,
2669 SrcFileID,
2670 SrcFileType,
2671 SrcFolderPath,
2672 SrcFolderPathFull,
2673 SrcFolderTypeDesc,
2674 SrcFolderID,
2675 SrcDocType,
2676 SrcDocDescription,
2677 SrcDocDate,
2678 SrcReceivedDate,
2679 SrcDocID,
2680 SrcDocLastModified,
2681 SrcDocCreated,
2682 SrcPageID,
2683 SrcPageDescription,
2684 SrcPageLastModified,
2685 SrcPageCreated,
2686 SrcPageMark,
2687 SrcImageSetID,
2688 SrcImageID,
2689 SrcImageVersion,
2690 SrcCritical,
2691 SrcPathDate,
2692 SrcDivisionNumber,
2693 SrcImageExt,
2694 SrcImageType,
2695 SrcPlatterID,
2696 SrcPlatterNearlineDeviceID,
2697 SrcImageVersionNearlineDeviceID,
2698 SrcImageVersionOnlineDeviceID,
2699 SrcAnnImageSetID,
2700 SrcAnnImageID,
2701 SrcAnnImageVersion,
2702 SrcAnnCritical,
2703 SrcAnnPathDate,
2704 SrcAnnDivisionNumber,
2705 SrcAnnImageExt,
2706 SrcAnnImageType,
2707 SrcAnnPlatterID,
2708 SrcAnnPlatterNearlineDeviceID,
2709 SrcAnnImageVersionNearlineDeviceID,
2710 SrcAnnImageVersionOnlineDeviceID
2711 )
2712 select
2713 DocumentID = @system + '_' + cast(SnapshotFile.FileID as varchar) + '_' + cast(SnapshotDocument.DocumentID as varchar),
2714 FileID = @system + '_' + cast(SnapshotFile.FileID as varchar),
2715 IRFileNumber = SnapshotFile.FileNumber,
2716 IRFileName = SnapshotFile.FileName,
2717 IRDocDate = SnapshotDocument.DocumentDate,
2718 Orientation = SnapshotImage.Orientation,
2719 PageNumber = SnapshotPage.PageNumber,
2720 System = @system,
2721 SrcDrawerID = SnapshotLocation.LocationID,
2722 SrcDrawer = SnapshotLocation.Name,
2723 SrcFileNumber = SnapshotFile.FileNumber,
2724 SrcFileName = SnapshotFile.FileName,
2725 SrcFileID = SnapshotFile.FileID,
2726 SrcFileType = SnapshotFile.FileType,
2727 SrcFolderPath = dbo.FolderPath(folder1.FolderID),
2728 SrcFolderPathFull = dbo.FolderPathFull(folder1.FolderID),
2729 SrcFolderTypeDesc = folder1.FolderTypeDesc,
2730 SrcFolderID = folder1.FolderID,
2731 SrcDocType = SnapshotDocument.DocType,
2732 SrcDocDescription = SnapshotDocument.Description,
2733 SrcDocDate = SnapshotDocument.DocumentDate,
2734 SrcReceivedDate = SnapshotDocument.ReceivedDate,
2735 SrcDocID = SnapshotDocument.DocumentID,
2736 SrcDocLastModified = SnapshotDocument.LastModified,
2737 SrcDocCreate = SnapshotDocument.Created,
2738 SrcPageID = SnapshotPage.PageID,
2739 SrcPageDescription = SnapshotPage.Description,
2740 SrcPageLastModified = SnapshotPage.LastModified,
2741 SrcPageCreated = SnapshotPage.Created,
2742 SrcPageMark = SnapshotPage.PageMark,
2743 SrcImageSetID = SnapshotImage.imagesetid,
2744 SrcImageID = SnapshotImage.imageid,
2745 SrcImageVersion = SnapshotImage.ImageVersion,
2746 SrcCritical = SnapshotImage.critical,
2747 SrcPathDate = SnapshotImage.PathDate,
2748 SrcDivisionNumber = SnapshotImage.DivisionNumber,
2749 SrcImageExt = SnapshotImage.ImageExt,
2750 SrcImageType = SnapshotImage.ImageType,
2751 SrcPlatterID = SnapshotImage.PlatterID,
2752 SrcPlatterNearlineDeviceID = SnapshotImage.PlatterNearlineDeviceID,
2753 SrcImageVersionNearlineDeviceID = SnapshotImage.ImageVersionNearlineDeviceID,
2754 SrcImageVersionOnlineDeviceID = SnapshotImage.ImageVersionOnlineDeviceID,
2755 SrcAnnImageSetID = Annotation.imagesetid,
2756 SrcAnnImageID = Annotation.imageid,
2757 SrcAnnImageVersion = Annotation.ImageVersion,
2758 SrcAnnCritical = Annotation.critical,
2759 SrcAnnPathDate = Annotation.PathDate,
2760 SrcAnnDivisionNumber = Annotation.DivisionNumber,
2761 SrcAnnImageExt = Annotation.ImageExt,
2762 SrcAnnImageType = Annotation.ImageType,
2763 SrcAnnPlatterID = Annotation.PlatterID,
2764 SrcAnnPlatterNearlineDeviceID = Annotation.PlatterNearlineDeviceID,
2765 SrcAnnImageVersionNearlineDeviceID = Annotation.ImageVersionNearlineDeviceID,
2766 SrcAnnImageVersionOnlineDeviceID = Annotation.ImageVersionOnlineDeviceID
2767 from SnapshotLocation
2768 join SnapshotFile on SnapshotFile.locationid = SnapshotLocation.locationid
2769 join SnapshotDocument on SnapshotFile.fileid = SnapshotDocument.fileid
2770 join SnapshotPage on SnapshotPage.documentid = SnapshotDocument.documentid
2771 join SnapshotImage on SnapshotPage.imagesetid = SnapshotImage.imagesetid
2772 left join SnapshotFolder as folder1 on folder1.folderid = SnapshotDocument.folderid
2773 left join SnapshotFolder as folder2 on folder2.folderid = folder1.parentid
2774 left join SnapshotFolder as folder3 on folder3.folderid = folder2.parentid
2775 left join SnapshotFolder as folder4 on folder4.folderid = folder3.parentid
2776 left join SnapshotFolder as folder5 on folder5.folderid = folder4.parentid
2777 left join SnapshotFolder as folder6 on folder6.folderid = folder5.parentid
2778 left join SnapshotFolder as folder7 on folder7.folderid = folder6.parentid
2779 left join SnapshotFolder as folder8 on folder8.folderid = folder7.parentid
2780 left join SnapshotFolder as folder9 on folder9.folderid = folder8.parentid
2781 left join SnapshotFolder as folder10 on folder10.folderid = folder9.parentid
2782 left join SnapshotImage as Annotation on SnapshotPage.imagesetid = Annotation.imagesetid
2783 and Annotation.ImageType = 1
2784 join ConfigDrawerList
2785 on ConfigDrawerList.drawer = SnapshotLocation.Name
2786 where SnapshotImage.ImageType <> 1 and purge <> 'All'
2787 and SnapshotPage.isDeleted = 0
2788 and SnapshotDocument.isDeleted = 0 and SnapshotFile.isDeleted = 0
2789 and isNull(folder1.isDeleted,0) = 0 and isNull(folder2.isDeleted,0) = 0
2790 and isNull(folder3.isDeleted,0) = 0 and isNull(folder4.isDeleted,0) = 0
2791 and isNull(folder5.isDeleted,0) = 0 and isNull(folder6.isDeleted,0) = 0
2792 and isNull(folder7.isDeleted,0) = 0 and isNull(folder8.isDeleted,0) = 0
2793 and isNull(folder9.isDeleted,0) = 0 and isNull(folder10.isDeleted,0) = 0
2794 and ConfigDrawerList.system = @system
2795
2796 --- Load Pages to put Folder Tasks on
2797 insert into dbo.MigrationPage with(tablock)
2798 (DocumentID,
2799 FileID,
2800 IRFileNumber,
2801 IRFileName,
2802 IRDocDate,
2803 Orientation,
2804 PageNumber,
2805 System,
2806 SrcDrawerID,
2807 SrcDrawer,
2808 SrcFileNumber,
2809 SrcFileName,
2810 SrcFileID,
2811 SrcFileType,
2812 SrcFolderPath,
2813 SrcFolderPathFull,
2814 SrcFolderTypeDesc,
2815 SrcFolderID,
2816 SrcDocType,
2817 SrcDocDescription,
2818 SrcDocDate,
2819 SrcReceivedDate,
2820 SrcDocID,
2821 SrcPageID,
2822 SrcPageDescription,
2823 SrcImageType)
2824 select
2825 DocumentID = @system + '_' + cast(SnapshotFile.FileID as varchar) + '_' + cast(SnapshotTask.TaskID as varchar) + '_Task',
2826 FileID = @system + '_' + cast(SnapshotFile.FileID as varchar),
2827 IRFileNumber = SnapshotFile.FileNumber,
2828 IRFileName = SnapshotFile.FileName,
2829 IRDocDate = convert(varchar(12),getDate(),101),
2830 Orientation = 0,
2831 PageNumber = 1,
2832 System = @system,
2833 SrcDrawerID = SnapshotLocation.LocationID,
2834 SrcDrawer = SnapshotLocation.Name,
2835 SrcFileNumber = SnapshotFile.FileNumber,
2836 SrcFileName = SnapshotFile.FileName,
2837 SrcFileID = SnapshotFile.FileID,
2838 SrcFileType = SnapshotFile.FileType,
2839 SrcFolderPath = dbo.FolderPath(folder1.FolderID),
2840 SrcFolderPathFull = dbo.FolderPathFull(folder1.FolderID),
2841 SrcFolderTypeDesc = folder1.FolderTypeDesc,
2842 SrcFolderID = folder1.FolderID,
2843 SrcDocType = 'Folder Task',
2844 SrcDocDescription = 'Task Attached to Folder',
2845 SrcDocDate = convert(varchar(12),getDate(),101),
2846 SrcReceivedDate = convert(varchar(12),getDate(),101),
2847 SrcDocID = SnapshotTask.TaskID,
2848 SrcPageID = SnapshotTask.TaskID,
2849 SrcPageDescription = SnapshotTask.Description,
2850 SrcImageType = -2 -- This indicates it is a fake page for hanging a task on a folder
2851 from SnapshotTask
2852 inner join SnapshotFolder as Folder1 on SnapshotTask.ObjectID = Folder1.FolderID
2853 inner join SnapshotFile on SnapshotFile.fileid = Folder1.fileid
2854 inner join SnapshotLocation on SnapshotFile.locationid = SnapshotLocation.locationid
2855 left join SnapshotFolder as folder2 on folder2.folderid = folder1.parentid
2856 left join SnapshotFolder as folder3 on folder3.folderid = folder2.parentid
2857 left join SnapshotFolder as folder4 on folder4.folderid = folder3.parentid
2858 left join SnapshotFolder as folder5 on folder5.folderid = folder4.parentid
2859 left join SnapshotFolder as folder6 on folder6.folderid = folder5.parentid
2860 left join SnapshotFolder as folder7 on folder7.folderid = folder6.parentid
2861 left join SnapshotFolder as folder8 on folder8.folderid = folder7.parentid
2862 left join SnapshotFolder as folder9 on folder9.folderid = folder8.parentid
2863 left join SnapshotFolder as folder10 on folder10.folderid = folder9.parentid
2864 inner join ConfigDrawerList on ConfigDrawerList.drawer = SnapshotLocation.Name
2865 where SnapshotTask.AttachedTo = 'Folder' and ConfigDrawerList.purge <> 'All'
2866 and SnapshotFile.isDeleted = 0
2867 and isNull(folder1.isDeleted,0) = 0 and isNull(folder2.isDeleted,0) = 0
2868 and isNull(folder3.isDeleted,0) = 0 and isNull(folder4.isDeleted,0) = 0
2869 and isNull(folder5.isDeleted,0) = 0 and isNull(folder6.isDeleted,0) = 0
2870 and isNull(folder7.isDeleted,0) = 0 and isNull(folder8.isDeleted,0) = 0
2871 and isNull(folder9.isDeleted,0) = 0 and isNull(folder10.isDeleted,0) = 0
2872 and ConfigDrawerList.system = @system
2873
2874 -- Load Pages for Tasks attached directly to the file
2875 insert into dbo.MigrationPage with(tablock)
2876 (DocumentID,
2877 FileID,
2878 IRFileNumber,
2879 IRFileName,
2880 IRDocDate,
2881 Orientation,
2882 PageNumber,
2883 System,
2884 SrcDrawerID,
2885 SrcDrawer,
2886 SrcFileNumber,
2887 SrcFileName,
2888 SrcFileID,
2889 SrcFileType,
2890 SrcFolderPath,
2891 SrcFolderPathFull,
2892 SrcFolderTypeDesc,
2893 SrcDocType,
2894 SrcDocDescription,
2895 SrcDocDate,
2896 SrcReceivedDate,
2897 SrcDocID,
2898 SrcPageID,
2899 SrcPageDescription,
2900 SrcImageType)
2901 select
2902 DocumentID = @system + '_' + cast(SnapshotFile.FileID as varchar) + '_' + cast(SnapshotTask.TaskID as varchar) + '_Task',
2903 FileID = @system + '_' + cast(SnapshotFile.FileID as varchar),
2904 IRFileNumber = SnapshotFile.FileNumber,
2905 IRFileName = SnapshotFile.FileName,
2906 IRDocDate = convert(varchar(12),getDate(),101),
2907 Orientation = 0,
2908 PageNumber = 1,
2909 System = @system,
2910 SrcDrawerID = SnapshotLocation.LocationID,
2911 SrcDrawer = SnapshotLocation.Name,
2912 SrcFileNumber = SnapshotFile.FileNumber,
2913 SrcFileName = SnapshotFile.FileName,
2914 SrcFileID = SnapshotFile.FileID,
2915 SrcFileType = SnapshotFile.FileType,
2916 SrcFolderPath = '',
2917 SrcFolderPathFull = '',
2918 SrcFolderTypeDesc = '',
2919 SrcDocType = 'File Task',
2920 SrcDocDescription = 'Task Attached to File',
2921 SrcDocDate = convert(varchar(12),getDate(),101),
2922 SrcReceivedDate = convert(varchar(12),getDate(),101),
2923 SrcDocID = SnapshotTask.TaskID,
2924 SrcPageID = SnapshotTask.TaskID,
2925 SrcPageDescription = SnapshotTask.Description,
2926 SrcImageType = -3 -- This indicates it is a fake page for hanging a task on a File
2927 from SnapshotTask
2928 inner join SnapshotFile on SnapshotFile.fileid = SnapshotTask.objectid
2929 inner join SnapshotLocation on SnapshotFile.locationid = SnapshotLocation.locationid
2930 inner join ConfigDrawerList on ConfigDrawerList.drawer = SnapshotLocation.Name
2931 where SnapshotTask.AttachedTo = 'File' and ConfigDrawerList.purge <> 'All'
2932 and SnapshotFile.isDeleted = 0
2933 and ConfigDrawerList.system = @system
2934
2935
2936 -- Load Pages for Tasks attached to Documents with no pages
2937 insert into dbo.MigrationPage with(tablock)
2938 (DocumentID,
2939 FileID,
2940 IRFileNumber,
2941 IRFileName,
2942 IRDocDate,
2943 Orientation,
2944 PageNumber,
2945 System,
2946 SrcDrawerID,
2947 SrcDrawer,
2948 SrcFileNumber,
2949 SrcFileName,
2950 SrcFileID,
2951 SrcFileType,
2952 SrcFolderPath,
2953 SrcFolderPathFull,
2954 SrcFolderTypeDesc,
2955 SrcFolderID,
2956 SrcDocType,
2957 SrcDocDescription,
2958 SrcDocDate,
2959 SrcReceivedDate,
2960 SrcDocID,
2961 SrcDocLastModified,
2962 SrcDocCreated,
2963 SrcPageID,
2964 SrcPageDescription,
2965 SrcImageType)
2966 select
2967 DocumentID = @system + '_' + cast(SnapshotFile.FileID as varchar) + '_' + cast(SnapshotDocument.DocumentID as varchar),
2968 FileID = @system + '_' + cast(SnapshotFile.FileID as varchar),
2969 IRFileNumber = SnapshotFile.FileNumber,
2970 IRFileName = SnapshotFile.FileName,
2971 IRDocDate = SnapshotDocument.DOCUMENTDATE,
2972 Orientation = 0,
2973 PageNumber = 1,
2974 System = @system,
2975 SrcDrawerID = SnapshotLocation.LocationID,
2976 SrcDrawer = SnapshotLocation.Name,
2977 SrcFileNumber = SnapshotFile.FileNumber,
2978 SrcFileName = SnapshotFile.FileName,
2979 SrcFileID = SnapshotFile.FileID,
2980 SrcFileType = SnapshotFile.FileType,
2981 SrcFolderPath = dbo.FolderPath(folder1.FolderID),
2982 SrcFolderPathFull = dbo.FolderPathFull(folder1.FolderID),
2983 SrcFolderTypeDesc = folder1.FolderTypeDesc,
2984 SrcFolderID = folder1.FolderID,
2985 SrcDocType = SnapshotDocument.DocType,
2986 SrcDocDescription = SnapshotDocument.Description,
2987 SrcDocDate = SnapshotDocument.DocumentDate,
2988 SrcReceivedDate = SnapshotDocument.ReceivedDate,
2989 SrcDocID = SnapshotDocument.DocumentID,
2990 SrcDocLastModified = SnapshotDocument.LastModified,
2991 SrcDocCreate = SnapshotDocument.Created,
2992 SrcPageID = SnapshotTask.TaskID,
2993 SrcPageDescription = SnapshotTask.Description,
2994 SrcImageType = -4 -- This indicates it is a fake page for hanging a task on an Empty Document
2995 from SnapshotTask
2996 inner join SnapshotFile on SnapshotTask.fileid = SnapshotFile.fileid
2997 inner join SnapshotLocation on SnapshotLocation.locationid = SnapshotFile.locationid
2998 inner join SnapshotDocument on SnapshotDocument.documentid = SnapshotTask.ObjectID
2999 left join SnapshotFolder as folder1 on folder1.folderid = SnapshotDocument.folderid
3000 left join SnapshotFolder as folder2 on folder2.folderid = folder1.parentid
3001 left join SnapshotFolder as folder3 on folder3.folderid = folder2.parentid
3002 left join SnapshotFolder as folder4 on folder4.folderid = folder3.parentid
3003 left join SnapshotFolder as folder5 on folder5.folderid = folder4.parentid
3004 left join SnapshotFolder as folder6 on folder6.folderid = folder5.parentid
3005 left join SnapshotFolder as folder7 on folder7.folderid = folder6.parentid
3006 left join SnapshotFolder as folder8 on folder8.folderid = folder7.parentid
3007 left join SnapshotFolder as folder9 on folder9.folderid = folder8.parentid
3008 left join SnapshotFolder as folder10 on folder10.folderid = folder9.parentid
3009 left join SnapshotPage on SnapshotTask.ObjectID = SnapshotPage.DocumentID
3010 and SnapshotPage.isdeleted = 0 -- Secret sauce is here
3011 inner join ConfigDrawerList on ConfigDrawerList.drawer = SnapshotLocation.Name
3012 where AttachedTo = 'Document'
3013 and SnapshotPage.PageID is null -- And Secret is here as well.
3014 and SnapshotDocument.isdeleted = 0
3015 and SnapshotFile.isDeleted = 0
3016 and isNull(folder1.isDeleted,0) = 0 and isNull(folder2.isDeleted,0) = 0
3017 and isNull(folder3.isDeleted,0) = 0 and isNull(folder4.isDeleted,0) = 0
3018 and isNull(folder5.isDeleted,0) = 0 and isNull(folder6.isDeleted,0) = 0
3019 and isNull(folder7.isDeleted,0) = 0 and isNull(folder8.isDeleted,0) = 0
3020 and isNull(folder9.isDeleted,0) = 0 and isNull(folder10.isDeleted,0) = 0
3021 and ConfigDrawerList.purge <> 'All'
3022 and ConfigDrawerList.system = @system
3023
3024 exec logEnd @logid
3025end
3026
3027GO
3028/****** Object: StoredProcedure [dbo].[loadPaths] Script Date: 21/11/2016 12:32:21 ******/
3029SET ANSI_NULLS ON
3030GO
3031SET QUOTED_IDENTIFIER ON
3032GO
3033create Procedure [dbo].[loadPaths]
3034 @system varchar(50)
3035as
3036begin
3037 set nocount on
3038 Set Transaction Isolation Level Read Uncommitted
3039
3040 declare @logid int, @ProcName varchar(50)
3041 set @ProcName = Object_Name(@@PROCID)
3042 exec logStart @procname, @system, null, @ID = @logid output
3043
3044 delete from MigrationPath where System = @system
3045
3046 raiserror ('Loading Device and Nearline Paths from Snapshot: %s',10,1,@system) with nowait
3047
3048 insert into MigrationPath
3049 select @system, 'Online', DeviceID, UNCPath from SnapshotDevice where devicetype <> 2
3050
3051 insert into MigrationPath
3052 select @system, 'Nearline', DeviceID, UNCPath from SnapshotDevice where devicetype = 2
3053
3054 exec logEnd @logid
3055end
3056
3057GO
3058/****** Object: StoredProcedure [dbo].[loadSecurity] Script Date: 21/11/2016 12:32:21 ******/
3059SET ANSI_NULLS ON
3060GO
3061SET QUOTED_IDENTIFIER ON
3062GO
3063create Procedure [dbo].[loadSecurity]
3064 @system varchar(50)
3065as
3066begin
3067 set nocount on
3068 Set Transaction Isolation Level Read Uncommitted
3069
3070 declare @logid int, @ProcName varchar(50)
3071 set @ProcName = Object_Name(@@PROCID)
3072 exec logStart @procname, @system, null, @ID = @logid output
3073
3074 delete from MigrationSecurity where System = @system
3075
3076 raiserror ('Loading Security Accounts from Snapshot: %s',10,1,@system) with nowait
3077
3078 insert into MigrationSecurity
3079 (System, AccountID, ExternalID, Name, Description, AccountType)
3080 select @system, AccountID, ExternalID, Name, Description, AccountType
3081 from SnapshotSecurity
3082
3083
3084 exec logEnd @logid
3085end
3086
3087GO
3088/****** Object: StoredProcedure [dbo].[loadTasks] Script Date: 21/11/2016 12:32:21 ******/
3089SET ANSI_NULLS ON
3090GO
3091SET QUOTED_IDENTIFIER ON
3092GO
3093Create Procedure [dbo].[loadTasks]
3094 @system varchar(50),
3095 @drawer varchar(255) = null
3096as
3097begin
3098 set nocount on
3099 Set Transaction Isolation Level Read Uncommitted
3100
3101 declare @logid int, @ProcName varchar(50)
3102 set @ProcName = Object_Name(@@PROCID)
3103 exec logStart @ProcName, @system, @drawer, @ID = @logid output
3104
3105 --exec prepareIndexes @table = 'MigrationPage', @index = 'IX_MigrationPage_tempdin'
3106
3107 if (@drawer is null)
3108 begin
3109 raiserror ('Loading Tasks for all Drawers in the ConfigDrawerList from System: %s',10,1,@system) with nowait
3110 insert into MigrationTask
3111 (FileID, DocumentID, PageID, Description, Priority, AvailableDate, System , SrcDrawer,
3112 SrcTaskID, SrcFlowID, SrcStepID, SrcAssignedToUserID)
3113 select -- If Task is on a Page we just simply hang the task on that page
3114 MigrationPage.FileID,
3115 MigrationPage.DocumentID,
3116 MigrationPage.ID,
3117 SnapshotTask.Description,
3118 SnapshotTask.Priority,
3119 AvailableDate = SnapshotTask.DateAvailable,
3120 MigrationPage.System,
3121 MigrationPage.srcDrawer,
3122 SrcTaskID = SnapshotTask.taskid,
3123 SrcFlowID = SnapshotTask.FlowName,
3124 SrcStepID = SnapshotTask.StepName,
3125 SrcAssignedToUserID = SnapshotTask.AssignedTo
3126 from SnapshotTask
3127 inner join MigrationPage on SnapshotTask.PAGEID = MigrationPage.SrcPageID
3128 and SnapshotTask.ObjectID = MigrationPage.SrcDocID
3129 where SnapshotTask.AttachedTo = 'Page'
3130 and MigrationPage.System = @system
3131 union all
3132 select -- If task is on a note we hang the task on the corresponding Note Page
3133 MigrationPage.FileID,
3134 MigrationPage.DocumentID,
3135 MigrationPage.ID,
3136 SnapshotTask.Description,
3137 SnapshotTask.Priority,
3138 AvailableDate = SnapshotTask.DateAvailable,
3139 MigrationPage.System,
3140 MigrationPage.srcDrawer,
3141 SrcTaskID = SnapshotTask.taskid,
3142 SrcFlowID = SnapshotTask.FlowName,
3143 SrcStepID = SnapshotTask.StepName,
3144 SrcAssignedToUserID = SnapshotTask.AssignedTo
3145 from SnapshotTask
3146 inner join MigrationPage on SnapshotTask.NoteID = MigrationPage.SrcNoteID
3147 where SnapshotTask.AttachedTo = 'Note' and SrcImageType > 1
3148 and MigrationPage.System = @system
3149 union all
3150 select -- If the task is on the document, we hang the task on the first page of that document.
3151 FileID, DocumentID, PageID, Description, Priority, AvailableDate,
3152 System, srcDrawer, SrcTaskID, SrcFlowID, SrcStepID, SrcAssignedToUserID
3153 from (select
3154 RowNum = Row_Number() Over(partition by SnapshotTask.taskid order by SnapshotTask.ObjectID, PageNumber),
3155 MigrationPage.FileID,
3156 MigrationPage.DocumentID,
3157 PageID = MigrationPage.ID,
3158 SnapshotTask.Description,
3159 SnapshotTask.Priority,
3160 AvailableDate = SnapshotTask.DateAvailable,
3161 MigrationPage.System,
3162 MigrationPage.srcDrawer,
3163 SrcTaskID = SnapshotTask.taskid,
3164 SrcFlowID = SnapshotTask.FlowName,
3165 SrcStepID = SnapshotTask.StepName,
3166 SrcAssignedToUserID = SnapshotTask.AssignedTo,
3167 MigrationPage.PageNumber
3168 from SnapshotTask
3169 inner join MigrationPage on SnapshotTask.ObjectID = MigrationPage.SrcDocID
3170 where SnapshotTask.AttachedTo = 'Document'
3171 and MigrationPage.System = @system) Pages
3172 where RowNum = 1
3173 union all
3174 select -- If task is on a folder, we hang the task on the first page of the 'FolderTask' Doctype we created.
3175 MigrationPage.FileID,
3176 MigrationPage.DocumentID,
3177 MigrationPage.ID,
3178 SnapshotTask.Description,
3179 SnapshotTask.Priority,
3180 AvailableDate = SnapshotTask.DateAvailable,
3181 MigrationPage.System,
3182 MigrationPage.srcDrawer,
3183 SrcTaskID = SnapshotTask.taskid,
3184 SrcFlowID = SnapshotTask.FlowName,
3185 SrcStepID = SnapshotTask.StepName,
3186 SrcAssignedToUserID = SnapshotTask.AssignedTo
3187 from SnapshotTask
3188 inner join MigrationPage on SnapshotTask.ObjectID = MigrationPage.SrcFolderID
3189 and SnapshotTask.TaskID = MigrationPage.SrcPageid
3190 where SnapshotTask.AttachedTo = 'Folder' and MigrationPage.SrcImageType = -2
3191 and MigrationPage.System = @system
3192 union all
3193 select -- If task is on a file, we hang the task on the first page of the 'FileTask' Doctype we created.
3194 MigrationPage.FileID,
3195 MigrationPage.DocumentID,
3196 MigrationPage.ID,
3197 SnapshotTask.Description,
3198 SnapshotTask.Priority,
3199 AvailableDate = SnapshotTask.DateAvailable,
3200 MigrationPage.System,
3201 MigrationPage.srcDrawer,
3202 SrcTaskID = SnapshotTask.taskid,
3203 SrcFlowID = SnapshotTask.FlowName,
3204 SrcStepID = SnapshotTask.StepName,
3205 SrcAssignedToUserID = SnapshotTask.AssignedTo
3206 from SnapshotTask
3207 inner join MigrationPage on SnapshotTask.ObjectID = MigrationPage.SrcFileID
3208 and SnapshotTask.TaskID = MigrationPage.SrcPageid
3209 where SnapshotTask.AttachedTo = 'File' and MigrationPage.SrcImageType = -3
3210 and MigrationPage.System = @system
3211
3212 -- Update the MigrationFile Task Counts
3213 update MigrationFile
3214 set TaskCount = t.TaskCount
3215 from (select fileid, count(*) as TaskCount from MigrationTask
3216 where System = @system
3217 group by fileid) t
3218 where MigrationFile.ID = t.FileID
3219 and MigrationFile.System = @system
3220 end
3221 else
3222 begin
3223 raiserror ('Loading Tasks for Drawer: %s from System: %s',10,1,@drawer,@system) with nowait
3224 insert into MigrationTask
3225 (FileID, DocumentID, PageID, Description, Priority, AvailableDate, System , SrcDrawer,
3226 SrcTaskID, SrcFlowID, SrcStepID, SrcAssignedToUserID)
3227 select
3228 MigrationPage.FileID,
3229 MigrationPage.DocumentID,
3230 MigrationPage.ID,
3231 SnapshotTask.Description,
3232 SnapshotTask.Priority,
3233 AvailableDate = SnapshotTask.DateAvailable,
3234 MigrationPage.System,
3235 MigrationPage.srcDrawer,
3236 SrcTaskID = SnapshotTask.taskid,
3237 SrcFlowID = SnapshotTask.FlowName,
3238 SrcStepID = SnapshotTask.StepName,
3239 SrcAssignedToUserID = SnapshotTask.AssignedTo
3240 from SnapshotTask
3241 inner join MigrationPage on SnapshotTask.PAGEID = MigrationPage.SrcPageID
3242 and SnapshotTask.ObjectID = MigrationPage.SrcDocID
3243 where SnapshotTask.AttachedTo = 'Page'
3244 and MigrationPage.System = @system and MigrationPage.SrcDrawer = @drawer
3245 union all
3246 select
3247 MigrationPage.FileID,
3248 MigrationPage.DocumentID,
3249 MigrationPage.ID,
3250 SnapshotTask.Description,
3251 SnapshotTask.Priority,
3252 AvailableDate = SnapshotTask.DateAvailable,
3253 MigrationPage.System,
3254 MigrationPage.srcDrawer,
3255 SrcTaskID = SnapshotTask.taskid,
3256 SrcFlowID = SnapshotTask.FlowName,
3257 SrcStepID = SnapshotTask.StepName,
3258 SrcAssignedToUserID = SnapshotTask.AssignedTo
3259 from SnapshotTask
3260 inner join MigrationPage on SnapshotTask.NoteID = MigrationPage.SrcNoteID
3261 where SnapshotTask.AttachedTo = 'Note'
3262 and MigrationPage.System = @system and MigrationPage.SrcDrawer = @drawer
3263 union all
3264 select FileID, DocumentID, PageID, Description, Priority, AvailableDate,
3265 System, srcDrawer, SrcTaskID, SrcFlowID, SrcStepID, SrcAssignedToUserID
3266 from (select
3267 RowNum = Row_Number() Over(partition by SnapshotTask.taskid order by SnapshotTask.ObjectID, PageNumber),
3268 MigrationPage.FileID,
3269 MigrationPage.DocumentID,
3270 PageID = MigrationPage.ID,
3271 SnapshotTask.Description,
3272 SnapshotTask.Priority,
3273 AvailableDate = SnapshotTask.DateAvailable,
3274 MigrationPage.System,
3275 MigrationPage.srcDrawer,
3276 SrcTaskID = SnapshotTask.taskid,
3277 SrcFlowID = SnapshotTask.FlowName,
3278 SrcStepID = SnapshotTask.StepName,
3279 SrcAssignedToUserID = SnapshotTask.AssignedTo,
3280 MigrationPage.PageNumber
3281 from SnapshotTask
3282 inner join MigrationPage on SnapshotTask.ObjectID = MigrationPage.SrcDocID
3283 where SnapshotTask.AttachedTo = 'Document'
3284 and MigrationPage.System = @system and MigrationPage.SrcDrawer = @drawer) Pages
3285 where RowNum = 1
3286 union all
3287 select FileID, DocumentID, PageID, Description, Priority, AvailableDate,
3288 System, srcDrawer, SrcTaskID, SrcFlowID, SrcStepID, SrcAssignedToUserID
3289 from (select
3290 RowNum = Row_Number() Over(partition by SnapshotTask.taskid order by SnapshotTask.ObjectID, PageNumber),
3291 MigrationPage.FileID,
3292 MigrationPage.DocumentID,
3293 PageID = MigrationPage.ID,
3294 SnapshotTask.Description,
3295 SnapshotTask.Priority,
3296 AvailableDate = SnapshotTask.DateAvailable,
3297 MigrationPage.System,
3298 MigrationPage.srcDrawer,
3299 SrcTaskID = SnapshotTask.taskid,
3300 SrcFlowID = SnapshotTask.FlowName,
3301 SrcStepID = SnapshotTask.StepName,
3302 SrcAssignedToUserID = SnapshotTask.AssignedTo,
3303 MigrationPage.PageNumber
3304 from SnapshotTask
3305 inner join MigrationPage on SnapshotTask.ObjectID = MigrationPage.SrcFolderID
3306 where SnapshotTask.AttachedTo = 'Folder'
3307 and MigrationPage.System = @system and MigrationPage.SrcDrawer = @drawer) Pages
3308 where RowNum = 1
3309 union all
3310 select FileID, DocumentID, PageID, Description, Priority, AvailableDate,
3311 System, srcDrawer, SrcTaskID, SrcFlowID, SrcStepID, SrcAssignedToUserID
3312 from (select
3313 RowNum = Row_Number() Over(partition by SnapshotTask.taskid order by SnapshotTask.ObjectID, PageNumber),
3314 MigrationPage.FileID,
3315 MigrationPage.DocumentID,
3316 PageID = MigrationPage.ID,
3317 SnapshotTask.Description,
3318 SnapshotTask.Priority,
3319 AvailableDate = SnapshotTask.DateAvailable,
3320 MigrationPage.System,
3321 MigrationPage.srcDrawer,
3322 SrcTaskID = SnapshotTask.taskid,
3323 SrcFlowID = SnapshotTask.FlowName,
3324 SrcStepID = SnapshotTask.StepName,
3325 SrcAssignedToUserID = SnapshotTask.AssignedTo,
3326 MigrationPage.PageNumber
3327 from SnapshotTask
3328 inner join MigrationPage on SnapshotTask.FileID = MigrationPage.SrcFileID
3329 where SnapshotTask.AttachedTo = 'File'
3330 and MigrationPage.System = @system and MigrationPage.SrcDrawer = @drawer) Pages
3331 where RowNum = 1
3332
3333 update MigrationFile
3334 set TaskCount = t.TaskCount
3335 from (select fileid, count(*) as TaskCount from MigrationTask
3336 where System = @system and SrcDrawer = @drawer
3337 group by fileid) t
3338 where MigrationFile.ID = t.FileID
3339 and MigrationFile.System = @system
3340 and MigrationFile.SrcDrawer = @drawer
3341 end
3342 exec logEnd @logid
3343end
3344
3345GO
3346/****** Object: StoredProcedure [dbo].[loadTypes] Script Date: 21/11/2016 12:32:21 ******/
3347SET ANSI_NULLS ON
3348GO
3349SET QUOTED_IDENTIFIER ON
3350GO
3351CREATE Procedure [dbo].[loadTypes]
3352 @system varchar(50)
3353as
3354begin
3355 set nocount on
3356 Set Transaction Isolation Level Read Uncommitted
3357
3358 declare @logid int, @ProcName varchar(50)
3359 set @ProcName = Object_Name(@@PROCID)
3360 exec logStart @procname, @system, null, @ID = @logid output
3361
3362 delete from MigrationType where System = @system
3363
3364 raiserror ('Loading Document and Folder Types from Snapshot: %s',10,1,@system) with nowait
3365
3366 insert into MigrationType(system,kind,itemType,description)
3367 select distinct @system, 'Location', LocationType, LocationTypeDesc from SnapshotLocation
3368
3369 insert into MigrationType(system,kind,itemType,description)
3370 select distinct @system, 'File', FileType, FileTypeDesc from SnapshotFile
3371
3372 insert into MigrationType(system,kind,itemType,description)
3373 select distinct @system, 'Folder', FolderType, FolderTypeDesc from SnapshotFolder
3374
3375 insert into MigrationType(system,kind,itemType,description)
3376 select distinct @system, 'Document', DocType, isNull(DocTypeDesc,'') from SnapshotDocument
3377
3378 insert into MigrationType(system,kind,itemType,description)
3379 select distinct @system, 'Flow', FlowName, isNull(FlowDesc,'') from SnapshotTask
3380
3381 insert into MigrationType(system,kind,itemType,description)
3382 select distinct @system, 'Step', cast(FlowName as varchar) + '_' + cast(StepName as varchar), cast(isNull(StepDesc,'') as varchar(200)) from SnapshotTask
3383
3384 insert into MigrationType(system,kind,itemType,description)
3385 select distinct @system, 'User', AssignedTo, AssignedTo from SnapshotTask where AssignedTo is not null
3386
3387 insert into MigrationType(system,kind,itemType,description)
3388 select distinct @system, 'PageMark', PageMark, min(PageMarkDesc) from SnapshotPage
3389 where PageMark is not null
3390 group by PageMark
3391
3392 exec logEnd @logid
3393end
3394
3395
3396
3397GO
3398/****** Object: StoredProcedure [dbo].[logEnd] Script Date: 21/11/2016 12:32:21 ******/
3399SET ANSI_NULLS ON
3400GO
3401SET QUOTED_IDENTIFIER ON
3402GO
3403Create Procedure [dbo].[logEnd]
3404 @ID int
3405as
3406begin
3407 set nocount on
3408 update LogProcess
3409 set EndTime = getDate(), Duration = datediff(MILLISECOND,StartTime,getDate())
3410 where ID = @ID
3411
3412end
3413
3414GO
3415/****** Object: StoredProcedure [dbo].[logPhaseEnd] Script Date: 21/11/2016 12:32:21 ******/
3416SET ANSI_NULLS ON
3417GO
3418SET QUOTED_IDENTIFIER ON
3419GO
3420Create Procedure [dbo].[logPhaseEnd]
3421 @name varchar(100)
3422as
3423begin
3424 set nocount on
3425
3426 declare @count int
3427 select @count = count(*) from LogProcess where Name = @name
3428
3429 if (@count = 0)
3430 begin
3431 raiserror('No Phase: %s ... was ever started',1,16,@name)
3432 return
3433 end
3434
3435 if (@count > 1)
3436 begin
3437 raiserror('Check you Script! Phase: %s ... has been started more than once.',1,16,@name)
3438 return
3439 end
3440
3441 update LogProcess
3442 set EndTime = getDate(), Duration = datediff(MILLISECOND,StartTime,getDate())
3443 where Name = @name
3444end
3445
3446GO
3447/****** Object: StoredProcedure [dbo].[logPhaseStart] Script Date: 21/11/2016 12:32:21 ******/
3448SET ANSI_NULLS ON
3449GO
3450SET QUOTED_IDENTIFIER ON
3451GO
3452Create Procedure [dbo].[logPhaseStart]
3453 @name varchar(100)
3454as
3455begin
3456 set nocount on
3457 insert into LogProcess
3458 (Name, StartTime, isPhase) values (@name, getDate(),1)
3459
3460end
3461
3462GO
3463/****** Object: StoredProcedure [dbo].[logStart] Script Date: 21/11/2016 12:32:21 ******/
3464SET ANSI_NULLS ON
3465GO
3466SET QUOTED_IDENTIFIER ON
3467GO
3468Create Procedure [dbo].[logStart]
3469 @name varchar(100),
3470 @system varchar(20),
3471 @drawer varchar(4) = null,
3472 @param1 varchar(100) = null,
3473 @param2 varchar(100) = null,
3474 @param3 varchar(100) = null,
3475 @ID int output
3476as
3477begin
3478 set nocount on
3479 insert into LogProcess (
3480 Name,
3481 System,
3482 Drawer,
3483 OtherParam1,
3484 OtherParam2,
3485 OtherParam3,
3486 StartTime,
3487 isPhase
3488 )
3489 values (
3490 @name,
3491 @system,
3492 @drawer,
3493 left(@param1,50),
3494 left(@param2,50),
3495 left(@param3,50),
3496 getDate(),
3497 0
3498 )
3499
3500 set @ID = @@IDENTITY
3501end
3502
3503GO
3504/****** Object: StoredProcedure [dbo].[prepare] Script Date: 21/11/2016 12:32:21 ******/
3505SET ANSI_NULLS ON
3506GO
3507SET QUOTED_IDENTIFIER ON
3508GO
3509CREATE Procedure [dbo].[prepare]
3510 @system varchar(50) = null
3511as
3512begin
3513 set nocount on
3514
3515 declare @logid int, @ProcName varchar(50)
3516 set @ProcName = Object_Name(@@PROCID)
3517 exec logStart @procname, @system, null, @ID = @logid output
3518
3519 if (@system is null)
3520 Raiserror (' Preparing System for Processing',10,1) with nowait
3521 else
3522 Raiserror (' Preparing System for Processing: %s',10,1,@system) with nowait
3523
3524 exec prepareIndexes
3525 exec prepareFiles @system
3526
3527 exec logEnd @logid
3528end
3529
3530GO
3531/****** Object: StoredProcedure [dbo].[prepareFiles] Script Date: 21/11/2016 12:32:21 ******/
3532SET ANSI_NULLS ON
3533GO
3534SET QUOTED_IDENTIFIER ON
3535GO
3536CREATE Procedure [dbo].[prepareFiles]
3537 @system varchar(50) = null,
3538 @drawer varchar(100) = null,
3539 @filenumber varchar(100) = null
3540as
3541begin
3542 set nocount on
3543
3544 declare @logid int, @ProcName varchar(50)
3545 set @ProcName = Object_Name(@@PROCID)
3546 exec logStart @procname, @system, @drawer, @param1 = @filenumber, @ID = @logid output
3547 Raiserror (' Preparing Files',10,1) with nowait
3548 create table #Files (ID varchar(100), status int, primary key(ID))
3549
3550 if (@system is null)
3551 insert into #Files select ID, status from MigrationFile where status = -2
3552 else if @drawer is null
3553 insert into #Files select ID, status from MigrationFile where status = -2 and System = @system
3554 else if @filenumber is null
3555 insert into #Files select ID, status from MigrationFile where status = -2 and System = @system and SrcDrawer = @drawer
3556 else
3557 insert into #Files select ID, status from MigrationFile where status = -2 and System = @system and SrcDrawer = @drawer and SrcFileNumber = @filenumber
3558
3559 update MigrationFile
3560 set status = 0
3561 from #Files
3562 where MigrationFile.ID = #Files.ID
3563
3564 exec logEnd @logid
3565end
3566
3567GO
3568/****** Object: StoredProcedure [dbo].[prepareIndexes] Script Date: 21/11/2016 12:32:21 ******/
3569SET ANSI_NULLS ON
3570GO
3571SET QUOTED_IDENTIFIER ON
3572GO
3573Create Procedure [dbo].[prepareIndexes]
3574 @table varchar(50) = null,
3575 @index varchar(100) = null
3576as
3577begin
3578 declare @logid int, @ProcName varchar(50)
3579 set @ProcName = Object_Name(@@PROCID)
3580 exec logStart @procname, null, null, @param1 = @table, @param2 = @index, @ID = @logid output
3581
3582 /* ******************************************* Table: MigrationPage *****************************************************
3583 Indexes:
3584
3585
3586 ****************************************************************************************************************** */
3587 if (isNull(@table,'MigrationPage') = 'MigrationPage')
3588 begin
3589
3590 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationPage]') AND name = N'IX_MigrationPage_DocumentID')
3591 and isNull(@index,'IX_MigrationPage_DocumentID') = 'IX_MigrationPage_DocumentID'
3592 begin
3593 raiserror ('Building Index IX_MigrationPage_DocumentID on MigrationPage',10,1) with nowait
3594 CREATE NONCLUSTERED INDEX IX_MigrationPage_DocumentID ON dbo.MigrationPage
3595 (
3596 DocumentID ASC,
3597 pagenumber ASC
3598 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
3599 end
3600
3601 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationPage]') AND name = N'IX_MigrationPage_FileID')
3602 and isNull(@index,'IX_MigrationPage_FileID') = 'IX_MigrationPage_FileID'
3603 begin
3604 raiserror ('Building Index IX_MigrationPage_FileID on MigrationPage',10,1) with nowait
3605 CREATE NONCLUSTERED INDEX IX_MigrationPage_FileID ON dbo.MigrationPage
3606 (
3607 FileID ASC
3608 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
3609 end
3610
3611 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationPage]') AND name = N'IX_MigrationPage_MappingSample')
3612 and isNull(@index,'IX_MigrationPage_MappingSample') = 'IX_MigrationPage_MappingSample'
3613 begin
3614 raiserror ('Building Index IX_MigrationPage_MappingSample on MigrationPage',10,1) with nowait
3615 CREATE NONCLUSTERED INDEX IX_MigrationPage_MappingSample ON dbo.MigrationPage
3616 (
3617 [System] ASC,
3618 [SrcDrawer] ASC,
3619 [SrcFileNumber] ASC,
3620 [SrcFolderID] ASC,
3621 [SrcDocType] ASC
3622 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
3623 end
3624
3625
3626 end ----------------------------- End Table: MigrationPage ----------------------------------------
3627
3628 /* ******************************************* Table: MigrationFile *****************************************************
3629 Indexes:
3630 IX_MigrationFile_SystemDrawerFile
3631
3632 ****************************************************************************************************************** */
3633 if (isNull(@table,'MigrationFile') = 'MigrationFile')
3634 begin
3635 ---------------------------- Index: IX_MigrationFile_SystemDrawerFile ------------------------------------------------------
3636 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationFile]') AND name = N'IX_MigrationFile_SystemDrawerFile')
3637 and isNull(@index,'IX_MigrationFile_SystemDrawerFile') = 'IX_MigrationFile_SystemDrawerFile'
3638 begin
3639 raiserror ('Building Index IX_MigrationFile_SystemDrawerFile on MigrationFile',10,1) with nowait
3640
3641 CREATE NONCLUSTERED INDEX [IX_MigrationFile_SystemDrawerFile] ON [dbo].[MigrationFile]
3642 (
3643 [System] ASC,
3644 [SrcDrawer] ASC,
3645 [SrcFileNumber] ASC
3646 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
3647 end
3648
3649 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationFile]') AND name = N'IX_MigrationFile_PriorityStatus')
3650 and isNull(@index,'IX_MigrationFile_PriorityStatus') = 'IX_MigrationFile_PriorityStatus'
3651 begin
3652 raiserror ('Building Index IX_MigrationFile_PriorityStatus on MigrationFile',10,1) with nowait
3653
3654 CREATE NONCLUSTERED INDEX [IX_MigrationFile_PriorityStatus] ON [dbo].[MigrationFile]
3655 (
3656 [Priority] ASC,
3657 Status ASC
3658 )
3659
3660 /*
3661 The following check for and drop of can be removed in a later version. Leave in code at least through year 2016.
3662
3663 This index is superceded by IX_MigrationFile_PriorityStatus which improves Process performance especially when
3664 there are a large number of priority values. The status column needs to be covered by the index since it is used
3665 in a query predicate in Process.sql. Without status being part of the index, an extreme count (many hundreds of
3666 thousands) of reads are generatedUsing by said query.
3667 Query: select top 1 @priority = priority from MigrationFile where priority < @stopAtPriority and status = 0 order by priority
3668 */
3669 IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationFile]') AND name = N'IX_MigrationFile_Priority')
3670 and isNull(@index,'IX_MigrationFile_Priority') = 'IX_MigrationFile_Priority'
3671 begin
3672 raiserror ('Dropping Legacy Index IX_MigrationFile_Priority on MigrationFile',10,1) with nowait
3673
3674 drop INDEX [IX_MigrationFile_Priority] ON [dbo].[MigrationFile]
3675 end
3676 end
3677 end ----------------------------- End Table: MigrationFile ----------------------------------------
3678
3679 /* ******************************************* Table: MigrationDocument *****************************************************
3680 Indexes:
3681 IX_MigrationDocument_SystemDrawerFileDoc
3682
3683 ****************************************************************************************************************** */
3684 if (isNull(@table,'MigrationDocument') = 'MigrationDocument')
3685 begin
3686
3687 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationDocument]') AND name = N'IX_MigrationDocument_Priority')
3688 and isNull(@index,'IX_MigrationDocument_Priority') = 'IX_MigrationDocument_Priority'
3689 begin
3690 raiserror ('Building Index IX_MigrationDocument_Priority on MigrationDocument',10,1) with nowait
3691 CREATE NONCLUSTERED INDEX IX_MigrationDocument_Priority ON dbo.MigrationDocument
3692 (
3693 Priority ASC
3694 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
3695 end
3696
3697 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationDocument]') AND name = N'IX_MigrationDocument_StatusPriority')
3698 and isNull(@index,'IX_MigrationDocument_StatusPriority') = 'IX_MigrationDocument_StatusPriority'
3699 begin
3700 raiserror ('Building Index IX_MigrationDocument_StatusPriority on MigrationDocument',10,1) with nowait
3701 CREATE NONCLUSTERED INDEX IX_MigrationDocument_StatusPriority ON dbo.MigrationDocument
3702 (
3703 Status ASC,
3704 Priority ASC
3705 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
3706 end
3707
3708 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationDocument]') AND name = N'IX_MigrationDocument_Bookmark')
3709 and isNull(@index,'IX_MigrationDocument_Bookmark') = 'IX_MigrationDocument_Bookmark'
3710 begin
3711 raiserror ('Building Index IX_MigrationDocument_Bookmark on MigrationDocument',10,1) with nowait
3712 CREATE NONCLUSTERED INDEX IX_MigrationDocument_Bookmark ON dbo.MigrationDocument
3713 (
3714 BookMark ASC
3715 )
3716 INCLUDE ( ID) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
3717 end
3718
3719 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationDocument]') AND name = N'IX_MigrationDocument_FileID')
3720 and isNull(@index,'IX_MigrationDocument_FileID') = 'IX_MigrationDocument_FileID'
3721 begin
3722 raiserror ('Building Index IX_MigrationDocument_FileID on MigrationDocument',10,1) with nowait
3723 CREATE NONCLUSTERED INDEX IX_MigrationDocument_FileID ON dbo.MigrationDocument
3724 (
3725 FileID ASC
3726 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
3727 end
3728
3729 end ----------------------------- End Table: MigrationDocument ----------------------------------------
3730
3731 /* ******************************************* Table: MigrationTask *****************************************************
3732 Indexes:
3733 IX_MigrationPage_SystemDrawerFileDoc
3734
3735 ****************************************************************************************************************** */
3736 if (isNull(@table,'MigrationTask') = 'MigrationTask' and object_id('MigrationTask') is not null)
3737 begin
3738
3739 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationTask]') AND name = N'IX_MigrationTask_DocumentID')
3740 and isNull(@index,'IX_MigrationTask_DocumentID') = 'IX_MigrationTask_DocumentID'
3741 begin
3742 raiserror ('Building Index IX_MigrationTask_DocumentID on MigrationTask',10,1) with nowait
3743 CREATE NONCLUSTERED INDEX IX_MigrationTask_DocumentID ON dbo.MigrationTask
3744 (
3745 DocumentID ASC
3746 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
3747 end
3748
3749 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationTask]') AND name = N'IX_MigrationTask_PageID')
3750 and isNull(@index,'IX_MigrationTask_PageID') = 'IX_MigrationTask_PageID'
3751 begin
3752 raiserror ('Building Index IX_MigrationTask_PageID on MigrationTask',10,1) with nowait
3753 CREATE NONCLUSTERED INDEX IX_MigrationTask_PageID ON dbo.MigrationTask
3754 (
3755 PageID ASC
3756 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
3757 end
3758
3759 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MigrationTask]') AND name = N'IX_MigrationTask_FileID')
3760 and isNull(@index,'IX_MigrationTask_FileID') = 'IX_MigrationTask_FileID'
3761 begin
3762 raiserror ('Building Index IX_MigrationTask_FileID on MigrationTask',10,1) with nowait
3763 CREATE NONCLUSTERED INDEX IX_MigrationTask_FileID ON dbo.MigrationTask
3764 (
3765 FileID ASC
3766 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
3767 end
3768
3769
3770 end ----------------------------- End Table: MigrationTask ----------------------------------------
3771
3772 exec logEnd @logid
3773end
3774
3775GO
3776/****** Object: StoredProcedure [dbo].[prioritize] Script Date: 21/11/2016 12:32:21 ******/
3777SET ANSI_NULLS ON
3778GO
3779SET QUOTED_IDENTIFIER ON
3780GO
3781CREATE procedure [dbo].[prioritize]
3782 @system varchar(50),
3783 @drawer varchar(100) = null
3784as
3785begin
3786 set nocount on
3787
3788 declare @logid int, @ProcName varchar(50)
3789 set @ProcName = Object_Name(@@PROCID)
3790 exec logStart @ProcName, @system, @drawer, @ID = @logid output
3791
3792 exec prepareIndexes @table = 'MigrationFile', @index = 'IX_MigrationFile_SystemDrawerFile'
3793 if (@drawer is null)
3794 Raiserror(' Prioritizing Files for System: %s',10,1,@system) with nowait
3795 else
3796 Raiserror(' Prioritizing Files for System: %s',10,1,@system) with nowait
3797
3798 select * into #rules from ConfigPriority where System = @system
3799 if (@drawer is not null)
3800 delete from #rules where SrcDrawer <> @drawer
3801
3802 declare @priority int, @filedate datetime, @filenumber varchar(100), @rule varchar(15)
3803 declare @description varchar(200)
3804
3805 declare pCursor cursor local static for
3806 select Priority, [Rule], System, SrcDrawer, SrcFileNumber, filedate, description
3807 from #rules order by Priority
3808 open pCursor
3809 fetch from pCursor into @priority, @rule, @system, @drawer, @filenumber, @filedate, @description
3810 while @@fetch_status = 0
3811 begin
3812 Raiserror(' %s',10,1,@description) with nowait
3813 if @rule = 'Drawer'
3814 exec prioritizeDrawer @system, @drawer, @priority
3815 else if @rule = 'Sample'
3816 exec prioritizeSample @system, @drawer, @priority
3817 else if @rule = 'TaskFiles'
3818 exec prioritizeTaskFiles @system, @drawer, @priority
3819 else if @rule = 'TaskDocs'
3820 exec prioritizeTaskDocs @system, @drawer, @priority
3821 else if @rule = 'DocDate'
3822 exec prioritizeDocDate @system, @drawer, @filedate, @priority
3823 else if @rule = 'File'
3824 exec prioritizeFile @system, @drawer, @filenumber, @priority
3825
3826 fetch from pCursor into @priority, @rule, @system, @drawer, @filenumber, @filedate, @description
3827 end
3828 close pCursor
3829 deallocate pCursor
3830
3831 exec logEnd @logid
3832end
3833
3834
3835
3836GO
3837/****** Object: StoredProcedure [dbo].[prioritizeDocDate] Script Date: 21/11/2016 12:32:21 ******/
3838SET ANSI_NULLS ON
3839GO
3840SET QUOTED_IDENTIFIER ON
3841GO
3842CREATE procedure [dbo].[prioritizeDocDate]
3843 @system varchar(50),
3844 @drawer varchar(100) = null,
3845 @docdate datetime,
3846 @priority int,
3847 @override bit = 0 -- By default we do not lower a priority that is already set higher. 1 = override any priority
3848as
3849begin
3850 set nocount on
3851 declare @strDate varchar(12)
3852 set @strDate = CONVERT(varchar(12),@docdate,101)
3853
3854 declare @logid int, @ProcName varchar(50)
3855 set @ProcName = Object_Name(@@PROCID)
3856 exec logStart @ProcName, @system, @drawer, @param1 = @strdate, @ID = @logid output
3857
3858 exec prepareIndexes @table = 'MigrationFile', @index = 'IX_MigrationFile_SystemDrawerFile'
3859 exec prepareIndexes @table = 'MigrationDocument', @index = 'IX_MigrationDocument_FileID'
3860
3861 create table #Files (id varchar(100), Priority int, primary key(id))
3862
3863 if (@drawer is null)
3864 begin
3865 Raiserror(' Setting Files with Document Date < %s for System: %s to Priority: %d',10,1,@strdate, @system, @priority) with nowait
3866 insert into #Files
3867 select id, priority from MigrationFile where MostRecentDocDate >= @docdate and System = @system
3868 end
3869 else
3870 begin
3871 Raiserror(' Setting Files with Document Date < %s for System: %s, Drawer: %s to Priority: %d',10,1,@strdate, @system, @drawer, @priority) with nowait
3872 insert into #Files
3873 select id, priority from MigrationFile where MostRecentDocDate >= @docdate and System = @system and SrcDrawer = @drawer
3874 end
3875
3876 update #Files
3877 set Priority = case
3878 when @override = 1 then @priority
3879 when @priority < Priority then @priority
3880 else Priority
3881 end
3882
3883 update MigrationFile
3884 set Priority = #Files.priority
3885 from #Files
3886 where MigrationFile.ID = #Files.ID
3887
3888 update MigrationDocument
3889 set Priority = #Files.priority
3890 from #Files
3891 where MigrationDocument.FileID = #Files.ID
3892
3893 exec logEnd @logid
3894end
3895
3896GO
3897/****** Object: StoredProcedure [dbo].[prioritizeDrawer] Script Date: 21/11/2016 12:32:21 ******/
3898SET ANSI_NULLS ON
3899GO
3900SET QUOTED_IDENTIFIER ON
3901GO
3902create procedure [dbo].[prioritizeDrawer]
3903 @system varchar(50),
3904 @drawer varchar(100),
3905 @priority int,
3906 @override bit = 0 -- By default we do not lower a priority that is already set higher. 1 = override any priority
3907as
3908begin
3909 set nocount on
3910
3911 declare @logid int, @ProcName varchar(50)
3912 set @ProcName = Object_Name(@@PROCID)
3913 exec logStart @ProcName, @system, @drawer, @ID = @logid output
3914
3915 exec prepareIndexes @table = 'MigrationFile', @index = 'IX_MigrationFile_SystemDrawerFile'
3916 exec prepareIndexes @table = 'MigrationDocument', @index = 'IX_MigrationDocument_FileID'
3917
3918 create table #Files (id varchar(100), Priority int, primary key(id))
3919
3920 Raiserror(' Setting Files for System: %s in Drawer: %s to Priority: %d',10,1, @system, @drawer, @priority) with nowait
3921 insert into #Files
3922 select id, priority from MigrationFile where System = @system and SrcDrawer = @drawer
3923
3924 update #Files
3925 set Priority = case
3926 when @override = 1 then @priority
3927 when @priority < Priority then @priority
3928 else Priority
3929 end
3930
3931 update MigrationFile
3932 set Priority = #Files.priority
3933 from #Files
3934 where MigrationFile.ID = #Files.ID
3935
3936 update MigrationDocument
3937 set Priority = #Files.priority
3938 from #Files
3939 where MigrationDocument.FileID = #Files.ID
3940
3941 exec logEnd @logid
3942end
3943
3944GO
3945/****** Object: StoredProcedure [dbo].[prioritizeFile] Script Date: 21/11/2016 12:32:21 ******/
3946SET ANSI_NULLS ON
3947GO
3948SET QUOTED_IDENTIFIER ON
3949GO
3950CREATE procedure [dbo].[prioritizeFile]
3951 @system varchar(50),
3952 @drawer varchar(100),
3953 @filenumber varchar(255),
3954 @priority int,
3955 @override bit = 0 -- By default we do not lower a priority that is already set higher. 1 = override any priority
3956as
3957begin
3958 set nocount on
3959
3960 declare @logid int, @ProcName varchar(50)
3961 set @ProcName = Object_Name(@@PROCID)
3962 exec logStart @ProcName, @system, @drawer, @ID = @logid output
3963
3964 Raiserror(' Setting Files for System: %s, Drawer: %s, File Number: %s to Priority: %d',10,1, @system, @drawer, @filenumber, @priority) with nowait
3965
3966 exec prepareIndexes @table = 'MigrationFile', @index = 'IX_MigrationFile_SystemDrawerFile'
3967 exec prepareIndexes @table = 'MigrationDocument', @index = 'IX_MigrationDocument_FileID'
3968
3969 create table #Files (id varchar(100), Priority int, primary key(id))
3970
3971 insert into #Files
3972 select id, priority from MigrationFile where System = @system and SrcDrawer = @drawer and SrcFileNumber = @filenumber
3973
3974 update #Files
3975 set Priority = case
3976 when @override = 1 then @priority
3977 when @priority < Priority then @priority
3978 else Priority
3979 end
3980
3981 update MigrationFile
3982 set Priority = #Files.priority
3983 from #Files
3984 where MigrationFile.ID = #Files.ID
3985
3986 update MigrationDocument
3987 set Priority = #Files.priority
3988 from #Files
3989 where MigrationDocument.FileID = #Files.ID
3990
3991
3992 exec logEnd @logid
3993end
3994
3995GO
3996/****** Object: StoredProcedure [dbo].[prioritizeSample] Script Date: 21/11/2016 12:32:21 ******/
3997SET ANSI_NULLS ON
3998GO
3999SET QUOTED_IDENTIFIER ON
4000GO
4001create procedure [dbo].[prioritizeSample]
4002 @system varchar(50),
4003 @drawer varchar(100) = null,
4004 @priority int,
4005 @override bit = 0 -- By default we do not lower a priority that is already set higher. 1 = override any priority
4006as
4007begin
4008 set nocount on
4009
4010 declare @logid int, @ProcName varchar(50)
4011 set @ProcName = Object_Name(@@PROCID)
4012 exec logStart @ProcName, @system, @drawer, @ID = @logid output
4013
4014 exec prepareIndexes @table = 'MigrationFile', @index = 'IX_MigrationFile_SystemDrawerFile'
4015 exec prepareIndexes @table = 'MigrationPage', @index = 'IX_MigrationPage_MappingSample'
4016
4017 if (@drawer is null)
4018 Raiserror(' Setting Sample Combination Files for System: %s to Priority: %d',10,1,@system, @priority) with nowait
4019 else
4020 Raiserror(' Setting Sample Combination Files for System: %s, Drawer: %s to Priority: %d',10,1,@system,@drawer, @priority) with nowait
4021
4022 select fileid = min(fileid), System, SrcDrawer, SrcFolderPath, SrcDocType
4023 into #SampleDocCombinations
4024 from MigrationPage where System = @system and SrcDrawer = isNull(@drawer,SrcDrawer)
4025 group by System, SrcDrawer, SrcFolderPath, SrcDocType
4026
4027 select distinct fileid
4028 into #filelist
4029 from #SampleDocCombinations
4030
4031 if (object_id('MigrationTask') is not null) -- Only do this if we are migrating tasks
4032 begin
4033 select fileid = min(fileid), System, SrcDrawer, SrcFlowID, SrcStepID, SrcAssignedToUserID
4034 into #SampleTaskCombinations
4035 from MigrationTask where System = @system and SrcDrawer = isNull(@drawer,SrcDrawer)
4036 group by System, SrcDrawer, SrcFlowID, SrcStepID, SrcAssignedToUserID
4037
4038 insert into #filelist
4039 select distinct fileid from #SampleTaskCombinations
4040 end
4041
4042 select id, priority into #files from MigrationFile where id in (select fileid from #filelist)
4043
4044 update #Files
4045 set Priority = case
4046 when @override = 1 then @priority
4047 when @priority < Priority then @priority
4048 else Priority
4049 end
4050
4051 update MigrationFile
4052 set Priority = #Files.priority
4053 from #Files
4054 where MigrationFile.ID = #Files.ID
4055
4056 update MigrationDocument
4057 set Priority = #Files.priority
4058 from #Files
4059 where MigrationDocument.FileID = #Files.ID
4060
4061 exec logEnd @logid
4062end
4063
4064
4065
4066GO
4067/****** Object: StoredProcedure [dbo].[prioritizeTaskDocs] Script Date: 21/11/2016 12:32:21 ******/
4068SET ANSI_NULLS ON
4069GO
4070SET QUOTED_IDENTIFIER ON
4071GO
4072CREATE procedure [dbo].[prioritizeTaskDocs]
4073 @system varchar(50),
4074 @drawer varchar(100) = null,
4075 @priority int,
4076 @override bit = 0 -- By default we do not lower a priority that is already set higher. 1 = override any priority
4077as
4078begin
4079 set nocount on
4080
4081 declare @logid int, @ProcName varchar(50)
4082 set @ProcName = Object_Name(@@PROCID)
4083 exec logStart @ProcName, @system, @drawer, @ID = @logid output
4084
4085 exec prepareIndexes @table = 'MigrationFile', @index = 'IX_MigrationFile_SystemDrawerFile'
4086 exec prepareIndexes @table = 'MigrationDocument', @index = 'IX_MigrationDocument_FileID'
4087
4088 --create table #Files (id varchar(100), Priority int, primary key(id))
4089 create table #TaskDocs (FileID varchar(100), DocumentID varchar(100), Priority int);
4090
4091 if (@drawer is null)
4092 begin
4093 Raiserror(' Setting Documents with Tasks for System %s to Priority: %d',10,1,@system, @priority) with nowait
4094
4095 insert #TaskDocs(
4096 FileID,
4097 DocumentID,
4098 Priority
4099 )
4100 select distinct
4101 MigrationTask.FileID,
4102 MigrationTask.DocumentID,
4103 MigrationFile.priority
4104 from MigrationTask
4105 join MigrationFile on MigrationTask.FileID=MigrationFile.ID
4106 where MigrationFile.System=@System;
4107 end
4108 else
4109 begin
4110 Raiserror(' Setting Documents with Tasks for Drawer %s on System %s to Priority: %d',10,1,@drawer,@system, @priority) with nowait
4111
4112 insert #TaskDocs(
4113 FileID,
4114 DocumentID,
4115 Priority
4116 )
4117 select distinct
4118 MigrationTask.FileID,
4119 MigrationTask.DocumentID,
4120 MigrationFile.priority
4121 from MigrationTask
4122 join MigrationFile on MigrationTask.FileID=MigrationFile.ID
4123 where MigrationFile.System=@System
4124 and MigrationFile.SrcDrawer=@drawer;
4125 end
4126
4127 update #TaskDocs set
4128 Priority=
4129 case
4130 when @override=1 then @priority
4131 when #TaskDocs.Priority>@priority then @priority
4132 else #TaskDocs.Priority
4133 end
4134 from #TaskDocs
4135
4136 update MigrationDocument
4137 set Priority = #TaskDocs.priority
4138 from #TaskDocs
4139 where MigrationDocument.ID = #TaskDocs.DocumentID
4140
4141 exec logEnd @logid
4142end
4143
4144
4145
4146GO
4147/****** Object: StoredProcedure [dbo].[prioritizeTaskFiles] Script Date: 21/11/2016 12:32:21 ******/
4148SET ANSI_NULLS ON
4149GO
4150SET QUOTED_IDENTIFIER ON
4151GO
4152CREATE procedure [dbo].[prioritizeTaskFiles]
4153 @system varchar(50),
4154 @drawer varchar(100) = null,
4155 @priority int,
4156 @override bit = 0 -- By default we do not lower a priority that is already set higher. 1 = override any priority
4157as
4158begin
4159 set nocount on
4160
4161 declare @logid int, @ProcName varchar(50)
4162 set @ProcName = Object_Name(@@PROCID)
4163 exec logStart @ProcName, @system, @drawer, @ID = @logid output
4164
4165 exec prepareIndexes @table = 'MigrationFile', @index = 'IX_MigrationFile_SystemDrawerFile'
4166 exec prepareIndexes @table = 'MigrationDocument', @index = 'IX_MigrationDocument_FileID'
4167
4168 create table #Files (id varchar(100), Priority int, primary key(id))
4169
4170 if (@drawer is null)
4171 begin
4172 Raiserror(' Setting Files with Tasks for System %s to Priority: %d',10,1,@system, @priority) with nowait
4173 insert into #Files
4174 select id, priority from MigrationFile where TaskCount > 0 and System = @system
4175 end
4176 else
4177 begin
4178 Raiserror(' Setting Files with Tasks for Drawer %s on System %s to Priority: %d',10,1,@drawer,@system, @priority) with nowait
4179 insert into #Files
4180 select id, priority from MigrationFile where TaskCount > 0 and System = @system and SrcDrawer = @drawer
4181 end
4182
4183 update #Files
4184 set Priority = case
4185 when @override = 1 then @priority
4186 when @priority < Priority then @priority
4187 else Priority
4188 end
4189
4190 update MigrationFile
4191 set Priority = #Files.priority
4192 from #Files
4193 where MigrationFile.ID = #Files.ID
4194
4195 update MigrationDocument
4196 set Priority = #Files.priority
4197 from #Files
4198 where MigrationDocument.FileID = #Files.ID
4199
4200 exec logEnd @logid
4201end
4202
4203
4204
4205GO
4206/****** Object: StoredProcedure [dbo].[process] Script Date: 21/11/2016 12:32:21 ******/
4207SET ANSI_NULLS ON
4208GO
4209SET QUOTED_IDENTIFIER ON
4210GO
4211CREATE procedure [dbo].[process]
4212 @system varchar(50) = null,
4213 @drawer varchar(100) = null,
4214 @filenumber varchar(255) = null,
4215 @stopAtPriority int = 10, -- System will process until it reaches this Priority (default: 10 - All of them)
4216 @maxFiles int = 1000000000, -- Maximum number of files to process (1,000,000,000 = Unlimited)
4217 @pause numeric(2,1) = null, -- Time to wait between files in seconds
4218 @preferNearline bit = 0, -- preferNearline: If set to 1, file paths will prefer the nearline
4219 @processAttributesOverride bit = null, -- If this is null, the key\value from ConfigMigration will be used to determine the @processAttributes param value when calling exec process;
4220 @debug bit = 1 -- Kept at 1 to simulate prior behaviour after minor @debug changes in process* procs. Specify @debug=0 for mostly silent operation.
4221as
4222begin
4223 set nocount on
4224
4225 declare @logid int, @ProcName varchar(50)
4226 set @ProcName = Object_Name(@@PROCID)
4227
4228 raiserror ('Processing Files for Migration...',10,1,@system) with nowait
4229
4230 -- Fix any Files that were left in Pending when you stopped the process before
4231 update MigrationFile set status = 0 where status = 2
4232
4233 declare @fileCount int, @delay varchar(30)
4234 set @fileCount = 0
4235 if (@pause is not null)
4236 set @delay = '0:00:0' + cast(@pause as varchar)
4237 declare @fileid varchar(100) = '{$TEMPINITIALVALUE}'; -- Assign a temporary initial value so that it will not be null for the first attempt at entering the while loop.
4238
4239 declare @basesql nvarchar(1000), @sql nvarchar(1000)
4240 set @basesql = 'select top 1 @id = ID from MigrationFile where '
4241 if (@system is not null)
4242 set @basesql = @basesql + ' System = ''' + @system + ''' and '
4243 if (@drawer is not null)
4244 set @basesql = @basesql + ' SrcDrawer = ''' + @drawer + ''' and '
4245 if (@filenumber is not null)
4246 set @basesql = @basesql + ' SrcFileNumber = ''' + @filenumber + ''' and '
4247
4248 declare @processAttributes bit = 1;
4249 if @processAttributesOverride is null
4250 select @processAttributes = case ConfigValue when 'TRUE' then 1 when 'FALSE' then 0 else -9 end
4251 from ConfigMigration
4252 where ConfigKey='process_ExecuteProcessAttributesProc';
4253 else set @processAttributes = @processAttributesOverride;
4254
4255 declare @priority int
4256 set @priority = null
4257 select top 1 @priority = priority from MigrationFile where system=isnull(@system,system) and priority < @stopAtPriority and status = 0 order by priority
4258 set @sql = @basesql + ' status = 0 and priority = ' + cast(@priority as nvarchar)
4259 while @priority is not null and @fileid is not null and @filecount < @maxFiles
4260 begin
4261 set @fileid = null
4262 EXECUTE sp_executesql @sql, N'@id varchar(100) OUTPUT', @id = @fileid OUTPUT
4263 while @fileid is not null and @fileCount < @maxFiles
4264 begin
4265 exec logStart @ProcName, @system, @drawer, @param1 = @fileid, @ID = @logid output
4266 set @fileCount = @fileCount + 1
4267
4268 exec processPages @fileid = @fileid, @debug = @debug--,@processAttributes = @processAttributes
4269 exec processTasks @fileid, @debug
4270 exec processDocuments @fileid, @debug
4271
4272 set @fileid = null
4273 EXECUTE sp_executesql @sql, N'@id varchar(100) OUTPUT', @id = @fileid OUTPUT
4274 if (@delay is not null)
4275 waitfor delay @delay
4276 exec logEnd @logid
4277 end
4278 set @priority = null
4279 select top 1 @priority = priority from MigrationFile where system=isnull(@system,system) and priority < @stopAtPriority and status = 0 order by priority
4280 set @sql = @basesql + ' status = 0 and priority = ' + cast(@priority as nvarchar)
4281
4282 end
4283end
4284
4285GO
4286/****** Object: StoredProcedure [dbo].[processAttributes] Script Date: 21/11/2016 12:32:21 ******/
4287SET ANSI_NULLS ON
4288GO
4289SET QUOTED_IDENTIFIER ON
4290GO
4291CREATE Procedure [dbo].[processAttributes]
4292 @system varchar(40),
4293 @drawer varchar(4),
4294 @fileid varchar(100),
4295 @debug bit = 0
4296as
4297begin
4298 set nocount on
4299
4300 Set Transaction Isolation Level Read Uncommitted
4301
4302 declare @logid int, @ProcName varchar(50)
4303 set @ProcName = Object_Name(@@PROCID)
4304 exec logStart @procname, @system, @drawer, @param2 = @fileid, @ID = @logid output
4305
4306 Raiserror (' Processing Attributes for System: %s, Drawer: %s, File: %s',10,1,@system,@drawer,@fileid) with nowait
4307
4308 -- This is called from Process Pages.
4309 -- A temp table #Pages will already exist when called and you must make the changes to that table only.
4310 -- No need to actually update the IconPage table as this will be done at the end of processing
4311
4312 update #Pages
4313 set IRAttribute1 = SrcDocID
4314
4315 --proc file number handling
4316 update #Pages
4317 set IRFileNumber = ProcMapping.FileNumber, IRFileName = ProcMapping.ProcessorName
4318 from ProcMapping
4319 inner join #Pages on ProcMapping.ProcessorName = #Pages.IRAttribute5
4320 where srcfolderpathfull like 'PROCESSORS;%'
4321 and ProcMapping.ProcessorName = #Pages.IRAttribute5
4322
4323
4324
4325
4326 exec logEnd @logid
4327end
4328
4329GO
4330/****** Object: StoredProcedure [dbo].[processDocuments] Script Date: 21/11/2016 12:32:21 ******/
4331SET ANSI_NULLS ON
4332GO
4333SET QUOTED_IDENTIFIER ON
4334GO
4335Create Procedure [dbo].[processDocuments]
4336 @fileid varchar(100),
4337 @debug bit = 0
4338as
4339begin
4340 set nocount on
4341 Set Transaction Isolation Level Read Uncommitted
4342
4343 declare @system varchar(40), @drawer varchar(4), @fileno varchar(50)
4344 select @system = System, @drawer = SrcDrawer, @fileno = SrcFileNumber from MigrationFile where ID = @fileid
4345
4346 declare @logid int, @ProcName varchar(50)
4347 set @ProcName = Object_Name(@@PROCID)
4348 exec logStart @procname, @system, @drawer, @param1 = @fileno, @param2 = @fileid, @ID = @logid output
4349
4350 if (@debug >= 1)
4351 Raiserror (' Setting File and Documents to Migrate -> System: %s, Drawer: %s, File: %s',10,1,@system,@drawer,@fileno) with nowait
4352
4353 update MigrationFile set status = 2 where ID = @fileid
4354
4355 -- Make the document update
4356 update MigrationDocument
4357 set status = 0
4358 where FileID = @fileid
4359 and status = -2
4360
4361 update MigrationFile set status = 1 where ID = @fileid
4362
4363 exec logEnd @logid
4364end
4365
4366GO
4367/****** Object: StoredProcedure [dbo].[processNotes] Script Date: 21/11/2016 12:32:21 ******/
4368SET ANSI_NULLS ON
4369GO
4370SET QUOTED_IDENTIFIER ON
4371GO
4372create procedure [dbo].[processNotes]
4373 @phase varchar(20),
4374 @system varchar(50) = null
4375as
4376begin
4377 if (@phase = 'start')
4378 begin
4379 if (@system is null)
4380 raiserror('You must provide a system in order to process notes',18,1)
4381 -- Create the SecurityAccount table for the Note Deserializor tool.
4382 -- The Name of the table is hard coded and we may have multiple systems in play
4383 -- So we want to be sure we get the correct system.
4384 if (object_id('dbo.SecurityAccount') is not null)
4385 drop table dbo.SecurityAccount
4386
4387 select * into SecurityAccount from MigrationSecurity where system = @system
4388
4389 -- Mark the notes to process
4390 update MigrationDocument
4391 set HoldReason = 'Processing Notes'
4392 where System = @system
4393 and status = -5
4394 and HoldReason in ('Unprocessed Notes')
4395 end
4396
4397 if (@phase = 'run')
4398 begin
4399 select DefaultNote = Row_Number() over(order by FilePath),
4400 FilePath as path
4401 from MigrationPage
4402 inner join MigrationDocument on MigrationPage.DocumentID = MigrationDocument.ID
4403 where SrcImageType in (4,5)
4404 and status = -5
4405 and HoldReason in ('Processing Notes')
4406 end
4407
4408 if (@phase = 'finish')
4409 begin
4410 update MigrationPage
4411 set FilePath = left(filepath,len(filepath)-6)+'.html'
4412 from MigrationDocument inner join MigrationPage on MigrationPage.DocumentID = MigrationDocument.ID
4413 where MigrationDocument.status = -5
4414 and MigrationDocument.HoldReason = 'Processing Notes'
4415 and MigrationPage.FilePath like '%.notes'
4416
4417 update MigrationDocument
4418 set status = 0,
4419 HoldReason = 'Notes Processed'
4420 from MigrationDocument inner join MigrationPage on MigrationPage.DocumentID = MigrationDocument.ID
4421 where MigrationDocument.status = -5
4422 and MigrationDocument.HoldReason = 'Processing Notes'
4423 and MigrationPage.FilePath like '%.html'
4424
4425 if (object_id('dbo.SecurityAccount') is not null)
4426 drop table dbo.SecurityAccount
4427 end
4428
4429end
4430
4431GO
4432/****** Object: StoredProcedure [dbo].[processPages] Script Date: 21/11/2016 12:32:21 ******/
4433SET ANSI_NULLS ON
4434GO
4435SET QUOTED_IDENTIFIER ON
4436GO
4437-- For ImageRight .NET
4438CREATE Procedure [dbo].[processPages]
4439 @fileid varchar(100),
4440 -- preferNearline: If set to 1, file paths will prefer the nearline
4441 -- path on active images if nearline image is available.
4442 @debug bit = 0
4443as
4444begin
4445 set nocount on
4446 Set Transaction Isolation Level Read Uncommitted
4447
4448 declare @system varchar(40), @drawer varchar(4), @fileno varchar(50), @filename varchar(100)
4449 select @system = System, @drawer = SrcDrawer, @fileno = SrcFileNumber, @filename = SrcFileName
4450 from MigrationFile where ID = @fileid
4451
4452 declare @logid int, @ProcName varchar(50)
4453 set @ProcName = Object_Name(@@PROCID)
4454 exec logStart @procname, @system, @drawer, @param1 = @fileno, @param2 = @fileid, @ID = @logid output
4455
4456 Raiserror (' Processing Documents for System: %s, Drawer: %s, File: %s',10,1,@system,@drawer,@fileno) with nowait
4457
4458 update MigrationFile set status = 2 where ID = @fileid
4459
4460 if (object_id('tempdb..#Pages') is not null)
4461 drop table #Pages
4462
4463 select MigrationPage.* into #Pages
4464 from MigrationPage
4465 inner join MigrationDocument on MigrationPage.DocumentID = MigrationDocument.ID
4466 where MigrationDocument.FileID = @fileid
4467 and status <> 1 -- Skip pages for documents that have already been migrated.
4468
4469 if (@debug = 1)
4470 RAISERROR (' Updating the Path to Image on Disk', 10, 1) WITH NOWAIT
4471
4472 -- Nearline Devices
4473 update #Pages
4474 set FilePath = isNull(ConfigDeviceList.NewDevicePath,MigrationPath.Path) +
4475 '\' + substring(master.dbo.fn_varbintohexstr(CAST(SrcPathDate AS VARBINARY)),3,8) +
4476 '\' + REPLICATE('0', 8-len(SrcDivisionNumber)) + cast(SrcDivisionNumber as varchar(8)) +
4477 '\' + substring(master.dbo.fn_varbintohexstr(CAST(SrcImageID as varbinary)),3,8) +
4478 substring(master.dbo.fn_varbintohexstr(CAST(SrcImageVersion as varbinary)),3,8) +
4479 '.' + SrcImageExt
4480 from #Pages
4481 inner join MigrationPath on #Pages.SrcImageVersionNearlineDeviceID = MigrationPath.ID
4482 inner join ConfigDeviceList on MigrationPath.system = ConfigDeviceList.system
4483 and MigrationPath.path = ConfigDeviceList.OldDevicePath
4484 where #Pages.SrcImageType >= 0
4485 and MigrationPath.Storage = 'Nearline' and MigrationPath.system = @system
4486
4487 -- Online Devices
4488 update #Pages
4489 set FilePath = isNull(ConfigDeviceList.NewDevicePath,MigrationPath.Path) +
4490 '\' + substring(master.dbo.fn_varbintohexstr(CAST(SrcPathDate AS VARBINARY)),3,8) +
4491 '\' + REPLICATE('0', 8-len(SrcDivisionNumber)) + cast(SrcDivisionNumber as varchar(8)) +
4492 '\' + substring(master.dbo.fn_varbintohexstr(CAST(SrcImageID as varbinary)),3,8) +
4493 substring(master.dbo.fn_varbintohexstr(CAST(SrcImageVersion as varbinary)),3,8) +
4494 '.' + SrcImageExt
4495 from #Pages
4496 inner join MigrationPath on #Pages.SrcImageVersionOnlineDeviceID = MigrationPath.ID
4497 inner join ConfigDeviceList on MigrationPath.system = ConfigDeviceList.system
4498 and MigrationPath.path = ConfigDeviceList.OldDevicePath
4499 where #Pages.SrcImageType >= 0
4500 and MigrationPath.Storage = 'Online' and MigrationPath.system = @system
4501
4502 -- Folder Task Paths
4503 declare @FolderTaskPagePath varchar(500)
4504 select @FolderTaskPagePath = ConfigValue from ConfigMigration where ConfigKey = 'FolderTaskPagePath'
4505 update #Pages
4506 set FilePath = @FolderTaskPagePath
4507 where #Pages.SrcImageType = -2
4508 -- File Task Paths
4509 declare @FileTaskPagePath varchar(500)
4510 select @FileTaskPagePath = ConfigValue from ConfigMigration where ConfigKey = 'FileTaskPagePath'
4511 update #Pages
4512 set FilePath = @FileTaskPagePath
4513 where #Pages.SrcImageType = -3
4514 -- Empty Document Task Paths
4515 declare @EmptyDocumentTaskPagePath varchar(500)
4516 select @EmptyDocumentTaskPagePath = ConfigValue from ConfigMigration where ConfigKey = 'EmptyDocumentTaskPagePath'
4517 update #Pages
4518 set FilePath = @EmptyDocumentTaskPagePath
4519 where #Pages.SrcImageType = -4
4520
4521 -- Populate Annotations Table for annotations on Nearline
4522
4523 update #Pages
4524 set AnnotationsPath = isNull(ConfigDeviceList.NewDevicePath,MigrationPath.Path) +
4525 '\' + substring(master.dbo.fn_varbintohexstr(CAST(SrcAnnPathDate AS VARBINARY)),3,8) +
4526 '\' + REPLICATE('0', 8-len(SrcAnnDivisionNumber)) + cast(SrcAnnDivisionNumber as varchar(8)) +
4527 '\' + substring(master.dbo.fn_varbintohexstr(CAST(SrcAnnImageID as varbinary)),3,8) +
4528 substring(master.dbo.fn_varbintohexstr(CAST(SrcAnnImageVersion as varbinary)),3,8) +
4529 '.' + SrcAnnImageExt
4530 from #Pages
4531 inner join MigrationPath on #Pages.SrcAnnImageVersionNearlineDeviceID = MigrationPath.ID
4532 inner join ConfigDeviceList on MigrationPath.system = ConfigDeviceList.system
4533 and MigrationPath.path = ConfigDeviceList.OldDevicePath
4534 where #Pages.SrcImageType = 0 and #Pages.SrcAnnImageID is not null
4535 and MigrationPath.Storage = 'Nearline' and MigrationPath.system = @system
4536
4537 update #Pages
4538 set AnnotationsPath = isNull(ConfigDeviceList.NewDevicePath,MigrationPath.Path) +
4539 '\' + substring(master.dbo.fn_varbintohexstr(CAST(SrcAnnPathDate AS VARBINARY)),3,8) +
4540 '\' + REPLICATE('0', 8-len(SrcAnnDivisionNumber)) + cast(SrcAnnDivisionNumber as varchar(8)) +
4541 '\' + substring(master.dbo.fn_varbintohexstr(CAST(SrcAnnImageID as varbinary)),3,8) +
4542 substring(master.dbo.fn_varbintohexstr(CAST(SrcAnnImageVersion as varbinary)),3,8) +
4543 '.' + SrcAnnImageExt
4544 from #Pages
4545 inner join MigrationPath on #Pages.SrcAnnImageVersionOnlineDeviceID = MigrationPath.ID
4546 inner join ConfigDeviceList on MigrationPath.system = ConfigDeviceList.system
4547 and MigrationPath.path = ConfigDeviceList.OldDevicePath
4548 where #Pages.SrcImageType = 0 and #Pages.SrcAnnImageID is not null
4549 and MigrationPath.Storage = 'Online' and MigrationPath.system = @system
4550
4551 -- Fix Page Errors
4552 if exists(select * from ConfigPageCorrection where fileid = @fileid)
4553 begin
4554 if (@debug = 1)
4555 Raiserror (' Fixing Page Errors',10,1) with nowait
4556
4557 update #Pages
4558 set FilePath = NewFilePath
4559 from ConfigPageCorrection
4560 where #Pages.FilePath = ConfigPageCorrection.OldFilePath
4561 and ConfigPageCorrection.fileid = @fileid
4562
4563 update #Pages
4564 set AnnotationsPath = NewFilePath
4565 from ConfigPageCorrection
4566 where #Pages.AnnotationsPath = ConfigPageCorrection.OldFilePath
4567 and ConfigPageCorrection.fileid = @fileid
4568 end
4569
4570
4571 -- Populate Attributes
4572 if (@debug = 1)
4573 raiserror (' Updating Attributes',10,1) with nowait
4574 exec processAttributes @system, @drawer, @fileid, @debug
4575
4576 -- Apply file mappings to loaded data in Migration
4577 update #Pages
4578 set IRDrawer =
4579 case
4580 when MapDocument.DestDrawer = 'No Change' then #Pages.SrcDrawer
4581 when patindex('%->%',MapDocument.DestDrawer) > 0 then dbo.map(#Pages.SrcDrawer,MapDocument.DestDrawer)
4582 else MapDocument.DestDrawer
4583 end,
4584 IRFileType =
4585 case
4586 when MapDocument.DestFileType = 'No Change' then #Pages.SrcFileType
4587 when patindex('%->%',MapDocument.DestFileType) > 0 then dbo.map(#Pages.SrcFileType,MapDocument.DestFileType)
4588 else MapDocument.DestFileType
4589 end,
4590 IRFolderPath =
4591 case
4592 when MapDocument.DestFolderPath = 'No Change' then #Pages.SrcFolderPathFull
4593 when patindex('%->%',MapDocument.DestFolderPath) > 0 then dbo.map(#Pages.SrcFolderPathFull,MapDocument.DestFolderPath)
4594 else MapDocument.DestFolderPath
4595 end,
4596 IRDocType =
4597 case
4598 when MapDocument.DestDocType = 'No Change' then #Pages.SrcDocType
4599 when patindex('%->%',MapDocument.DestDocType) > 0 then dbo.map(#Pages.SrcDocType,MapDocument.DestDocType)
4600 else MapDocument.DestDocType end,
4601 IRDocDescription = SrcDocDescription,
4602 IRPageDescription = SrcPageDescription
4603 from MapDocument
4604 where #Pages.System = MapDocument.System
4605 and #Pages.SrcDrawer = MapDocument.SrcDrawer
4606 and #Pages.SrcFolderPath = MapDocument.SrcFolderPath
4607 and #Pages.SrcDocType = MapDocument.SrcDocType
4608 and #Pages.SrcFileType = MapDocument.SrcFileType
4609
4610 if (@debug = 1)
4611 Raiserror (' Parameter Replacement Folder Type Paths',10,1) with nowait
4612 declare @maxAttribute int, @currentAttribute int, @sql nvarchar(300), @attrib varchar(20)
4613 set @maxAttribute = 15
4614 set @currentAttribute = 1
4615
4616 while @currentAttribute <= @maxAttribute
4617 begin
4618 set @attrib = 'IRAttribute' + cast(@currentAttribute as varchar)
4619 if exists(select * from #Pages where IRFolderPath like '%${' + @attrib + '}%')
4620 begin
4621 if (@debug = 1)
4622 Raiserror (' %s',10,1,@attrib) with nowait
4623 set @sql = 'update #Pages set IRFolderPath = REPLACE(IRFolderPath,''${' + @attrib + '}'', ISNULL(' + @attrib + ','''')) ' +
4624 ' where IRFolderPath like ''%${' + @attrib + '}%'' and ' + @attrib + ' is not null'
4625 exec (@sql)
4626 end
4627 set @currentAttribute = @currentAttribute + 1
4628 end
4629
4630 if exists(select * from #Pages where IRFolderPath like '%${IRFileName}%')
4631 begin
4632 if (@debug = 1)
4633 Raiserror (' IRFileName',10,1,@attrib) with nowait
4634 update #Pages set IRFolderPath = REPLACE(IRFolderPath,'${IRFileName}',IRFileName) where IRFolderPath like '%${IRFileName}%'
4635 end
4636
4637 -- Parameter Replacement for DocTypes
4638 if (@debug = 1)
4639 Raiserror (' Parameter Replacement Document Types',10,1) with nowait
4640 set @currentAttribute = 1
4641
4642 while @currentAttribute <= @maxAttribute
4643 begin
4644 set @attrib = 'IRAttribute' + cast(@currentAttribute as varchar)
4645 if exists(select * from #Pages where IRDocType like '%${' + @attrib + '}%')
4646 begin
4647 Raiserror (' %s',10,1,@attrib) with nowait
4648 set @sql = 'update #Pages set IRDocType = REPLACE(IRDocType,''${' + @attrib + '}'', ISNULL(' + @attrib + ','''')) ' +
4649 ' where IRDocType like ''%${' + @attrib + '}%'' and ' + @attrib + ' is not null'
4650 exec (@sql)
4651 end
4652 set @currentAttribute = @currentAttribute + 1
4653 end
4654
4655 -- Page Marks
4656 if (@debug = 1)
4657 Raiserror (' Mapping PageMarks',10,1) with nowait
4658 update #Pages
4659 set IRPageMark = MapMark.DestMarkID
4660 from MapMark
4661 where MapMark.System = #Pages.System
4662 and MapMark.SrcDrawer = #Pages.SrcDrawer
4663 and MapMark.MarkType = 'page'
4664 and MapMark.SrcMarkID = #Pages.SrcPageMark
4665 and #Pages.SrcPageMark is not null
4666 and MapMark.DestFileType <> 'Do Not Migrate' -- Excludes mappings we intentionally suppress.
4667
4668 -- Update the MigrationPage Table
4669 update MigrationPage
4670 set FilePath = #Pages.FilePath,
4671 AnnotationsPath = #Pages.AnnotationsPath,
4672 IRFileName = @filename,
4673 SrcFileName = @filename,
4674 IRDrawer = #Pages.IRDrawer,
4675 IRFileType = #Pages.IRFileType,
4676 IRFileNumber = #Pages.IRFileNumber,
4677 IRFolderPath = #Pages.IRFolderPath,
4678 IRDocType = #Pages.IRDocType,
4679 IRDocDate = #Pages.IRDocDate,
4680 IRPageMark = #Pages.IRPageMark,
4681 IRDocDescription = #Pages.IRDocDescription,
4682 IRPageDescription = #Pages.IRPageDescription,
4683 IRAttribute1 = #Pages.IRAttribute1,
4684 IRAttribute2 = #Pages.IRAttribute2,
4685 IRAttribute3 = #Pages.IRAttribute3,
4686 IRAttribute4 = #Pages.IRAttribute4,
4687 IRAttribute5 = #Pages.IRAttribute5,
4688 IRAttribute6 = #Pages.IRAttribute6,
4689 IRAttribute7 = #Pages.IRAttribute7,
4690 IRAttribute8 = #Pages.IRAttribute8,
4691 IRAttribute9 = #Pages.IRAttribute9,
4692 IRAttribute10 = #Pages.IRAttribute10,
4693 IRAttribute11 = #Pages.IRAttribute11,
4694 IRAttribute12 = #Pages.IRAttribute12,
4695 IRAttribute13 = #Pages.IRAttribute13,
4696 IRAttribute14 = #Pages.IRAttribute14,
4697 IRAttribute15 = #Pages.IRAttribute15
4698 from #Pages
4699 where MigrationPage.FileID = @fileid
4700 and MigrationPage.ID = #Pages.ID
4701 /*
4702 -- Process the FUP File Entries
4703 CREATE TABLE #FUPRecords
4704 (
4705 [System] [varchar](100) NOT NULL,
4706 [SrcDrawer] [varchar](4) NOT NULL,
4707 [FileID] [varchar](100) NOT NULL,
4708 [IRDrawer] [varchar](50) NOT NULL,
4709 [IRFileType] [varchar](50) NOT NULL,
4710 [IRFileNumber] [varchar](50) NOT NULL,
4711 [IRFileName] [varchar](50) NULL,
4712 [SrcUserData1] [varchar](10) NULL,
4713 [SrcUserData2] [varchar](20) NULL,
4714 [SrcUserData3] [varchar](30) NULL,
4715 [SrcUserData4] [varchar](40) NULL,
4716 [SrcUserData5] [varchar](50) NULL,
4717 [SrcFileOwner] [varchar](50) NULL,
4718 [SrcFileMark1] [int] NULL,
4719 [SrcFileMark2] [int] NULL,
4720 [SrcFileMark3] [int] NULL,
4721 [UserData1AttrName] [varchar](50) NULL,
4722 [UserData2AttrName] [varchar](50) NULL,
4723 [UserData3AttrName] [varchar](50) NULL,
4724 [UserData4AttrName] [varchar](50) NULL,
4725 [UserData5AttrName] [varchar](50) NULL,
4726 [FileOwnerAttrName] [varchar](50) NULL,
4727 [FileMark1ID] [int] NULL,
4728 [FileMark2ID] [int] NULL,
4729 [FileMark3ID] [int] NULL)
4730
4731 insert into #FUPRecords
4732 (System, SrcDrawer, FileID, IRDrawer, IRFileType, IRFileNumber, IRFileName,
4733 SrcUserData1, SrcUserData2, SrcUserData3, SrcUserData4, SrcUserData5, SrcFileOwner, SrcFileMark1, SrcFileMark2, SrcFileMark3)
4734 select distinct *
4735 from (select #Pages.System, #Pages.SrcDrawer, Fileid, IRDrawer, IRFileType, IRFileNumber, IRFileName = @filename,
4736 SrcUserData1, SrcUserData2, SrcUserData3, SrcUserData4, Srcuserdata5, Srcfileowner, SrcFileMark1, SrcFileMark2, SrcFileMark3
4737 from #Pages
4738 inner join MigrationFile
4739 on #Pages.FileID = MigrationFile.ID) pagelist
4740
4741
4742 -- Map File Level Attributes
4743 update #FUPRecords
4744 set UserData1AttrName = MapFileTypeAttribute.DestAttrName1,
4745 UserData2AttrName = MapFileTypeAttribute.DestAttrName2,
4746 UserData3AttrName = MapFileTypeAttribute.DestAttrName3,
4747 UserData4AttrName = MapFileTypeAttribute.DestAttrName4,
4748 UserData5AttrName = MapFileTypeAttribute.DestAttrName5
4749 from MapFileTypeAttribute
4750 where #FUPRecords.irFileType = MapFileTypeAttribute.DestFileType
4751
4752 -- Update Records if no filemark is set
4753 update #FUPRecords set FileMark1ID = 0 where SrcFileMark1 = 0
4754 update #FUPRecords set FileMark2ID = 0 where SrcFileMark2 = 0
4755 update #FUPRecords set FileMark3ID = 0 where SrcFileMark3 = 0
4756
4757 -- Map the FileMarks
4758 update #FUPRecords
4759 set FileMark1ID = DestMarkID
4760 from MapMark
4761 where #FUPRecords.IRFileType = MapMark.DestFileType
4762 and MapMark.MarkType='file'
4763 and #FUPRecords.SrcFileMark1 = SrcMarkValue
4764
4765 update #FUPRecords
4766 set FileMark2ID = DestMarkID
4767 from MapMark
4768 where #FUPRecords.IRFileType = MapMark.DestFileType
4769 and MapMark.MarkType='file'
4770 and #FUPRecords.SrcFileMark2 = SrcMarkValue
4771
4772 update #FUPRecords
4773 set FileMark3ID = DestMarkID
4774 from MapMark
4775 where #FUPRecords.IRFileType = MapMark.DestFileType
4776 and MapMark.MarkType='file'
4777 and #FUPRecords.SrcFileMark3 = SrcMarkValue
4778
4779 -- Insert new FUP Record
4780 insert into MigrationFUP
4781 (Status, System, SrcDrawer, FileID, IRDrawer, IRFileType, IRFileNumber, IRFileName,
4782 SrcUserData1, SrcUserData2, SrcUserData3, SrcUserData4, SrcUserData5, SrcFileOwner, SrcFileMark1, SrcFileMark2, SrcFileMark3,
4783 UserData1AttrName, UserData2AttrName, UserData3AttrName, UserData4AttrName, UserData5AttrName, FileOwnerAttrName,
4784 FileMark1ID, FileMark2ID, FileMark3ID)
4785 select Status = 0, * from #FUPRecords
4786 */
4787
4788 -- Process Pages Put on Hold During Mapping
4789 select MigrationDocument.ID, Status, HoldReason
4790 into #Documents
4791 from MigrationDocument, #Pages
4792 where #Pages.DocumentID = MigrationDocument.ID
4793
4794 -- Reset all previous items marked for Purge (they might be okay now)
4795 update #Documents set status = -2 where status = -9
4796 -- If anything was marked "Do Not Migrate"... then set it to purge.
4797 update #Documents
4798 set status = -9,
4799 HoldReason=null -- Prevents\Fixes Issue #50
4800 where ID in (select distinct DocumentID from #Pages where IRDrawer = 'Do Not Migrate')
4801
4802 update #Documents
4803 set status = -2
4804 where ID in (select DocumentID from #Pages)
4805 and status = -5
4806 and HoldReason in ('Unmapped Document','Some Pages have no Image File Path','Unmapped PageMarks')
4807
4808 -- Place unmapped documents on hold
4809 update #Documents
4810 set status = -5, HoldReason = 'Unprocessed Notes'
4811 where ID in (select DocumentID from #Pages where SrcImageType in (4,5) and FilePath like '%.notes')
4812
4813 update #Documents
4814 set status = -5, HoldReason = 'Unmapped Document'
4815 where ID in (select DocumentID from #Pages where IRDrawer is null or IRDrawer='')
4816
4817 update #Documents
4818 set status = -5, HoldReason = 'Some Pages have no Image File Path'
4819 where ID in (select DocumentID from #Pages where FilePath is null)
4820
4821 update #Documents
4822 set status = -5, HoldReason = 'Unmapped Document (Intentional SrcDrawer={$HOLD})'
4823 where ID in (select DocumentID from #Pages where IRDrawer like'%{$HOLD}%')
4824
4825 update #Documents
4826 set status = -5, HoldReason = 'Unmapped PageMarks'
4827 where ID in (select DocumentID from #Pages
4828 where SrcPageMark is not null and IRPageMark is null
4829 and SrcPageMark not in (select SrcMarkID from MapPageMark
4830 where System = @system and SrcDrawer = #Pages.SrcDrawer
4831 and DestFileType = 'Do Not Migrate'))
4832
4833 -- Make the document update
4834 update MigrationDocument
4835 set status = #Documents.status,
4836 HoldReason = #Documents.HoldReason
4837 from #Documents
4838 where MigrationDocument.ID = #Documents.ID
4839
4840
4841 exec logEnd @logid
4842
4843end
4844
4845GO
4846/****** Object: StoredProcedure [dbo].[processTasks] Script Date: 21/11/2016 12:32:21 ******/
4847SET ANSI_NULLS ON
4848GO
4849SET QUOTED_IDENTIFIER ON
4850GO
4851Create Procedure [dbo].[processTasks]
4852 @fileid varchar(100) = null,
4853 @drawer varchar(4) = null,
4854 @system varchar(255) = null,
4855 @debug int = 0
4856as
4857begin
4858 if @debug>0
4859 raiserror('Starting procedure processTasks. DEBUG level specified as %d',0,1,@debug);
4860
4861 if @debug=0
4862 set nocount on
4863
4864 declare @rowCount int;
4865 declare @fileno varchar(50)
4866
4867 if @fileid is not null -- These values will retain their current values or remain null if @fileid is null
4868 select @system = System, @drawer = SrcDrawer, @fileno = SrcFileNumber from MigrationFile where ID = @fileid
4869
4870 declare @logid int, @ProcName varchar(50)
4871 set @ProcName = Object_Name(@@PROCID)
4872 exec logStart @procname, @system, @drawer, @param1 = @fileno, @param2 = @fileid, @ID = @logid output
4873
4874 if (@debug >= 1)
4875 Raiserror (' Processing Tasks for System: %s, Drawer: %s, File: %s',10,1,@system,@drawer,@fileno) with nowait
4876
4877 if @fileid is not null -- Only update the status to 2 if there was a fileid specified. This proc should run less than a few minutes, so setting the files to 2 may not be necessary.
4878 update MigrationFile set status = 2 where ID = @fileid
4879
4880 if @debug >= 2
4881 raiserror('DEBUG: Variable values prior to insert into #Tasks: @fileid=%s; @drawer=%s; @system=%s',0,1,@fileid,@drawer,@system);
4882
4883 select *
4884 into #Tasks
4885 from MigrationTask
4886 where FileID = isnull(@fileid,FileID)
4887 and SrcDrawer = isnull(@drawer,SrcDrawer)
4888 and System = isnull(@system,System);
4889 set @rowCount=@@ROWCOUNT;
4890 if (@debug >= 1)
4891 raiserror('Rows inserted to temp #Tasks: %d',0,1,@rowCount)
4892
4893 update #Tasks
4894 set #Tasks.flowid = MapTask.DestFlowProgName,
4895 #Tasks.stepid = MapTask.DestStepProgName
4896 from MapTask
4897 where MapTask.System = #Tasks.System
4898 and MapTask.SrcFlowID = #Tasks.SrcFlowID
4899 and MapTask.SrcStepid = #Tasks.SrcStepID
4900
4901
4902 if (@debug >= 2)
4903 Raiserror (' Task Assignee Mappings for System: %s, Drawer: %s, File: %s',10,1,@system,@drawer,@fileno) with nowait
4904 update #Tasks
4905 set #Tasks.AssignedToUserID = MapUser.DestAccountID
4906 from MapUser
4907 where MapUser.System = #Tasks.System
4908 and #Tasks.SrcAssignedToUserID = MapUser.SrcUserID
4909
4910 update #Tasks
4911 set #Tasks.AssignedToUserID = ''
4912 from MapUser
4913 where MapUser.System = #Tasks.System
4914 and #Tasks.SrcAssignedToUserID is null
4915
4916 -- Set any null assigned to userid values or mapped ${UNASSIGNED} values to be unassigned (empty string)
4917 update #Tasks set
4918 AssignedToUserID=''
4919 from #Tasks
4920 where #Tasks.SrcAssignedToUserID is null
4921 or #Tasks.AssignedToUserID in('{$UNASSIGNED}','${UNASSIGNED}') -- "{$UNASSIGNED}" is deprecated. Use "${UNASSIGNED}" for new work.
4922
4923 if (@debug >= 2) -- Show #Tasks prior to updating MigrationTask
4924 select * from #Tasks;
4925
4926 update MigrationTask
4927 set MigrationTask.AssignedToUserID = #Tasks.AssignedToUserID,
4928 MigrationTask.FlowID = #Tasks.FlowID,
4929 MigrationTask.StepID = #Tasks.StepID
4930 from #Tasks
4931 where MigrationTask.ID = #Tasks.ID
4932
4933 -- Reset any mappings that were on hold for unmapped tasks before (they might be fixed)
4934 update MigrationDocument
4935 set status = -2
4936 where ID in (select DocumentID from #Tasks)
4937 and HoldReason in ('Unmapped Task', 'Unmapped Task Assignee')
4938
4939 -- Place Unmapped task documents on Hold.
4940 update MigrationDocument
4941 set status = -5, HoldReason = 'Unmapped Task'
4942 where ID in (
4943 select DocumentID
4944 from #Tasks
4945 where FlowID is null
4946 or FlowID=''
4947 or StepID is null
4948 or StepID=''
4949 )
4950 and status = -2
4951
4952 update MigrationDocument
4953 set status = -5, HoldReason = 'Unmapped Task Assignee'
4954 where ID in (select DocumentID from #Tasks where AssignedToUserID is null)
4955 and status = -2
4956
4957 exec logEnd @logid
4958end
4959
4960GO
4961/****** Object: StoredProcedure [dbo].[purge] Script Date: 21/11/2016 12:32:21 ******/
4962SET ANSI_NULLS ON
4963GO
4964SET QUOTED_IDENTIFIER ON
4965GO
4966CREATE Procedure [dbo].[purge]
4967 @system varchar(50) = null,
4968 @drawer varchar(100) = null,
4969 @filenumber varchar(255) = null
4970as
4971begin
4972 set nocount on
4973
4974 declare @logid int, @ProcName varchar(50)
4975 set @ProcName = Object_Name(@@PROCID)
4976 exec logStart @procname, @system, @drawer, @param1 = @filenumber, @ID = @logid output
4977
4978 if exists(select * from ConfigDrawerList
4979 where system = isNull(@system,system) and drawer = isNull(@drawer,drawer)
4980 and purge in ('Date','Files'))
4981 begin
4982 Raiserror (' Marking Files for Purge',10,1) with nowait
4983 update MigrationFile
4984 set status = -9
4985 from ConfigDrawerList, ConfigPurgeList
4986 where MigrationFile.System = ConfigDrawerList.system
4987 and MigrationFile.SrcDrawer = ConfigDrawerList.drawer
4988 and MigrationFile.System = ConfigPurgeList.System
4989 and MigrationFile.SrcDrawer = ConfigPurgeList.SrcDrawer
4990 and MigrationFile.SrcFileNumber = ConfigPurgeList.SrcFileNumber
4991 and ConfigDrawerList.purge = 'Files'
4992 and MigrationFile.System = isNull(@system,MigrationFile.System)
4993 and MigrationFile.SrcDrawer = isNull(@drawer,MigrationFile.SrcDrawer)
4994 and MigrationFile.SrcFileNumber = isNull(@filenumber, MigrationFile.SrcFileNumber)
4995
4996 update MigrationFile
4997 set status = -9
4998 from ConfigDrawerList
4999 where MigrationFile.System = ConfigDrawerList.system
5000 and MigrationFile.SrcDrawer = ConfigDrawerList.drawer
5001 and MigrationFile.MostRecentDocDate < ConfigDrawerList.purgedate
5002 and ConfigDrawerList.purge = 'Date'
5003 and ConfigDrawerList.purgedate is not null
5004 and MigrationFile.System = isNull(@system,MigrationFile.System)
5005 and MigrationFile.SrcDrawer = isNull(@drawer,MigrationFile.SrcDrawer)
5006 and MigrationFile.SrcFileNumber = isNull(@filenumber, MigrationFile.SrcFileNumber)
5007
5008 -- Update all the Documents
5009 update MigrationDocument
5010 set status = -9
5011 from MigrationFile
5012 where MigrationDocument.FileID = MigrationFile.ID
5013 and MigrationFile.status = -9
5014
5015 end
5016 else
5017 Raiserror (' No Matching Purge Directives',10,1) with nowait
5018
5019 exec logEnd @logid
5020end
5021
5022GO
5023/****** Object: StoredProcedure [dbo].[raiseMessage] Script Date: 21/11/2016 12:32:21 ******/
5024SET ANSI_NULLS ON
5025GO
5026SET QUOTED_IDENTIFIER ON
5027GO
5028create procedure [dbo].[raiseMessage]
5029 @message varchar(4000),
5030 @severity int = 10,
5031 @state int = 1,
5032 @arg1 varchar(2000) = '',
5033 @arg2 varchar(2000) = '',
5034 @rowCount int = null,
5035 @nestedDepth int = 0,
5036 @arg3 varchar(2000) = '',
5037 @arg4 varchar(2000) = '',
5038 @arg5 varchar(2000) = '',
5039 @suppressDateTimeStamp int = 0
5040as
5041 /*
5042 Description: raiseMessage is intended to facilitate succinct on screen status logging for long running and complex
5043 scripts in SSMS by generating date\time stamps for each entry, rows affected integrated into the message where
5044 applicable, nesting the messages to differentiate sub-processes, etc. raiseMessage leverages raiserror and thus
5045 all of the parameters for raiserror is supported - up to five arguments (currently).
5046
5047 Parameters
5048 @message is the main message that you want to display
5049 Remark (snippet from MSDN): " If the message contains 2,048 or more characters, only the first 2,044 are displayed and an ellipsis is added to indicate that the message has been truncated. Note that substitution parameters consume more characters than the output shows because of internal storage behavior. For example, the substitution parameter of %d with an assigned value of 2 actually produces one character in the message string but also internally takes up three additional characters of storage. This storage requirement decreases the number of available characters for message output."
5050 @severity - defaulted to 10 to default as a message instead of error.
5051 @state defaulted 1. See MSDN documentation on RAISERROR for usage.
5052 @rowCount is used to pass in the @@ROWCOUNT auto variable
5053 @nestedDepth auto-indents the message between the time stamp and the message text
5054 @arg1-@arg5 are optional arguments that aligns with the [ ,argument [ ,...n ] ] RAISERROR syntax.
5055
5056 Example usage:
5057
5058 set nocount on
5059 exec raiseMessage @message='Starting: raiseMessage Demo.sql', @nestedDepth=0
5060 exec raiseMessage @message='Begining Process', @nestedDepth=1
5061 exec raiseMessage @message='Selecting rows from FooBar', @nestedDepth=2
5062 select * from FooBar
5063 exec raiseMessage @message='Finished selecting rows from FooBar', @rowCount=@@ROWCOUNT, @nestedDepth=2
5064 exec raiseMessage @message='Done', @nestedDepth=0
5065 exec raiseMessage '%s the %s %s %s, %s.', 10, 1, 'Open', 'pod', 99999, 0, 'bay', 'door', 'HAL'
5066 exec raiseMessage @message='I''m sorry, Dave, but I can''t do that.',
5067 @severity=15,
5068 @state=1,
5069 @arg1='Dave',
5070 @nestedDepth=1
5071
5072 /* -- Example Message pane output
5073 2016-01-11 13:11:27: Starting: raiseMessage Demo.sql
5074 2016-01-11 13:11:27: Begining Process
5075 2016-01-11 13:11:27: Selecting rows from FooBar
5076 2016-01-11 13:11:27: Finished selecting rows from FooBar - Rows Affected: 1234
5077 2016-01-11 13:11:27: Done
5078 2016-01-11 13:11:27: Open the pod bay door, HAL. - Rows Affected: 99999
5079 Msg 50000, Level 15, State 1, Procedure raiseMessage, Line 53
5080 2016-01-11 13:11:27: I'm sorry, Dave, but I can't do that.
5081 */
5082 */
5083begin
5084 declare @formattedMessage varchar(4000)
5085 set @formattedMessage =
5086 case @suppressDateTimeStamp
5087 when 0
5088 then convert(varchar,getdate(),120) + ': '
5089 else ''
5090 end
5091 + replicate(' ',@nestedDepth*4)
5092 + @message
5093 + case
5094 when @rowcount is not null
5095 then ' - Rows Affected: ' + CAST(@rowcount as varchar(50))
5096 else ''
5097 end;
5098
5099 raiserror(@formattedMessage,@severity,@state,@arg1,@arg2,@arg3,@arg4,@arg5) with nowait;
5100 if len(@formattedMessage)>2000 raiserror('The prior raiseMessage call may have truncated the message due to constraints of RAISERROR.',10,1)
5101end
5102
5103GO
5104/****** Object: StoredProcedure [dbo].[reportErrors] Script Date: 21/11/2016 12:32:21 ******/
5105SET ANSI_NULLS ON
5106GO
5107SET QUOTED_IDENTIFIER ON
5108GO
5109create procedure [dbo].[reportErrors]
5110 @errortype varchar(1000) = null,
5111 @priority int = null
5112as
5113begin
5114
5115 if (@errortype is null)
5116 begin
5117 SELECT left(LogProgress.errormessage,50) as errormessage, Documents = COUNT(*) , Pages = SUM(MigrationDocument.pagecount)
5118 into #ErrorDocs
5119 FROM LogProgress
5120 INNER JOIN MigrationDocument ON MigrationDocument.ID = LogProgress.DocumentID
5121 WHERE MigrationDocument.Status = -1 AND LogProgress.success = 0
5122 and MigrationDocument.Priority<=isnull(@Priority,MigrationDocument.Priority)
5123 GROUP BY left(LogProgress.errormessage,50)
5124 ORDER BY Documents DESC
5125
5126 select left(LogProgress.errormessage,50) as errormessage, Tasks = COUNT(*)
5127 into #ErrorTasks
5128 from LogProgress, MigrationTask, MigrationDocument
5129 where MigrationDocument.ID = LogProgress.DocumentID
5130 and LogProgress.DocumentID = MigrationTask.DocumentID
5131 and LogProgress.errormessage is not null
5132 and MigrationDocument.Priority<=isnull(@Priority,MigrationDocument.Priority)
5133 group by left(LogProgress.errormessage,50)
5134
5135 select #ErrorDocs.*, Tasks = ISNULL(Tasks,0)
5136 from #ErrorDocs left join #ErrorTasks on #ErrorDocs.errormessage = #ErrorTasks.errormessage
5137 order by Documents desc
5138 end
5139 else
5140 begin
5141 SELECT errormessage, Documents = COUNT(*) , Pages = SUM(MigrationDocument.pagecount)
5142 into #ErrorDocs2
5143 FROM LogProgress
5144 INNER JOIN MigrationDocument ON MigrationDocument.ID = LogProgress.DocumentID
5145 WHERE MigrationDocument.Status = -1 AND LogProgress.success = 0 and errormessage like @errortype + '%'
5146 and MigrationDocument.Priority<=isnull(@Priority,MigrationDocument.Priority)
5147 GROUP BY LogProgress.errormessage
5148 ORDER BY Documents DESC
5149
5150 select errormessage, Tasks = COUNT(*)
5151 into #ErrorTasks2
5152 from LogProgress, MigrationTask
5153 where LogProgress.DocumentID = MigrationTask.DocumentID
5154 and LogProgress.errormessage like @errortype + '%'
5155 group by LogProgress.errormessage
5156
5157 select #ErrorDocs2.*, Tasks = ISNULL(Tasks,0)
5158 from #ErrorDocs2 left join #ErrorTasks2 on #ErrorDocs2.errormessage = #ErrorTasks2.errormessage
5159 order by Documents desc
5160 end
5161
5162 select MigrationDocument.FileID, LogProgress.DocumentID, System, SrcDrawer, SrcFileNumber, Errormessage
5163 from MigrationDocument, LogProgress
5164 where MigrationDocument.ID = LogProgress.Documentid
5165 and LogProgress.errormessage is not null
5166 and LogProgress.errormessage like isNull(@errortype,'%') + '%'
5167 and MigrationDocument.Status = -1
5168 and MigrationDocument.Priority<=isnull(@Priority,MigrationDocument.Priority)
5169
5170end
5171
5172GO
5173/****** Object: StoredProcedure [dbo].[reportHolds] Script Date: 21/11/2016 12:32:21 ******/
5174SET ANSI_NULLS ON
5175GO
5176SET QUOTED_IDENTIFIER ON
5177GO
5178create procedure [dbo].[reportHolds]
5179as
5180begin
5181 select System, HoldReason, Count(*) as DocCount
5182 from MigrationDocument
5183 where status = -5
5184 group by System, HoldReason
5185 order by DocCount desc
5186end
5187
5188GO
5189/****** Object: StoredProcedure [dbo].[reportLoadStats] Script Date: 21/11/2016 12:32:21 ******/
5190SET ANSI_NULLS ON
5191GO
5192SET QUOTED_IDENTIFIER ON
5193GO
5194Create Procedure [dbo].[reportLoadStats]
5195 @system varchar(50) = null -- System to run stats for (set to NULL for all)
5196as
5197begin
5198
5199select Drawer = srcDrawer,
5200 Files = count(distinct FileID),
5201 Documents = count(distinct DocumentID),
5202 Pages = count(*),
5203 Tasks = (select count(*) from MigrationTask where MigrationTask.srcDrawer = MigrationPage.srcDrawer),
5204 Annotations = sum(case when SrcAnnImageID is not null then 1 else 0 end)
5205 into #Pages
5206 from MigrationPage
5207 where srcImageType = 0
5208 group by srcDrawer
5209
5210
5211 select
5212 Drawer = srcDrawer,
5213 Notes = count(*)
5214 into #Notes
5215 from MigrationPage
5216 where srcImageType > 1
5217 group by srcDrawer
5218
5219 select MigrationLoad = ' ',
5220 Drawer = #Pages.Drawer,
5221 Files, Documents, Pages, Tasks, Annotations, Notes = isNull(Notes,0)
5222 from #Pages
5223 left join #Notes on #Pages.Drawer = #Notes.Drawer
5224
5225end
5226
5227GO
5228/****** Object: StoredProcedure [dbo].[reportPerformance] Script Date: 21/11/2016 12:32:21 ******/
5229SET ANSI_NULLS ON
5230GO
5231SET QUOTED_IDENTIFIER ON
5232GO
5233create procedure [dbo].[reportPerformance]
5234 @Migration bit = 0,
5235 @Process bit = 0,
5236 @History bit = 0
5237as
5238begin
5239 if object_id('tempdb..#reportM') is not null
5240 drop table #reportM
5241 if object_id('tempdb..#reportP') is not null
5242 drop table #reportP
5243
5244 if (@Migration = 1)
5245 begin
5246 select
5247 [Machine Name] = case when (grouping(machinename)=1) then 'All Machines' else machinename end,
5248 MinTimeStamp = MIN(timestamp),
5249 MaxTimeStamp = MAX(timestamp),
5250 Docs = COUNT(MigrationDocument.id),
5251 DocsPerHour = case
5252 when max(timestamp) > min(timestamp)
5253 then round(COUNT(distinct MigrationDocument.id)/cast(MAX(timestamp)-MIN(timestamp) as float)/24.0,0)
5254 else 0.0
5255 end,
5256 Pages = Sum(PageCount),
5257 PagesPerDoc = case
5258 when count(MigrationDocument.ID) > 0
5259 then round(cast(sum(PageCount) as float)/cast(count(MigrationDocument.id) as float),1)
5260 else 0.0
5261 end,
5262 PagesPerHour = case
5263 when max(timestamp) > min(timestamp)
5264 then round(cast(sum(PageCount) as float)/(cast(MAX(timestamp)-MIN(timestamp) as float)*24),0)
5265 else 0.0
5266 end
5267 into #reportM
5268 from MigrationDocument with(nolock)
5269 where status in (1,-1) and timestamp>DATEADD(MI,-5, GETDATE())
5270 group by machinename with rollup
5271
5272 declare @DocsLeft int, @PagesLeft int
5273 select @DocsLeft = count(ID), @PagesLeft = sum(PageCount) from MigrationDocument where status = 0
5274
5275 --select count(distinct [Machine Name]) from #reportM where [Machine Name]<>'All Machines'
5276 update #reportM set [Machine Name]=[Machine Name]+' ('+cast((select count(distinct [Machine Name]) from #reportM where [Machine Name]<>'All Machines') as varchar(50))+' Machines Reporting)' where [Machine Name]='All Machines';
5277
5278 select *,
5279 DocHoursLeft = case when DocsPerHour = 0 then 0 else round(cast(@DocsLeft as float)/ cast(DocsPerHour as float),2) end,
5280 PageHoursLeft = case when PagesPerHour = 0 then 0 else round(cast(@PagesLeft as float)/ cast(PagesPerHour as float),2) end
5281 from #reportM
5282 order by
5283 case when [Machine Name] like 'All Machines (% Machines Reporting)' then 0 else 1 end asc, --Force the "All Machines" total to be the first record in the results
5284 [Machine Name] asc -- Secondary sort for the actual machine names to put them in order
5285 end
5286
5287 if (@Process = 1)
5288 begin
5289 select
5290 StartTime = min(StartTime),
5291 EndTime = max(EndTime),
5292 Files = count(MigrationFile.ID),
5293 Documents = sum(DocumentCount),
5294 Pages = sum(PageCount),
5295 Tasks = sum(TaskCount)
5296 into #reportP
5297 from LogProcess, MigrationFile
5298 where LogProcess.OtherParam1 = MigrationFile.ID and name = 'process'
5299 and EndTime > DATEADD(MI,-5,getDate())
5300 and StartTime > DATEADD(MI,-5,getDate())
5301 and MigrationFile.status = 1
5302
5303 select Process = '', StartTime, EndTime,
5304 Files = replace(convert(varchar,cast(Files as money),1),'.00',''),
5305 FilesPerHour = replace(convert(varchar,cast(round(cast(Files as float) / cast(EndTime - StartTime as float) / 24.0,0) as money),1),'.00',''),
5306 Documents = replace(convert(varchar,cast(Documents as money),1),'.00',''),
5307 DocsPerHour = replace(convert(varchar,cast(round(cast(Documents as float) / cast(EndTime - StartTime as float) / 24.0,0) as money),1),'.00',''),
5308 Pages = replace(convert(varchar,cast(Pages as money),1),'.00',''),
5309 PagesPerHour = replace(convert(varchar,cast(round(cast(Pages as float) / cast(EndTime - StartTime as float) / 24.0,0) as money),1),'.00','')
5310 from #reportP
5311 end
5312
5313 if (@History = 1)
5314 begin
5315
5316 select
5317 Process = '',
5318 [Hour] = dateadd(mi, datepart(minute, EndTime) / 60 * 60, dateadd(hh, datediff(hh, 0, EndTime), 0)),
5319 Files = replace(convert(varchar,cast(Count(*) as money),1),'.00',''),
5320 Documents = replace(convert(varchar,cast(Sum(DocumentCount) as money),1),'.00',''),
5321 Pages = replace(convert(varchar,cast(Sum(PageCount) as money),1),'.00','')
5322 into #Processed
5323 from LogProcess, MigrationFile
5324 where LogProcess.OtherParam1 = MigrationFile.ID and name = 'process'
5325 and MigrationFile.status = 1
5326 group by dateadd(mi, datepart(minute, EndTime) / 60 * 60, dateadd(hh, datediff(hh, 0, EndTime), 0))
5327
5328 select Migration = '',
5329 [Hour] = dateadd(mi, datepart(minute, cq.timestamp) / 60 * 60, dateadd(hh, datediff(hh, 0, cq.timestamp), 0)),
5330 Documents = replace(convert(varchar,cast(Count(*) as money),1),'.00',''),
5331 Pages = replace(convert(varchar,cast(Sum(PageCount) as money),1),'.00','')
5332 into #Migrated
5333 from MigrationDocument cq
5334 where status = 1
5335 group by dateadd(mi, datepart(minute, cq.timestamp) / 60 * 60, dateadd(hh, datediff(hh, 0, cq.timestamp), 0))
5336
5337 select [Hour] = isNull(#Processed.[Hour],#Migrated.[Hour]),
5338 ProcessedFiles = isNull(#Processed.Files,'0'),
5339 ProcessedDocs = isNull(#Processed.Documents,'0'),
5340 MigratedDocs = isNull(#Migrated.Documents,'0'),
5341 ProcessedPages = isNull(#Processed.Pages,'0'),
5342 MigratedPages = isNull(#Migrated.Pages,'0')
5343 from #Processed full join #Migrated
5344 on #Processed.[Hour] = #Migrated.[Hour]
5345 order by [Hour] desc
5346
5347 end
5348end
5349
5350
5351
5352GO
5353/****** Object: StoredProcedure [dbo].[reportProcess] Script Date: 21/11/2016 12:32:21 ******/
5354SET ANSI_NULLS ON
5355GO
5356SET QUOTED_IDENTIFIER ON
5357GO
5358create Procedure [dbo].[reportProcess]
5359 @Name varchar(100) = null,
5360 @phasesOnly bit = 0,
5361 @showHistory bit = 0
5362as
5363begin
5364 select top 20 ID, Name,
5365 [Duration (sec)] = cast(round(Duration / 1000.0,1) as numeric(10,1)),
5366 [Duration (min)] = cast(round(Duration / 1000.0 / 60.0,1) as numeric(10,1)),
5367 StartTime, EndTime,
5368 System, Drawer, OtherParam1, OtherParam2, OtherParam3
5369 from LogProcess
5370 where Name = isNull(@Name, Name)
5371 and isPhase = case when @phasesOnly = 1 then 1 else isPhase end
5372 order by ID desc
5373
5374 select Name, max(StartTime) as LastExecuted,
5375 cast(round(sum(Duration) / 1000.0 / 60.0,1) as numeric(10,1)) as [Duration (min)]
5376 from LogProcess
5377 where Name = isNull(@Name, Name)
5378 and isPhase = case when @phasesOnly = 1 then 1 else isPhase end
5379 group by Name
5380 order by LastExecuted desc
5381
5382 if (@showHistory = 1)
5383 begin
5384 select *,
5385 [Duration (sec)] = cast(round(Duration / 1000.0,1) as numeric(10,1)),
5386 [Duration (min)] = cast(round(Duration / 1000.0 / 60.0,1) as numeric(10,1))
5387 from LogProcessHistory
5388 where Name = isNull(@Name, Name)
5389 order by ID desc
5390 end
5391 end
5392
5393GO
5394/****** Object: StoredProcedure [dbo].[reportSnapshotStats] Script Date: 21/11/2016 12:32:21 ******/
5395SET ANSI_NULLS ON
5396GO
5397SET QUOTED_IDENTIFIER ON
5398GO
5399create procedure [dbo].[reportSnapshotStats]
5400 @system varchar(50)
5401as
5402begin
5403 set nocount on
5404 Set Transaction Isolation Level Read Uncommitted
5405
5406 declare @logid int, @ProcName varchar(50)
5407 set @ProcName = Object_Name(@@PROCID)
5408 exec logStart @procname, @system, @ID = @logid output
5409
5410 --exec indexSnapshot ....
5411
5412 RAISERROR (' Documents', 10, 1) WITH NOWAIT
5413 if Object_id('tempdb..#documents') is not null
5414 drop table #documents
5415
5416 select Drawer = SnapshotLocation.name, SnapshotFile.fileid, SnapshotDocument.documentid,
5417 Pages = count(*),
5418 PagesH = sum(case when (SnapshotPage.isdeleted + SnapshotDocument.isdeleted + SnapshotFile.isdeleted + isNull(folder1.isdeleted,0) + isNull(folder2.isdeleted,0)
5419 + isNull(folder3.isdeleted,0) + isNull(folder4.isdeleted,0) + isNull(folder5.isdeleted,0) + isNull(folder6.isdeleted,0)
5420 + isNull(folder7.isdeleted,0) + isNull(folder8.isdeleted,0) + isNull(folder9.isdeleted,0) + isNull(folder10.isdeleted,0)) = 0 then 0 else 1 end),
5421 PagesV = sum(case when (SnapshotPage.isdeleted + SnapshotDocument.isdeleted + SnapshotFile.isdeleted + isNull(folder1.isdeleted,0) + isNull(folder2.isdeleted,0)
5422 + isNull(folder3.isdeleted,0) + isNull(folder4.isdeleted,0) + isNull(folder5.isdeleted,0) + isNull(folder6.isdeleted,0)
5423 + isNull(folder7.isdeleted,0) + isNull(folder8.isdeleted,0) + isNull(folder9.isdeleted,0) + isNull(folder10.isdeleted,0)) = 0 then 1 else 0 end),
5424 Annotations = sum(case when Annotation.imageid is not null then 1 else 0 end),
5425 AnnotationsH = sum(case when (SnapshotPage.isdeleted + SnapshotDocument.isdeleted + SnapshotFile.isdeleted + isNull(folder1.isdeleted,0) + isNull(folder2.isdeleted,0)
5426 + isNull(folder3.isdeleted,0) + isNull(folder4.isdeleted,0) + isNull(folder5.isdeleted,0) + isNull(folder6.isdeleted,0)
5427 + isNull(folder7.isdeleted,0) + isNull(folder8.isdeleted,0) + isNull(folder9.isdeleted,0) + isNull(folder10.isdeleted,0)) > 0
5428 and Annotation.imageid is not null then 1 else 0 end),
5429 AnnotationsV = sum(case when (SnapshotPage.isdeleted + SnapshotDocument.isdeleted + SnapshotFile.isdeleted + isNull(folder1.isdeleted,0) + isNull(folder2.isdeleted,0)
5430 + isNull(folder3.isdeleted,0) + isNull(folder4.isdeleted,0) + isNull(folder5.isdeleted,0) + isNull(folder6.isdeleted,0)
5431 + isNull(folder7.isdeleted,0) + isNull(folder8.isdeleted,0) + isNull(folder9.isdeleted,0) + isNull(folder10.isdeleted,0)) = 0
5432 and Annotation.imageid is not null then 1 else 0 end)
5433 into #documents
5434 from SnapshotLocation
5435 join SnapshotFile on SnapshotFile.locationid = SnapshotLocation.locationid
5436 join SnapshotDocument on SnapshotFile.fileid = SnapshotDocument.fileid
5437 join SnapshotPage on SnapshotPage.documentid = SnapshotDocument.documentid
5438 left join SnapshotFolder as folder1 on folder1.folderid = SnapshotDocument.folderid
5439 left join SnapshotFolder as folder2 on folder2.folderid = folder1.parentid
5440 left join SnapshotFolder as folder3 on folder3.folderid = folder2.parentid
5441 left join SnapshotFolder as folder4 on folder4.folderid = folder3.parentid
5442 left join SnapshotFolder as folder5 on folder5.folderid = folder4.parentid
5443 left join SnapshotFolder as folder6 on folder6.folderid = folder5.parentid
5444 left join SnapshotFolder as folder7 on folder7.folderid = folder6.parentid
5445 left join SnapshotFolder as folder8 on folder8.folderid = folder7.parentid
5446 left join SnapshotFolder as folder9 on folder9.folderid = folder8.parentid
5447 left join SnapshotFolder as folder10 on folder10.folderid = folder9.parentid
5448 left join SnapshotImage as Annotation on SnapshotPage.imagesetid = Annotation.imagesetid
5449 and Annotation.ImageType = 1
5450 group by SnapshotLocation.name, SnapshotFile.fileid, SnapshotDocument.documentid
5451
5452
5453
5454 RAISERROR (' Files', 10, 1) WITH NOWAIT
5455 if Object_id('tempdb..#files') is not null
5456 drop table #files
5457
5458 select drawer, #documents.fileid,
5459 Documents = count(*),
5460 DocumentsV = sum(case when PagesV > 0 then 1 else 0 end),
5461 DocumentsH = sum(case when PagesV = 0 then 1 else 0 end),
5462 Pages = sum(Pages),
5463 PagesV = sum(PagesV),
5464 PagesH = sum(PagesH),
5465 Annotations = sum(Annotations),
5466 AnnotationsV = sum(AnnotationsV),
5467 AnnotationsH = sum(AnnotationsH),
5468 Tasks = (select count(*) from SnapshotTask where SnapshotTask.fileid = #documents.fileid)
5469 into #files
5470 from #documents
5471 group by drawer, #documents.fileid
5472
5473 RAISERROR (' Notes', 10, 1) WITH NOWAIT
5474 if Object_id('tempdb..#notes') is not null
5475 drop table #notes
5476
5477 select drawer = SnapshotLocation.name, Notes = sum(Notes), NotesH = sum(NotesH), NotesV = sum(NotesV)
5478 into #notes
5479 from (select fileid = isNull(SnapshotFile.fileid,Folder1.fileid),
5480 Notes = count(*),
5481 NotesH = sum(case when (SnapshotNote.isdeleted + SnapshotNote.hidden + isNull(SnapshotFile.isdeleted,0)
5482 + isNull(folder1.isdeleted,0) + isNull(folder2.isdeleted,0) + isNull(folder3.isdeleted,0)
5483 + isNull(folder4.isdeleted,0) + isNull(folder5.isdeleted,0) + isNull(folder6.isdeleted,0)
5484 + isNull(folder7.isdeleted,0) + isNull(folder8.isdeleted,0) + isNull(folder9.isdeleted,0)
5485 + isNull(folder10.isdeleted,0)) > 0 then 1 else 0 end),
5486 NotesV = sum(case when (SnapshotNote.isdeleted + SnapshotNote.hidden + isNull(SnapshotFile.isdeleted,0)
5487 + isNull(folder1.isdeleted,0) + isNull(folder2.isdeleted,0) + isNull(folder3.isdeleted,0)
5488 + isNull(folder4.isdeleted,0) + isNull(folder5.isdeleted,0) + isNull(folder6.isdeleted,0)
5489 + isNull(folder7.isdeleted,0) + isNull(folder8.isdeleted,0) + isNull(folder9.isdeleted,0)
5490 + isNull(folder10.isdeleted,0)) = 0 then 1 else 0 end)
5491
5492 from SnapshotNote
5493 left join SnapshotFile on SnapshotNote.objectid = SnapshotFile.fileid
5494 left join SnapshotFolder as Folder1 on SnapshotNote.objectid = Folder1.folderid
5495 left join SnapshotFolder as folder2 on folder2.folderid = folder1.parentid
5496 left join SnapshotFolder as folder3 on folder3.folderid = folder2.parentid
5497 left join SnapshotFolder as folder4 on folder4.folderid = folder3.parentid
5498 left join SnapshotFolder as folder5 on folder5.folderid = folder4.parentid
5499 left join SnapshotFolder as folder6 on folder6.folderid = folder5.parentid
5500 left join SnapshotFolder as folder7 on folder7.folderid = folder6.parentid
5501 left join SnapshotFolder as folder8 on folder8.folderid = folder7.parentid
5502 left join SnapshotFolder as folder9 on folder9.folderid = folder8.parentid
5503 left join SnapshotFolder as folder10 on folder10.folderid = folder9.parentid
5504 group by isNull(SnapshotFile.fileid,Folder1.fileid)) NoteList
5505 inner join SnapshotFile on NoteList.fileid = SnapshotFile.fileid
5506 inner join SnapshotLocation on SnapshotFile.locationid = SnapshotLocation.locationid
5507 group by SnapshotLocation.Name
5508
5509 RAISERROR (' Drawers', 10, 1) WITH NOWAIT
5510 if Object_id('tempdb..#drawers') is not null
5511 drop table #drawers
5512
5513 select Files.*, Notes = isNull(#notes.Notes,0),
5514 NotesV = isNull(#notes.NotesV,0), NotesH = isNull(#notes.NotesH,0)
5515 into #drawers
5516 from (select drawer,
5517 Files = count(*),
5518 FilesV = isNull(sum(case when DocumentsV > 0 then 1 else 0 end),0),
5519 FilesH = isNull(sum(case when DocumentsV = 0 then 1 else 0 end),0),
5520 Documents = isNull(sum(Documents),0),
5521 DocumentsV = isNull(sum(DocumentsV),0),
5522 DocumentsH = isNull(sum(DocumentsH),0),
5523 Pages = isNull(sum(Pages),0),
5524 PagesV = isNull(sum(PagesV),0),
5525 PagesH = isNull(sum(PagesH),0),
5526 Annotations = sum(Annotations),
5527 AnnotationsV = sum(AnnotationsV),
5528 AnnotationsH = sum(AnnotationsH),
5529 Tasks = sum(Tasks)
5530 from #files
5531 group by drawer) Files
5532 left join #notes on Files.drawer = #notes.drawer
5533
5534 RAISERROR ('Generate Reconciliation', 10, 1) WITH NOWAIT
5535 if Object_id('tempdb..#Reconcile') is not null
5536 drop table #Reconcile
5537
5538 select top 1 SnapShot from SnapShotDocument
5539
5540 select orderno = 1,
5541 [Line Item] = cast('Total' as varchar(10)),
5542 Drawers = count(*),
5543 Files = sum(FilesV) + sum(FilesH),
5544 Documents = sum(DocumentsV) + sum(DocumentsH),
5545 Pages = sum(PagesV) + sum(PagesH),
5546 Annotations = sum(AnnotationsV) + sum(AnnotationsH)
5547 into #Reconcile
5548 from #drawers
5549
5550 insert into #Reconcile
5551 select orderno = 2,
5552 [Line Item] = 'Hidden',
5553 Drawers = sum(case when FilesV = 0 then 1 else 0 end) * -1,
5554 Files = sum(FilesH) * -1,
5555 Documents = sum(DocumentsH) * -1,
5556 Pages = sum(PagesH) * -1,
5557 Annotations = sum(AnnotationsH) * -1
5558 from #drawers
5559
5560 insert into #Reconcile
5561 select orderno = 3,
5562 [Line Item] = 'Visible',
5563 Drawers = sum(case when FilesV > 0 then 1 else 0 end),
5564 Files = sum(FilesV),
5565 Documents = sum(DocumentsV),
5566 Pages = sum(PagesV),
5567 Annotations = sum(AnnotationsV)
5568 from #drawers
5569
5570 select [Line Item], Drawers, Files, Documents, Pages, Annotations
5571 from #Reconcile
5572 order by orderno
5573
5574
5575 RAISERROR ('..Complete', 10, 1) WITH NOWAIT
5576
5577 RAISERROR ('Generate Universe', 10, 1) WITH NOWAIT
5578 if Object_id('tempdb..#tasksU') is not null
5579 drop table #tasksU
5580
5581 -- Get the number of files in the drawer
5582
5583
5584 select [IRUniverse] = ' ',#drawers.Drawer as Name, Description = isNull(Drawer.Description,'Does Not Exist'),
5585 [Files] = isNull(Files,0), [Documents] = isNull(Documents,0), [Pages] = isNull(Pages,0), isNull(Tasks,0) as Tasks,
5586 isNull(Annotations,0) as Annotations, isNull(Notes,0) as Notes
5587 from #drawers
5588 left join SnapshotLocation as Drawer on Drawer.name = #drawers.drawer
5589 order by Name
5590 RAISERROR ('..Complete', 10, 1) WITH NOWAIT
5591
5592 RAISERROR ('Generate Visible Stats', 10, 1) WITH NOWAIT
5593 if Object_id('tempdb..#tasksV') is not null
5594 drop table #tasksV
5595
5596 -- Get the number of files in the drawer
5597
5598 RAISERROR ('Generate Hidden Stats', 10, 1) WITH NOWAIT
5599 select [IRDeleted] = ' ',#drawers.Drawer as Name, Description = isNull(Drawer.Description,'Does Not Exist'),
5600 [Files] = isNull(FilesH,0), [Documents] = isNull(DocumentsH,0), [Pages] = isNull(PagesH,0), 0 as Tasks,
5601 Annotations = isNull(AnnotationsH,0), isNull(NotesH,0) as Notes
5602 from #drawers
5603 left join SnapshotLocation as Drawer on Drawer.name = #drawers.drawer
5604 order by Name
5605 RAISERROR ('..Complete', 10, 1) WITH NOWAIT
5606
5607 select [IRVisible] = ' ',#drawers.Drawer as Name, Description = isNull(Drawer.Description,'Does Not Exist'),
5608 [Files] = isNull(FilesV,0), [Documents] = isNull(DocumentsV,0), [Pages] = isNull(PagesV,0), isNull(Tasks,0) as Tasks,
5609 Annotations = isNull(AnnotationsV,0), isNull(NotesV,0) as Notes
5610 from #drawers
5611 left join SnapshotLocation as Drawer on Drawer.name = #drawers.drawer
5612 where isNull(FilesV,0) > 0
5613 order by Name
5614 RAISERROR ('..Complete', 10, 1) WITH NOWAIT
5615exec logEnd @logid
5616end
5617
5618GO
5619/****** Object: StoredProcedure [dbo].[reportStatus] Script Date: 21/11/2016 12:32:21 ******/
5620SET ANSI_NULLS ON
5621GO
5622SET QUOTED_IDENTIFIER ON
5623GO
5624create procedure [dbo].[reportStatus]
5625 @system varchar(50) = null,
5626 @drawer varchar(100) = null,
5627 @includePriority bit = 1
5628as
5629begin
5630
5631 declare @totalPages float, @totalDocs float, @totalFiles float
5632
5633 select @totalDocs = COUNT(*),
5634 @totalPages = sum(PageCount)
5635 from MigrationDocument
5636 where SrcDrawer = ISNULL(@drawer,SrcDrawer)
5637 and System = isnull(@system,System)
5638
5639 select @totalFiles = COUNT(*) from MigrationFile
5640 where SrcDrawer = ISNULL(@drawer,SrcDrawer)
5641 and System = isnull(@system,System)
5642
5643 select
5644 Priority,
5645 Status = ConfigStatus.Description + ' (' + cast(MigrationDocument.Status as varchar) + ')',
5646 Documents = COUNT(*),
5647 Pages = sum(PageCount)
5648 into #reportMigration
5649 from MigrationDocument, ConfigStatus
5650 where MigrationDocument.status = ConfigStatus.status
5651 and SrcDrawer = ISNULL(@drawer,SrcDrawer)
5652 and System = isNull(@system,System)
5653 group by Priority, MigrationDocument.Status, ConfigStatus.Description
5654
5655 select
5656 Priority,
5657 Status = ConfigStatus.Description + ' (' + cast(MigrationFile.Status as varchar) + ')',
5658 Files = COUNT(*)
5659 into #reportProcess
5660 from MigrationFile, ConfigStatus
5661 where MigrationFile.status = ConfigStatus.status
5662 and SrcDrawer = ISNULL(@drawer,SrcDrawer)
5663 and System = isNull(@system,System)
5664 group by Priority, MigrationFile.Status, ConfigStatus.Description
5665
5666 select
5667 Priority = isNull(#reportMigration.Priority,#reportProcess.priority),
5668 Status = isNull(#reportMigration.Status,#reportProcess.Status),
5669 Files = isNull(#reportProcess.Files,0),
5670 Documents = isNull(#reportMigration.Documents,0),
5671 Pages = isNull(#reportMigration.Pages,0)
5672 into #report
5673 from #reportMigration
5674 full join #reportProcess
5675 on #reportMigration.Priority = #reportProcess.Priority
5676 and #reportMigration.Status = #reportProcess.Status
5677
5678 if(@includePriority=1)
5679 select Priority = case when (Grouping(Priority) = 1) then 'All' else cast(Priority as varchar(4)) end,
5680 Status = case
5681 when (GROUPING(Status) = 1) then '-------------------'
5682 else Status
5683 end,
5684 [Files] = sum(Files),
5685 Documents = sum(Documents),
5686 Pages = sum(Pages),
5687 [PercentFiles] = cast(sum(round((CAST(Files as float) / @totalFiles) * 100.0,2)) as varchar) + '%',
5688 [PercentDocs] = cast(sum(round((CAST(Documents as float) / @totalDocs) * 100.0,4)) as varchar) + '%',
5689 [PercentPages] = cast(sum(round((CAST(Pages as float) / @totalPages) * 100.0,4)) as varchar) + '%'
5690 from #report
5691 group by Priority, Status with rollup
5692 else
5693 select Status = case
5694 when (GROUPING(Status) = 1) then 'All'
5695 else cast(Status as varchar(50))
5696 end,
5697 [Files] = sum(Files),
5698 Documents = sum(Documents),
5699 Pages = sum(Pages),
5700 [PercentFiles] = cast(sum(round((CAST(Files as float) / @totalFiles) * 100.0,2)) as varchar) + '%',
5701 [PercentDocs] = cast(sum(round((CAST(Documents as float) / @totalDocs) * 100.0,4)) as varchar) + '%',
5702 [PercentPages] = cast(sum(round((CAST(Pages as float) / @totalPages) * 100.0,4)) as varchar) + '%'
5703 from #report
5704 group by Status with rollup
5705
5706
5707
5708
5709end
5710
5711
5712GO
5713/****** Object: StoredProcedure [dbo].[reprocessFileErrors] Script Date: 21/11/2016 12:32:21 ******/
5714SET ANSI_NULLS ON
5715GO
5716SET QUOTED_IDENTIFIER ON
5717GO
5718CREATE procedure [dbo].[reprocessFileErrors]
5719 @errortype varchar(1000),
5720 @DocumentID varchar(100) = null,
5721 @processAttributesOverride bit = null, -- If this is null, the key\value from ConfigMigration will be used to determine the @processAttributes param value when calling exec process;
5722 @debug bit = 0
5723as
5724begin
5725 set nocount on
5726
5727 declare @logid int, @ProcName varchar(50)
5728 set @ProcName = Object_Name(@@PROCID)
5729 declare @errorparam varchar(50)
5730 set @errorparam = left(@errortype,50)
5731 exec logStart @procname, @system = null, @param1 = @errorparam, @ID = @logid output
5732 Raiserror (' Reprocessing Errors of type: %s',10,1, @errortype) with nowait
5733
5734 declare @processAttributes bit = 1;
5735 if @processAttributesOverride is null
5736 select @processAttributes = case ConfigValue when 'TRUE' then 1 when 'FALSE' then 0 else -9 end
5737 from ConfigMigration
5738 where ConfigKey='process_ExecuteProcessAttributesProc';
5739 else set @processAttributes = @processAttributesOverride;
5740
5741 -- get the list of all the documents with errors of this type.
5742 SELECT LogID = LogProgress.ID,
5743 DocumentID = MigrationDocument.ID,
5744 FileID = MigrationDocument.FileID,
5745 System = MigrationDocument.System
5746 INTO #ErrorList
5747 FROM LogProgress INNER JOIN MigrationDocument
5748 ON MigrationDocument.ID = LogProgress.DocumentID
5749 WHERE MigrationDocument.Status = -1 AND LogProgress.success = 0 and errormessage like @errortype + '%'
5750 AND MigrationDocument.ID = isNull(@DocumentID,MigrationDocument.ID)
5751
5752 -- Move all the old errors to LogProgressHistory
5753 insert into LogProgressHistory
5754 select getDate(), * from LogProgress
5755 where LogProgress.ID in (select LogID from #ErrorList)
5756
5757 delete from LogProgress where LogProgress.ID in (select LogID from #ErrorList)
5758
5759 -- Reset the errored documents back to loaded status so they can be reprocessed.
5760 update MigrationDocument
5761 set status = -2
5762 from #ErrorList
5763 where MigrationDocument.ID = #ErrorList.DocumentID
5764
5765 -- Reset the IRDrawer to null so that we can verify if they are mapped correctly later.
5766 update MigrationPage
5767 set IRDrawer = null
5768 from #ErrorList
5769 where MigrationPage.DocumentID = #ErrorList.DocumentID
5770
5771 declare @system varchar(50)
5772
5773 -- Now go through each distinct file and process them. We do NOT change the status of the file
5774 -- since we might still be processing the initial load and don't want that process to pick these up.
5775 declare @fileid varchar(100), @fileLogID int, @filecount int, @doccount int
5776 set @filecount = 0
5777 select @doccount = count(distinct DocumentID) from #ErrorList
5778 declare fileCursor cursor local static for
5779 select distinct fileid, System from #ErrorList
5780 open fileCursor
5781 fetch from fileCursor into @fileid, @system
5782 while @@fetch_status = 0
5783 begin
5784 exec logStart @procname, @system = @system, @param1 = @fileid, @param2 = @errorparam, @ID = @fileLogID output
5785 Raiserror (' Reprocessing Errors of type: %s',10,1, @errortype) with nowait
5786 exec processPages @fileid = @fileid, @debug = @debug--, @processAttributes = @processAttributes,
5787 exec processTasks @fileid = @fileid, @debug = @debug
5788 exec processDocuments @fileid = @fileid, @debug = @debug
5789 exec logEnd @fileLogID
5790 set @filecount = @filecount + 1
5791 fetch from fileCursor into @fileid, @system
5792 end
5793 close fileCursor
5794 deallocate fileCursor
5795
5796 Raiserror (' ********** Completed Reprocessing Errors! ',10,1) with nowait
5797 Raiserror (' Total Number of Files: %d',10,1, @filecount) with nowait
5798 Raiserror (' Total Number of Documents: %d',10,1, @doccount) with nowait
5799 exec logEnd @logid
5800end
5801
5802
5803GO
5804/****** Object: StoredProcedure [dbo].[restoreSnapshot] Script Date: 21/11/2016 12:32:21 ******/
5805SET ANSI_NULLS ON
5806GO
5807SET QUOTED_IDENTIFIER ON
5808GO
5809create procedure [dbo].[restoreSnapshot]
5810 @system varchar(50)
5811as
5812begin
5813 if not exists(select * from sys.tables where name like 'z' + @system + '_Snapshot%')
5814 begin
5815 Raiserror('No such Archived Snapshot exists!',16,1)
5816 return
5817 end
5818
5819 if exists(select * from sys.tables where name like 'Snapshot%')
5820 begin
5821 Raiserror('There is already an active Snapshot',16,1)
5822 return
5823 end
5824
5825 declare @archiveName varchar(100)
5826 declare @tablename varchar(100)
5827 declare aCursor cursor local static for
5828 select name from sys.tables where name like 'z' + @system + '_Snapshot%'
5829 open aCursor
5830 fetch from aCursor into @archivename
5831 while (@@FETCH_STATUS = 0)
5832 begin
5833 set @tablename = right(@archivename,len(@archivename)-len(@system)-2)
5834 exec sp_rename @archivename, @tableName
5835 fetch from aCursor into @archivename
5836 end
5837 close aCursor
5838 deallocate aCursor
5839
5840end
5841
5842GO
5843/****** Object: StoredProcedure [dbo].[resubmitDocumentErrors] Script Date: 21/11/2016 12:32:21 ******/
5844SET ANSI_NULLS ON
5845GO
5846SET QUOTED_IDENTIFIER ON
5847GO
5848create procedure [dbo].[resubmitDocumentErrors]
5849 @errortype varchar(1000),
5850 @documentID varchar(100)=null
5851as
5852begin
5853 create table #docs(DocumentID varchar(100));
5854 if @documentID is not null
5855 insert #docs(DocumentID)
5856 select DocumentID --into #docs
5857 from LogProgress where success = 0 and errormessage like @errortype + '%' and DocumentID=@documentid
5858 else
5859 insert #docs(DocumentID)
5860 select DocumentID --into #docs
5861 from LogProgress where success = 0 and errormessage like @errortype + '%'
5862
5863 delete from LogProgress where DocumentID in (select DocumentID from #docs)
5864
5865 update MigrationDocument set status = 0 where ID in (select DocumentID from #docs)
5866end
5867
5868GO
5869/****** Object: StoredProcedure [dbo].[showVersion] Script Date: 21/11/2016 12:32:21 ******/
5870SET ANSI_NULLS ON
5871GO
5872SET QUOTED_IDENTIFIER ON
5873GO
5874 Create Procedure [dbo].[showVersion]
5875 as
5876 begin
5877 raiserror('Current Icon Script Build is Version: 2.4.04',10,1)
5878 select Version = '2.4.04'
5879 end
5880
5881GO
5882/****** Object: StoredProcedure [dbo].[takeDestStructureSnapshot] Script Date: 21/11/2016 12:32:21 ******/
5883SET ANSI_NULLS ON
5884GO
5885SET QUOTED_IDENTIFIER ON
5886GO
5887CREATE procedure [dbo].[takeDestStructureSnapshot]
5888 @database varchar(50),
5889 @linkedServer varchar(50) = null,
5890 @oracle bit = 0,
5891 @debug bit = 0,
5892 @execute bit = 1
5893 /* This procedure will be a work in progress and should allow verification of the current mapping
5894 against the current destination database. Currently, only the verification for PageMarks are implemented
5895 */
5896 as
5897 begin
5898 declare @logid int, @ProcName varchar(50)
5899 set @ProcName = Object_Name(@@PROCID)
5900 exec logStart @procname, null, @ID = @logid output
5901
5902 declare @sql varchar(5000)
5903 declare @table varchar(50)
5904 declare @debugMessage varchar(5000)
5905
5906 if (@oracle = 0)
5907 set @database = @database + '.dbo'
5908
5909
5910 set @table = 'DestStructureSnapshotObjectType'
5911 RAISERROR (' Taking New %s', 10, 1,@table) WITH NOWAIT;
5912 set @sql = '
5913 select typeid as typeid,
5914 classid as typeClassID,
5915 name as typeName,
5916 description as typeDescription,
5917 lastmodified as typeLastModified,
5918 programmaticname as typeProgrammaticName
5919 from ' + @database + '.ObjectType WITH (NOLOCK)'
5920
5921 if (@linkedServer is not null)
5922 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
5923 ' from openquery(' + @linkedServer + ', ''' + @sql + ''') as T'
5924 else
5925 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
5926 ' from (' + @sql + ') as T'
5927
5928 if (@debug>0)
5929 begin
5930 set @debugMessage = 'DEBUG: Prepared statement for table %s'+CHAR(13) + CHAR(10)+ '%s'
5931 raiserror(@debugMessage,0,1,@table,@sql)
5932 end
5933 if (@execute=1)
5934 begin
5935 if exists(select * from information_schema.tables where table_name=@table)
5936 exec (N'drop table '+@table)
5937 exec (@sql)
5938 end
5939
5940 set @table = 'DestStructureSnapshotAttributeDef'
5941 RAISERROR (' Taking New %s', 10, 1,@table) WITH NOWAIT;
5942 set @sql = '
5943 select attributeid as attributeid,
5944 name as attrName,
5945 type as attrType,
5946 description as attrDescription,
5947 displayname as attrDisplayname
5948 from ' + @database + '.AttributeDef WITH (NOLOCK)'
5949
5950 if (@linkedServer is not null)
5951 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
5952 ' from openquery(' + @linkedServer + ', ''' + @sql + ''') as T'
5953 else
5954 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
5955 ' from (' + @sql + ') as T'
5956
5957 if (@debug>0)
5958 begin
5959 set @debugMessage = 'DEBUG: Prepared statement for table %s'+CHAR(13) + CHAR(10)+ '%s'
5960 raiserror(@debugMessage,0,1,@table,@sql)
5961 end
5962 if (@execute=1)
5963 begin
5964 if exists(select * from information_schema.tables where table_name=@table)
5965 exec (N'drop table '+@table)
5966 exec (@sql)
5967 end
5968
5969 set @table = 'DestStructureSnapshotObjectAttributeRules'
5970 RAISERROR (' Taking New %s', 10, 1,@table) WITH NOWAIT;
5971 set @sql = '
5972 select ObjectType.typeid as typeid,
5973 ObjectType.classid as typeClassID,
5974 ObjectType.name as TypeName,
5975 AttributeDef.attributeid as attributeid,
5976 AttributeDef.description as attrDescription,
5977 AttributeDef.displayname as attrDisplayname
5978 from ' + @database + '.ObjectAttributeRules WITH (NOLOCK)
5979 join ' + @database + '.ObjectType WITH (NOLOCK) on ObjectAttributeRules.typeid=ObjectType.typeid
5980 join ' + @database + '.AttributeDef WITH (NOLOCK) on ObjectAttributeRules.attributeid=AttributeDef.attributeid'
5981
5982 if (@linkedServer is not null)
5983 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
5984 ' from openquery(' + @linkedServer + ', ''' + @sql + ''') as T'
5985 else
5986 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
5987 ' from (' + @sql + ') as T'
5988
5989 if (@debug>0)
5990 begin
5991 set @debugMessage = 'DEBUG: Prepared statement for table %s'+CHAR(13) + CHAR(10)+ '%s'
5992 raiserror(@debugMessage,0,1,@table,@sql)
5993 end
5994 if (@execute=1)
5995 begin
5996 if exists(select * from information_schema.tables where table_name=@table)
5997 exec (N'drop table '+@table)
5998 exec (@sql)
5999 end
6000
6001 set @table = 'DestStructureSnapshotWorkFlow'
6002 RAISERROR (' Taking New %s', 10, 1,@table) WITH NOWAIT;
6003 set @sql = '
6004 select FlowDef.flowid,
6005 FlowDef.flowname,
6006 FlowDef.flowalias as FlowProgName,
6007 StepRootDef.steprootid,
6008 StepRootDef.stepname,
6009 StepRootDef.stepalias as StepProgName
6010 from ' + @database + '.FlowDef WITH (NOLOCK)
6011 join ' + @database + '.StepRootDef
6012 on FlowDef.flowid=StepRootDef.flowid'
6013
6014 if (@linkedServer is not null)
6015 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6016 ' from openquery(' + @linkedServer + ', ''' + @sql + ''') as T'
6017 else
6018 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6019 ' from (' + @sql + ') as T'
6020
6021 if (@debug>0)
6022 begin
6023 set @debugMessage = 'DEBUG: Prepared statement for table %s'+CHAR(13) + CHAR(10)+ '%s'
6024 raiserror(@debugMessage,0,1,@table,@sql)
6025 end
6026 if (@execute=1)
6027 begin
6028 if exists(select * from information_schema.tables where table_name=@table)
6029 exec (N'drop table '+@table)
6030 exec (@sql)
6031 end
6032
6033 set @table = 'DestStructureSnapshotMarkAllow'
6034 RAISERROR (' Taking New %s', 10, 1,@table) WITH NOWAIT;
6035 set @sql = '
6036 select ''''page'''' as markType,
6037 PageMarkDef.pagemarkid as pageMarkID,
6038 PageMarkDef.description as pageMarkDescription,
6039 PageMarkDef.programmaticname as pageMarkProgName,
6040 ObjectType.typeid as typeid,
6041 ObjectType.name as typeName,
6042 ObjectType.classid as typeClassid,
6043 ObjectType.programmaticname as typeProgName
6044 from ' + @database + '.PageMarkAllow with(nolock)
6045 join ' + @database + '.PageMarkDef with(nolock) on PageMarkAllow.pagemarkid=PageMarkDef.pagemarkid
6046 join ' + @database + '.ObjectType with(nolock) on PageMarkAllow.typeid=ObjectType.typeid
6047 union all
6048 select ''''file'''' as markType,
6049 FileMarkDef.filemarkid as fileMarkID,
6050 FileMarkDef.description as fileMarkDescription,
6051 FileMarkDef.programmaticname as fileMarkProgName,
6052 ObjectType.typeid as typeid,
6053 ObjectType.name as typeName,
6054 ObjectType.classid as typeClassid,
6055 ObjectType.programmaticname as typeProgName
6056 from ' + @database + '.FileMarkAllow with(nolock)
6057 join ' + @database + '.FileMarkDef with(nolock) on FileMarkAllow.filemarkid=FileMarkDef.filemarkid
6058 join ' + @database + '.ObjectType with(nolock) on FileMarkAllow.typeid=ObjectType.typeid'
6059
6060 if (@linkedServer is not null)
6061 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6062 ' from openquery(' + @linkedServer + ', ''' + @sql + ''') as T'
6063 else
6064 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6065 ' from (' + @sql + ') as T'
6066
6067 if (@debug>0)
6068 begin
6069 set @debugMessage = 'DEBUG: Prepared statement for table %s'+CHAR(13) + CHAR(10)+ '%s'
6070 raiserror(@debugMessage,0,1,@table,@sql)
6071 end
6072 if (@execute=1)
6073 begin
6074 if exists(select * from information_schema.tables where table_name=@table)
6075 exec (N'drop table '+@table)
6076 exec (@sql)
6077 end
6078
6079 set @table = 'DestStructureSnapshotMarkDef'
6080 RAISERROR (' Taking New %s', 10, 1,@table) WITH NOWAIT;
6081 set @sql = '
6082 select ''''page'''' as markType,
6083 PageMarkDef.pagemarkid as MarkID,
6084 PageMarkDef.description as MarkDescription,
6085 PageMarkDef.color as MarkColor,
6086 PageMarkDef.programmaticname as MarkProgrammaticName
6087 from ' + @database + '.PageMarkDef with(nolock)
6088 union all
6089 select ''''file'''' as markType,
6090 FileMarkDef.filemarkid as MarkID,
6091 FileMarkDef.description as MarkDescription,
6092 FileMarkDef.color as MarkColor,
6093 FileMarkDef.programmaticname as MarkProgrammaticName
6094 from ' + @database + '.FileMarkDef with(nolock)'
6095
6096 if (@linkedServer is not null)
6097 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6098 ' from openquery(' + @linkedServer + ', ''' + @sql + ''') as T'
6099 else
6100 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6101 ' from (' + @sql + ') as T'
6102
6103 if (@debug>0)
6104 begin
6105 set @debugMessage = 'DEBUG: Prepared statement for table %s'+CHAR(13) + CHAR(10)+ '%s'
6106 raiserror(@debugMessage,0,1,@table,@sql)
6107 end
6108 if (@execute=1)
6109 begin
6110 if exists(select * from information_schema.tables where table_name=@table)
6111 exec (N'drop table '+@table)
6112 exec (@sql)
6113 end
6114
6115 set @table = 'DestStructureSnapshotSecurityAccount'
6116 RAISERROR (' Taking New %s', 10, 1,@table) WITH NOWAIT;
6117 set @sql = '
6118 select accountid,
6119 externalid,
6120 name,
6121 description,
6122 accounttype,
6123 disabled
6124 from ' + @database + '.SecurityAccount with(nolock)'
6125
6126 if (@linkedServer is not null)
6127 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6128 ' from openquery(' + @linkedServer + ', ''' + @sql + ''') as T'
6129 else
6130 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6131 ' from (' + @sql + ') as T'
6132
6133 if (@debug>0)
6134 begin
6135 set @debugMessage = 'DEBUG: Prepared statement for table %s'+CHAR(13) + CHAR(10)+ '%s'
6136 raiserror(@debugMessage,0,1,@table,@sql)
6137 end
6138 if (@execute=1)
6139 begin
6140 if exists(select * from information_schema.tables where table_name=@table)
6141 exec (N'drop table '+@table)
6142 exec (@sql)
6143 end
6144
6145 set @table = 'DestStructureSnapshotTypeRules' -- What file types are allowed in drawers
6146 RAISERROR (' Taking New %s', 10, 1,@table) WITH NOWAIT;
6147 set @sql = '
6148 select TypeRules.parenttypeid as parentTypeID,
6149 ParentType.classid as ParentClassid,
6150 ParentType.name as ParentName,
6151 ParentType.description as ParentDescription,
6152 TypeRules.childtypeid as childTypeID,
6153 ChildType.classid as ChildClassid,
6154 ChildType.name as ChildName,
6155 ChildType.description as ChildDescription
6156 from ' + @database + '.TypeRules with(nolock)
6157 join ' + @database + '.ObjectType as ParentType with(nolock) on TypeRules.parenttypeid=ParentType.typeid
6158 join ' + @database + '.ObjectType as ChildType with(nolock) on TypeRules.childtypeid=ChildType.typeid'
6159
6160 if (@linkedServer is not null)
6161 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6162 ' from openquery(' + @linkedServer + ', ''' + @sql + ''') as T'
6163 else
6164 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6165 ' from (' + @sql + ') as T'
6166
6167 if (@debug>0)
6168 begin
6169 set @debugMessage = 'DEBUG: Prepared statement for table %s'+CHAR(13) + CHAR(10)+ '%s'
6170 raiserror(@debugMessage,0,1,@table,@sql)
6171 end
6172 if (@execute=1)
6173 begin
6174 if exists(select * from information_schema.tables where table_name=@table)
6175 exec (N'drop table '+@table)
6176 exec (@sql)
6177 end
6178
6179 set @table = 'DestStructureSnapshotLocations'
6180 RAISERROR (' Taking New %s', 10, 1,@table) WITH NOWAIT;
6181 set @sql = '
6182 select Locations.locationid,
6183 Locations.parentid,
6184 Locations.name as locationName,
6185 ObjectType.typeid as locationTypeID,
6186 ObjectType.classid as typeClassID,
6187 ObjectType.name as typeName,
6188 ObjectType.programmaticName as typeProgName
6189 from ' + @database + '.Locations
6190 join ' + @database + '.ObjectLink on Locations.locationid=ObjectLink.objectid
6191 join ' + @database + '.ObjectType on ObjectLink.typeid=ObjectType.typeid'
6192
6193 if (@linkedServer is not null)
6194 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6195 ' from openquery(' + @linkedServer + ', ''' + @sql + ''') as T'
6196 else
6197 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6198 ' from (' + @sql + ') as T'
6199
6200 if (@debug>0)
6201 begin
6202 set @debugMessage = 'DEBUG: Prepared statement for table %s'+CHAR(13) + CHAR(10)+ '%s'
6203 raiserror(@debugMessage,0,1,@table,@sql)
6204 end
6205 if (@execute=1)
6206 begin
6207 if exists(select * from information_schema.tables where table_name=@table)
6208 exec (N'drop table '+@table)
6209 exec (@sql)
6210 end
6211
6212 RAISERROR ('..Complete', 10, 1) WITH NOWAIT
6213 exec logEnd @logid
6214 end
6215
6216GO
6217/****** Object: StoredProcedure [dbo].[takeSnapshot] Script Date: 21/11/2016 12:32:21 ******/
6218SET ANSI_NULLS ON
6219GO
6220SET QUOTED_IDENTIFIER ON
6221GO
6222create procedure [dbo].[takeSnapshot]
6223 @database varchar(100),
6224 @linkedServer varchar(100) = null,
6225 @oracle bit = 0
6226as
6227begin
6228 declare @logid int, @ProcName varchar(50)
6229 set @ProcName = Object_Name(@@PROCID)
6230 exec logStart @procname, null, @ID = @logid output
6231
6232 declare @sql varchar(5000)
6233 declare @table varchar(50)
6234
6235 set nocount on;
6236 declare @current_col nvarchar(130); -- Max identifier length in SQL Server plus 2 char for identifier delimiters
6237 declare @pivot_column_string nvarchar(MAX);
6238 set @pivot_column_string='' -- Initialize the value to non-null for string concetenation. Keep this separate from the declare due to SQL 2005 not allowing default values on local variables.
6239
6240 -- Exit if snapshot already exists
6241 if object_id('SnapshotFile') is not null
6242 begin
6243 Raiserror('SnapShot already Exists... You must drop or archive the current snapshot first',16,1)
6244 return
6245 end
6246
6247 if (@oracle = 0)
6248 set @database = @database + '.dbo'
6249
6250 RAISERROR (' Taking New File Snapshot', 10, 1) WITH NOWAIT
6251 set @table = 'SnapshotFile'
6252 set @sql='select
6253 FILENUMBER,
6254 FILENAME,
6255 LOCATIONID,
6256 FILEID,
6257 FILES.LASTMODIFIED,
6258 CREATED,
6259 DATELASTOPENED,
6260 ISTEMPORARY,
6261 ISDELETED,
6262 OBJECTTYPE.NAME as FILETYPE,
6263 OBJECTTYPE.DESCRIPTION as FILETYPEDESC
6264 from '+@database+'.FILES with(nolock)
6265 join '+@database+'.OBJECTLINK with(nolock)
6266 ON FILES.FILEID = OBJECTLINK.OBJECTID
6267 JOIN ' + @database + '.OBJECTTYPE
6268 ON OBJECTLINK.TYPEID = OBJECTTYPE.TYPEID';
6269
6270 if (@linkedServer is not null)
6271 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6272 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6273 else
6274 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6275 ' from (' + @sql + ') as T'
6276
6277 exec (@sql)
6278
6279 RAISERROR (' Taking New Location Snapshot', 10, 1) WITH NOWAIT
6280 set @table = 'SnapshotLocation'
6281 set @sql='SELECT
6282 LOCATIONID,
6283 PARENTID,
6284 LOCATIONS.NAME,
6285 LOCATIONS.DESCRIPTION,
6286 OBJECTTYPE.NAME AS LOCATIONTYPE,
6287 OBJECTTYPE.DESCRIPTION as LOCATIONTYPEDESC
6288 from '+@database+'.LOCATIONS with(nolock)
6289 join '+@database+'.OBJECTLINK with(nolock)
6290 on LOCATIONS.LOCATIONID = OBJECTLINK.OBJECTID
6291 JOIN ' + @database + '.OBJECTTYPE
6292 ON OBJECTLINK.TYPEID = OBJECTTYPE.TYPEID' ;
6293
6294 if (@linkedServer is not null)
6295 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6296 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6297 else
6298 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6299 ' from (' + @sql + ') as T'
6300
6301 exec (@sql)
6302
6303 /* It is pretty important that the description be NULL if it matches
6304 the folder type name or is empty since it is used to build the path
6305 efficiently when the pages are loaded (loadPages) */
6306 RAISERROR (' Taking New Folder Snapshot', 10, 1) WITH NOWAIT
6307 set @table = 'SnapshotFolder'
6308 set @sql='SELECT
6309 DOCFOLDERID AS FOLDERID,
6310 PARENTID,
6311 CASE
6312 WHEN len(DOCFOLDER.DESCRIPTION) = 0 THEN NULL
6313 WHEN DOCFOLDER.DESCRIPTION = OBJECTTYPE.NAME THEN NULL
6314 ELSE DOCFOLDER.DESCRIPTION
6315 END as DESCRIPTION,
6316 DOCFOLDER.LASTMODIFIED,
6317 FILEID,
6318 CREATED,
6319 ISDELETED,
6320 OBJECTTYPE.NAME AS FOLDERTYPE,
6321 OBJECTTYPE.DESCRIPTION as FOLDERTYPEDESC
6322 FROM ' + @database + '.DOCFOLDER WITH(NOLOCK)
6323 JOIN ' + @database + '.OBJECTLINK WITH(NOLOCK)
6324 ON DOCFOLDER.DOCFOLDERID = OBJECTLINK.OBJECTID
6325 JOIN ' + @database + '.OBJECTTYPE
6326 ON OBJECTLINK.TYPEID = OBJECTTYPE.TYPEID
6327 WHERE OBJECTTYPE.CLASSID = -2';
6328
6329 if (@linkedServer is not null)
6330 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6331 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6332 else
6333 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6334 ' from (' + @sql + ') as T'
6335
6336 exec (@sql)
6337
6338 RAISERROR (' Taking New Document Snapshot', 10, 1) WITH NOWAIT
6339 set @table = 'SnapshotDocument'
6340 set @sql='SELECT
6341 DOCFOLDER.DOCFOLDERID as DOCUMENTID,
6342 FOLDERID = PARENTID,
6343 DOCFOLDER.DESCRIPTION,
6344 DOCFOLDER.LASTMODIFIED,
6345 FILEID,
6346 CREATED,
6347 ISDELETED,
6348 DOCUMENT.DOCUMENTDATE,
6349 DOCUMENT.RECEIVEDDATE,
6350 OBJECTTYPE.NAME as DOCTYPE,
6351 OBJECTTYPE.DESCRIPTION as DOCTYPEDESC
6352 FROM ' + @database + '.DOCFOLDER WITH(NOLOCK)
6353 JOIN ' + @database + '.DOCUMENT WITH(NOLOCK)
6354 ON DOCFOLDER.DOCFOLDERID = DOCUMENT.DOCFOLDERID
6355 JOIN ' + @database + '.OBJECTLINK WITH(NOLOCK)
6356 ON DOCFOLDER.DOCFOLDERID = OBJECTLINK.OBJECTID
6357 JOIN ' + @database + '.OBJECTTYPE
6358 ON OBJECTLINK.TYPEID = OBJECTTYPE.TYPEID
6359 WHERE OBJECTTYPE.CLASSID = -1';
6360
6361 if (@linkedServer is not null)
6362 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6363 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6364 else
6365 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6366 ' from (' + @sql + ') as T'
6367
6368 exec (@sql)
6369
6370 RAISERROR (' Taking New Page Snapshot', 10, 1) WITH NOWAIT
6371 set @table = 'SnapshotPage'
6372 set @sql='SELECT
6373 PAGES.PAGEID,
6374 PAGES.DESCRIPTION,
6375 PAGENUMBER,
6376 IMAGESETID,
6377 LASTMODIFIED,
6378 CREATED,
6379 DOCUMENTID,
6380 ISDELETED,
6381 PAGEMARKDEF.PROGRAMMATICNAME as PAGEMARK,
6382 PAGEMARKDEF.DESCRIPTION as PAGEMARKDESC
6383 FROM ' + @database + '.PAGES WITH(NOLOCK)
6384 LEFT JOIN ' + @database + '.PAGEMARK WITH(NOLOCK) on PAGEMARK.PAGEID = PAGES.PAGEID
6385 LEFT JOIN ' + @database + '.PAGEMARKDEF WITH(NOLOCK) on PAGEMARK.PAGEMARKID = PAGEMARKDEF.PAGEMARKID';
6386
6387 if (@linkedServer is not null)
6388 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6389 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6390 else
6391 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6392 ' from (' + @sql + ') as T'
6393
6394 exec (@sql)
6395
6396 RAISERROR (' Taking New Image Snapshot', 10, 1) WITH NOWAIT
6397 set @table = 'SnapshotImage'
6398 set @sql='SELECT
6399 IMS.IMAGESETID AS IMAGESETID,
6400 IV.IMAGEID AS IMAGEID,
6401 IV.IMAGEVERSION AS IMAGEVERSION,
6402 IV.CRITICAL AS CRITICAL,
6403 IV.PATHDATE AS PATHDATE,
6404 IV.DIVISIONNUMBER AS DIVISIONNUMBER,
6405 IV.ROTATION AS ORIENTATION,
6406 I.EXT AS IMAGEEXT,
6407 I.TYPE AS IMAGETYPE,
6408 PL.PLATTERID AS PLATTERID,
6409 PL.NEARLINEDEVICE AS PLATTERNEARLINEDEVICEID,
6410 IV.NEARLINEDEVICE AS IMAGEVERSIONNEARLINEDEVICEID,
6411 IV.ONLINEDEVICE AS IMAGEVERSIONONLINEDEVICEID
6412 FROM ' + @database + '.IMAGESET IMS WITH(NOLOCK)
6413 JOIN ' + @database + '.IMAGESETVERSIONDATA ISVD WITH(NOLOCK) ON ISVD.IMAGESETID = IMS.IMAGESETID AND IMS.CURRENTVERSION = ISVD.IMAGESETVERSION
6414 JOIN ' + @database + '.IMAGEVERSION IV WITH(NOLOCK) ON ISVD.IMAGEID = IV.IMAGEID AND IV.IMAGEVERSION = ISVD.IMAGEVERSION
6415 JOIN ' + @database + '.IMAGE I WITH(NOLOCK) ON I.IMAGEID = IV.IMAGEID
6416 LEFT JOIN ' + @database + '.BURNHISTORY BH WITH(NOLOCK) ON IV.IMAGEID = BH.IMAGEID AND IV.IMAGEVERSION = BH.IMAGEVERSION
6417 LEFT JOIN ' + @database + '.PLATTER PL WITH(NOLOCK) ON PL.PLATTERID = BH.PLATTERID'
6418
6419
6420 if (@linkedServer is not null)
6421 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6422 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6423 else
6424 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6425 ' from (' + @sql + ') as T'
6426
6427 exec (@sql)
6428
6429 if(select ConfigValue from ConfigMigration where ConfigKey='TakeSnapshot_GernerateSnapshotBatches')='TRUE'
6430 begin
6431 RAISERROR (' Taking New Batches Snapshot', 10, 1) WITH NOWAIT
6432 set @table = 'SnapshotBatches'
6433 set @sql='
6434 select
6435 Pages.documentid,
6436 Pages.pageid,
6437 ImageSet.imagesetid,
6438 Batches.batchid,
6439 Batches.accountid,
6440 SecurityAccount.name as CreatedBy,
6441 Batches.programid,
6442 IRPrograms.programname
6443 from ' + @database + '.Pages
6444 join ' + @database + '.ImageSet on Pages.imagesetid=ImageSet.imagesetid
6445 join ' + @database + '.Batches on ImageSet.batchid=Batches.batchid
6446 join ' + @database + '.IRPrograms on Batches.programid=IRPrograms.programid
6447 join ' + @database + '.SecurityAccount on Batches.accountid=SecurityAccount.accountid'
6448
6449 if (@linkedServer is not null)
6450 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6451 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6452 else
6453 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6454 ' from (' + @sql + ') as T'
6455
6456 exec (@sql)
6457 end -- /TakeSnapshot_GernerateSnapshotBatches
6458
6459 RAISERROR (' Taking New Device Snapshot', 10, 1) WITH NOWAIT
6460 set @table = 'SnapshotDevice'
6461 set @sql='SELECT * FROM ' + @database + '.DEVICE WITH(NOLOCK)'
6462
6463 if (@linkedServer is not null)
6464 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6465 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6466 else
6467 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6468 ' from (' + @sql + ') as T'
6469
6470 exec (@sql)
6471
6472 RAISERROR (' Taking New Task Snapshot', 10, 1) WITH NOWAIT
6473 set @table = 'SnapshotTask'
6474 set @sql='SELECT TASKID,
6475 TASK.FILEID,
6476 CASE
6477 WHEN TASK.NOTEID IS NOT NULL THEN ''Note''
6478 WHEN OBJECTTYPE.CLASSID = -1 AND PAGENUMBER IS NOT NULL THEN ''Page''
6479 WHEN OBJECTTYPE.CLASSID = -1 THEN ''Document''
6480 WHEN OBJECTTYPE.CLASSID = -2 THEN ''Folder''
6481 WHEN OBJECTTYPE.CLASSID = -3 THEN ''File''
6482 END AS ATTACHEDTO,
6483 FLOWDEF.FLOWNAME,
6484 FLOWDEF.DESCRIPTION as FLOWDESC,
6485 STEPROOTDEF.STEPNAME,
6486 STEPROOTDEF.DESCRIPTION as STEPDESC,
6487 SECURITYACCOUNT.NAME AS ASSIGNEDTO,
6488 TASK.OBJECTID,
6489 PAGENUMBER AS PAGEID,
6490 NOTEID,
6491 TASK.PRIORITY,
6492 TASK.STATUS,
6493 TASK.DESCRIPTION,
6494 DATEAVAILABLE
6495 FROM ' + @database + '.TASK WITH(NOLOCK)
6496 INNER JOIN ' + @database + '.OBJECTLINK WITH(NOLOCK) ON OBJECTLINK.OBJECTID = TASK.OBJECTID
6497 INNER JOIN ' + @database + '.OBJECTTYPE WITH(NOLOCK) ON OBJECTLINK.TYPEID = OBJECTTYPE.TYPEID
6498 INNER JOIN ' + @database + '.STEPROOTDEF WITH(NOLOCK) ON TASK.STEPID = STEPROOTDEF.STEPROOTID
6499 INNER JOIN ' + @database + '.FLOWDEF WITH(NOLOCK) ON STEPROOTDEF.FLOWID = FLOWDEF.FLOWID
6500 LEFT JOIN ' + @database + '.SECURITYACCOUNT WITH(NOLOCK) ON TASK.ASSIGNEDTO = SECURITYACCOUNT.ACCOUNTID'
6501
6502 if (@linkedServer is not null)
6503 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6504 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6505 else
6506 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6507 ' from (' + @sql + ') as T'
6508
6509 exec (@sql)
6510
6511 RAISERROR (' Taking New Note Snapshot', 10, 1) WITH NOWAIT
6512 set @table = 'SnapshotNote'
6513 set @sql='SELECT OBJECTNOTES.NOTEID,
6514 OBJECTNOTES.OBJECTID,
6515 OBJECTNOTES.ISDELETED,
6516 OBJECTNOTESDETAIL.HIDDEN,
6517 OBJECTNOTES.NOTETYPEID,
6518 OBJECTNOTES.DEFAULTNOTE,
6519 OBJECTNOTESDETAIL.IMAGESETID
6520 FROM '+ @database +'.OBJECTNOTES WITH(NOLOCK)
6521 JOIN '+ @database +'.OBJECTNOTESDETAIL WITH(NOLOCK)
6522 ON OBJECTNOTES.NOTEID = OBJECTNOTESDETAIL.NOTEID'
6523
6524 if (@linkedServer is not null)
6525 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6526 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6527 else
6528 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6529 ' from (' + @sql + ') as T'
6530
6531 exec (@sql)
6532
6533 RAISERROR (' Taking New Security Snapshot', 10, 1) WITH NOWAIT
6534 set @table = 'SnapshotSecurity'
6535 set @sql='SELECT ACCOUNTID,
6536 EXTERNALID,
6537 NAME,
6538 DESCRIPTION,
6539 ACCOUNTTYPE
6540 FROM '+ @database +'.SECURITYACCOUNT WITH(NOLOCK)';
6541
6542 if (@linkedServer is not null)
6543 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6544 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6545 else
6546 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6547 ' from (' + @sql + ') as T'
6548
6549 exec (@sql)
6550
6551 RAISERROR (' Taking New Attribute Snapshot', 10, 1) WITH NOWAIT
6552 set @table = 'SnapshotAttribute'
6553 set @sql='SELECT
6554 OBJECTLINK.OBJECTID,
6555 OBJECTNAME = OBJECTTYPE.NAME,
6556 OBJECTTYPE =
6557 CASE OBJECTTYPE.CLASSID
6558 WHEN -1 THEN ''Document''
6559 WHEN -2 THEN ''Folder''
6560 WHEN -3 THEN ''File''
6561 END,
6562 ATTRIBUTEVAL.ATTRIBUTEID,
6563 ATTRIBUTENAME = ATTRIBUTEDEF.NAME,
6564 ATTRIBUTEVALUE = ATTRIBUTEVAL.CHARVALUE
6565 FROM ' + @database + '.OBJECTLINK WITH(NOLOCK)
6566 INNER JOIN ' + @database + '.OBJECTTYPE WITH(NOLOCK) ON OBJECTLINK.TYPEID = OBJECTTYPE.TYPEID
6567 INNER JOIN (SELECT OBJECTID, ATTRIBUTEID, CHARVALUE FROM ' + @database + '.ATTRIBUTECHAR WITH(NOLOCK)
6568 UNION ALL
6569 SELECT OBJECTID, ATTRIBUTEID, CONVERT(VARCHAR(12),DATEVALUE,101) FROM ' + @database + '.ATTRIBUTEDATE WITH(NOLOCK)
6570 UNION ALL
6571 SELECT OBJECTID, ATTRIBUTEID, LTRIM(STR(FLOATVALUE,25,5)) FROM ' + @database + '.ATTRIBUTEFLOAT WITH(NOLOCK)
6572 UNION ALL
6573 SELECT OBJECTID, ATTRIBUTEID, CAST(ATTRIBUTEINT.INTVALUE AS VARCHAR) FROM ' + @database + '.ATTRIBUTEINT WITH(NOLOCK) ) ATTRIBUTEVAL
6574 ON OBJECTLINK.OBJECTID = ATTRIBUTEVAL.OBJECTID
6575 INNER JOIN ' + @database + '.ATTRIBUTEDEF WITH(NOLOCK) ON ATTRIBUTEDEF.ATTRIBUTEID = ATTRIBUTEVAL.ATTRIBUTEID
6576 WHERE OBJECTTYPE.CLASSID IN (-1,-2,-3)';
6577
6578 if (@linkedServer is not null)
6579 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6580 ' from openquery(' + @linkedServer + ', ''' + replace(@sql,'''','''''') + ''') as T'
6581 else
6582 set @sql = 'select SnapShot = getDate(), * into dbo.' + @table +
6583 ' from (' + @sql + ') as T'
6584
6585 exec (@sql)
6586
6587 RAISERROR ('..Complete', 10, 1) WITH NOWAIT
6588 exec logEnd @logid
6589end
6590GO
6591/****** Object: StoredProcedure [dbo].[validateMappingAgainstDestSnapshot] Script Date: 21/11/2016 12:32:21 ******/
6592SET ANSI_NULLS ON
6593GO
6594SET QUOTED_IDENTIFIER ON
6595GO
6596create procedure [dbo].[validateMappingAgainstDestSnapshot]
6597 @system varchar(50) = null,
6598 @database varchar(100) = null,
6599 @linkedServer varchar(100) = null
6600as
6601begin
6602 set nocount on;
6603 if @database is not null
6604 begin
6605 exec raiseMessage 'validateMappingAgainstDestSnapshot: Taking new DestStructureSnapshot'
6606 exec takeDestStructureSnapshot @database=@database, @linkedServer=@linkedServer
6607 end
6608 else
6609 exec raiseMessage 'validateMappingAgainstDestSnapshot: @database not spedificed. Bypassing takeDestStructureSnapshot'
6610
6611 select top 1 Snapshot as ShapshotDate from DestStructureSnapshotObjectType;
6612
6613 select 'Invalid Drawer' as Status,
6614 DestDrawer, COUNT(*) as Mappings
6615 from MapDocument
6616 where System=isnull(@system,System)
6617 and DestDrawer not in('Do Not Migrate','omit','delete')
6618 and DestDrawer not in(
6619 select locationName
6620 from DestStructureSnapshotLocations
6621 )
6622 group by DestDrawer;
6623
6624 select 'Invalid FileType' as Status,
6625 DestFileType, COUNT(*) as Mappings
6626 from MapDocument
6627 where System=isnull(@system,System)
6628 and DestFileType not in('Do Not Migrate','omit','delete')
6629 and DestFileType not in(
6630 select typeName
6631 from DestStructureSnapshotObjectType
6632 where typeClassID=-3
6633 )
6634 group by DestFileType;
6635
6636 ;with FolderTypes as(
6637 select distinct --DestFolderPath,
6638 case
6639 when DestFolderPath like '%\\%' then substring(DestFolderPath,1,charindex('\\',DestFolderPath,1)-1)
6640 else DestFolderPath
6641 end as CurrentNode,
6642 case
6643 when DestFolderPath like '%\\%' then substring(DestFolderPath,Charindex('\\',DestFolderPath,1)+2,10000)
6644 else null
6645 end as Remaining
6646 from MapDocument
6647 where System=isnull(@system,System)
6648 union all
6649 select CurrentNode, null as Remaining
6650 from FolderTypes
6651 where Remaining is not null
6652 ),
6653 MappedFolders as(
6654 select
6655 case
6656 when 0<charindex(';',CurrentNode)
6657 then SUBSTRING(CurrentNode,1,CHARINDEX(';',CurrentNode)-1)
6658 else CurrentNode
6659 end as FolderType
6660 from FolderTypes
6661 where CurrentNode not in('Do Not Migrate','omit','delete')
6662 )
6663 select 'Invalid FolderType' as Status,
6664 FolderType
6665 from MappedFolders
6666 where MappedFolders.FolderType not in(
6667 select typeName
6668 from DestStructureSnapshotObjectType
6669 where typeClassID=-2
6670 )
6671 group by FolderType;
6672
6673 select 'Invalid DocType' as Status,
6674 DestDocType
6675 from MapDocument
6676 where System=isnull(@system,System)
6677 and DestDocType not in('Do Not Migrate','omit','delete')
6678 and DestDocType not in(
6679 select typeName
6680 from DestStructureSnapshotObjectType
6681 where typeClassID=-1
6682 )
6683 group by DestDocType;
6684
6685 select 'Invalid Mark' as Status,
6686 DestMarkProgrammaticName
6687 from MapMark
6688 where System=isnull(@system,System)
6689 and DestMarkProgrammaticName not in('Do Not Migrate','{$OMIT}')
6690 and not exists(
6691 select *
6692 from DestStructureSnapshotMarkDef
6693 where MapMark.markType=DestStructureSnapshotMarkDef.MarkType
6694 and MapMark.DestMarkProgrammaticName=DestStructureSnapshotMarkDef.MarkProgrammaticName
6695 )
6696
6697 -- Show page marks that may not be allowed on the file type
6698 /* Note that this is a fuzzy logic scenario and CURRENTLY VERY EXPERIMENTAL. There is not any file type in
6699 the mark mapping, so there is not
6700 a definitive method to determine what file type a mark needs to be migrated to from the mapping alone. In
6701 order to do that, the processPageMarks must be executed first and the file types must be pulled from ProcessPage.
6702 This query (below) doesn't do that. It takes a distinct list of all file types in the MapDocument table and
6703 cross joins that to all of the page marks. This will return false negatives if the client doesnt' intend to add
6704 all page marks to all file types.
6705 The solution to validating mark mapping may be to first pre-process all marks and file types for pages that have marks.
6706 */
6707 -- CM: COMMENTED OUT 2016-04-22
6708 -- select *
6709 -- from MapMark
6710 -- cross join (
6711 -- select distinct
6712 -- MapDocument.system,
6713 -- MapDocument.DestFileType ,
6714 -- DestStructureSnapshotObjectType.typeid
6715 -- from MapDocument
6716 -- join DestStructureSnapshotObjectType on MapDocument.DestFileType=DestStructureSnapshotObjectType.typeName
6717 -- where typeClassID=-3
6718 -- ) MapDestFileType
6719 -- where MapMark.System=MapDestFileType.System
6720 -- and exists(
6721 -- select *
6722 -- from DestStructureSnapshotMarkAllow
6723 -- where MapMark.MarkType=DestStructureSnapshotMarkAllow.markType
6724 -- and MapMark.DestMarkID=DestStructureSnapshotMarkAllow.pageMarkID
6725 -- and MapDestFileType.typeid=DestStructureSnapshotMarkAllow.typeid
6726 -- )
6727 -- order by DestMarkDesc
6728
6729
6730 -- Validate Flows
6731 select 'Invalid Flow' as Status,
6732 *
6733 from MapTask
6734 where System=isnull(@system,System)
6735 and DestFlowProgName not in('','Do Not Migrate')
6736 and not exists(
6737 select *
6738 from DestStructureSnapshotWorkFlow
6739 where MapTask.DestFlowProgName=DestStructureSnapshotWorkFlow.FlowProgName
6740 )
6741 order by DestFlowProgName
6742 -- Validate Steps
6743 select 'Invalid Step' as Status,
6744 *
6745 from MapTask
6746 where System=isnull(@system,System)
6747 and DestFlowProgName not in('','Do Not Migrate')
6748 and not exists(
6749 select *
6750 from DestStructureSnapshotWorkFlow
6751 where MapTask.DestStepProgName=DestStructureSnapshotWorkFlow.StepProgName
6752 )
6753 order by DestStepProgName
6754 -- Validate Flow\Step combinations - may be invalid due to invalid flow or step as noted by prior queries
6755 select 'Invalid Flow\Step Combination' as Status,
6756 *
6757 from MapTask
6758 where System=isnull(@system,System)
6759 and DestFlowProgName<>'Do Not Migrate'
6760 and not exists(
6761 select *
6762 from DestStructureSnapshotWorkFlow
6763 where MapTask.DestFlowProgName=DestStructureSnapshotWorkFlow.FlowProgName
6764 and MapTask.DestStepProgName=DestStructureSnapshotWorkFlow.StepProgName
6765 )
6766 and DestFlowProgName<>''
6767 order by DestFlowProgName, DestStepProgName
6768
6769 -- TODO: Validate WF User Mappings
6770 -- select 'Invalid DocType' as Status,
6771 -- *
6772 -- from bleh
6773 -- where bleh
6774end
6775
6776GO
6777/****** Object: StoredProcedure [dbo].[validateMappings] Script Date: 21/11/2016 12:32:21 ******/
6778SET ANSI_NULLS ON
6779GO
6780SET QUOTED_IDENTIFIER ON
6781GO
6782create Procedure [dbo].[validateMappings]
6783 @system varchar(50) = null,
6784 @drawer varchar(100) = null,
6785 @validationMode varchar(100) = 'PostProcess', -- Value should be either PreProcess or PostProcess
6786 -- PreProcess: Validates the mapping prior to executing process
6787 -- PostProcess: Validates the mapping after executing process
6788 @validateDocs bit = 1,
6789 @validatePageMarks bit = 1,
6790 @validateFileMarks bit = 1,
6791 @validateTasks bit = 1,
6792 @validateWorkFlowUsers bit = 1
6793as
6794begin
6795 set nocount on
6796 Set Transaction Isolation Level Read Uncommitted
6797
6798 declare @logid int, @ProcName varchar(50)
6799 set @ProcName = Object_Name(@@PROCID)
6800 exec logStart @procname, @system, @drawer, @ID = @logid output
6801
6802 if @validationMode not in('PostProcess','PreProcess')
6803 begin
6804 raiserror('validateMappings ERROR: @validationMode must be either PostProcess or PreProcess',15,1)
6805 return
6806 end
6807
6808 --exec prepareIndexes @table = 'MigrationPage', @index = 'IX_MigrationPage_MappingSample'
6809 --exec prepareIndexes @table = 'MigrationPage', @index = 'IX_MigrationPage_DocumentID'
6810
6811 if @validateDocs=1
6812 begin
6813 RAISERROR (' Validating Document Mappings', 10, 1) WITH NOWAIT
6814
6815 -- PAGE Mappings
6816 select MigrationPage.System, MigrationPage.SrcDrawer, MigrationPage.SrcFileType,
6817 MigrationPage.SrcFolderPath, MigrationPage.SrcDocType,
6818 FileNumber = min(MigrationPage.SrcFileNumber), PageCount = count(MigrationPage.ID)
6819 into #SampleDocs
6820 from MigrationDocument, MigrationPage
6821 where MigrationDocument.System = isNull(@system, MigrationDocument.System)
6822 and MigrationDocument.SrcDrawer = isNull(@drawer,MigrationDocument.SrcDrawer)
6823 and MigrationPage.DocumentID = MigrationDocument.ID and MigrationDocument.status > -9
6824 group by MigrationPage.System, MigrationPage.SrcDrawer, MigrationPage.SrcFileType, MigrationPage.SrcFolderPath, MigrationPage.SrcDocType
6825
6826 select System, SrcDrawer, SrcFolderPath, SrcDocType
6827 into #DocMap
6828 from MapDocument
6829 where System = isNull(@system,System) and SrcDrawer = isNull(@drawer,SrcDrawer)
6830
6831 create table #UnMappedDocs( -- Using Create Table instead of select into due to SQL Parser thinking that I'm trying to create the temp table twice when trying to select into in the if else.
6832 [Status] varchar(500),
6833 [Source System] varchar(500),
6834 [Source Drawer] varchar(500),
6835 [Source File Type] varchar(500),
6836 [Source Drawer Description] varchar(500),
6837 [Source Drawer Owner] varchar(500),
6838 [Source Document Type] varchar(500),
6839 [Source Document Name] varchar(500),
6840 [Source Folder Type] varchar(500),
6841 [Source Folder Description] varchar(500),
6842 [No of Pages] varchar(500),
6843 [Sample File] varchar(500)
6844 )
6845
6846 if @validationMode='PostProcess'
6847 begin
6848 insert #UnMappedDocs
6849 select distinct
6850 [Status] = 'Missing',
6851 [Source System] = #SampleDocs.System,
6852 [Source Drawer] = #SampleDocs.SrcDrawer,
6853 [Source File Type] = isnull(#SampleDocs.SrcFileType,''),
6854 [Source Drawer Description] = isNull((select top 1 Description from MigrationType
6855 where System = #SampleDocs.System and Kind = 'Location' and ItemType = #SampleDocs.SrcDrawer),''),
6856 [Source Drawer Owner] = cast('' as varchar(50)),
6857 [Source Document Type] = #SampleDocs.SrcDocType,
6858 [Source Document Name] = isNull((select top 1 Description from MigrationType
6859 where System = #SampleDocs.System and Kind = 'Document' and ItemType = #SampleDocs.SrcDocType),''),
6860 [Source Folder Type] = #SampleDocs.SrcFolderPath,
6861 [Source Folder Description] = isNull((select top 1 Description from MigrationType
6862 where System = #SampleDocs.System and Kind = 'Folder' and ItemType = #SampleDocs.SrcFolderPath),''),
6863 [No of Pages] = PageCount,
6864 [Sample File] = '''' + FileNumber
6865 from #SampleDocs
6866 full join #DocMap on #SampleDocs.System = #DocMap.System
6867 and #SampleDocs.SrcDrawer = #DocMap.SrcDrawer
6868 and #SampleDocs.SrcFolderPath = #DocMap.SrcFolderPath
6869 and #SampleDocs.SrcDocType = #DocMap.SrcDocType
6870 where #DocMap.System is null
6871 end
6872 else
6873 begin
6874 insert #UnMappedDocs
6875 select distinct
6876 [Status] = 'Missing',
6877 [Source System] = #SampleDocs.System,
6878 [Source Drawer] = #SampleDocs.SrcDrawer,
6879 [Source File Type] = isnull(#SampleDocs.SrcFileType,''),
6880 [Source Drawer Description] = isNull((select top 1 Description from MigrationType
6881 where System = #SampleDocs.System and Kind = 'Location' and ItemType = #SampleDocs.SrcDrawer),''),
6882 [Source Drawer Owner] = cast('' as varchar(50)),
6883 [Source Document Type] = #SampleDocs.SrcDocType,
6884 [Source Document Name] = isNull((select top 1 Description from MigrationType
6885 where System = #SampleDocs.System and Kind = 'Document' and ItemType = #SampleDocs.SrcDocType),''),
6886 [Source Folder Type] = #SampleDocs.SrcFolderPath,
6887 [Source Folder Description] = isNull((select top 1 Description from MigrationType
6888 where System = #SampleDocs.System and Kind = 'Folder' and ItemType = #SampleDocs.SrcFolderPath),''),
6889 [No of Pages] = PageCount,
6890 [Sample File] = '''' + FileNumber
6891 from #SampleDocs
6892 where not exists(
6893 select *
6894 from #DocMap
6895 where #SampleDocs.System = #DocMap.System
6896 and #SampleDocs.SrcDrawer = #DocMap.SrcDrawer
6897 and #SampleDocs.SrcFolderPath = #DocMap.SrcFolderPath
6898 and #SampleDocs.SrcDocType = #DocMap.SrcDocType
6899 )
6900 end
6901
6902 if exists(select * from #UnMappedDocs)
6903 begin
6904 raiserror ('ERROR: Some Pages did not have a valid Document Mapping',12,1) with nowait
6905 select * from #UnMappedDocs
6906 order by [Source Drawer], [Source Document Type]
6907 end
6908 else
6909 begin
6910 Raiserror(' ******All Documents have a Mapping!',10,1)
6911 end
6912 end
6913 else raiserror(' Skipping Document Mapping Validation', 10,1);
6914
6915 if @validatePageMarks=1
6916 begin
6917 RAISERROR (' Validating PageMark Mappings', 10, 1) WITH NOWAIT
6918 -- PageMARK mappings
6919
6920 select System,
6921 SrcDrawer,
6922 SrcPageMark,
6923 PageCount = count(*),
6924 SampleFile = max(MigrationPage.SrcFileNumber)
6925 into #SampleMarks
6926 from MigrationPage
6927 where System = isNull(@system,System)
6928 and SrcDrawer = isNull(@drawer,SrcDrawer)
6929 and SrcPageMark <> '0'
6930 and SrcPageMark is not null
6931 group by System, SrcDrawer, SrcPageMark
6932
6933 create table #UnmappedPageMarks(
6934 [Status] varchar(500),
6935 System varchar(500),
6936 SrcDrawer varchar(500),
6937 SrcMark varchar(500),
6938 SrcDescription varchar(500),
6939 NoOfPages varchar(500),
6940 SampleFile varchar(255)
6941 )
6942
6943 if @validationMode='PostProcess'
6944 insert #UnmappedPageMarks
6945 select Status = 'Missing',
6946 System = #SampleMarks.System,
6947 SrcDrawer = #SampleMarks.SrcDrawer,
6948 SrcMark = #SampleMarks.SrcPageMark,
6949 SrcDescription = MigrationType.Description,
6950 NoOfPages = PageCount,
6951 SampleFile
6952 from #SampleMarks
6953 left join MigrationType
6954 on #SampleMarks.SrcPageMark=MigrationType.ItemType
6955 and #SampleMarks.SrcDrawer=MigrationType.Drawer
6956 and #SampleMarks.system=MigrationType.system
6957 where MigrationType.kind='PageMark'
6958 and not exists(
6959 select *
6960 from MapMark
6961 where System = isNull(@system,System)
6962 and SrcDrawer = isNull(@drawer,SrcDrawer)
6963 and MapMark.MarkType='page'
6964 and #SampleMarks.System = MapMark.System
6965 and #SampleMarks.SrcDrawer = MapMark.SrcDrawer
6966 and #SampleMarks.SrcPageMark = MapMark.SrcMarkID
6967 )
6968 else
6969 insert #UnmappedPageMarks
6970 select Status = 'Missing',
6971 System = #SampleMarks.System,
6972 SrcDrawer = #SampleMarks.SrcDrawer,
6973 SrcMark = #SampleMarks.SrcPageMark,
6974 SrcDescription = MigrationType.Description,
6975 NoOfPages = PageCount,
6976 SampleFile
6977 from #SampleMarks
6978 left join MigrationType
6979 on #SampleMarks.SrcPageMark=MigrationType.ItemType
6980 and #SampleMarks.SrcDrawer=MigrationType.Drawer
6981 and #SampleMarks.system=MigrationType.system
6982 where MigrationType.kind='PageMark'
6983
6984 if exists(select * from #UnmappedPageMarks)
6985 begin
6986 raiserror ('ERROR: Some PageMarks did not have a valid Mapping',12,1) with nowait
6987 select Status as Status,
6988 System as 'Source System',
6989 SrcDrawer as 'Source Drawer',
6990 SrcMark as 'Source Mark',
6991 SrcDescription as 'Source Description',
6992 NoOfPages as 'No of Pages',
6993 SampleFile as 'Sample File'
6994 from #UnmappedPageMarks
6995 order by Status,
6996 System,
6997 SrcDrawer,
6998 SrcMark
6999 end
7000 else
7001 raiserror (' PageMarks are Mapped Successfully!',10,1) with nowait
7002 end
7003 else raiserror(' Skipping PageMark Mapping Validation',10,1);
7004
7005 if @validateFileMarks=1
7006 begin
7007 RAISERROR (' Validating FileMark Mappings', 10, 1) WITH NOWAIT
7008 -- FileMARK mappings
7009
7010 ;with FileMarks as(
7011 select System,
7012 SrcDrawer,
7013 SrcFileMark1 as SrcFileMark,
7014 Count(*) as Count,
7015 max(SrcFileNumber) as SrcFileNumber
7016 from MigrationFile
7017 where SrcFileMark1>0
7018 group by System,
7019 SrcDrawer,
7020 SrcFileMark1
7021 union all
7022 select System,
7023 SrcDrawer,
7024 SrcFileMark2 as SrcFileMark,
7025 Count(*) as Count,
7026 max(SrcFileNumber) as SrcFileNumber
7027 from MigrationFile
7028 where SrcFileMark2>0
7029 group by
7030 System,
7031 SrcDrawer,
7032 SrcFileMark2
7033 union all
7034 select System,
7035 SrcDrawer,
7036 SrcFileMark3 as SrcFileMark,
7037 Count(*) as Count,
7038 max(SrcFileNumber) as SrcFileNumber
7039 from MigrationFile
7040 where SrcFileMark3>0
7041 group by System,
7042 SrcDrawer,
7043 SrcFileMark3
7044 )
7045 select 'Missing' as Status,
7046 FileMarks.System,
7047 FileMarks.SrcDrawer,
7048 FileMarks.SrcFileMark,
7049 MigrationType.Description,
7050 FileCount = sum(count),
7051 SampleFile = max(SrcFileNumber)
7052 into #SampleFileMarks
7053 from FileMarks
7054 left join MigrationType on FileMarks.System=MigrationType.System
7055 and FileMarks.SrcDrawer=MigrationType.Drawer
7056 and FileMarks.SrcFileMark=MigrationType.ItemType
7057 and MigrationType.Kind='FileMark'
7058 group by FileMarks.System,
7059 FileMarks.SrcDrawer,
7060 FileMarks.SrcFileMark,
7061 MigrationType.Description
7062 order by FileMarks.System,
7063 FileMarks.SrcDrawer,
7064 FileMarks.SrcFileMark
7065
7066 create table #UnmappedFileMarks(
7067 [Status] varchar(500),
7068 System varchar(500),
7069 SrcDrawer varchar(500),
7070 SrcMark varchar(500),
7071 SrcDescription varchar(500),
7072 NoOfFiles varchar(500),
7073 SampleFile varchar(255)
7074 )
7075
7076 insert #UnmappedFileMarks
7077 select Status = 'Missing',
7078 System = #SampleFileMarks.System,
7079 SrcDrawer = #SampleFileMarks.SrcDrawer,
7080 SrcMark = #SampleFileMarks.SrcFileMark,
7081 SrcDescription = MigrationType.Description,
7082 NoOfFiles = FileCount,
7083 SampleFile
7084 from #SampleFileMarks
7085 left join MigrationType
7086 on #SampleFileMarks.SrcFileMark=MigrationType.ItemType
7087 and #SampleFileMarks.SrcDrawer=MigrationType.Drawer
7088 and #SampleFileMarks.system=MigrationType.system
7089 where MigrationType.kind='FileMark'
7090 and not exists(
7091 select *
7092 from MapMark
7093 where System = isNull(@system,System)
7094 and SrcDrawer = isNull(@drawer,SrcDrawer)
7095 and MapMark.MarkType='file'
7096 and #SampleFileMarks.System = MapMark.System
7097 and #SampleFileMarks.SrcDrawer = MapMark.SrcDrawer
7098 and #SampleFileMarks.SrcFileMark = MapMark.SrcMarkID
7099 )
7100
7101 if exists(select * from #UnmappedFileMarks)
7102 begin
7103 raiserror ('ERROR: Some FileMarks did not have a valid Mapping',12,1) with nowait
7104 select Status as Status,
7105 System as 'Source System',
7106 SrcDrawer as 'Source Drawer',
7107 SrcMark as 'Source Mark',
7108 SrcDescription as 'Source Description',
7109 NoOfFiles as 'No of Files',
7110 SampleFile as 'Sample File'
7111 from #UnmappedFileMarks
7112 order by Status,
7113 System,
7114 SrcDrawer,
7115 SrcMark
7116 end
7117 else
7118 raiserror (' FileMarks are Mapped Successfully!',10,1) with nowait
7119 end
7120 else raiserror(' Skipping FileMark Mapping Validation',10,1);
7121
7122 if @validateTasks=1
7123 begin
7124 -- Look for Unmapped Tasks
7125 RAISERROR (' Validating Task Mappings', 10, 1) WITH NOWAIT
7126 select System, SrcFlowID, SrcStepID, COUNT(*) as TaskCount
7127 into #SampleTasks
7128 from MigrationTask
7129 where System = isNull(@system,System)
7130 group by System, SrcFlowID, SrcStepID
7131
7132 select System, SrcFlowID, SrcStepID
7133 into #TaskMap
7134 from MapTask
7135 where System = isNull(@system,System)
7136
7137 create table #UnmappedTasks(
7138 [Status] varchar(500),
7139 [Source System] varchar(500),
7140 [Source Flow ID] varchar(500),
7141 [Source Flow Name] varchar(500),
7142 [Source Flow Description] varchar(500),
7143 [Source Step ID] varchar(500),
7144 [Step Description] varchar(500),
7145 [No of Tasks] varchar(500)
7146 );
7147
7148 if @validationMode='PostProcess'
7149 insert #UnmappedTasks
7150 select Status = 'Missing',
7151 [Source System] = #SampleTasks.System,
7152 [Source Flow ID] = #SampleTasks.SrcFlowID,
7153 [Source Flow Name] = (select top 1 Description from MigrationType
7154 where System = isNull(@system,System) and Kind = 'Flow' and ItemType = #SampleTasks.SrcFlowID),
7155 [Source Flow Description] = (select top 1 Description from MigrationType
7156 where System = isNull(@system,System) and Kind = 'Flow' and ItemType = #SampleTasks.SrcFlowID),
7157 [Source Step ID] = #SampleTasks.SrcStepID,
7158 [Step Description] = (select top 1 Description from MigrationType
7159 where System = isNull(@system,System) and Kind = 'Step'
7160 and ItemType = cast(#SampleTasks.SrcFlowID as varchar) + '_' + cast(#SampleTasks.SrcStepID as varchar)),
7161 [No of Tasks] = TaskCount
7162 from #SampleTasks
7163 full join #TaskMap on #SampleTasks.System = #TaskMap.System
7164 and #SampleTasks.SrcFlowID = #TaskMap.srcFlowid
7165 and #SampleTasks.SrcStepID = #TaskMap.srcStepid
7166 where #TaskMap.System is null
7167 else
7168 insert #UnmappedTasks
7169 select Status = 'Missing',
7170 [Source System] = #SampleTasks.System,
7171 [Source Flow ID] = #SampleTasks.SrcFlowID,
7172 [Source Flow Name] = (select top 1 Description from MigrationType
7173 where System = isNull(@system,System) and Kind = 'Flow' and ItemType = #SampleTasks.SrcFlowID),
7174 [Source Flow Description] = (select top 1 Description from MigrationType
7175 where System = isNull(@system,System) and Kind = 'Flow' and ItemType = #SampleTasks.SrcFlowID),
7176 [Source Step ID] = #SampleTasks.SrcStepID,
7177 [Step Description] = (select top 1 Description from MigrationType
7178 where System = isNull(@system,System) and Kind = 'Step'
7179 and ItemType = cast(#SampleTasks.SrcFlowID as varchar) + '_' + cast(#SampleTasks.SrcStepID as varchar)),
7180 [No of Tasks] = TaskCount
7181 from #SampleTasks
7182 where not exists(
7183 select *
7184 from #TaskMap
7185 where #SampleTasks.System = #TaskMap.System
7186 and #SampleTasks.SrcFlowID = #TaskMap.srcFlowid
7187 and #SampleTasks.SrcStepID = #TaskMap.srcStepid
7188 )
7189
7190 if exists(select * from #UnmappedTasks)
7191 begin
7192 raiserror ('ERROR: Some Tasks did not have a valid workflow Mapping',12,1) with nowait
7193 select * from #UnmappedTasks
7194 end
7195 else
7196 raiserror('********** No Unmapped Tasks!',10,1) with nowait
7197 end
7198 else raiserror(' Skipping FileMark Mapping Validation',10,1);
7199
7200 if @validateWorkFlowUsers=1
7201 begin
7202 -- Task Assigned User Checking
7203 RAISERROR (' Validating User Mappings', 10, 1) WITH NOWAIT
7204 select System, SrcAssignedToUserID, count(*) as TaskCount
7205 into #SampleUsers
7206 from MigrationTask
7207 where SrcAssignedToUserID is not null and System = isNull(@system,System)
7208 group by System, SrcAssignedToUserID
7209
7210 select System, SrcUserID
7211 into #UserMap
7212 from MapUser
7213 where System = isNull(@system,System)
7214
7215 create table #UnmappedUsers(
7216 Status varchar(500),
7217 [Source System] varchar(500),
7218 [Source User ID] varchar(500),
7219 [Source User Name] varchar(500),
7220 [No. Of Tasks Assigned] varchar(500)
7221 )
7222
7223 if @validationMode='PostProcess'
7224 insert #UnmappedUsers
7225 select Status = 'Missing',
7226 [Source System] = #SampleUsers.System,
7227 [Source User ID] = #SampleUsers.SrcAssignedToUserID,
7228 [Source User Name] = (select top 1 description from MigrationType
7229 where System = isNull(@system,System) and Kind = 'User' and ItemType = #SampleUsers.SrcAssignedToUserID),
7230 [No. Of Tasks Assigned] = TaskCount
7231 from #SampleUsers
7232 full join #UserMap on #SampleUsers.System = #UserMap.System
7233 and #SampleUsers.SrcAssignedToUserID = #UserMap.SrcUserID
7234 where #UserMap.System is null
7235 else
7236 insert #UnmappedUsers
7237 select Status = 'Missing',
7238 [Source System] = #SampleUsers.System,
7239 [Source User ID] = #SampleUsers.SrcAssignedToUserID,
7240 [Source User Name] = (select top 1 description from MigrationType
7241 where System = isNull(@system,System) and Kind = 'User' and ItemType = #SampleUsers.SrcAssignedToUserID),
7242 [No. Of Tasks Assigned] = TaskCount
7243 from #SampleUsers
7244 where not exists(
7245 select *
7246 from #UserMap
7247 where #SampleUsers.System = #UserMap.System
7248 and #SampleUsers.SrcAssignedToUserID = #UserMap.SrcUserID
7249 )
7250
7251 if exists(select * from #UnmappedUsers)
7252 begin
7253 raiserror ('ERROR: Some Tasks did not have a valid ''assigned to'' user mapping',12,1) with nowait
7254 select * from #UnmappedUsers
7255 order by [Source User ID]
7256 end
7257 else
7258 raiserror (' Task ''assigned to'' users are Mapped Successfully!',10,1) with nowait
7259 end
7260 else raiserror(' Skipping PageMark Mapping Validation',10,1);
7261
7262
7263 exec logEnd @logid
7264end
7265
7266GO
7267USE [master]
7268GO
7269ALTER DATABASE [iConIRNet] SET READ_WRITE
7270GO