-
Notifications
You must be signed in to change notification settings - Fork 4k
Support for Serverless specific parameters for CRUD #9105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e3d76f7
4c21244
d82b629
016d789
0155cb6
33ad5af
a5a34e7
6aa4d7d
ab64e4a
0fd143b
7465bfb
afdc0aa
9958b22
128f008
f1742c2
c50ac2d
2eab05c
70f544c
ba51237
c11bb72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,39 @@ function Test-CreateVcoreDatabaseWithLicenseType | |
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests creating a Serverless based database | ||
#> | ||
function Test-CreateServerlessDatabase | ||
{ | ||
# Setup | ||
$location = Get-Location "Microsoft.Sql" "operations" "Japan East" | ||
$rg = Create-ResourceGroupForTest $location | ||
$server = Create-ServerForTest $rg $location | ||
|
||
try | ||
{ | ||
# Create with Edition and RequestedServiceObjectiveName | ||
$databaseName = Get-DatabaseName | ||
$job1 = New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -RequestedServiceObjectiveName GP_S_Gen5_2 -AutoPauseDelayInMinutes 360 -MinVCore 0.5 -AsJob | ||
$job1 | Wait-Job | ||
$db = $job1.Output | ||
|
||
Assert-AreEqual $databaseName $db.DatabaseName | ||
Assert-NotNull $db.MaxSizeBytes | ||
Assert-AreEqual GP_S_Gen5_2 $db.CurrentServiceObjectiveName | ||
Assert-AreEqual 2 $db.Capacity | ||
Assert-AreEqual 360 $db.AutoPauseDelayInMinutes | ||
Assert-AreEqual 0.5 $db.MinimumCapacity | ||
Assert-AreEqual GeneralPurpose $db.Edition | ||
} | ||
finally | ||
{ | ||
Remove-ResourceGroupForTest $rg | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests creating a database with sample name. | ||
|
@@ -512,6 +545,74 @@ function Test-UpdateDatabaseWithZoneRedundant () | |
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests updating a vcore database | ||
#> | ||
function Test-UpdateServerlessDatabase() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good test, thx |
||
{ | ||
# Setup | ||
$location = Get-Location "Microsoft.Sql" "operations" "Japan East" | ||
$rg = Create-ResourceGroupForTest $location | ||
$server = Create-ServerForTest $rg $location | ||
|
||
$databaseName = Get-DatabaseName | ||
$db = New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName ` | ||
-VCore 2 -Edition GeneralPurpose -ComputeGeneration Gen5 -MaxSizeBytes 250GB -ComputeModel Serverless | ||
Assert-AreEqual $db.DatabaseName $databaseName | ||
|
||
try | ||
{ | ||
# Alter with defaults | ||
$job = Set-AzSqlDatabase -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName ` | ||
-AsJob | ||
$job | Wait-Job | ||
$db1 = $job.Output | ||
|
||
Assert-AreEqual $db1.DatabaseName $db.DatabaseName | ||
Assert-NotNull $db1.MaxSizeBytes | ||
Assert-NotNull $db1.Edition | ||
Assert-NotNull $db1.CurrentServiceObjectiveName | ||
Assert-NotNull $db1.MinimumCapacity | ||
Assert-NotNull $db1.AutoPauseDelayInMinutes | ||
|
||
# Alter to dtu database | ||
$job = Set-AzSqlDatabase -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName ` | ||
-Edition Premium -AsJob | ||
$job | Wait-Job | ||
$db1 = $job.Output | ||
Assert-AreEqual $db1.DatabaseName $db.DatabaseName | ||
Assert-AreEqual $db1.Edition Premium | ||
Assert-Null $db1.MinimumCapacity | ||
Assert-Null $db1.AutoPauseDelayInMinutes | ||
|
||
# Alter back to Serverless | ||
$job = Set-AzSqlDatabase -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName ` | ||
-VCore 2 -Edition GeneralPurpose -ComputeModel Serverless -ComputeGeneration Gen5 -AsJob | ||
$job | Wait-Job | ||
$db1 = $job.Output | ||
Assert-AreEqual $db1.DatabaseName $db.DatabaseName | ||
Assert-AreEqual $db1.Edition GeneralPurpose | ||
Assert-AreEqual $db1.CurrentServiceObjectiveName GP_S_Gen5_2 | ||
Assert-NotNull $db1.MinimumCapacity | ||
Assert-NotNull $db1.AutoPauseDelayInMinutes | ||
|
||
# Alter mincapacity and AutoPauseDelayInMinutes | ||
$job = Set-AzSqlDatabase -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName ` | ||
-Vcore 2 -Edition GeneralPurpose -ComputeModel Serverless -ComputeGeneration Gen5 -MinimumCapacity 2 -AutoPauseDelayInMinutes 1440 -AsJob | ||
$job | Wait-Job | ||
$db1 = $job.Output | ||
Assert-AreEqual $db1.DatabaseName $db.DatabaseName | ||
Assert-AreEqual $db1.Edition GeneralPurpose | ||
Assert-AreEqual $db1.CurrentServiceObjectiveName GP_S_Gen5_2 | ||
Assert-AreEqual $db1.MinimumCapacity 2 | ||
Assert-AreEqual $db1.AutoPauseDelayInMinutes 1440 | ||
} | ||
finally | ||
{ | ||
Remove-ResourceGroupForTest $rg | ||
} | ||
} | ||
<# | ||
.SYNOPSIS | ||
Tests updating a database with zone redundancy not specified | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,16 @@ public class AzureSqlDatabaseModel | |
/// </summary> | ||
public string LicenseType { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the Auto pause delay of the database | ||
/// </summary> | ||
public int? AutoPauseDelayInMinutes { get; set; } | ||
|
||
/// <summary> | ||
/// Minimal capacity that database will always have allocated, if not paused | ||
/// </summary> | ||
public double? MinimumCapacity { get; set; } | ||
|
||
/// <summary> | ||
/// Construct AzureSqlDatabaseModel | ||
/// </summary> | ||
|
@@ -213,6 +223,8 @@ public AzureSqlDatabaseModel(string resourceGroup, string serverName, Management | |
ReadScale = readScale; | ||
|
||
ZoneRedundant = false; | ||
AutoPauseDelayInMinutes = null; | ||
MinimumCapacity = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be setting these. Otherwise they will always be null in response! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I'm wrong. This is converting from legacy model |
||
} | ||
|
||
/// <summary> | ||
|
@@ -259,6 +271,9 @@ public AzureSqlDatabaseModel(string resourceGroup, string serverName, Management | |
SkuName = database.Sku == null ? null : database.Sku.Name; | ||
|
||
LicenseType = database.LicenseType; | ||
|
||
AutoPauseDelayInMinutes = database.AutoPauseDelay; | ||
MinimumCapacity = database.MinCapacity; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Microsoft.Azure.Commands.Sql.Database.Model | ||
{ | ||
public class DatabaseComputeModel | ||
{ | ||
public const string Provisioned = "Provisioned"; | ||
|
||
public const string Serverless = "Serverless"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,7 +157,9 @@ internal AzureSqlDatabaseModel UpsertDatabaseWithNewSdk(string resourceGroup, st | |
SampleName = model.SampleName, | ||
ZoneRedundant = model.Database.ZoneRedundant, | ||
ElasticPoolId = elasticPoolId, | ||
LicenseType = model.Database.LicenseType | ||
LicenseType = model.Database.LicenseType, | ||
AutoPauseDelay = model.Database.AutoPauseDelayInMinutes, | ||
MinCapacity = model.Database.MinimumCapacity, | ||
}); | ||
|
||
return CreateDatabaseModelFromResponse(resourceGroup, serverName, resp); | ||
|
@@ -338,17 +340,20 @@ public void RenameDatabase(string resourceGroupName, string serverName, string d | |
/// Standard | Standard | ||
/// Basic | Basic | ||
/// Premium | Premium | ||
/// | ||
/// Also adds _S in the end of SkuName in case if it is Serverless | ||
/// </summary> | ||
/// <param name="tier">Azure Sql database edition</param> | ||
/// <param name="isServerless">If sku should be serverless type</param> | ||
/// <returns>The sku name</returns> | ||
public static string GetDatabaseSkuName(string tier) | ||
public static string GetDatabaseSkuName(string tier, bool isServerless = false) | ||
{ | ||
if (string.IsNullOrWhiteSpace(tier)) | ||
{ | ||
return null; | ||
} | ||
|
||
return SqlSkuUtils.GetVcoreSkuPrefix(tier) ?? tier; | ||
return (SqlSkuUtils.GetVcoreSkuPrefix(tier) ?? tier) + (isServerless ? "_S" : ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is already a unit test for this method, would be nice if you added |
||
} | ||
|
||
/// <summary> | ||
|
Uh oh!
There was an error while loading. Please reload this page.