mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Fixing some postgres tests
This commit is contained in:
parent
9ed51d11cc
commit
7bd78bfaac
@ -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<int>("ShowID")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Slug")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Thumb")
|
||||
.HasColumnType("text");
|
||||
|
||||
@ -428,6 +431,9 @@ namespace Kyoo.Postgresql.Migrations
|
||||
b.Property<int>("ShowID")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Slug")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime?>("StartDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
@ -552,6 +558,9 @@ namespace Kyoo.Postgresql.Migrations
|
||||
b.Property<string>("Path")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Slug")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.HasColumnType("text");
|
||||
|
@ -386,6 +386,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
{
|
||||
ID = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Slug = table.Column<string>(type: "text", nullable: true),
|
||||
ShowID = table.Column<int>(type: "integer", nullable: false),
|
||||
SeasonNumber = table.Column<int>(type: "integer", nullable: false),
|
||||
Title = table.Column<string>(type: "text", nullable: true),
|
||||
@ -411,6 +412,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
{
|
||||
ID = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Slug = table.Column<string>(type: "text", nullable: true),
|
||||
ShowID = table.Column<int>(type: "integer", nullable: false),
|
||||
SeasonID = table.Column<int>(type: "integer", nullable: true),
|
||||
SeasonNumber = table.Column<int>(type: "integer", nullable: false),
|
||||
@ -497,6 +499,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
{
|
||||
ID = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Slug = table.Column<string>(type: "text", nullable: true),
|
||||
Title = table.Column<string>(type: "text", nullable: true),
|
||||
Language = table.Column<string>(type: "text", nullable: true),
|
||||
Codec = table.Column<string>(type: "text", nullable: true),
|
@ -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<int>("ShowID")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Slug")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Thumb")
|
||||
.HasColumnType("text");
|
||||
|
||||
@ -426,6 +429,9 @@ namespace Kyoo.Postgresql.Migrations
|
||||
b.Property<int>("ShowID")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Slug")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime?>("StartDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
@ -550,6 +556,9 @@ namespace Kyoo.Postgresql.Migrations
|
||||
b.Property<string>("Path")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Slug")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.HasColumnType("text");
|
||||
|
||||
|
@ -27,16 +27,19 @@ namespace Kyoo.Postgresql
|
||||
/// </summary>
|
||||
private readonly bool _skipConfigure;
|
||||
|
||||
/// <summary>
|
||||
/// A basic constructor that set default values (query tracker behaviors, mapping enums...)
|
||||
/// </summary>
|
||||
public PostgresContext()
|
||||
|
||||
static PostgresContext()
|
||||
{
|
||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<Status>();
|
||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<ItemType>();
|
||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<StreamType>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A basic constructor that set default values (query tracker behaviors, mapping enums...)
|
||||
/// </summary>
|
||||
public PostgresContext() { }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="PostgresContext"/> using specific options
|
||||
/// </summary>
|
||||
@ -44,9 +47,6 @@ namespace Kyoo.Postgresql
|
||||
public PostgresContext(DbContextOptions options)
|
||||
: base(options)
|
||||
{
|
||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<Status>();
|
||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<ItemType>();
|
||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<StreamType>();
|
||||
_skipConfigure = true;
|
||||
}
|
||||
|
||||
|
@ -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<DatabaseContext> _options;
|
||||
|
||||
public string Template { get; }
|
||||
|
||||
@ -68,20 +68,24 @@ namespace Kyoo.Tests
|
||||
string id = Guid.NewGuid().ToString().Replace('-', '_');
|
||||
Template = $"kyoo_template_{id}";
|
||||
|
||||
DbContextOptions<DatabaseContext> options = new DbContextOptionsBuilder<DatabaseContext>()
|
||||
_options = new DbContextOptionsBuilder<DatabaseContext>()
|
||||
.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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user