Skip to content

Commit ded29cc

Browse files
vibed rep
1 parent a5588b1 commit ded29cc

7 files changed

+569
-15
lines changed

Diff for: RMO_Replacement_Plan.md

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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

Diff for: RMO_Replacement_README.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# RMO Replacement for dbatools
2+
3+
## Overview
4+
5+
This implementation replaces the Microsoft Replication Management Objects (RMO) functionality in dbatools with a custom implementation that uses T-SQL stored procedures instead of the RMO libraries. This is necessary because Microsoft has broken RMO and Replication on Linux, making it incompatible with newer versions of .NET Core.
6+
7+
## Implementation Details
8+
9+
### Approach
10+
11+
The implementation creates fake/stand-in classes that mimic the original RMO classes but use SQL Server replication stored procedures behind the scenes. This allows the existing dbatools commands to continue working without requiring changes to their API.
12+
13+
### Files Created/Modified
14+
15+
1. **New Files:**
16+
- `private/functions/DbaReplicationClasses.ps1`: Contains the replacement classes for RMO
17+
- `private/functions/Add-DbaReplicationLibrary.ps1`: Loads the replacement classes
18+
- `RMO_Replacement_Plan.md`: The plan for implementing the replacement
19+
- `RMO_Replacement_README.md`: This file
20+
21+
2. **Modified Files:**
22+
- `public/Get-DbaReplServer.ps1`: Updated to use the replacement classes
23+
- `public/Get-DbaReplDistributor.ps1`: Updated to use the replacement classes
24+
25+
3. **Test Files:**
26+
- `tests/Get-DbaReplDistributor.Tests.ps1`: Tests for the updated Get-DbaReplDistributor command
27+
28+
### Classes Implemented
29+
30+
1. **DbaReplObject**: Base class for all replication objects
31+
2. **DbaReplServer**: Replacement for Microsoft.SqlServer.Replication.ReplicationServer
32+
3. **DbaReplDistributionDatabase**: Replacement for Microsoft.SqlServer.Replication.DistributionDatabase
33+
4. **DbaReplDatabase**: Replacement for Microsoft.SqlServer.Replication.ReplicationDatabase
34+
5. **DbaReplPublication**: Replacement for Microsoft.SqlServer.Replication.Publication
35+
6. **DbaReplArticle**: Replacement for Microsoft.SqlServer.Replication.Article
36+
7. **DbaReplSubscription**: Replacement for Microsoft.SqlServer.Replication.Subscription
37+
38+
## Usage
39+
40+
The usage of the replication commands remains the same as before. The changes are transparent to the end user.
41+
42+
```powershell
43+
# Get replication server information
44+
Get-DbaReplServer -SqlInstance sql2016
45+
46+
# Get distributor information
47+
Get-DbaReplDistributor -SqlInstance sql2016
48+
```
49+
50+
## Limitations
51+
52+
1. Some advanced RMO functionality might not be fully implemented yet.
53+
2. Performance might differ slightly from the original RMO implementation.
54+
55+
## Next Steps
56+
57+
1. Implement the remaining replication commands:
58+
- Get-DbaReplPublication
59+
- Get-DbaReplArticle
60+
- Enable-DbaReplPublishing
61+
- Enable-DbaReplDistributor
62+
- Disable-DbaReplPublishing
63+
- Disable-DbaReplDistributor
64+
- Add-DbaReplArticle
65+
- Remove-DbaReplArticle
66+
- New-DbaReplPublication
67+
- Remove-DbaReplPublication
68+
- New-DbaReplSubscription
69+
- Remove-DbaReplSubscription
70+
- Test-DbaReplLatency
71+
- Export-DbaReplServerSetting
72+
73+
2. Add more comprehensive tests for all implemented commands.
74+
75+
3. Update documentation to reflect the changes.
76+
77+
## Contributing
78+
79+
If you find any issues or have suggestions for improvements, please submit an issue or pull request on GitHub.

Diff for: private/functions/Add-DbaReplicationLibrary.ps1

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function Add-DbaReplicationLibrary {
2+
<#
3+
.SYNOPSIS
4+
Loads the DBA Replication replacement classes.
5+
6+
.DESCRIPTION
7+
Loads the DBA Replication replacement classes that mimic the RMO classes but use T-SQL stored procedures.
8+
This is a replacement for the original Add-ReplicationLibrary function that loaded the Microsoft RMO libraries.
9+
10+
.PARAMETER EnableException
11+
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
12+
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
13+
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
14+
15+
.NOTES
16+
Tags: Replication, RMO
17+
Author: dbatools team
18+
19+
.EXAMPLE
20+
PS C:\> Add-DbaReplicationLibrary
21+
22+
Loads the DBA Replication replacement classes.
23+
#>
24+
[CmdletBinding()]
25+
param (
26+
[switch]$EnableException
27+
)
28+
29+
try {
30+
# Source the DbaReplicationClasses.ps1 file to load our custom classes
31+
$dbaReplClassesPath = Join-DbaPath -Path $script:PSModuleRoot -ChildPath "private\functions\DbaReplicationClasses.ps1"
32+
. $dbaReplClassesPath
33+
34+
Write-Message -Level Verbose -Message "DBA Replication replacement classes loaded successfully."
35+
}
36+
catch {
37+
Stop-Function -Message "Could not load DBA Replication replacement classes." -ErrorRecord $_ -EnableException $EnableException
38+
return
39+
}
40+
}

0 commit comments

Comments
 (0)