Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.

namespace Microsoft.Azure.Management.Sql
{
using Microsoft.Rest.Azure;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

internal partial class DatabasesOperations
{
/// <summary>
/// Renames a database.
/// </summary>
/// <param name='resourceGroupName'>
/// The name of the resource group that contains the resource. You can
/// obtain this value from the Azure Resource Manager API or the
/// portal.
/// </param>
/// <param name='serverName'>
/// The name of the server.
/// </param>
/// <param name='databaseName'>
/// The name of the database to rename.
/// </param>
/// <param name='newName'>
/// The new name that the database should be renamed to.
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
/// <exception cref="Microsoft.Rest.Azure.CloudException">
/// Thrown when the operation returned an invalid status code
/// </exception>
/// <exception cref="Microsoft.Rest.ValidationException">
/// Thrown when a required parameter is null
/// </exception>
public async Task<AzureOperationResponse> RenameWithHttpMessagesAsync(
string resourceGroupName,
string serverName,
string databaseName,
string newName,
Dictionary<string, List<string>> customHeaders = null,
CancellationToken cancellationToken = default(CancellationToken))
{
return await this.RenameWithHttpMessagesAsync(
resourceGroupName,
serverName,
databaseName,
new Models.ResourceMoveDefinition(
string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}/databases/{3}",
this.Client.SubscriptionId,
resourceGroupName,
serverName,
newName)),
customHeaders,
cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.

namespace Microsoft.Azure.Management.Sql
{
using System.Threading;
using System.Threading.Tasks;

public partial class DatabasesOperationsExtensions
{
/// <summary>
/// Renames a database.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='resourceGroupName'>
/// The name of the resource group that contains the resource. You can obtain
/// this value from the Azure Resource Manager API or the portal.
/// </param>
/// <param name='serverName'>
/// The name of the server.
/// </param>
/// <param name='databaseName'>
/// The name of the database to rename.
/// </param>
/// <param name='newName'>
/// The new name that the database should be renamed to.
/// </param>
public static void Rename(
this IDatabasesOperations operations,
string resourceGroupName,
string serverName,
string databaseName,
string newName)
{
RenameAsync(operations, resourceGroupName, serverName, databaseName, newName).GetAwaiter().GetResult();
}

/// <summary>
/// Renames a database.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='resourceGroupName'>
/// The name of the resource group that contains the resource. You can obtain
/// this value from the Azure Resource Manager API or the portal.
/// </param>
/// <param name='serverName'>
/// The name of the server.
/// </param>
/// <param name='databaseName'>
/// The name of the database to rename.
/// </param>
/// <param name='newName'>
/// The new name that the database should be renamed to.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
public static async Task RenameAsync(
this IDatabasesOperations operations,
string resourceGroupName,
string serverName,
string databaseName,
string newName,
CancellationToken cancellationToken = default(CancellationToken))
{
(await operations.RenameWithHttpMessagesAsync(
resourceGroupName,
serverName,
databaseName,
newName,
null,
cancellationToken).ConfigureAwait(false)).Dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.

namespace Microsoft.Azure.Management.Sql
{
using Microsoft.Rest.Azure;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

public partial interface IDatabasesOperations
{
/// <summary>
/// Renames a database.
/// </summary>
/// <param name='resourceGroupName'>
/// The name of the resource group that contains the resource. You can
/// obtain this value from the Azure Resource Manager API or the
/// portal.
/// </param>
/// <param name='serverName'>
/// The name of the server.
/// </param>
/// <param name='databaseName'>
/// The name of the database to rename.
/// </param>
/// <param name='newName'>
/// The new name that the database should be renamed to.
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
/// <exception cref="Microsoft.Rest.Azure.CloudException">
/// Thrown when the operation returned an invalid status code
/// </exception>
/// <exception cref="Microsoft.Rest.ValidationException">
/// Thrown when a required parameter is null
/// </exception>
Task<AzureOperationResponse> RenameWithHttpMessagesAsync(
string resourceGroupName,
string serverName,
string databaseName,
string newName,
Dictionary<string, List<string>> customHeaders = null,
CancellationToken cancellationToken = default(CancellationToken));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReleaseNotes>
<![CDATA[
New features:
- Added more convenient method to rename databases, `Databases.Rename(resourceGroupName, serverName, databaseName, newName)`.
- Added support for Auto-tuning REST API
]]>
</PackageReleaseNotes>
Expand Down
16 changes: 13 additions & 3 deletions src/SDKs/SqlManagement/Sql.Tests/DatabaseCrudScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void TestRenameDatabase()
});
Assert.NotNull(db1);

// Rename
// Rename using id
string newSuffix = "_renamed";
string newName = db1.Name + newSuffix;
string newId = db1.Id + newSuffix;
Expand All @@ -136,8 +136,18 @@ public void TestRenameDatabase()
});

// Get database at its new id
Database db2 = sqlClient.Databases.Get(resourceGroup.Name, server.Name, newName);
Assert.Equal(newId, db2.Id);
Database newDb = sqlClient.Databases.Get(resourceGroup.Name, server.Name, newName);
Assert.Equal(newId, newDb.Id);

// Rename using new name
string newSuffix2 = "2";
string newName2 = newName + newSuffix2;
string newId2 = newId + newSuffix2;
sqlClient.Databases.Rename(resourceGroup.Name, server.Name, newName, newName2);

// Get database at its new id
Database newDb2 = sqlClient.Databases.Get(resourceGroup.Name, server.Name, newName2);
Assert.Equal(newId2, newDb2.Id);
}
}

Expand Down
Loading