Support altering the default script for AzurePostgresFlexibleServer in .NET Aspire
Is there an existing issue for this?
- [x] I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
Currently, the AddAzurePostgresFlexibleServer(...).AddDatabase(...).WithCreationScript(...) API works well, but it returns an IResourceBuilder<AzurePostgresFlexibleServerDatabaseResource> which is not compatible with PostgresDatabaseResource. This inconsistency makes it difficult to generalize database setup logic (e.g., if switching between local Postgres and Azure).
Screenshot of the error for reference:
Describe the solution you'd like
It would be helpful if:
- There was a unified interface for database resources.
-
Or better guidance/docs/examples for using
WithCreationScriptin theAzurePostgresFlexibleServerscenario.
Additional context
No response
It’s not clear how we’d generalize this yet. We did a minimum implementation for dev only. Running script in deployment environments is something we want to do but it’s non trivial
@davidfowl I understand — but in that case, would it be possible to support running the script in dev environments when using RunAsContainer() mode? That alone could really help improve the development experience.
That should already work if you do RunAsContainer(c => c.WithCreationScript(..))
@davidfowl It doesn’t seem to work as expected — when I try RunAsContainer(cfg => cfg.WithCreationScript(...)), I get a type mismatch error. The builder is for PostgresServerResource, but WithCreationScript appears to expect a PostgresDatabaseResource.
Error:
Cannot convert instance argument type 'Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.PostgresServerResource>' to 'Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.PostgresDatabaseResource>'`
Ah, I see.
@sebastienros @RussKie We should do this as part of the database work in 9.3
@foxminchan are you able to provide a small standalone repro?
@RussKie I’m not able to provide a standalone repro at the moment. However, I’ve created an issue in my project (a POC) that describes the scenario in detail: https://github.com/foxminchan/BookWorm/issues/34. If a standalone repro is necessary, I can prepare and share one later.
I understand the problem and can talk to @RussKie
@sebastienros as part of this work we should make these annotations public
@davidfowl It used to be public ... https://github.com/dotnet/aspire/pull/8535