Skip to content

Commit

Permalink
Tweak the API for Azure edition options.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd committed Oct 23, 2019
1 parent 3691782 commit a618f06
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 108 deletions.
86 changes: 64 additions & 22 deletions src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public static bool CanSetDatabaseMaxSize(
/// Configures the service tier (EDITION) for Azure SQL Database.
/// </para>
/// <para>
/// Literals should be delimited with ''. See Azure SQL Database documentation for supported values.
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
Expand All @@ -333,32 +333,53 @@ public static ModelBuilder HasServiceTier([NotNull] this ModelBuilder modelBuild
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NotNull(serviceTier, nameof(serviceTier));

modelBuilder.Model.SetServiceTier(serviceTier);
modelBuilder.Model.SetServiceTierSql("'" + serviceTier + "'");

return modelBuilder;
}

/// <summary>
/// <para>
/// Attempts to configure the service tier (EDITION) for Azure SQL Database.
/// Configures the service tier (EDITION) for Azure SQL Database.
/// </para>
/// <para>
/// Literals should be delimited with ''. See Azure SQL Database documentation for supported values.
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="serviceTier"> The service tier of the database. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static ModelBuilder HasServiceTierSql([NotNull] this ModelBuilder modelBuilder, [NotNull] string serviceTier)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NotNull(serviceTier, nameof(serviceTier));

modelBuilder.Model.SetServiceTierSql(serviceTier);

return modelBuilder;
}

/// <summary>
/// <para>
/// Attempts to configure the service tier (EDITION) for Azure SQL Database.
/// </para>
/// <para>
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="serviceTier"> The expression for service tier of the database. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns>
/// The same builder instance if the configuration was applied,
/// <c>null</c> otherwise.
/// </returns>
public static IConventionModelBuilder HasServiceTier(
public static IConventionModelBuilder HasServiceTierSql(
[NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string serviceTier, bool fromDataAnnotation = false)
{
if (modelBuilder.CanSetServiceTier(serviceTier, fromDataAnnotation))
if (modelBuilder.CanSetServiceTierSql(serviceTier, fromDataAnnotation))
{
modelBuilder.Metadata.SetServiceTier(serviceTier, fromDataAnnotation);
modelBuilder.Metadata.SetServiceTierSql(serviceTier, fromDataAnnotation);
return modelBuilder;
}

Expand All @@ -369,59 +390,80 @@ public static IConventionModelBuilder HasServiceTier(
/// Returns a value indicating whether the given value can be set as the service tier of the database.
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="serviceTier"> The service tier of the database. </param>
/// <param name="serviceTier"> The expression for service tier of the database. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <c>true</c> if the given value can be set as the service tier of the database. </returns>
public static bool CanSetServiceTier(
public static bool CanSetServiceTierSql(
[NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string serviceTier, bool fromDataAnnotation = false)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));

return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.ServiceTier, serviceTier, fromDataAnnotation);
return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.ServiceTierSql, serviceTier, fromDataAnnotation);
}

/// <summary>
/// <para>
/// Configures the performance level (SERVICE_OBJECTIVE) for Azure SQL Database.
/// </para>
/// <para>
/// Literals should be delimited with ''. See Azure SQL Database documentation for supported values.
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="performanceLevel"> The performance level of the database. </param>
/// <param name="performanceLevel"> The string literal performance level of the database. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static ModelBuilder HasPerformanceLevel([NotNull] this ModelBuilder modelBuilder, [NotNull] string performanceLevel)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NotNull(performanceLevel, nameof(performanceLevel));

modelBuilder.Model.SetPerformanceLevel(performanceLevel);
modelBuilder.Model.SetPerformanceLevelSql("'" + performanceLevel + "'");

return modelBuilder;
}

/// <summary>
/// <para>
/// Configures the performance level expression (SERVICE_OBJECTIVE) for Azure SQL Database.
/// </para>
/// <para>
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="performanceLevel"> The expression for performance level of the database. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static ModelBuilder HasPerformanceLevelSql([NotNull] this ModelBuilder modelBuilder, [NotNull] string performanceLevel)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NotNull(performanceLevel, nameof(performanceLevel));

modelBuilder.Model.SetPerformanceLevelSql(performanceLevel);

return modelBuilder;
}

/// <summary>
/// <para>
/// Attempts to configure the performance level (SERVICE_OBJECTIVE) for Azure SQL Database.
/// Attempts to configure the performance level expression (SERVICE_OBJECTIVE) for Azure SQL Database.
/// </para>
/// <para>
/// Literals should be delimited with ''. See Azure SQL Database documentation for supported values.
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="performanceLevel"> The performance level of the database. </param>
/// <param name="performanceLevel"> The expression for performance level of the database. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns>
/// The same builder instance if the configuration was applied,
/// <c>null</c> otherwise.
/// </returns>
public static IConventionModelBuilder HasPerformanceLevel(
public static IConventionModelBuilder HasPerformanceLevelSql(
[NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string performanceLevel, bool fromDataAnnotation = false)
{
if (modelBuilder.CanSetPerformanceLevel(performanceLevel, fromDataAnnotation))
if (modelBuilder.CanSetPerformanceLevelSql(performanceLevel, fromDataAnnotation))
{
modelBuilder.Metadata.SetPerformanceLevel(performanceLevel, fromDataAnnotation);
modelBuilder.Metadata.SetPerformanceLevelSql(performanceLevel, fromDataAnnotation);
return modelBuilder;
}

Expand All @@ -432,15 +474,15 @@ public static IConventionModelBuilder HasPerformanceLevel(
/// Returns a value indicating whether the given value can be set as the performance level of the database.
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="performanceLevel"> The performance level of the database. </param>
/// <param name="performanceLevel"> The performance level of the database expression. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <c>true</c> if the given value can be set as the performance level of the database. </returns>
public static bool CanSetPerformanceLevel(
public static bool CanSetPerformanceLevelSql(
[NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string performanceLevel, bool fromDataAnnotation = false)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));

return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.PerformanceLevel, performanceLevel, fromDataAnnotation);
return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.PerformanceLevelSql, performanceLevel, fromDataAnnotation);
}

/// <summary>
Expand Down
34 changes: 17 additions & 17 deletions src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,75 +250,75 @@ public static void SetDatabaseMaxSize(
/// </summary>
/// <param name="model"> The model. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the maximum size of the database. </returns>
public static ConfigurationSource? GetMaxSizeConfigurationSource([NotNull] this IConventionModel model)
public static ConfigurationSource? GetDatabaseMaxSizeConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(SqlServerAnnotationNames.MaxDatabaseSize)?.GetConfigurationSource();

/// <summary>
/// Returns the service tier of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <returns> The service tier of the database. </returns>
public static string GetServiceTier([NotNull] this IModel model)
=> (string)model[SqlServerAnnotationNames.ServiceTier];
public static string GetServiceTierSql([NotNull] this IModel model)
=> (string)model[SqlServerAnnotationNames.ServiceTierSql];

/// <summary>
/// Sets the service tier of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <param name="value"> The value to set. </param>
public static void SetServiceTier([NotNull] this IMutableModel model, [CanBeNull] string value)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTier, value);
public static void SetServiceTierSql([NotNull] this IMutableModel model, [CanBeNull] string value)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTierSql, value);

