⚡️ This library handles schema creation and migrations for Quartz.NET using EntityFrameworkCore migrations toolkit with one line of configuration ⚡️
🚧 Feel free to create as issue for driver support 🚧
dotnet add package AppAny.Quartz.EntityFrameworkCore.Migrations.MySql
dotnet add package AppAny.Quartz.EntityFrameworkCore.Migrations.PostgreSQL
dotnet add package AppAny.Quartz.EntityFrameworkCore.Migrations.SQLite
dotnet add package AppAny.Quartz.EntityFrameworkCore.Migrations.SqlServer
✅ Configure the DbContext
that will hold the Quartz.NET tables
public class DatabaseContext : DbContext
{
// ...
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Prefix and schema can be passed as parameters
// Adds Quartz.NET MySql schema to EntityFrameworkCore
modelBuilder.AddQuartz(builder => builder.UseMySql());
// Adds Quartz.NET PostgreSQL schema to EntityFrameworkCore
modelBuilder.AddQuartz(builder => builder.UsePostgreSql());
// Adds Quartz.NET SQLite schema to EntityFrameworkCore
modelBuilder.AddQuartz(builder => builder.UseSQLite());
// Adds Quartz.NET SqlServer schema to EntityFrameworkCore
modelBuilder.AddQuartz(builder => builder.UseSqlServer());
}
}
✅ (Optional) ASP.NET Core Integration Configuration
// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddQuartz(q =>
{
q.UsePersistentStore(c =>
{
// Use for MySQL database
c.UseMySql(mysqlOptions =>
{
mysqlOptions.UseDriverDelegate<MySQLDelegate>();
mysqlOptions.ConnectionString = ...;
mysqlOptions.TablePrefix = ...;
});
// Use for PostgresSQL database
c.UsePostgres(postgresOptions =>
{
postgresOptions.UseDriverDelegate<PostgreSQLDelegate>();
postgresOptions.ConnectionString = ...;
postgresOptions.TablePrefix = ...;
});
// Use for SQLite database
c.UseSQLite(sqlLiteOptions =>
{
sqlLiteOptions.UseDriverDelegate<SQLiteDelegate>();
sqlLiteOptions.ConnectionString = ...;
sqlLiteOptions.TablePrefix = ...;
});
// Use for SqlServer database
c.UseSqlServer(sqlServerOptions =>
{
sqlServerOptions.UseDriverDelegate<SqlServerDelegate>();
sqlServerOptions.ConnectionString = ...;
sqlServerOptions.TablePrefix = ...;
});
});
});
}
✅ Add EntityFrameworkCore migration with Quartz.NET schema dotnet ef migrations add AddQuartz
and then
-
🚩 Add in-process migration using
databaseContext.Database.MigrateAsync()
-
🚩 Add out-of-process migration using
dotnet ef database update
-
🚩 Extract SQL for your migration tool
dotnet ef migrations script PreviousMigration AddQuartz