New: Log database engine version on startup
This commit is contained in:
parent
80630bf97f
commit
6ab1d8e16b
|
@ -0,0 +1,69 @@
|
||||||
|
using System.Data;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using FluentMigrator;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Instrumentation;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Datastore.Migration
|
||||||
|
{
|
||||||
|
[Maintenance(MigrationStage.BeforeAll, TransactionBehavior.None)]
|
||||||
|
public class DatabaseEngineVersionCheck : FluentMigrator.Migration
|
||||||
|
{
|
||||||
|
protected readonly Logger _logger;
|
||||||
|
|
||||||
|
public DatabaseEngineVersionCheck()
|
||||||
|
{
|
||||||
|
_logger = NzbDroneLogger.GetLogger(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Up()
|
||||||
|
{
|
||||||
|
IfDatabase("sqlite").Execute.WithConnection(LogSqliteVersion);
|
||||||
|
IfDatabase("postgres").Execute.WithConnection(LogPostgresVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Down()
|
||||||
|
{
|
||||||
|
// No-op
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LogSqliteVersion(IDbConnection conn, IDbTransaction tran)
|
||||||
|
{
|
||||||
|
using (var versionCmd = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
versionCmd.Transaction = tran;
|
||||||
|
versionCmd.CommandText = "SELECT sqlite_version();";
|
||||||
|
|
||||||
|
using (var reader = versionCmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
var version = reader.GetString(0);
|
||||||
|
|
||||||
|
_logger.Info("SQLite {0}", version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LogPostgresVersion(IDbConnection conn, IDbTransaction tran)
|
||||||
|
{
|
||||||
|
using (var versionCmd = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
versionCmd.Transaction = tran;
|
||||||
|
versionCmd.CommandText = "SHOW server_version";
|
||||||
|
|
||||||
|
using (var reader = versionCmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
var version = reader.GetString(0);
|
||||||
|
var cleanVersion = Regex.Replace(version, @"\(.*?\)", "");
|
||||||
|
|
||||||
|
_logger.Info("Postgres {0}", cleanVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,12 +42,13 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||||
serviceProvider = new ServiceCollection()
|
serviceProvider = new ServiceCollection()
|
||||||
.AddLogging(b => b.AddNLog())
|
.AddLogging(b => b.AddNLog())
|
||||||
.AddFluentMigratorCore()
|
.AddFluentMigratorCore()
|
||||||
|
.Configure<RunnerOptions>(cfg => cfg.IncludeUntaggedMaintenances = true)
|
||||||
.ConfigureRunner(
|
.ConfigureRunner(
|
||||||
builder => builder
|
builder => builder
|
||||||
.AddPostgres()
|
.AddPostgres()
|
||||||
.AddNzbDroneSQLite()
|
.AddNzbDroneSQLite()
|
||||||
.WithGlobalConnectionString(connectionString)
|
.WithGlobalConnectionString(connectionString)
|
||||||
.WithMigrationsIn(Assembly.GetExecutingAssembly()))
|
.ScanIn(Assembly.GetExecutingAssembly()).For.All())
|
||||||
.Configure<TypeFilterOptions>(opt => opt.Namespace = "NzbDrone.Core.Datastore.Migration")
|
.Configure<TypeFilterOptions>(opt => opt.Namespace = "NzbDrone.Core.Datastore.Migration")
|
||||||
.Configure<ProcessorOptions>(opt =>
|
.Configure<ProcessorOptions>(opt =>
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue