Skip to content

Commit bb0f64c

Browse files
committed
Add PartnerDatabaseName to New-AzSqlDatabaseSecondary cmdlet
1 parent 8441690 commit bb0f64c

File tree

9 files changed

+3538
-5
lines changed

9 files changed

+3538
-5
lines changed

src/Sql/Sql.Test/ScenarioTests/DatabaseReplicationTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public void TestCreateSecondaryDatabase()
4646
RunPowerShellTest("Test-CreateSecondaryDatabase");
4747
}
4848

49+
[Fact]
50+
[Trait(Category.AcceptanceType, Category.CheckIn)]
51+
public void TestCreateNamedSecondaryDatabase()
52+
{
53+
RunPowerShellTest("Test-CreateNamedSecondaryDatabase");
54+
}
55+
4956
[Fact]
5057
[Trait(Category.AcceptanceType, Category.CheckIn)]
5158
public void TestGetReplicationLink()

src/Sql/Sql.Test/ScenarioTests/DatabaseReplicationTests.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,48 @@ function Test-CreateSecondaryDatabase()
155155
}
156156
}
157157

158+
<#
159+
.SYNOPSIS
160+
Tests creating a named secondary database
161+
#>
162+
function Test-CreateNamedSecondaryDatabase()
163+
{
164+
# Setup
165+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
166+
$rg = Create-ResourceGroupForTest $location
167+
$server = Create-ServerForTest $rg $location
168+
$database = Create-DatabaseForTest $rg $server
169+
170+
$partRg = Create-ResourceGroupForTest $location
171+
$partServer = Create-ServerForTest $partRg $location
172+
173+
try
174+
{
175+
# Create Named Readable Secondary
176+
$readSecondary = New-AzSqlDatabaseSecondary -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $database.DatabaseName `
177+
-PartnerResourceGroupName $partRg.ResourceGroupName -PartnerServerName $partServer.ServerName -PartnerDatabaseName "secondary" -AllowConnections All
178+
Assert-NotNull $readSecondary.LinkId
179+
Assert-AreEqual $readSecondary.ResourceGroupName $rg.ResourceGroupName
180+
Assert-AreEqual $readSecondary.ServerName $server.ServerName
181+
Assert-AreEqual $readSecondary.DatabaseName $database.DatabaseName
182+
Assert-AreEqual $readSecondary.Role "Primary"
183+
Assert-AreEqual $readSecondary.Location $location
184+
Assert-AreEqual $readSecondary.PartnerResourceGroupName $partRg.ResourceGroupName
185+
Assert-AreEqual $readSecondary.PartnerServerName $partServer.ServerName
186+
Assert-AreEqual $readSecondary.PartnerDatabaseName "secondary"
187+
Assert-NotNull $readSecondary.PartnerRole
188+
Assert-AreEqual $readSecondary.PartnerLocation $location
189+
Assert-NotNull $readSecondary.AllowConnections
190+
Assert-NotNull $readSecondary.ReplicationState
191+
Assert-NotNull $readSecondary.PercentComplete
192+
}
193+
finally
194+
{
195+
Remove-ResourceGroupForTest $rg
196+
Remove-ResourceGroupForTest $partRg
197+
}
198+
}
199+
158200
<#
159201
.SYNOPSIS
160202
Tests getting a secondary database

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseReplicationTests/TestCreateNamedSecondaryDatabase.json

Lines changed: 3451 additions & 0 deletions
Large diffs are not rendered by default.

src/Sql/Sql/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
## Upcoming Release
2121
* Fix vulnerability assessment set baseline cmdlets functionality to work on master db for azure database and limit it on managed instance system databases.
2222
* Fix an error when creating SQL instance failover group
23+
* Added PartnerDatabaseName parameter to New-AzSqlDatabaseSecondary cmdlet.
2324

2425
## Version 2.1.1
2526
* Update references in .psd1 to use relative path

src/Sql/Sql/Replication/Cmdlet/NewAzureSqlDatabaseSecondary.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ public class NewAzureSqlDatabaseSecondary : AzureSqlDatabaseSecondaryCmdletBase
8888
[ValidateNotNullOrEmpty]
8989
public string PartnerServerName { get; set; }
9090

91+
/// <summary>
92+
/// Gets or sets the name of the secondary.
93+
/// </summary>
94+
[Parameter(Mandatory = false,
95+
HelpMessage = "The name of the secondary database to create.")]
96+
[ValidateNotNullOrEmpty]
97+
public string PartnerDatabaseName { get; set; }
98+
9199
/// <summary>
92100
/// Gets or sets the read intent of the secondary (ReadOnly is not yet supported).
93101
/// </summary>
@@ -187,6 +195,7 @@ protected override IEnumerable<AzureReplicationLinkModel> ApplyUserInputToModel(
187195
DatabaseName = this.DatabaseName,
188196
PartnerResourceGroupName = this.PartnerResourceGroupName,
189197
PartnerServerName = this.PartnerServerName,
198+
PartnerDatabaseName = string.IsNullOrWhiteSpace(this.PartnerDatabaseName) ? this.DatabaseName : this.PartnerDatabaseName,
190199
SecondaryElasticPoolName = this.SecondaryElasticPoolName,
191200
AllowConnections = this.AllowConnections,
192201
Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),

src/Sql/Sql/Replication/Model/AzureReplicationLinkModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public class AzureReplicationLinkModel : AzureSqlDatabaseReplicationModelBase
3232
/// </summary>
3333
public string PartnerServerName { get; set; }
3434

35+
/// <summary>
36+
/// Gets or sets the name of the secondary
37+
/// </summary>
38+
public string PartnerDatabaseName { get; set; }
39+
3540
/// <summary>
3641
/// Get or sets the AllowConnections setting for the Replication Link
3742
/// </summary>

src/Sql/Sql/Replication/Services/AzureSqlDatabaseReplicationAdapter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ internal AzureReplicationLinkModel CreateLinkWithNewSdk(string resourceGroupName
259259
serverName,
260260
model.SecondaryElasticPoolName);
261261

262-
var resp = ReplicationCommunicator.CreateCopy(resourceGroupName, serverName, model.DatabaseName, new Management.Sql.Models.Database
262+
var resp = ReplicationCommunicator.CreateCopy(resourceGroupName, serverName, model.PartnerDatabaseName, new Management.Sql.Models.Database
263263
{
264264
Location = model.PartnerLocation,
265265
SourceDatabaseId = string.Format(AzureReplicationLinkModel.SourceIdTemplate, _subscription.Id.ToString(),
@@ -348,6 +348,7 @@ private AzureReplicationLinkModel CreateReplicationLinkModelFromReplicationLinkR
348348
model.LinkId = new Guid(resp.Name);
349349
model.PartnerResourceGroupName = partnerResourceGroupName;
350350
model.PartnerServerName = resp.Properties.PartnerServer;
351+
model.PartnerDatabaseName = resp.Properties.PartnerDatabase;
351352
model.ResourceGroupName = resourceGroupName;
352353
model.ServerName = serverName;
353354
model.DatabaseName = databaseName;
@@ -385,6 +386,7 @@ private AzureReplicationLinkModel CreateReplicationLinkModelFromResponse(string
385386
model.LinkId = new Guid(resp.Name);
386387
model.PartnerResourceGroupName = partnerResourceGroupName;
387388
model.PartnerServerName = resp.PartnerServer;
389+
model.PartnerDatabaseName = resp.PartnerDatabase;
388390
model.ResourceGroupName = resourceGroupName;
389391
model.ServerName = serverName;
390392
model.DatabaseName = databaseName;

src/Sql/Sql/Sql.types.ps1xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<Name>Location</Name>
1818
<Name>PartnerResourceGroupName</Name>
1919
<Name>PartnerServerName</Name>
20+
<Name>PartnerDatabaseName</Name>
2021
<Name>PartnerRole</Name>
2122
<Name>PartnerLocation</Name>
2223
<Name>AllowConnections</Name>

src/Sql/Sql/help/New-AzSqlDatabaseSecondary.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ Creates a secondary database for an existing database and starts data replicatio
1717
```
1818
New-AzSqlDatabaseSecondary [-DatabaseName] <String> [-SecondaryServiceObjectiveName <String>]
1919
[-SecondaryElasticPoolName <String>] [-Tags <Hashtable>] -PartnerResourceGroupName <String>
20-
-PartnerServerName <String> [-AllowConnections <AllowConnections>] [-AsJob] [-LicenseType <String>]
21-
[-ServerName] <String> [-ResourceGroupName] <String> [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
22-
[-Confirm] [<CommonParameters>]
20+
-PartnerServerName <String> [-PartnerDatabaseName <String>] [-AllowConnections <AllowConnections>] [-AsJob]
21+
[-LicenseType <String>] [-ServerName] <String> [-ResourceGroupName] <String>
22+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2323
```
2424

2525
### VcoreBasedDatabase
2626
```
2727
New-AzSqlDatabaseSecondary [-DatabaseName] <String> [-Tags <Hashtable>] -PartnerResourceGroupName <String>
28-
-PartnerServerName <String> [-AllowConnections <AllowConnections>] [-AsJob]
28+
-PartnerServerName <String> [-PartnerDatabaseName <String>] [-AllowConnections <AllowConnections>] [-AsJob]
2929
-SecondaryComputeGeneration <String> -SecondaryVCore <Int32> [-LicenseType <String>] [-ServerName] <String>
3030
[-ResourceGroupName] <String> [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
3131
[<CommonParameters>]
@@ -125,6 +125,21 @@ Accept pipeline input: False
125125
Accept wildcard characters: False
126126
```
127127
128+
### -PartnerDatabaseName
129+
The name of the secondary database to create.
130+
131+
```yaml
132+
Type: System.String
133+
Parameter Sets: (All)
134+
Aliases:
135+
136+
Required: False
137+
Position: Named
138+
Default value: None
139+
Accept pipeline input: False
140+
Accept wildcard characters: False
141+
```
142+
128143
### -PartnerResourceGroupName
129144
Specifies the name of the Azure Resource Group to which this cmdlet assigns the secondary database.
130145

0 commit comments

Comments
 (0)