The following scripts provide examples that can be modified to apply different priorities to documents.
Prioritize Documents by "Max Matter Date"
All the documents in a matter are prioritized based on the Created/Modified date of the most recently added/edited document. In this way, all documents for matters that have been worked on recently transfer sooner and documents related to matters that haven't been touched in a while transfer later.
For giant migrations, this is the best way to prioritize documents.
- ;WITH P1 AS (
- --Get the date of the most recent document for each parent...
- SELECT
- Final_Parent_Type,
- Final_Parent_Id,
- MAX(COALESCE(Final_Updated_At, Final_Created_At, '1900-01-01')) MaxDocDate
- FROM (
- SELECT
- Final_Parent_Type,
- Final_Parent_Id,
- Final_Created_At,
- Final_Updated_At
- FROM
- __M_Documents_Digital_Files
- UNION
- SELECT
- Files.Final_Parent_Type,
- Files.Final_Parent_Id,
- Versions.Final_Created_At,
- Versions.Final_Updated_At
- FROM
- __M_Documents_Digital_Files Files,
- __M_Documents_Digital_Files_Versions Versions
- WHERE 1=1
- AND Versions.Final_DocumentFile_Id = Files.Id
- ) DateList
-
- GROUP BY
- Final_Parent_Type,
- Final_Parent_Id
- ), P2 AS (
- --Calculate the Action_Priority for each Parent based on MaxDocDate
- SELECT
- P1.Final_Parent_Type,
- P1.Final_Parent_Id,
- Action_Priority = 5000
- + (DATEPART(YEAR, MaxDocDate) * 100) --Prioritize by the year of the most recent doc for each parent.
- --+ (DATEPART(MONTH, MaxDocDate) * 001) --To get more granular, you can add MONTH by removing the comment ('--') at the start of this line.
- FROM
- P1
- )
- UPDATE --Set the action Priority
- df
- SET
- Action_Priority = P2.Action_Priority
- FROM
- __M_Documents_Digital_Files df,
- P2
- WHERE 1=1
- AND P2.Final_Parent_Id = df.Final_Parent_Id
- AND P2.Final_Parent_Type = df.Final_Parent_Type
Prioritize Documents for Active Matters
For small migrations, this is the recommend way to prioritize documents,
- UPDATE
- __M_Documents_Digital_Files
- SET
- Action_Group = 6000
- WHERE 1=1
- AND Final_Parent_Type = '__M_Matters'
- AND Final_Parent_Id IN (
- SELECT
- Id
- FROM
- __M_Matters
- WHERE 1=1
- AND Final_Status = 'Active'
- )
Prioritize Large/Small Documents
If you are restoring into a system that has different action limits at different times, this can help you optimize throughout.
Big documents should be prioritized when action limits are small and small documents should be prioritized when action limits are big.
- --Prioritize documents based on size.
- UPDATE
- __M_Documents_Digital_Files
- SET
- Action_Group = 6000
- WHERE 1=1
- AND Id IN (
- SELECT
- Final_DocumentFile_Id
- FROM
- __M_Documents_Digital_Files_Versions
- WHERE 1=1
- --Change this to be < or > depending on what you want.
- AND Final_Meta_ContentSize < 10 * 1024 * 1024 -- 10MB
- AND Result_Id = ''
- )
Prioritize Documents for Specific Matters
- --Prioritize documents for specific matters.
- UPDATE
- __M_Documents_Digital_Files
- SET
- Action_Group = 6000
- WHERE 1=1
- AND Result_Id = ''
- AND Final_Parent_Type = '__M_Matters'
- AND Final_Parent_Id IN (
- SELECT
- Id
- FROM
- __M_Matters
- WHERE 1=1
- AND Final_ReferenceCode IN (
- 'ABC-001',
- 'ABC-002'
- )
- )
Prioritize Documents whose versions have not been fully uploaded
- UPDATE
- __M_Documents_Digital_Files
- SET
- Action_Group = 6000
- WHERE 1=1
- AND Id IN (
- SELECT
- Final_DocumentFile_Id
- FROM
- __M_Documents_Digital_Files_Versions
- WHERE 1=1
- AND Result_Id = ''
- )
Prioritize Documents that have not been started
- UPDATE
- __M_Documents_Digital_Files
- SET
- Action_Group = 6000
- WHERE 1=1
- AND Result_Id = ''