Skip to content

Commit

Permalink
Ensure Path Exists for Quartz Database
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Jan 6, 2024
1 parent e60ea00 commit ccbcdd3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Shoko.Server/Scheduling/QuartzStartup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Data.SqlClient;
using System.IO;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.DependencyInjection;
using MySqlConnector;
Expand Down Expand Up @@ -40,6 +41,8 @@ private static void UseDatabase(this IServiceCollectionQuartzConfigurator q)
q.UsePersistentStore(options =>
{
var settings = Utils.SettingsProvider.GetSettings();
if (string.IsNullOrEmpty(settings.Quartz?.ConnectionString))
throw new ArgumentNullException(nameof(settings.Quartz.ConnectionString), @"The connection string for Quartz was null");
if (settings.Quartz.DatabaseType.Trim().Equals(Constants.DatabaseType.SqlServer, StringComparison.InvariantCultureIgnoreCase))
{
EnsureQuartzDatabaseExists_SQLServer(settings.Quartz.ConnectionString);
Expand Down Expand Up @@ -650,6 +653,8 @@ PRIMARY KEY (SCHED_NAME,LOCK_NAME))
private static void EnsureQuartzDatabaseExists_SQLite(string connectionString)
{
using var conn = new SqliteConnection(connectionString);
var path = Path.GetDirectoryName(conn.DataSource);
Directory.CreateDirectory(path!);
conn.Open();
var existsCommand = new SqliteCommand("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='QRTZ_TRIGGERS'", conn);
var result = (long)existsCommand.ExecuteScalar()!;
Expand Down

0 comments on commit ccbcdd3

Please sign in to comment.