Skip to content

Commit

Permalink
Exclude or Include Tables from Cloud Migration (#27773)
Browse files Browse the repository at this point in the history
#### Summary
Enables a developer:
- To prepare packages of tables for cloud sync
- Disable some tables for cloud sync- those that are set as default
during initial setup - in order to save database space.
- Select custom tables programmatically

#### Work Item(s)
Fixes #27655

@nikolakukrika There are some tests in the Codeunit 139656 "Hybrid Cloud
Management Tests". I am not sure if new tests are needed for this
change.
Fixes
[AB#558218](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/558218)
  • Loading branch information
miljance authored Dec 12, 2024
1 parent 42a98a0 commit 0bb636e
Showing 1 changed file with 107 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,39 @@ codeunit 40021 "Cloud Mig. Replicate Data Mgt."
exit(CanBeIncluded);
end;

procedure IncludeTableToReplication(TableID: Integer; CompanyName: Text[30])
begin
IncludeExcludeTableFromReplication(TableID, CompanyName, true);
end;

procedure ExcludeTableFromReplication(TableID: Integer; CompanyName: Text[30])
begin
IncludeExcludeTableFromReplication(TableID, CompanyName, false);
end;

local procedure IncludeExcludeTableFromReplication(TableID: Integer; CompanyName: Text[30]; NewReplicateData: Boolean)
var
IntelligentCloudStatus: Record "Intelligent Cloud Status";
TablesModified: Text;
SeparatorChar: Char;
begin
IntelligentCloudStatus.SetRange("Table Id", TableID);
IntelligentCloudStatus.SetRange("Company Name", CompanyName);
if not IntelligentCloudStatus.FindSet() then
exit;

CheckCanChangeTheTable(IntelligentCloudStatus);
SeparatorChar := ',';
IntelligentCloudStatus.FindSet();
repeat
UpdateReplicateDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewReplicateData);
until IntelligentCloudStatus.Next() = 0;

LogMessageForChangedReplicateData(Format(TableID), NewReplicateData);
end;

internal procedure IncludeExcludeTablesFromCloudMigration(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; NewReplicateData: Boolean)
var
HybridCloudManagement: Codeunit "Hybrid Cloud Management";
TelemetryDictionary: Dictionary of [Text, Text];
TablesModified: Text;
SeparatorChar: Char;
begin
Expand All @@ -83,49 +112,105 @@ codeunit 40021 "Cloud Mig. Replicate Data Mgt."

SeparatorChar := ',';
repeat
if IntelligentCloudStatus."Replicate Data" <> NewReplicateData then begin
InsertInitialLog(IntelligentCloudStatus);
IntelligentCloudStatus."Replicate Data" := NewReplicateData;
IntelligentCloudStatus.Modify();
InsertModifyLog(IntelligentCloudStatus);
TablesModified += IntelligentCloudStatus."Table Name" + SeparatorChar;
end;
UpdateReplicateDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewReplicateData);
until IntelligentCloudStatus.Next() = 0;

TablesModified := TablesModified.TrimEnd(SeparatorChar);
LogMessageForChangedReplicateData(TablesModified, NewReplicateData);
end;

local procedure UpdateReplicateDataForTable(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; var TablesModified: Text; SeparatorChar: Char; NewReplicateData: Boolean)
begin
if IntelligentCloudStatus."Replicate Data" <> NewReplicateData then begin
InsertInitialLog(IntelligentCloudStatus);
IntelligentCloudStatus."Replicate Data" := NewReplicateData;
IntelligentCloudStatus.Modify();
InsertModifyLog(IntelligentCloudStatus);
TablesModified += IntelligentCloudStatus."Table Name" + SeparatorChar;
end;
end;

local procedure LogMessageForChangedReplicateData(TablesModified: Text; NewReplicateData: Boolean)
var
HybridCloudManagement: Codeunit "Hybrid Cloud Management";
TelemetryDictionary: Dictionary of [Text, Text];
begin
TelemetryDictionary.Add('Category', HybridCloudManagement.GetTelemetryCategory());
TelemetryDictionary.Add('TablesModified', TablesModified);
TelemetryDictionary.Add('ReplicateData', Format(NewReplicateData, 0, 9));
Session.LogMessage('0000MRJ', ChangedReplicationPropertyLbl, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, TelemetryDictionary);
end;

