Skip to content

appany/AppAny.Quartz.EntityFrameworkCore.Migrations

Repository files navigation

πŸ’₯ 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