aspire icon indicating copy to clipboard operation
aspire copied to clipboard

Support altering the default script for AzurePostgresFlexibleServer in .NET Aspire

Open foxminchan opened this issue 8 months ago • 7 comments

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:

Image

Image

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 WithCreationScript in the AzurePostgresFlexibleServer scenario.

Additional context

No response

foxminchan avatar Apr 29 '25 03:04 foxminchan

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 avatar Apr 29 '25 03:04 davidfowl

@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.

foxminchan avatar Apr 29 '25 03:04 foxminchan

That should already work if you do RunAsContainer(c => c.WithCreationScript(..))

davidfowl avatar Apr 29 '25 04:04 davidfowl

@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.

Image

Error:

Cannot convert instance argument type 'Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.PostgresServerResource>' to 'Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.PostgresDatabaseResource>'`

foxminchan avatar Apr 29 '25 04:04 foxminchan

Ah, I see.

@sebastienros @RussKie We should do this as part of the database work in 9.3

davidfowl avatar Apr 29 '25 04:04 davidfowl

@foxminchan are you able to provide a small standalone repro?

RussKie avatar Apr 29 '25 06:04 RussKie

@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.

foxminchan avatar Apr 29 '25 11:04 foxminchan

I understand the problem and can talk to @RussKie

davidfowl avatar May 02 '25 09:05 davidfowl

@sebastienros as part of this work we should make these annotations public

davidfowl avatar May 10 '25 03:05 davidfowl

@davidfowl It used to be public ... https://github.com/dotnet/aspire/pull/8535

sebastienros avatar May 10 '25 05:05 sebastienros