Skip to content

jsonb datatype for sql server, and aspire conditional startup for sql #1149

@kallievz

Description

@kallievz

Hi Community.

I managed to get SQL Migrations running by commenting a couple of lines of code in the Apphost, but not fully ideal for a template.

Question i have in order to make it play both ways:
Alternative of nvarcharmax for Payload columns, in stead of jsonb.

On Aspire Startup, how would i go about setting the environment to dictate to start up from SQL, or from postgres.
Sql Db is local for dev, but remote for production.

Almost like what was done in the ConnectionStringValidator class:

        switch (dbProvider?.ToUpperInvariant())
        {
            case DbProviders.PostgreSQL:
                // Postgres container + database

var postgres = builder.AddPostgres("postgres").WithDataVolume("fsh-postgres-data").AddDatabase("fsh");

builder.AddProject<Projects.Playground_Api>("playground-api")
.WithReference(postgres)
.WithEnvironment("ASPNETCORE_ENVIRONMENT", "Production")
.WithEnvironment("OpenTelemetryOptions__Exporter__Otlp__Endpoint", "https://localhost:4317")
.WithEnvironment("OpenTelemetryOptions__Exporter__Otlp__Protocol", "grpc")
.WithEnvironment("OpenTelemetryOptions__Exporter__Otlp__Enabled", "true")
.WithEnvironment("DatabaseOptions__Provider", "POSTGRESQL")
.WithEnvironment("DatabaseOptions__ConnectionString", postgres.Resource.ConnectionStringExpression)
.WithEnvironment("DatabaseOptions__MigrationsAssembly", "FSH.Playground.Migrations.PostgreSQL")
.WaitFor(postgres)
.WithReference(redis)
.WithEnvironment("CachingOptions__Redis", redis.Resource.ConnectionStringExpression)
.WaitFor(redis);
break;
case DbProviders.MSSQL:
// SQLcontainer + database
var sqlServer = builder.AddSql("postgres").WithDataVolume("fsh-sql-data").AddDatabase("fsh");

builder.AddProject<Projects.Playground_Api>("playground-api")
.WithReference(sqlServer )
.WithEnvironment("ASPNETCORE_ENVIRONMENT", "Production")
.WithEnvironment("OpenTelemetryOptions__Exporter__Otlp__Endpoint", "https://localhost:4317")
.WithEnvironment("OpenTelemetryOptions__Exporter__Otlp__Protocol", "grpc")
.WithEnvironment("OpenTelemetryOptions__Exporter__Otlp__Enabled", "true")
.WithEnvironment("DatabaseOptions__Provider", "SQL")
.WithEnvironment("DatabaseOptions__ConnectionString", sql.Resource.ConnectionStringExpression)
.WithEnvironment("DatabaseOptions__MigrationsAssembly", "FSH.Playground.Migrations.MSSQL")
.WaitFor(sqlServer )
.WithReference(redis)
.WithEnvironment("CachingOptions__Redis", redis.Resource.ConnectionStringExpression)
.WaitFor(redis);

                break;
            default:
                break;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions