Skip to content

Commit 70c8925

Browse files
authored
Move database script annotations to their respective projects (#8535)
Contributes to #7811
1 parent dd6efd7 commit 70c8925

File tree

5 files changed

+58
-29
lines changed

5 files changed

+58
-29
lines changed

src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ public static IResourceBuilder<PostgresDatabaseResource> WithCreationScript(this
419419
ArgumentNullException.ThrowIfNull(builder);
420420
ArgumentNullException.ThrowIfNull(script);
421421

422-
builder.WithAnnotation(new CreationScriptAnnotation(script));
422+
builder.WithAnnotation(new PostgresCreateDatabaseScriptAnnotation(script));
423423

424424
return builder;
425425
}
@@ -493,7 +493,7 @@ private static string WritePgAdminServerJson(IEnumerable<PostgresServerResource>
493493

494494
private static async Task CreateDatabaseAsync(NpgsqlConnection npgsqlConnection, PostgresDatabaseResource npgsqlDatabase, IServiceProvider serviceProvider, CancellationToken cancellationToken)
495495
{
496-
var scriptAnnotation = npgsqlDatabase.Annotations.OfType<CreationScriptAnnotation>().LastOrDefault();
496+
var scriptAnnotation = npgsqlDatabase.Annotations.OfType<PostgresCreateDatabaseScriptAnnotation>().LastOrDefault();
497497

498498
try
499499
{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Aspire.Hosting.ApplicationModel;
5+
6+
namespace Aspire.Hosting.Postgres;
7+
8+
/// <summary>
9+
/// Represents an annotation for defining a script to create a database in PostgreSQL.
10+
/// </summary>
11+
internal sealed class PostgresCreateDatabaseScriptAnnotation : IResourceAnnotation
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="PostgresCreateDatabaseScriptAnnotation"/> class.
15+
/// </summary>
16+
/// <param name="script">The script used to create the database.</param>
17+
public PostgresCreateDatabaseScriptAnnotation(string script)
18+
{
19+
ArgumentNullException.ThrowIfNull(script);
20+
Script = script;
21+
}
22+
23+
/// <summary>
24+
/// Gets the script used to create the database.
25+
/// </summary>
26+
public string Script { get; }
27+
}

src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public static IResourceBuilder<SqlServerDatabaseResource> WithCreationScript(thi
195195
ArgumentNullException.ThrowIfNull(builder);
196196
ArgumentNullException.ThrowIfNull(script);
197197

198-
builder.WithAnnotation(new CreationScriptAnnotation(script));
198+
builder.WithAnnotation(new SqlServerCreateDatabaseScriptAnnotation(script));
199199

200200
return builder;
201201
}
@@ -204,7 +204,7 @@ private static async Task CreateDatabaseAsync(SqlConnection sqlConnection, SqlSe
204204
{
205205
try
206206
{
207-
var scriptAnnotation = sqlDatabase.Annotations.OfType<CreationScriptAnnotation>().LastOrDefault();
207+
var scriptAnnotation = sqlDatabase.Annotations.OfType<SqlServerCreateDatabaseScriptAnnotation>().LastOrDefault();
208208

209209
if (scriptAnnotation?.Script == null)
210210
{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Aspire.Hosting.ApplicationModel;
5+
6+
namespace Aspire.Hosting;
7+
8+
/// <summary>
9+
/// Represents an annotation for defining a script to create a database in SQL Server.
10+
/// </summary>
11+
internal sealed class SqlServerCreateDatabaseScriptAnnotation : IResourceAnnotation
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="SqlServerCreateDatabaseScriptAnnotation"/> class.
15+
/// </summary>
16+
/// <param name="script">The script used to create the database.</param>
17+
public SqlServerCreateDatabaseScriptAnnotation(string script)
18+
{
19+
ArgumentNullException.ThrowIfNull(script);
20+
Script = script;
21+
}
22+
23+
/// <summary>
24+
/// Gets the script used to create the database.
25+
/// </summary>
26+
public string Script { get; }
27+
}

src/Aspire.Hosting/ApplicationModel/CreationScriptAnnotation.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)