|
| 1 | +# Plan for Replacing RMO Functionality in dbatools |
| 2 | + |
| 3 | +## Background |
| 4 | +Microsoft has broken RMO (Replication Management Objects) and Replication on Linux. The RMO libraries are no longer compatible with newer versions of .NET Core on Linux, showing errors like "binary format not supported" even though it's x64. We need to replace all replication functionality in dbatools with a solution that works on both Windows and Linux. |
| 5 | + |
| 6 | +## Approach |
| 7 | +Create fake/stand-in classes that mimic the original RMO classes but use SQL Server replication stored procedures behind the scenes instead of the actual RMO libraries. |
| 8 | + |
| 9 | +## 1. Analysis Phase |
| 10 | + |
| 11 | +### 1.1 Identify All RMO-Dependent Commands |
| 12 | +- Get-DbaReplServer |
| 13 | +- Get-DbaReplPublication |
| 14 | +- Get-DbaReplArticle |
| 15 | +- Get-DbaReplDistributor |
| 16 | +- Enable-DbaReplPublishing |
| 17 | +- Enable-DbaReplDistributor |
| 18 | +- Disable-DbaReplPublishing |
| 19 | +- Disable-DbaReplDistributor |
| 20 | +- Add-DbaReplArticle |
| 21 | +- Remove-DbaReplArticle |
| 22 | +- New-DbaReplPublication |
| 23 | +- Remove-DbaReplPublication |
| 24 | +- New-DbaReplSubscription |
| 25 | +- Remove-DbaReplSubscription |
| 26 | +- Test-DbaReplLatency |
| 27 | +- Export-DbaReplServerSetting |
| 28 | +- Other replication-related commands |
| 29 | + |
| 30 | +### 1.2 Analyze RMO Class Structure |
| 31 | +Understand the RMO class hierarchy to create appropriate replacements: |
| 32 | +- ReplicationServer |
| 33 | +- ReplicationDatabase |
| 34 | +- Publication (TransPublication, MergePublication) |
| 35 | +- Article (TransArticle, MergeArticle) |
| 36 | +- Subscription (TransSubscription, MergeSubscription) |
| 37 | + |
| 38 | +## 2. Design Phase |
| 39 | + |
| 40 | +### 2.1 Create Replacement Class Structure |
| 41 | +Design replacement classes that mimic RMO but use T-SQL internally: |
| 42 | +- DbaReplServer |
| 43 | +- DbaReplDatabase |
| 44 | +- DbaReplPublication |
| 45 | +- DbaReplArticle |
| 46 | +- DbaReplSubscription |
| 47 | +- Other necessary classes |
| 48 | + |
| 49 | +### 2.2 Map RMO Methods to T-SQL Stored Procedures |
| 50 | +Identify the T-SQL stored procedures that can replace RMO functionality: |
| 51 | +- sp_get_distributor |
| 52 | +- sp_helppublication |
| 53 | +- sp_helparticle |
| 54 | +- sp_adddistributor |
| 55 | +- sp_dropdistributor |
| 56 | +- sp_replicationdboption |
| 57 | +- sp_addpublication |
| 58 | +- sp_droppublication |
| 59 | +- sp_addarticle |
| 60 | +- sp_droparticle |
| 61 | +- sp_addsubscription |
| 62 | +- sp_dropsubscription |
| 63 | +- Other replication stored procedures |
| 64 | + |
| 65 | +## 3. Implementation Phase |
| 66 | + |
| 67 | +### 3.1 Create Core Infrastructure |
| 68 | +1. Create a new module file for replication replacement classes |
| 69 | +2. Implement base connection and utility functions |
| 70 | +3. Create mock classes that mimic RMO structure but use T-SQL |
| 71 | + |
| 72 | +### 3.2 Implement Command Replacements |
| 73 | +Starting with Get-DbaReplDistributor as suggested: |
| 74 | +1. Create DbaReplServer Class |
| 75 | +2. Implement sp_get_distributor Call |
| 76 | +3. Map Results to Class Properties |
| 77 | +4. Test on Windows |
| 78 | +5. Test on Linux |
| 79 | +6. Move to next command |
| 80 | + |
| 81 | +### 3.3 Implement Remaining Commands |
| 82 | +Follow a similar pattern for each command, in order of complexity: |
| 83 | +1. Get commands (read-only operations) |
| 84 | +2. Enable/Disable commands (configuration operations) |
| 85 | +3. Add/New commands (creation operations) |
| 86 | +4. Remove commands (deletion operations) |
| 87 | +5. Test commands (diagnostic operations) |
| 88 | + |
| 89 | +## 4. Testing Phase |
| 90 | + |
| 91 | +### 4.1 Unit Testing |
| 92 | +Create unit tests for each replacement command: |
| 93 | +- Test basic functionality |
| 94 | +- Test edge cases |
| 95 | +- Test error handling |
| 96 | +- Test performance |
| 97 | + |
| 98 | +### 4.2 Integration Testing |
| 99 | +Test commands working together in common replication scenarios: |
| 100 | +- Setup distributor |
| 101 | +- Configure publishing |
| 102 | +- Create publication |
| 103 | +- Add articles |
| 104 | +- Create subscription |
| 105 | +- Test replication |
| 106 | +- Clean up |
| 107 | + |
| 108 | +### 4.3 Cross-Platform Testing |
| 109 | +Ensure functionality works on both Windows and Linux: |
| 110 | +- Test on Windows |
| 111 | +- Test on Linux |
| 112 | +- Compare results |
| 113 | +- Fix discrepancies |
| 114 | + |
| 115 | +## 5. Documentation and Deployment |
| 116 | + |
| 117 | +### 5.1 Update Documentation |
| 118 | +Update help files and examples for all replaced commands. |
| 119 | + |
| 120 | +### 5.2 Create Migration Guide |
| 121 | +Document any API changes or behavior differences for users. |
| 122 | + |
| 123 | +## 6. Detailed Implementation Approach |
| 124 | + |
| 125 | +For each command, we'll follow this pattern: |
| 126 | +1. Create a replacement class that mimics the RMO class |
| 127 | +2. Implement the class methods using T-SQL stored procedures |
| 128 | +3. Update the command to use the new class instead of RMO |
| 129 | +4. Ensure backward compatibility with existing scripts |
| 130 | + |
| 131 | +For example, for Get-DbaReplDistributor: |
| 132 | +```powershell |
| 133 | +# Current implementation using RMO |
| 134 | +$distributor = Get-DbaReplServer -SqlInstance $instance |
| 135 | +# Properties accessed: IsDistributor, DistributionDatabases, etc. |
| 136 | +
|
| 137 | +# New implementation using T-SQL |
| 138 | +# 1. Create DbaReplServer class that mimics ReplicationServer |
| 139 | +# 2. Implement IsDistributor property using sp_get_distributor |
| 140 | +# 3. Implement DistributionDatabases property using sp_helpdistributiondb |
| 141 | +# 4. Update Get-DbaReplServer to use the new class |
0 commit comments