I have a .NET Core web application which is hosted on docker image. This application uses PostgreSQL which is hosted on cloud database service.
We added a Hangfire which will use the same cloud database service as our main application.
public void ConfigureServices(IServiceCollection services)
{
...
services.AddHangfire(x => x.UsePostgreSqlStorage(ConnectionString));
...
}
and in Configure method:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseHangfireServer();
app.UseHangfireDashboard();
...
}
Now we have a problem to start the application if our database service is not available (or the database does not exist).
I tried to use:
services.AddHangfire(x => x.UsePostgreSqlStorage(ConnectionString, new PostgreSqlStorageOptions
{
PrepareSchemaIfNecessary = false
}));
but now I cannot create database schema once the database service is up and running. I could not find any migration scripts for Hangfire.PostgreSql so I can push them with my other business migrations.
I know that for Hangfire.SqlServer there is Install.sql script with which we can create database schema, but for PostgreSql nothing.
In CI/CD pipeline we want to build and run the application first and then to apply migration scripts on the database service, so we don't have the database available when starting the application.