internal procedure ChangePreserveCloudData(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; NewPreserveCloudData: Boolean)
procedure SetPreserveDataForTable(TableID: Integer; CompanyName: Text[30])
begin
SetResetPreserveDataForTable(TableID, CompanyName, true);
end;

procedure ResetPreserveDataForTable(TableID: Integer; CompanyName: Text[30])
begin
SetResetPreserveDataForTable(TableID, CompanyName, false);
end;

local procedure SetResetPreserveDataForTable(TableID: Integer; CompanyName: Text[30]; NewPreserveCloudData: Boolean)
var
HybridCloudManagement: Codeunit "Hybrid Cloud Management";
TelemetryDictionary: Dictionary of [Text, Text];
IntelligentCloudStatus: Record "Intelligent Cloud Status";
TablesModified: Text;
SeparatorChar: Char;
begin
IntelligentCloudStatus.SetRange("Table Id", TableID);
IntelligentCloudStatus.SetRange("Company Name", CompanyName);
if not IntelligentCloudStatus.FindSet() then
exit;

CheckCanChangeTheTable(IntelligentCloudStatus);
SeparatorChar := ',';
IntelligentCloudStatus.FindSet();
repeat
if IntelligentCloudStatus."Preserve Cloud Data" <> NewPreserveCloudData then begin
if (not NewPreserveCloudData) and (IntelligentCloudStatus."Table Id" = Database::"Tenant Media") then
Error(NotPossibleToReplaceTenantMediaTableErr);
UpdatePreserveDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewPreserveCloudData);
until IntelligentCloudStatus.Next() = 0;

if (NewPreserveCloudData) and (IntelligentCloudStatus."Company Name" = '') then
Error(NotPossibleToDeltaSyncDataPerCompanyErr);
LogMessageForChangedPreserveData(Format(TableID), NewPreserveCloudData);
end;

InsertInitialLog(IntelligentCloudStatus);
IntelligentCloudStatus."Preserve Cloud Data" := NewPreserveCloudData;
IntelligentCloudStatus.Modify();
InsertModifyLog(IntelligentCloudStatus);
end;
internal procedure ChangePreserveCloudData(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; NewPreserveCloudData: Boolean)
var
TablesModified: Text;
SeparatorChar: Char;
begin
if not IntelligentCloudStatus.FindSet() then
exit;

SeparatorChar := ',';
repeat
UpdatePreserveDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewPreserveCloudData);
until IntelligentCloudStatus.Next() = 0;

TablesModified := TablesModified.TrimEnd(SeparatorChar);
LogMessageForChangedPreserveData(TablesModified, NewPreserveCloudData);
end;

local procedure UpdatePreserveDataForTable(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; var TablesModified: Text; SeparatorChar: Char; NewPreserveCloudData: Boolean)
begin
if IntelligentCloudStatus."Preserve Cloud Data" <> NewPreserveCloudData then begin
if (not NewPreserveCloudData) and (IntelligentCloudStatus."Table Id" = Database::"Tenant Media") then
Error(NotPossibleToReplaceTenantMediaTableErr);

if (NewPreserveCloudData) and (IntelligentCloudStatus."Company Name" = '') then
Error(NotPossibleToDeltaSyncDataPerCompanyErr);

InsertInitialLog(IntelligentCloudStatus);
IntelligentCloudStatus."Preserve Cloud Data" := NewPreserveCloudData;
IntelligentCloudStatus.Modify();
InsertModifyLog(IntelligentCloudStatus);
TablesModified += IntelligentCloudStatus."Table Name" + SeparatorChar;
end;
end;

local procedure LogMessageForChangedPreserveData(TablesModified: Text; NewPreserveCloudData: Boolean)
var
HybridCloudManagement: Codeunit "Hybrid Cloud Management";
TelemetryDictionary: Dictionary of [Text, Text];
begin
TelemetryDictionary.Add('Category', HybridCloudManagement.GetTelemetryCategory());
TelemetryDictionary.Add('TablesModified', TablesModified);
TelemetryDictionary.Add('PreserveCloudData', Format(NewPreserveCloudData, 0, 9));
Expand Down

0 comments on commit 0bb636e

Please sign in to comment.