Skip to main content

Database

At the time of writing Flux supports Sqlite, SQL Server and PostgreSQL. But it's trivial for us to support any other database that is supported by Entity Framework so if you need MySQL or something else, please let us know.

Install NuGet package

We recommend that you always include the Sqlite package because it makes local development easy. After you've picked eg Sqlite and SQL Server you modify your Program.cs like this:

var fluxBuilder = builder.Services
.AddFlux()
.AddProcessing()
.AddApi()
.AddUI()
;

if (builder.Environment.IsDevelopment())
{
fluxBuilder.AddSqlite();
}
else
{
fluxBuilder.AddSqlServer(options =>
{
// By default Flux will look for a connection string by calling IConfiguration.GetConnectionString("sqlserver")
// (or "postgres") but you can implement your own loader like this if you need.
options.ConnectionStringLoader = serviceProvider => "Data Source=localhost;Initial Catalog=flux;Integrated Security=true";
});
}

fluxBuilder.Build();

Running migrations

Flux uses Entity Framework and will include database migrations in some versions. It's left up to you to run migrations during deploy or during application startup, but you need to ensure that you're not running the same migrations on different servers at the same time.

Flux includes a IMigrationRunner that you can use which will take a distributed database lock and run migrations inside it. Which means that it's safe to run during application startup like this:

var builder = WebApplication.CreateBuilder(args);

builder.Services
.AddFlux()
// Other .Add() calls
.Build();

await app.Services.GetRequiredService<IMigrationRunner>().RunMigrations(CancellationToken.None);
Backward compatibility

Minor and patch releases of Flux will always be backward compatible which means that you can do zero-downtime deployment. But major versions of Flux might contain migrations that aren't backward compatible and requires downtime until migrations have run. Major versions have dedicated upgrade documentation that states if the upgrade deploy has any migrations that require downtime.