/// <summary>
/// Sets the service tier of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <param name="value"> The value to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetServiceTier(
public static void SetServiceTierSql(
[NotNull] this IConventionModel model, [CanBeNull] string value, bool fromDataAnnotation = false)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTier, value, fromDataAnnotation);
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTierSql, value, fromDataAnnotation);

/// <summary>
/// Returns the <see cref="ConfigurationSource" /> for the service tier of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the service tier of the database. </returns>
public static ConfigurationSource? GetServiceTierConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(SqlServerAnnotationNames.ServiceTier)?.GetConfigurationSource();
public static ConfigurationSource? GetServiceTierSqlConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(SqlServerAnnotationNames.ServiceTierSql)?.GetConfigurationSource();

/// <summary>
/// Returns the performance level of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <returns> The performance level of the database. </returns>
public static string GetPerformanceLevel([NotNull] this IModel model)
=> (string)model[SqlServerAnnotationNames.PerformanceLevel];
public static string GetPerformanceLevelSql([NotNull] this IModel model)
=> (string)model[SqlServerAnnotationNames.PerformanceLevelSql];

/// <summary>
/// Sets the performance level of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <param name="value"> The value to set. </param>
public static void SetPerformanceLevel([NotNull] this IMutableModel model, [CanBeNull] string value)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevel, value);
public static void SetPerformanceLevelSql([NotNull] this IMutableModel model, [CanBeNull] string value)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevelSql, value);

/// <summary>
/// Sets the performance level of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <param name="value"> The value to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetPerformanceLevel(
public static void SetPerformanceLevelSql(
[NotNull] this IConventionModel model, [CanBeNull] string value, bool fromDataAnnotation = false)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevel, value, fromDataAnnotation);
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevelSql, value, fromDataAnnotation);

/// <summary>
/// Returns the <see cref="ConfigurationSource" /> for the performance level of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the performance level of the database. </returns>
public static ConfigurationSource? GetPerformanceLevelConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(SqlServerAnnotationNames.PerformanceLevel)?.GetConfigurationSource();
public static ConfigurationSource? GetPerformanceLevelSqlConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(SqlServerAnnotationNames.PerformanceLevelSql)?.GetConfigurationSource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ public static class SqlServerAnnotationNames
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public const string ServiceTier = Prefix + "ServiceTier";
public const string ServiceTierSql = Prefix + "ServiceTierSql";

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public const string PerformanceLevel = Prefix + "PerformanceLevel";
public const string PerformanceLevelSql = Prefix + "PerformanceLevelSql";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand Down Expand Up @@ -48,8 +47,8 @@ public SqlServerMigrationsAnnotationProvider([NotNull] MigrationsAnnotationProvi
public override IEnumerable<IAnnotation> For(IModel model)
{
var maxSize = model.GetDatabaseMaxSize();
var serviceTier = model.GetServiceTier();
var performanceLevel = model.GetPerformanceLevel();
var serviceTier = model.GetServiceTierSql();
var performanceLevel = model.GetPerformanceLevelSql();
if (maxSize != null
|| serviceTier != null
|| performanceLevel != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,16 @@ public virtual void Model_annotations_are_stored_in_snapshot()
Test(
builder => builder.HasAnnotation("AnnotationName", "AnnotationValue")
.HasDatabaseMaxSize("100 MB")
.HasServiceTier("'basic'")
.HasPerformanceLevel("'S0'"),
.HasServiceTier("basic")
.HasPerformanceLevel("S0"),
AddBoilerPlate(
@"
modelBuilder
.HasAnnotation(""AnnotationName"", ""AnnotationValue"")
.HasAnnotation(""Relational:MaxIdentifierLength"", 128)
.HasAnnotation(""SqlServer:DatabaseMaxSize"", ""100 MB"")
.HasAnnotation(""SqlServer:PerformanceLevel"", ""'S0'"")
.HasAnnotation(""SqlServer:ServiceTier"", ""'basic'"")
.HasAnnotation(""SqlServer:PerformanceLevelSql"", ""'S0'"")
.HasAnnotation(""SqlServer:ServiceTierSql"", ""'basic'"")
.HasAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn);"),
o =>
{
Expand Down
Loading

0 comments on commit a618f06

Please sign in to comment.