1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-03-05 13:20:20 -05:00

New: Bump minimum Postgres version to 15 for FluentMigrator

This commit is contained in:
Bogdan
2025-09-28 18:42:54 +03:00
committed by Mark McDowall
parent bef2986357
commit 5f846ab51e
13 changed files with 23 additions and 40 deletions

View File

@@ -18,7 +18,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("Profiles").Row(new
{
Id = 0,
Name = "SDTV",
Cutoff = 1,
Items = new List<object>

View File

@@ -16,7 +16,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("Profiles").Row(new
{
Id = 0,
Name = "SDTV",
Cutoff = 1,
Items = "[ { \"quality\": 1, \"allowed\": true } ]",

View File

@@ -22,7 +22,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("Profiles").Row(new
{
Id = 0,
Name = "SDTV",
Cutoff = 1,
Items = $"[{GenerateQualityJson(1, true)}, {GenerateQualityJson((int)Quality.WEBRip480p, false)}, {GenerateQualityJson((int)Quality.WEBRip720p, false)}, {GenerateQualityJson((int)Quality.WEBRip1080p, false)}, {GenerateQualityJson((int)Quality.WEBRip2160p, false)}]"
@@ -45,7 +44,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("Profiles").Row(new
{
Id = 0,
Name = "SDTV",
Cutoff = 1,
Items = $"[{GenerateQualityJson(1, true)}, {GenerateQualityJson((int)Quality.DVD, false)}, {GenerateQualityJson((int)Quality.Bluray480p, false)}]"
@@ -68,7 +66,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("Profiles").Row(new
{
Id = 0,
Name = "SDTV",
Cutoff = 1,
Items = $"[{GenerateQualityJson(1, true)}, {GenerateQualityJson((int)Quality.WEBRip480p, false)}, {GenerateQualityJson((int)Quality.WEBRip720p, false)}, {GenerateQualityJson((int)Quality.WEBRip1080p, false)}]"
@@ -91,7 +88,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("Profiles").Row(new
{
Id = 0,
Name = "SDTV",
Cutoff = 1,
Items = $"[{GenerateQualityJson(1, true)}, {GenerateQualityJson((int)Quality.WEBRip480p, false)}, {GenerateQualityJson((int)Quality.WEBRip720p, false)}, {GenerateQualityJson((int)Quality.WEBRip1080p, false)}, {GenerateQualityJson((int)Quality.WEBRip2160p, false)}]"

View File

@@ -16,7 +16,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("Profiles").Row(new
{
Id = 0,
Name = "Bluray",
Cutoff = 7,
Items = "[ { \"quality\": 7, \"allowed\": true }, { \"quality\": 19, \"allowed\": true } ]"
@@ -38,12 +37,11 @@ namespace NzbDrone.Core.Test.Datastore.Migration
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Profiles").Row(new
{
Id = 0,
Name = "Bluray",
Cutoff = 7,
Items = "[ { \"id\": 1001, \"name\": \"Why?!\", \"allowed\": true, \"items\": [{ \"quality\": 8, \"allowed\": true }, { \"quality\": 7, \"allowed\": true }] }, { \"quality\": 19, \"allowed\": true } ]"
});
{
Name = "Bluray",
Cutoff = 7,
Items = "[ { \"id\": 1001, \"name\": \"Why?!\", \"allowed\": true, \"items\": [{ \"quality\": 8, \"allowed\": true }, { \"quality\": 7, \"allowed\": true }] }, { \"quality\": 19, \"allowed\": true } ]"
});
});
var profiles = db.Query<Profile122>("SELECT \"Items\" FROM \"Profiles\" LIMIT 1");

View File

@@ -11,12 +11,11 @@ namespace NzbDrone.Core.Test.Datastore.Migration
[TestFixture]
public class mediainfo_channel_propertiesFixture : MigrationTest<mediainfo_channels>
{
private void AddEpisodeFile(mediainfo_channels m, int id)
private void AddEpisodeFile(mediainfo_channels m, int seriesId)
{
var episode = new
{
Id = id,
SeriesId = id,
SeriesId = seriesId,
Quality = new { }.ToJson(),
Size = 0,
DateAdded = DateTime.UtcNow,

View File

@@ -60,7 +60,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
c.Insert.IntoTable("EpisodeFiles").Row(new
{
Id = 1,
SeriesId = 1,
RelativePath = episodePath,
Quality = new { }.ToJson(),

View File

@@ -30,7 +30,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("CustomFilters").Row(new
{
Id = 1,
Type = "series",
Label = "Is Both",
Filters = filtersString
@@ -67,7 +66,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("CustomFilters").Row(new
{
Id = 1,
Type = "series",
Label = "Is Both",
Filters = filtersString
@@ -104,7 +102,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("CustomFilters").Row(new
{
Id = 1,
Type = "series",
Label = "Is Both",
Filters = filtersString
@@ -141,7 +138,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("CustomFilters").Row(new
{
Id = 1,
Type = "series",
Label = "Is Both",
Filters = filtersString
@@ -178,7 +174,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("CustomFilters").Row(new
{
Id = 1,
Type = "series",
Label = "Is Both",
Filters = filtersString
@@ -215,7 +210,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("CustomFilters").Row(new
{
Id = 1,
Type = "series",
Label = "Is Both",
Filters = filtersString
@@ -252,7 +246,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("CustomFilters").Row(new
{
Id = 1,
Type = "series",
Label = "Is Both",
Filters = filtersString
@@ -295,7 +288,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("CustomFilters").Row(new
{
Id = 1,
Type = "series",
Label = "Is Both",
Filters = filtersString
@@ -335,7 +327,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("CustomFilters").Row(new
{
Id = 1,
Type = "series",
Label = "Is Both",
Filters = filtersString

View File

@@ -27,7 +27,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("QualityProfiles").Row(new
{
Id = 0,
Name = "Bluray",
Cutoff = 7,
Items = $"[{GenerateQualityJson((int)Quality.DVD, true)}, {GenerateQualityJson((int)Quality.Bluray480p, true)}, {GenerateQualityJson((int)Quality.Bluray720p, false)}]"
@@ -50,7 +49,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("QualityProfiles").Row(new
{
Id = 0,
Name = "Bluray",
Cutoff = 7,
Items = $"[{GenerateQualityJson((int)Quality.DVD, true)}, {GenerateQualityJson((int)Quality.Bluray480p, false)}, {GenerateQualityJson((int)Quality.Bluray720p, false)}]"
@@ -73,7 +71,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("QualityProfiles").Row(new
{
Id = 0,
Name = "Bluray",
Cutoff = 7,
Items = $"[{GenerateQualityGroupJson(1000, "DVD", new[] { (int)Quality.DVD, (int)Quality.Bluray480p }, true)}, {GenerateQualityJson((int)Quality.Bluray720p, false)}]"
@@ -97,7 +94,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("QualityProfiles").Row(new
{
Id = 0,
Name = "Bluray",
Cutoff = 7,
Items = $"[{GenerateQualityJson((int)Quality.DVD, true)}, {GenerateQualityJson((int)Quality.Bluray480p, false)}, {GenerateQualityJson((int)Quality.Bluray576p, false)}, {GenerateQualityJson((int)Quality.Bluray720p, false)}]"
@@ -120,7 +116,6 @@ namespace NzbDrone.Core.Test.Datastore.Migration
{
c.Insert.IntoTable("QualityProfiles").Row(new
{
Id = 0,
Name = "Bluray",
Cutoff = 7,
Items = $"[{GenerateQualityGroupJson(1000, "DVD", new[] { (int)Quality.DVD, (int)Quality.Bluray480p, (int)Quality.Bluray576p }, true)}, {GenerateQualityJson((int)Quality.Bluray720p, false)}]"

View File

@@ -18,8 +18,8 @@ namespace NzbDrone.Core.Datastore.Migration
public override void Up()
{
IfDatabase("sqlite").Execute.WithConnection(LogSqliteVersion);
IfDatabase("postgresql").Execute.WithConnection(LogPostgresVersion);
IfDatabase(ProcessorId.SQLite).Execute.WithConnection(LogSqliteVersion);
IfDatabase(ProcessorId.PostgreSQL).Execute.WithConnection(LogPostgresVersion);
}
private void LogSqliteVersion(IDbConnection conn, IDbTransaction tran)

View File

@@ -8,8 +8,8 @@ namespace NzbDrone.Core.Datastore.Migration
{
protected override void MainDbUpgrade()
{
IfDatabase("sqlite").Execute.Sql("DELETE FROM \"MetadataFiles\" WHERE \"Consumer\" = 'RoksboxMetadata' AND \"Type\" = 5 AND (\"RelativePath\" LIKE '%/metadata/%' OR \"RelativePath\" LIKE '%\\metadata\\%')");
IfDatabase("postgresql").Execute.Sql("DELETE FROM \"MetadataFiles\" WHERE \"Consumer\" = 'RoksboxMetadata' AND \"Type\" = 5 AND (\"RelativePath\" LIKE '%/metadata/%' OR \"RelativePath\" LIKE '%\\\\metadata\\\\%')");
IfDatabase(ProcessorId.SQLite).Execute.Sql("DELETE FROM \"MetadataFiles\" WHERE \"Consumer\" = 'RoksboxMetadata' AND \"Type\" = 5 AND (\"RelativePath\" LIKE '%/metadata/%' OR \"RelativePath\" LIKE '%\\metadata\\%')");
IfDatabase(ProcessorId.PostgreSQL).Execute.Sql("DELETE FROM \"MetadataFiles\" WHERE \"Consumer\" = 'RoksboxMetadata' AND \"Type\" = 5 AND (\"RelativePath\" LIKE '%/metadata/%' OR \"RelativePath\" LIKE '%\\\\metadata\\\\%')");
}
}
}

View File

@@ -8,10 +8,10 @@ namespace NzbDrone.Core.Datastore.Migration
{
protected override void MainDbUpgrade()
{
IfDatabase("sqlite").Alter.Table("ImportListExclusions").AlterColumn("TvdbId").AsInt32();
IfDatabase(ProcessorId.SQLite).Alter.Table("ImportListExclusions").AlterColumn("TvdbId").AsInt32();
// PG cannot autocast varchar to integer
IfDatabase("postgresql").Execute.Sql("ALTER TABLE \"ImportListExclusions\" ALTER COLUMN \"TvdbId\" TYPE INTEGER USING \"TvdbId\"::integer");
IfDatabase(ProcessorId.PostgreSQL).Execute.Sql("ALTER TABLE \"ImportListExclusions\" ALTER COLUMN \"TvdbId\" TYPE INTEGER USING \"TvdbId\"::integer");
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Reflection;
using FluentMigrator;
using FluentMigrator.Runner;
using FluentMigrator.Runner.Generators;
using FluentMigrator.Runner.Initialization;
@@ -31,14 +32,19 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
_logger.Info("*** Migrating {0} ***", connectionString);
var db = databaseType == DatabaseType.SQLite ? "sqlite" : "postgresql";
var db = databaseType switch
{
DatabaseType.SQLite => ProcessorId.SQLite,
DatabaseType.PostgreSQL => ProcessorId.PostgreSQL,
_ => throw new NotImplementedException($"Unknown database type: {databaseType}")
};
var serviceProvider = new ServiceCollection()
.AddLogging(b => b.AddNLog())
.AddFluentMigratorCore()
.Configure<RunnerOptions>(cfg => cfg.IncludeUntaggedMaintenances = true)
.ConfigureRunner(builder => builder
.AddPostgres()
.AddPostgres15_0()
.AddNzbDroneSQLite()
.WithGlobalConnectionString(connectionString)
.ScanIn(Assembly.GetExecutingAssembly()).For.All())

View File

@@ -50,7 +50,8 @@ namespace NzbDrone.Test.Common.Datastore
Port = options.Port,
Username = options.User,
Password = options.Password,
Enlist = false
Enlist = false,
IncludeErrorDetail = true,
};
return builder.ConnectionString;