diff --git a/Kyoo.Postgresql/Migrations/20210607202403_Initial.Designer.cs b/Kyoo.Postgresql/Migrations/20210616203804_Initial.Designer.cs similarity index 98% rename from Kyoo.Postgresql/Migrations/20210607202403_Initial.Designer.cs rename to Kyoo.Postgresql/Migrations/20210616203804_Initial.Designer.cs index fe975800..83f90e5c 100644 --- a/Kyoo.Postgresql/Migrations/20210607202403_Initial.Designer.cs +++ b/Kyoo.Postgresql/Migrations/20210616203804_Initial.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace Kyoo.Postgresql.Migrations { [DbContext(typeof(PostgresContext))] - [Migration("20210607202403_Initial")] + [Migration("20210616203804_Initial")] partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -23,7 +23,7 @@ namespace Kyoo.Postgresql.Migrations .HasPostgresEnum(null, "status", new[] { "finished", "airing", "planned", "unknown" }) .HasPostgresEnum(null, "stream_type", new[] { "unknown", "video", "audio", "subtitle", "attachment" }) .HasAnnotation("Relational:MaxIdentifierLength", 63) - .HasAnnotation("ProductVersion", "5.0.6") + .HasAnnotation("ProductVersion", "5.0.7") .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); modelBuilder.Entity("Kyoo.Models.Collection", b => @@ -85,6 +85,9 @@ namespace Kyoo.Postgresql.Migrations b.Property("ShowID") .HasColumnType("integer"); + b.Property("Slug") + .HasColumnType("text"); + b.Property("Thumb") .HasColumnType("text"); @@ -428,6 +431,9 @@ namespace Kyoo.Postgresql.Migrations b.Property("ShowID") .HasColumnType("integer"); + b.Property("Slug") + .HasColumnType("text"); + b.Property("StartDate") .HasColumnType("timestamp without time zone"); @@ -552,6 +558,9 @@ namespace Kyoo.Postgresql.Migrations b.Property("Path") .HasColumnType("text"); + b.Property("Slug") + .HasColumnType("text"); + b.Property("Title") .HasColumnType("text"); diff --git a/Kyoo.Postgresql/Migrations/20210607202403_Initial.cs b/Kyoo.Postgresql/Migrations/20210616203804_Initial.cs similarity index 99% rename from Kyoo.Postgresql/Migrations/20210607202403_Initial.cs rename to Kyoo.Postgresql/Migrations/20210616203804_Initial.cs index 18df2ec7..94367a9d 100644 --- a/Kyoo.Postgresql/Migrations/20210607202403_Initial.cs +++ b/Kyoo.Postgresql/Migrations/20210616203804_Initial.cs @@ -386,6 +386,7 @@ namespace Kyoo.Postgresql.Migrations { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Slug = table.Column(type: "text", nullable: true), ShowID = table.Column(type: "integer", nullable: false), SeasonNumber = table.Column(type: "integer", nullable: false), Title = table.Column(type: "text", nullable: true), @@ -411,6 +412,7 @@ namespace Kyoo.Postgresql.Migrations { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Slug = table.Column(type: "text", nullable: true), ShowID = table.Column(type: "integer", nullable: false), SeasonID = table.Column(type: "integer", nullable: true), SeasonNumber = table.Column(type: "integer", nullable: false), @@ -497,6 +499,7 @@ namespace Kyoo.Postgresql.Migrations { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Slug = table.Column(type: "text", nullable: true), Title = table.Column(type: "text", nullable: true), Language = table.Column(type: "text", nullable: true), Codec = table.Column(type: "text", nullable: true), diff --git a/Kyoo.Postgresql/Migrations/PostgresContextModelSnapshot.cs b/Kyoo.Postgresql/Migrations/PostgresContextModelSnapshot.cs index 0e8a675c..a88a7ab2 100644 --- a/Kyoo.Postgresql/Migrations/PostgresContextModelSnapshot.cs +++ b/Kyoo.Postgresql/Migrations/PostgresContextModelSnapshot.cs @@ -21,7 +21,7 @@ namespace Kyoo.Postgresql.Migrations .HasPostgresEnum(null, "status", new[] { "finished", "airing", "planned", "unknown" }) .HasPostgresEnum(null, "stream_type", new[] { "unknown", "video", "audio", "subtitle", "attachment" }) .HasAnnotation("Relational:MaxIdentifierLength", 63) - .HasAnnotation("ProductVersion", "5.0.6") + .HasAnnotation("ProductVersion", "5.0.7") .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); modelBuilder.Entity("Kyoo.Models.Collection", b => @@ -83,6 +83,9 @@ namespace Kyoo.Postgresql.Migrations b.Property("ShowID") .HasColumnType("integer"); + b.Property("Slug") + .HasColumnType("text"); + b.Property("Thumb") .HasColumnType("text"); @@ -426,6 +429,9 @@ namespace Kyoo.Postgresql.Migrations b.Property("ShowID") .HasColumnType("integer"); + b.Property("Slug") + .HasColumnType("text"); + b.Property("StartDate") .HasColumnType("timestamp without time zone"); @@ -550,6 +556,9 @@ namespace Kyoo.Postgresql.Migrations b.Property("Path") .HasColumnType("text"); + b.Property("Slug") + .HasColumnType("text"); + b.Property("Title") .HasColumnType("text"); diff --git a/Kyoo.Postgresql/PostgresContext.cs b/Kyoo.Postgresql/PostgresContext.cs index 4836601c..c6efa395 100644 --- a/Kyoo.Postgresql/PostgresContext.cs +++ b/Kyoo.Postgresql/PostgresContext.cs @@ -26,16 +26,19 @@ namespace Kyoo.Postgresql /// Should the configure step be skipped? This is used when the database is created via DbContextOptions. /// private readonly bool _skipConfigure; - - /// - /// A basic constructor that set default values (query tracker behaviors, mapping enums...) - /// - public PostgresContext() + + + static PostgresContext() { NpgsqlConnection.GlobalTypeMapper.MapEnum(); NpgsqlConnection.GlobalTypeMapper.MapEnum(); NpgsqlConnection.GlobalTypeMapper.MapEnum(); } + + /// + /// A basic constructor that set default values (query tracker behaviors, mapping enums...) + /// + public PostgresContext() { } /// /// Create a new using specific options @@ -44,9 +47,6 @@ namespace Kyoo.Postgresql public PostgresContext(DbContextOptions options) : base(options) { - NpgsqlConnection.GlobalTypeMapper.MapEnum(); - NpgsqlConnection.GlobalTypeMapper.MapEnum(); - NpgsqlConnection.GlobalTypeMapper.MapEnum(); _skipConfigure = true; } diff --git a/Kyoo.Tests/Library/TestContext.cs b/Kyoo.Tests/Library/TestContext.cs index ed3e46c4..0ecb4637 100644 --- a/Kyoo.Tests/Library/TestContext.cs +++ b/Kyoo.Tests/Library/TestContext.cs @@ -31,7 +31,7 @@ namespace Kyoo.Tests .Options; using DatabaseContext context = New(); - context.Database.EnsureCreated(); + context.Database.Migrate(); TestSample.FillDatabase(context); } @@ -57,7 +57,7 @@ namespace Kyoo.Tests public sealed class PostgresFixture : IDisposable { - private readonly PostgresContext _context; + private readonly DbContextOptions _options; public string Template { get; } @@ -68,20 +68,24 @@ namespace Kyoo.Tests string id = Guid.NewGuid().ToString().Replace('-', '_'); Template = $"kyoo_template_{id}"; - DbContextOptions options = new DbContextOptionsBuilder() + _options = new DbContextOptionsBuilder() .UseNpgsql(Connection) .Options; - _context = new PostgresContext(options); - _context.Database.EnsureCreated(); - TestSample.FillDatabase(_context); - _context.Database.CloseConnection(); + using PostgresContext context = new(_options); + context.Database.Migrate(); + + using NpgsqlConnection conn = (NpgsqlConnection)context.Database.GetDbConnection(); + conn.Open(); + conn.ReloadTypes(); + + TestSample.FillDatabase(context); } public void Dispose() { - _context.Database.EnsureDeleted(); - _context.Dispose(); + using PostgresContext context = new(_options); + context.Database.EnsureDeleted(); } }