From fb1225060e6936baa5e0b4ef0e425ae5f8e4f053 Mon Sep 17 00:00:00 2001 From: eeckert Date: Thu, 28 Sep 2023 15:14:17 -0600 Subject: [PATCH] account for migration status in new Outputs... --- Generate Egnyte Export.sql | 15 ++++++--------- Get-ProjectFolders.ps1 | 31 +++++++++++++++++++------------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Generate Egnyte Export.sql b/Generate Egnyte Export.sql index e30d735..769ca20 100644 --- a/Generate Egnyte Export.sql +++ b/Generate Egnyte Export.sql @@ -1,20 +1,19 @@ -- Generate Non-Duplicated PARENT FOLDER List DROP TABLE DataInventory; CREATE TABLE DataInventory AS -Select * -from ( +Select * from ( SELECT SERVER, REPLACE( Parent, "X:\","\\mpe.ca\datadrive\") AS UNCPath, REPLACE(REPLACE(Parent,("\\mpe.ca\datadrive\" || Server),"/Shared/N-Data"),"\","/") AS EgnytePath, sum(FileCount) as FileCount, Sum(FileSize) as FileSize, 'Parent' as Source, Status from FolderData - Where Parent in ( - SELECT Parent FROM NonDupParent - ) + Where Parent in ( + SELECT Parent FROM NonDupParent + ) + AND FolderData.fld_MigrationID IS NULL GROUP by UNCPath ) - union SELECT SERVER, REPLACE(PATH,"X:\","\\mpe.ca\datadrive\") AS UNCPath, @@ -22,6 +21,4 @@ SELECT SERVER, FileCount, FileSize, 'Project' as Source, Status from FolderData Where FolderData.Project in ( SELECT Project FROM NonDupProject) --- AND FolderData.Parent in ( --- Select Parent FROM NonDupParent --- ); \ No newline at end of file +AND FolderData.fld_MigrationID IS NULL; \ No newline at end of file diff --git a/Get-ProjectFolders.ps1 b/Get-ProjectFolders.ps1 index 29639c6..2758f85 100644 --- a/Get-ProjectFolders.ps1 +++ b/Get-ProjectFolders.ps1 @@ -135,15 +135,16 @@ $OfficeList | ForEach-Object -parallel { else { $out = [PSCustomObject]@{ - Server = $Server - Project = $ProjectNumber.ToString() - Parent = $folder_Parent - Path = $Path - FileCount = $folder_FileCount - FileSize = $folder_FileSize - FileLastWrite = $folder_LastWrite - FileLastAccess = $folder_LastAccess - Status = $null # added to support Migration Status + Server = $Server + Project = $ProjectNumber.ToString() + Parent = $folder_Parent + Path = $Path + FileCount = $folder_FileCount + FileSize = $folder_FileSize + FileLastWrite = $folder_LastWrite + FileLastAccess = $folder_LastAccess + Status = $null # added to support Migration Status + fld_MigrationID = $null } | Out-DataTable Invoke-SQLiteBulkCopy -DataSource $PathToDB_Copy -Table "FolderData" -DataTable $out -Force @@ -193,8 +194,8 @@ foreach ($status in $MigrationStatus_import) { $SQLSourcePath += '\' } $SQLDestPath = $status.'Destination Path'.replace("'", "`'") #SQL Formatting - if ($SQLDestPath -notmatch '\\$') { - $SQLDestPath += '\' + if ($SQLDestPath -notmatch '\/$') { + $SQLDestPath += '/' } $SQLMigrationID = $status.'Migration ID' $SQLMigrationName = $status.'Migration Name' @@ -208,14 +209,20 @@ foreach ($status in $MigrationStatus_import) { Invoke-SqliteQuery -DataSource $PathToDB -Query $Query } else { - $Query = "INSERT INTO MigrationStatus VALUES ('$SQLMigrationID','$SQLMigrationName',`'$SQLSourcePath`',`'$SQLDestPath`','$SQLMigrationStatus')" + $Query = "INSERT INTO MigrationStatus VALUES ('$SQLMigrationID','$SQLMigrationName',`'$SQLSourcePath`',`'$SQLDestPath`','$SQLMigrationStatus','')" Invoke-SqliteQuery -DataSource $PathToDB -Query $Query } } +# Update DB with new Data from MigrationStatus +$Query = 'update FolderData SET fld_MigrationID = (SELECT MigrationID from MigrationStatus where Parent = MigrationFolderSource);' +Invoke-SqliteQuery -DataSource $PathToDB -Query $Query +## DB Now contains MigrationID in fld_MigrationID Column. We can now reliably track the individual folder status' +$query = "update FolderData set Status = (Select MigrationStatus from MigrationStatus where fld_MigrationID = MigrationID);" +Invoke-SqliteQuery -DataSource $PathToDB -Query $Query