account for migration status in new Outputs...

This commit is contained in:
Erik Eckert 2023-09-28 15:14:17 -06:00
parent 9a2adc0d68
commit fb1225060e
2 changed files with 25 additions and 21 deletions

View File

@ -1,20 +1,19 @@
-- Generate Non-Duplicated PARENT FOLDER List -- Generate Non-Duplicated PARENT FOLDER List
DROP TABLE DataInventory; DROP TABLE DataInventory;
CREATE TABLE DataInventory AS CREATE TABLE DataInventory AS
Select * Select * from (
from (
SELECT SERVER, SELECT SERVER,
REPLACE( REPLACE(
Parent, Parent,
"X:\","\\mpe.ca\datadrive\") AS UNCPath, "X:\","\\mpe.ca\datadrive\") AS UNCPath,
REPLACE(REPLACE(Parent,("\\mpe.ca\datadrive\" || Server),"/Shared/N-Data"),"\","/") AS EgnytePath, 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 sum(FileCount) as FileCount, Sum(FileSize) as FileSize, 'Parent' as Source, Status from FolderData
Where Parent in ( Where Parent in (
SELECT Parent FROM NonDupParent SELECT Parent FROM NonDupParent
) )
AND FolderData.fld_MigrationID IS NULL
GROUP by UNCPath GROUP by UNCPath
) )
union union
SELECT SERVER, SELECT SERVER,
REPLACE(PATH,"X:\","\\mpe.ca\datadrive\") AS UNCPath, REPLACE(PATH,"X:\","\\mpe.ca\datadrive\") AS UNCPath,
@ -22,6 +21,4 @@ SELECT SERVER,
FileCount, FileSize, 'Project' as Source, Status from FolderData FileCount, FileSize, 'Project' as Source, Status from FolderData
Where FolderData.Project in ( Where FolderData.Project in (
SELECT Project FROM NonDupProject) SELECT Project FROM NonDupProject)
-- AND FolderData.Parent in ( AND FolderData.fld_MigrationID IS NULL;
-- Select Parent FROM NonDupParent
-- );

View File

@ -135,15 +135,16 @@ $OfficeList | ForEach-Object -parallel {
else { else {
$out = [PSCustomObject]@{ $out = [PSCustomObject]@{
Server = $Server Server = $Server
Project = $ProjectNumber.ToString() Project = $ProjectNumber.ToString()
Parent = $folder_Parent Parent = $folder_Parent
Path = $Path Path = $Path
FileCount = $folder_FileCount FileCount = $folder_FileCount
FileSize = $folder_FileSize FileSize = $folder_FileSize
FileLastWrite = $folder_LastWrite FileLastWrite = $folder_LastWrite
FileLastAccess = $folder_LastAccess FileLastAccess = $folder_LastAccess
Status = $null # added to support Migration Status Status = $null # added to support Migration Status
fld_MigrationID = $null
} | Out-DataTable } | Out-DataTable
Invoke-SQLiteBulkCopy -DataSource $PathToDB_Copy -Table "FolderData" -DataTable $out -Force Invoke-SQLiteBulkCopy -DataSource $PathToDB_Copy -Table "FolderData" -DataTable $out -Force
@ -193,8 +194,8 @@ foreach ($status in $MigrationStatus_import) {
$SQLSourcePath += '\' $SQLSourcePath += '\'
} }
$SQLDestPath = $status.'Destination Path'.replace("'", "`'") #SQL Formatting $SQLDestPath = $status.'Destination Path'.replace("'", "`'") #SQL Formatting
if ($SQLDestPath -notmatch '\\$') { if ($SQLDestPath -notmatch '\/$') {
$SQLDestPath += '\' $SQLDestPath += '/'
} }
$SQLMigrationID = $status.'Migration ID' $SQLMigrationID = $status.'Migration ID'
$SQLMigrationName = $status.'Migration Name' $SQLMigrationName = $status.'Migration Name'
@ -208,14 +209,20 @@ foreach ($status in $MigrationStatus_import) {
Invoke-SqliteQuery -DataSource $PathToDB -Query $Query Invoke-SqliteQuery -DataSource $PathToDB -Query $Query
} }
else { 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 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