You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Initial corrections.
* Updated MySQL and PostgreSQL data seeding sections for Apsire 9.3
* One small correction.
* Corrected one code link.
* Incorporated feedback from @adegeo.
Copy file name to clipboardExpand all lines: docs/database/seed-database-data.md
+16-10Lines changed: 16 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -36,11 +36,11 @@ By default, .NET Aspire database integrations rely on containerized databases, w
36
36
37
37
## Seed data using SQL scripts
38
38
39
-
In .NET Aspire 9.2, the recommended method for executing database seeding scripts depends on the database server you use:
39
+
The recommended method for executing database seeding scripts depends on the database server you use:
40
40
41
41
### [SQL Server](#tab/sql-server)
42
42
43
-
In .NET Aspire 9.2 and later versions, you can use the <xref:Aspire.Hosting.SqlServerBuilderExtensions.WithCreationScript*> method to ensure a T-SQL script is run when the database is created. Add SQL code to this script that creates and populates the database, the necessary tables, and other database objects.
43
+
Starting with .NET Aspire 9.2, you can use the <xref:Aspire.Hosting.SqlServerBuilderExtensions.WithCreationScript*> method to ensure a T-SQL script is run when the database is created. Add SQL code to this script that creates and populates the database, the necessary tables, and other database objects.
44
44
45
45
The following code is an example T-SQL script that creates and populates an address book database:
46
46
@@ -56,7 +56,7 @@ Next, in the app host's *AppHost.cs* (or *Program.cs*) file, create the database
- Create a SQL Server container by calling `builder.AddSqlServer()`.
62
62
- Ensures that data is persisted across debugging sessions by calling `WithDataVolume()` and `WithLifetime(ContainerLifetime.Persistent)`.
@@ -65,7 +65,7 @@ This code:
65
65
66
66
### [PostgreSQL](#tab/postgresql)
67
67
68
-
In .NET Aspire 9.2, the `WithCreationScript()` method isn't supported for the PostgreSQL integration. Instead, you must use a bind mount and deploy the setup SQL script to it, so that the data is seeded when the container initializes the database.
68
+
Starting with .NET Aspire 9.3, the `WithCreationScript()` method is supported for the PostgreSQL integration but, because there is no `USE DATABASE` in PostgreSQL, it only supports operations against the default database. For example, you can issue `CREATE DATABASE` statements to create other databases, but you can't populate them with tables and data. Instead, you must use a bind mount and deploy the setup SQL script to it, so that the data is seeded when the container initializes the database.
69
69
70
70
The following code is an example PostgreSQL script that creates and populates a to do list database:
71
71
@@ -77,15 +77,21 @@ In the app host's *AppHost.cs* (or *Program.cs*) file, create the database and m
77
77
78
78
### [MySQL](#tab/mysql)
79
79
80
-
In .NET Aspire 9.2, the `WithCreationScript()` method isn't supported for the MySQL integration. Instead, you must use a bind mount and deploy the setup SQL script to it, so that the data is seeded when the container initializes the database.
80
+
Starting with .NET Aspire 9.3, you can use the <xref:Aspire.Hosting.MySqlBuilderExtensions.WithCreationScript*> method to ensure a MySQL script is run when the database is created. Add SQL code to this script that creates and populates the database, the necessary tables, and other database objects.
81
81
82
-
The following code is an example MySQL script that creates and populates a product catalog database:
82
+
In the following App Host code, the script is created as a string and passed to the `WithCreationScript` method:
If you run this code, you can use the PHP My Admin resource to check that a table called **catalog** has been created and populated with products.
89
95
90
96
---
91
97
@@ -96,7 +102,7 @@ You can also seed data in .NET Aspire projects using EF Core by explicitly runni
96
102
> [!IMPORTANT]
97
103
> These types of configurations should only be done during development, so make sure to add a conditional that checks your current environment context.
98
104
99
-
Add the following code to the _:::no-loc text="Program.cs"::: file of your **API Service** project.
105
+
Add the following code to the _:::no-loc text="Program.cs":::_ file of your **API Service** project.
0 commit comments