fix(db): restore the PostgreSQL upgrade path
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful

The v12.0 rebase replaced the PostgreSQL provider's initial migration instead of
adding to it, so an existing database kept the pre-12.0 schema while the code
migrations ran against it and startup aborted on a missing NormalizedUsername.

- restore 20260305010333_InitialPostgreSql as the baseline
- add 20260306000000_UpgradeToServer12Schema carrying it to the 12.0 model
- convert OwnerId and PrimaryVersionId to uuid with explicit casts, clear
  unparseable ids and repoint dangling owners at the placeholder item
- drop orphaned permissions and preferences before UserId becomes non-nullable
- add 20260524120336_AddUniqueNormalizedUsernameIndex after the code migration
  that fills the column in
- read an empty or unknown encoding.xml EncoderPreset as the default
- cover both paths against a real PostgreSQL and guard the migration ordering
This commit is contained in:
2026-09-12 15:32:12 +10:00
parent dcb6ae396c
commit 2e3d24cc05
11 changed files with 4687 additions and 152 deletions
@@ -0,0 +1,50 @@
using System.IO;
using System.Xml.Serialization;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using Xunit;
namespace Jellyfin.Model.Tests.Configuration;
public class EncodingOptionsTests
{
[Theory]
[InlineData("<EncoderPreset></EncoderPreset>")]
[InlineData("<EncoderPreset />")]
[InlineData("<EncoderPreset> </EncoderPreset>")]
[InlineData("<EncoderPreset>notapreset</EncoderPreset>")]
public void Deserialize_UnreadableEncoderPreset_FallsBackToDefault(string encoderPresetElement)
{
var options = Deserialize($"<EncodingOptions>{encoderPresetElement}<H264Crf>21</H264Crf></EncodingOptions>");
Assert.Equal(EncoderPreset.auto, options.EncoderPreset);
// The rest of the file has to survive: a throwing preset used to discard every other encoding setting.
Assert.Equal(21, options.H264Crf);
}
[Fact]
public void Deserialize_KnownEncoderPreset_IsKept()
{
var options = Deserialize("<EncodingOptions><EncoderPreset>veryfast</EncoderPreset></EncodingOptions>");
Assert.Equal(EncoderPreset.veryfast, options.EncoderPreset);
}
[Fact]
public void Serialize_WritesTheEncoderPresetElement()
{
var serializer = new XmlSerializer(typeof(EncodingOptions));
using var writer = new StringWriter();
serializer.Serialize(writer, new EncodingOptions { EncoderPreset = EncoderPreset.slow });
Assert.Contains("<EncoderPreset>slow</EncoderPreset>", writer.ToString(), System.StringComparison.Ordinal);
}
private static EncodingOptions Deserialize(string xml)
{
var serializer = new XmlSerializer(typeof(EncodingOptions));
using var reader = new StringReader(xml);
return (EncodingOptions)serializer.Deserialize(reader)!;
}
}