/AppAny.Quartz.EntityFrameworkCore.Migrations

EntityFrameworkCore PostgreSQL migrations for Quartz.NET

Primary LanguageC#MIT LicenseMIT

💥 EntityFrameworkCore migrations for Quartz.NET 💥

License Nuget Downloads Tests codecov

⚡️ This library handles schema creation and migrations for Quartz.NET using EntityFrameworkCore migrations toolkit with one line of configuration ⚡️

💡 Supported drivers 💡

🚧 Feel free to create as issue for driver support 🚧

🔧 Installation 🔧

MySql

dotnet add package AppAny.Quartz.EntityFrameworkCore.Migrations.MySql

PostgreSQL

dotnet add package AppAny.Quartz.EntityFrameworkCore.Migrations.PostgreSQL

SQLite

dotnet add package AppAny.Quartz.EntityFrameworkCore.Migrations.SQLite

SqlServer

dotnet add package AppAny.Quartz.EntityFrameworkCore.Migrations.SqlServer

🎨 Usage 🎨

✅ 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 = ...;
            });
        });
    });
}

🚩 Finish 🚩

✅ 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