Skip to content

Commit 3d83731

Browse files
authored
Merge pull request Azure#5009 from jaredmoo/renameDb
Command to Rename SQL database
2 parents 746e529 + 3ba2e0e commit 3d83731

File tree

154 files changed

+209869
-199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+209869
-199
lines changed

src/ResourceManager/Sql/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Added ability to rename database using Set-AzureRmSqlDatabase
2122

2223
## Version 4.0.1
2324
* Fixed assembly loading issue that caused some cmdlets to fail when executing

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@
8181
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.15.1.0-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
8282
</Reference>
8383
<Reference Include="Microsoft.Azure.Management.Sql, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
84-
<SpecificVersion>False</SpecificVersion>
85-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.8.0-preview\lib\net452\Microsoft.Azure.Management.Sql.dll</HintPath>
84+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.10.0-preview\lib\net452\Microsoft.Azure.Management.Sql.dll</HintPath>
8685
<Private>True</Private>
8786
</Reference>
8887
<Reference Include="Microsoft.Azure.Management.Storage">
@@ -263,7 +262,7 @@
263262
<None Include="ScenarioTests\DatabaseCrudStretchTests.ps1">
264263
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
265264
</None>
266-
<None Include="ScenarioTests\ServerDnsAliasTests.ps1" >
265+
<None Include="ScenarioTests\ServerDnsAliasTests.ps1">
267266
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
268267
</None>
269268
<None Include="ScenarioTests\ServerUpgradeTests.ps1">
@@ -668,6 +667,9 @@
668667
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudTests\TestDatabaseRemove.json">
669668
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
670669
</None>
670+
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudTests\TestDatabaseRename.json">
671+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
672+
</None>
671673
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudTests\TestDatabaseUpdate.json">
672674
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
673675
</None>
@@ -989,16 +991,16 @@
989991
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.VirtualNetworkRuleTest\TestVirtualNetworkRuleRemove.json">
990992
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
991993
</None>
992-
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerDnsAliasTests\TestCreateServerDnsAlias.json">
994+
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerDnsAliasTests\TestCreateServerDnsAlias.json">
993995
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
994996
</None>
995-
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerDnsAliasTests\TestServerDnsAliasGet.json">
997+
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerDnsAliasTests\TestServerDnsAliasGet.json">
996998
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
997999
</None>
998-
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerDnsAliasTests\TestServerDnsAliasUpdate.json">
1000+
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerDnsAliasTests\TestServerDnsAliasUpdate.json">
9991001
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
10001002
</None>
1001-
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerDnsAliasTests\TestServerDnsAliasRemove.json">
1003+
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerDnsAliasTests\TestServerDnsAliasRemove.json">
10021004
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
10031005
</None>
10041006
</ItemGroup>

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DatabaseCrudTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ public void TestDatabaseUpdateWithZoneRedundancyNotSpecified()
8080
RunPowerShellTest("Test-UpdateDatabaseWithZoneRedundantNotSpecified");
8181
}
8282

83+
[Fact]
84+
[Trait(Category.AcceptanceType, Category.CheckIn)]
85+
public void TestDatabaseRename()
86+
{
87+
RunPowerShellTest("Test-RenameDatabase");
88+
}
89+
8390
[Fact]
8491
[Trait(Category.AcceptanceType, Category.CheckIn)]
8592
public void TestDatabaseGet()

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DatabaseCrudTests.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,48 @@ function Test-UpdateDatabaseWithZoneRedundantNotSpecified ()
329329
}
330330
}
331331

332+
<#
333+
.SYNOPSIS
334+
Tests renaming a database
335+
#>
336+
function Test-RenameDatabase
337+
{
338+
# Setup
339+
$rg = Create-ResourceGroupForTest
340+
341+
try
342+
{
343+
$location = "westcentralus"
344+
$server = Create-ServerForTest $rg $location
345+
346+
# Create with default values
347+
$databaseName = Get-DatabaseName
348+
$db1 = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -MaxSizeBytes 1GB
349+
Assert-AreEqual $db1.DatabaseName $databaseName
350+
351+
# Rename with params
352+
$name2 = "name2"
353+
$db2 = Set-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -NewName $name2
354+
Assert-AreEqual $db2.DatabaseName $name2
355+
356+
Assert-ThrowsContains -script { $db1 | Get-AzureRmSqlDatabase } -message "not found"
357+
$db2 | Get-AzureRmSqlDatabase
358+
359+
# Rename with piping
360+
$name3 = "name3"
361+
$db3 = $db2 | Set-AzureRmSqlDatabase -NewName $name3
362+
Assert-AreEqual $db3.DatabaseName $name3
363+
364+
Assert-ThrowsContains -script { $db1 | Get-AzureRmSqlDatabase } -message "not found"
365+
Assert-ThrowsContains -script { $db2 | Get-AzureRmSqlDatabase } -message "not found"
366+
$db3 | Get-AzureRmSqlDatabase
367+
}
368+
finally
369+
{
370+
Remove-ResourceGroupForTest $rg
371+
}
372+
}
373+
332374

333375
<#
334376
.SYNOPSIS

0 commit comments

Comments
 (0)