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
|
namespace Kyoo.Postgresql.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(PostgresContext))]
|
[DbContext(typeof(PostgresContext))]
|
||||||
[Migration("20210607202403_Initial")]
|
[Migration("20210616203804_Initial")]
|
||||||
partial class Initial
|
partial class Initial
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -23,7 +23,7 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
.HasPostgresEnum(null, "status", new[] { "finished", "airing", "planned", "unknown" })
|
.HasPostgresEnum(null, "status", new[] { "finished", "airing", "planned", "unknown" })
|
||||||
.HasPostgresEnum(null, "stream_type", new[] { "unknown", "video", "audio", "subtitle", "attachment" })
|
.HasPostgresEnum(null, "stream_type", new[] { "unknown", "video", "audio", "subtitle", "attachment" })
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63)
|
.HasAnnotation("Relational:MaxIdentifierLength", 63)
|
||||||
.HasAnnotation("ProductVersion", "5.0.6")
|
.HasAnnotation("ProductVersion", "5.0.7")
|
||||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
modelBuilder.Entity("Kyoo.Models.Collection", b =>
|
modelBuilder.Entity("Kyoo.Models.Collection", b =>
|
||||||
@ -85,6 +85,9 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
b.Property<int>("ShowID")
|
b.Property<int>("ShowID")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Slug")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<string>("Thumb")
|
b.Property<string>("Thumb")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
@ -428,6 +431,9 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
b.Property<int>("ShowID")
|
b.Property<int>("ShowID")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Slug")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<DateTime?>("StartDate")
|
b.Property<DateTime?>("StartDate")
|
||||||
.HasColumnType("timestamp without time zone");
|
.HasColumnType("timestamp without time zone");
|
||||||
|
|
||||||
@ -552,6 +558,9 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
b.Property<string>("Path")
|
b.Property<string>("Path")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Slug")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<string>("Title")
|
b.Property<string>("Title")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
@ -386,6 +386,7 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
{
|
{
|
||||||
ID = table.Column<int>(type: "integer", nullable: false)
|
ID = table.Column<int>(type: "integer", nullable: false)
|
||||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Slug = table.Column<string>(type: "text", nullable: true),
|
||||||
ShowID = table.Column<int>(type: "integer", nullable: false),
|
ShowID = table.Column<int>(type: "integer", nullable: false),
|
||||||
SeasonNumber = table.Column<int>(type: "integer", nullable: false),
|
SeasonNumber = table.Column<int>(type: "integer", nullable: false),
|
||||||
Title = table.Column<string>(type: "text", nullable: true),
|
Title = table.Column<string>(type: "text", nullable: true),
|
||||||
@ -411,6 +412,7 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
{
|
{
|
||||||
ID = table.Column<int>(type: "integer", nullable: false)
|
ID = table.Column<int>(type: "integer", nullable: false)
|
||||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Slug = table.Column<string>(type: "text", nullable: true),
|
||||||
ShowID = table.Column<int>(type: "integer", nullable: false),
|
ShowID = table.Column<int>(type: "integer", nullable: false),
|
||||||
SeasonID = table.Column<int>(type: "integer", nullable: true),
|
SeasonID = table.Column<int>(type: "integer", nullable: true),
|
||||||
SeasonNumber = table.Column<int>(type: "integer", nullable: false),
|
SeasonNumber = table.Column<int>(type: "integer", nullable: false),
|
||||||
@ -497,6 +499,7 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
{
|
{
|
||||||
ID = table.Column<int>(type: "integer", nullable: false)
|
ID = table.Column<int>(type: "integer", nullable: false)
|
||||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Slug = table.Column<string>(type: "text", nullable: true),
|
||||||
Title = table.Column<string>(type: "text", nullable: true),
|
Title = table.Column<string>(type: "text", nullable: true),
|
||||||
Language = table.Column<string>(type: "text", nullable: true),
|
Language = table.Column<string>(type: "text", nullable: true),
|
||||||
Codec = 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, "status", new[] { "finished", "airing", "planned", "unknown" })
|
||||||
.HasPostgresEnum(null, "stream_type", new[] { "unknown", "video", "audio", "subtitle", "attachment" })
|
.HasPostgresEnum(null, "stream_type", new[] { "unknown", "video", "audio", "subtitle", "attachment" })
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63)
|
.HasAnnotation("Relational:MaxIdentifierLength", 63)
|
||||||
.HasAnnotation("ProductVersion", "5.0.6")
|
.HasAnnotation("ProductVersion", "5.0.7")
|
||||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
modelBuilder.Entity("Kyoo.Models.Collection", b =>
|
modelBuilder.Entity("Kyoo.Models.Collection", b =>
|
||||||
@ -83,6 +83,9 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
b.Property<int>("ShowID")
|
b.Property<int>("ShowID")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Slug")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<string>("Thumb")
|
b.Property<string>("Thumb")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
@ -426,6 +429,9 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
b.Property<int>("ShowID")
|
b.Property<int>("ShowID")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Slug")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<DateTime?>("StartDate")
|
b.Property<DateTime?>("StartDate")
|
||||||
.HasColumnType("timestamp without time zone");
|
.HasColumnType("timestamp without time zone");
|
||||||
|
|
||||||
@ -550,6 +556,9 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
b.Property<string>("Path")
|
b.Property<string>("Path")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Slug")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<string>("Title")
|
b.Property<string>("Title")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
@ -26,16 +26,19 @@ namespace Kyoo.Postgresql
|
|||||||
/// Should the configure step be skipped? This is used when the database is created via DbContextOptions.
|
/// Should the configure step be skipped? This is used when the database is created via DbContextOptions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly bool _skipConfigure;
|
private readonly bool _skipConfigure;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A basic constructor that set default values (query tracker behaviors, mapping enums...)
|
static PostgresContext()
|
||||||
/// </summary>
|
|
||||||
public PostgresContext()
|
|
||||||
{
|
{
|
||||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<Status>();
|
NpgsqlConnection.GlobalTypeMapper.MapEnum<Status>();
|
||||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<ItemType>();
|
NpgsqlConnection.GlobalTypeMapper.MapEnum<ItemType>();
|
||||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<StreamType>();
|
NpgsqlConnection.GlobalTypeMapper.MapEnum<StreamType>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A basic constructor that set default values (query tracker behaviors, mapping enums...)
|
||||||
|
/// </summary>
|
||||||
|
public PostgresContext() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new <see cref="PostgresContext"/> using specific options
|
/// Create a new <see cref="PostgresContext"/> using specific options
|
||||||
@ -44,9 +47,6 @@ namespace Kyoo.Postgresql
|
|||||||
public PostgresContext(DbContextOptions options)
|
public PostgresContext(DbContextOptions options)
|
||||||
: base(options)
|
: base(options)
|
||||||
{
|
{
|
||||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<Status>();
|
|
||||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<ItemType>();
|
|
||||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<StreamType>();
|
|
||||||
_skipConfigure = true;
|
_skipConfigure = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ namespace Kyoo.Tests
|
|||||||
.Options;
|
.Options;
|
||||||
|
|
||||||
using DatabaseContext context = New();
|
using DatabaseContext context = New();
|
||||||
context.Database.EnsureCreated();
|
context.Database.Migrate();
|
||||||
TestSample.FillDatabase(context);
|
TestSample.FillDatabase(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ namespace Kyoo.Tests
|
|||||||
|
|
||||||
public sealed class PostgresFixture : IDisposable
|
public sealed class PostgresFixture : IDisposable
|
||||||
{
|
{
|
||||||
private readonly PostgresContext _context;
|
private readonly DbContextOptions<DatabaseContext> _options;
|
||||||
|
|
||||||
public string Template { get; }
|
public string Template { get; }
|
||||||
|
|
||||||
@ -68,20 +68,24 @@ namespace Kyoo.Tests
|
|||||||
string id = Guid.NewGuid().ToString().Replace('-', '_');
|
string id = Guid.NewGuid().ToString().Replace('-', '_');
|
||||||
Template = $"kyoo_template_{id}";
|
Template = $"kyoo_template_{id}";
|
||||||
|
|
||||||
DbContextOptions<DatabaseContext> options = new DbContextOptionsBuilder<DatabaseContext>()
|
_options = new DbContextOptionsBuilder<DatabaseContext>()
|
||||||
.UseNpgsql(Connection)
|
.UseNpgsql(Connection)
|
||||||
.Options;
|
.Options;
|
||||||
|
|
||||||
_context = new PostgresContext(options);
|
using PostgresContext context = new(_options);
|
||||||
_context.Database.EnsureCreated();
|
context.Database.Migrate();
|
||||||
TestSample.FillDatabase(_context);
|
|
||||||
_context.Database.CloseConnection();
|
using NpgsqlConnection conn = (NpgsqlConnection)context.Database.GetDbConnection();
|
||||||
|
conn.Open();
|
||||||
|
conn.ReloadTypes();
|
||||||
|
|
||||||
|
TestSample.FillDatabase(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_context.Database.EnsureDeleted();
|
using PostgresContext context = new(_options);
|
||||||
_context.Dispose();
|
context.Database.EnsureDeleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user