mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Fixing SQLite episode triggers
This commit is contained in:
parent
27ed470970
commit
6f87139815
@ -60,7 +60,7 @@ namespace Kyoo.Models
|
|||||||
[SerializeIgnore] public string ShowSlug { private get; set; }
|
[SerializeIgnore] public string ShowSlug { private get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ID of the Show containing this episode. This value is only set when the <see cref="Show"/> has been loaded.
|
/// The ID of the Show containing this episode.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SerializeIgnore] public int ShowID { get; set; }
|
[SerializeIgnore] public int ShowID { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -69,7 +69,7 @@ namespace Kyoo.Models
|
|||||||
[LoadableRelation(nameof(ShowID))] public Show Show { get; set; }
|
[LoadableRelation(nameof(ShowID))] public Show Show { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ID of the Season containing this episode. This value is only set when the <see cref="Season"/> has been loaded.
|
/// The ID of the Season containing this episode.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SerializeIgnore] public int? SeasonID { get; set; }
|
[SerializeIgnore] public int? SeasonID { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -41,7 +41,7 @@ namespace Kyoo.Models
|
|||||||
[SerializeIgnore] public string ShowSlug { private get; set; }
|
[SerializeIgnore] public string ShowSlug { private get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ID of the Show containing this season. This value is only set when the <see cref="Show"/> has been loaded.
|
/// The ID of the Show containing this season.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SerializeIgnore] public int ShowID { get; set; }
|
[SerializeIgnore] public int ShowID { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -94,7 +94,7 @@ namespace Kyoo.Models
|
|||||||
[EditableRelation] [LoadableRelation] public ICollection<MetadataID<Show>> ExternalIDs { get; set; }
|
[EditableRelation] [LoadableRelation] public ICollection<MetadataID<Show>> ExternalIDs { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ID of the Studio that made this show. This value is only set when the <see cref="Studio"/> has been loaded.
|
/// The ID of the Studio that made this show.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SerializeIgnore] public int? StudioID { get; set; }
|
[SerializeIgnore] public int? StudioID { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -119,7 +119,7 @@ namespace Kyoo.Models
|
|||||||
[SerializeIgnore] public StreamType Type { get; set; }
|
[SerializeIgnore] public StreamType Type { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ID of the episode that uses this track. This value is only set when the <see cref="Episode"/> has been loaded.
|
/// The ID of the episode that uses this track.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SerializeIgnore] public int EpisodeID { get; set; }
|
[SerializeIgnore] public int EpisodeID { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -163,13 +163,9 @@ namespace Kyoo
|
|||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
foreach (PropertyInfo property in type.GetProperties())
|
foreach (PropertyInfo property in type.GetProperties())
|
||||||
{
|
{
|
||||||
if (!property.CanWrite)
|
if (!property.CanWrite || property.GetCustomAttribute<ComputedAttribute>() != null)
|
||||||
continue;
|
continue;
|
||||||
|
property.SetValue(obj, property.PropertyType.GetClrDefault());
|
||||||
object defaultValue = property.PropertyType.IsValueType
|
|
||||||
? Activator.CreateInstance(property.PropertyType)
|
|
||||||
: null;
|
|
||||||
property.SetValue(obj, defaultValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -132,14 +132,6 @@ namespace Kyoo
|
|||||||
{
|
{
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity<Track>()
|
|
||||||
.Property(t => t.IsDefault)
|
|
||||||
.ValueGeneratedNever();
|
|
||||||
|
|
||||||
modelBuilder.Entity<Track>()
|
|
||||||
.Property(t => t.IsForced)
|
|
||||||
.ValueGeneratedNever();
|
|
||||||
|
|
||||||
modelBuilder.Entity<Show>()
|
modelBuilder.Entity<Show>()
|
||||||
.HasMany(x => x.Seasons)
|
.HasMany(x => x.Seasons)
|
||||||
.WithOne(x => x.Show)
|
.WithOne(x => x.Show)
|
||||||
|
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace Kyoo.Postgresql.Migrations
|
namespace Kyoo.Postgresql.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(PostgresContext))]
|
[DbContext(typeof(PostgresContext))]
|
||||||
[Migration("20210623174924_Initial")]
|
[Migration("20210627141933_Initial")]
|
||||||
partial class Initial
|
partial class Initial
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -69,11 +69,11 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
.HasColumnName("id")
|
.HasColumnName("id")
|
||||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
b.Property<int>("AbsoluteNumber")
|
b.Property<int?>("AbsoluteNumber")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("absolute_number");
|
.HasColumnName("absolute_number");
|
||||||
|
|
||||||
b.Property<int>("EpisodeNumber")
|
b.Property<int?>("EpisodeNumber")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("episode_number");
|
.HasColumnName("episode_number");
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("season_id");
|
.HasColumnName("season_id");
|
||||||
|
|
||||||
b.Property<int>("SeasonNumber")
|
b.Property<int?>("SeasonNumber")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("season_number");
|
.HasColumnName("season_number");
|
||||||
|
|
@ -415,9 +415,9 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
slug = table.Column<string>(type: "text", nullable: true),
|
slug = table.Column<string>(type: "text", nullable: true),
|
||||||
show_id = table.Column<int>(type: "integer", nullable: false),
|
show_id = table.Column<int>(type: "integer", nullable: false),
|
||||||
season_id = table.Column<int>(type: "integer", nullable: true),
|
season_id = table.Column<int>(type: "integer", nullable: true),
|
||||||
season_number = table.Column<int>(type: "integer", nullable: false),
|
season_number = table.Column<int>(type: "integer", nullable: true),
|
||||||
episode_number = table.Column<int>(type: "integer", nullable: false),
|
episode_number = table.Column<int>(type: "integer", nullable: true),
|
||||||
absolute_number = table.Column<int>(type: "integer", nullable: false),
|
absolute_number = table.Column<int>(type: "integer", nullable: true),
|
||||||
path = table.Column<string>(type: "text", nullable: true),
|
path = table.Column<string>(type: "text", nullable: true),
|
||||||
thumb = table.Column<string>(type: "text", nullable: true),
|
thumb = table.Column<string>(type: "text", nullable: true),
|
||||||
title = table.Column<string>(type: "text", nullable: true),
|
title = table.Column<string>(type: "text", nullable: true),
|
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace Kyoo.Postgresql.Migrations
|
namespace Kyoo.Postgresql.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(PostgresContext))]
|
[DbContext(typeof(PostgresContext))]
|
||||||
[Migration("20210623174932_Triggers")]
|
[Migration("20210627141941_Triggers")]
|
||||||
partial class Triggers
|
partial class Triggers
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -69,11 +69,11 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
.HasColumnName("id")
|
.HasColumnName("id")
|
||||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
b.Property<int>("AbsoluteNumber")
|
b.Property<int?>("AbsoluteNumber")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("absolute_number");
|
.HasColumnName("absolute_number");
|
||||||
|
|
||||||
b.Property<int>("EpisodeNumber")
|
b.Property<int?>("EpisodeNumber")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("episode_number");
|
.HasColumnName("episode_number");
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("season_id");
|
.HasColumnName("season_id");
|
||||||
|
|
||||||
b.Property<int>("SeasonNumber")
|
b.Property<int?>("SeasonNumber")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("season_number");
|
.HasColumnName("season_number");
|
||||||
|
|
@ -37,10 +37,10 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
BEGIN
|
BEGIN
|
||||||
NEW.slug := CONCAT(
|
NEW.slug := CONCAT(
|
||||||
(SELECT slug FROM shows WHERE id = NEW.show_id),
|
(SELECT slug FROM shows WHERE id = NEW.show_id),
|
||||||
'-s',
|
CASE
|
||||||
NEW.season_number,
|
WHEN NEW.season_number IS NULL THEN CONCAT('-', NEW.absolute_number)
|
||||||
'e',
|
ELSE CONCAT('-s', NEW.season_number, 'e', NEW.episode_number)
|
||||||
NEW.episode_number
|
END
|
||||||
);
|
);
|
||||||
RETURN NEW;
|
RETURN NEW;
|
||||||
END
|
END
|
||||||
@ -48,7 +48,8 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
|
|
||||||
// language=PostgreSQL
|
// language=PostgreSQL
|
||||||
migrationBuilder.Sql(@"
|
migrationBuilder.Sql(@"
|
||||||
CREATE TRIGGER episode_slug_trigger BEFORE INSERT OR UPDATE OF episode_number, season_number, show_id ON episodes
|
CREATE TRIGGER episode_slug_trigger
|
||||||
|
BEFORE INSERT OR UPDATE OF absolute_number, episode_number, season_number, show_id ON episodes
|
||||||
FOR EACH ROW EXECUTE PROCEDURE episode_slug_update();");
|
FOR EACH ROW EXECUTE PROCEDURE episode_slug_update();");
|
||||||
|
|
||||||
|
|
||||||
@ -60,7 +61,11 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
AS $$
|
AS $$
|
||||||
BEGIN
|
BEGIN
|
||||||
UPDATE seasons SET slug = CONCAT(NEW.slug, '-s', season_number) WHERE show_id = NEW.id;
|
UPDATE seasons SET slug = CONCAT(NEW.slug, '-s', season_number) WHERE show_id = NEW.id;
|
||||||
UPDATE episodes SET slug = CONCAT(NEW.slug, '-s', season_number, 'e', episode_number) WHERE show_id = NEW.id;
|
UPDATE episodes SET slug = CASE
|
||||||
|
WHEN season_number IS NULL THEN CONCAT(NEW.slug, '-', absolute_number)
|
||||||
|
ELSE CONCAT(NEW.slug, '-s', season_number, 'e', episode_number)
|
||||||
|
END
|
||||||
|
WHERE show_id = NEW.id;
|
||||||
RETURN NEW;
|
RETURN NEW;
|
||||||
END
|
END
|
||||||
$$;");
|
$$;");
|
@ -67,11 +67,11 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
.HasColumnName("id")
|
.HasColumnName("id")
|
||||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||||
|
|
||||||
b.Property<int>("AbsoluteNumber")
|
b.Property<int?>("AbsoluteNumber")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("absolute_number");
|
.HasColumnName("absolute_number");
|
||||||
|
|
||||||
b.Property<int>("EpisodeNumber")
|
b.Property<int?>("EpisodeNumber")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("episode_number");
|
.HasColumnName("episode_number");
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("season_id");
|
.HasColumnName("season_id");
|
||||||
|
|
||||||
b.Property<int>("SeasonNumber")
|
b.Property<int?>("SeasonNumber")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("season_number");
|
.HasColumnName("season_number");
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ namespace Kyoo.SqLite.Migrations
|
|||||||
BEGIN
|
BEGIN
|
||||||
UPDATE Episodes
|
UPDATE Episodes
|
||||||
SET Slug = (SELECT Slug from Shows WHERE ID = ShowID) ||
|
SET Slug = (SELECT Slug from Shows WHERE ID = ShowID) ||
|
||||||
CASE (SeasonNumber)
|
CASE
|
||||||
WHEN NULL THEN '-' || AbsoluteNumber
|
WHEN SeasonNumber IS NULL THEN '-' || AbsoluteNumber
|
||||||
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
||||||
END
|
END
|
||||||
WHERE ID == new.ID;
|
WHERE ID == new.ID;
|
||||||
@ -40,8 +40,8 @@ namespace Kyoo.SqLite.Migrations
|
|||||||
BEGIN
|
BEGIN
|
||||||
UPDATE Episodes
|
UPDATE Episodes
|
||||||
SET Slug = (SELECT Slug from Shows WHERE ID = ShowID) ||
|
SET Slug = (SELECT Slug from Shows WHERE ID = ShowID) ||
|
||||||
CASE (SeasonNumber)
|
CASE
|
||||||
WHEN NULL THEN '-' || AbsoluteNumber
|
WHEN SeasonNumber IS NULL THEN '-' || AbsoluteNumber
|
||||||
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
||||||
END
|
END
|
||||||
WHERE ID == new.ID;
|
WHERE ID == new.ID;
|
||||||
@ -55,8 +55,8 @@ namespace Kyoo.SqLite.Migrations
|
|||||||
UPDATE Seasons SET Slug = new.Slug || '-s' || SeasonNumber WHERE ShowID = new.ID;
|
UPDATE Seasons SET Slug = new.Slug || '-s' || SeasonNumber WHERE ShowID = new.ID;
|
||||||
UPDATE Episodes
|
UPDATE Episodes
|
||||||
SET Slug = new.Slug ||
|
SET Slug = new.Slug ||
|
||||||
CASE (SeasonNumber)
|
CASE
|
||||||
WHEN NULL THEN '-' || AbsoluteNumber
|
WHEN SeasonNumber IS NULL THEN '-' || AbsoluteNumber
|
||||||
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
||||||
END
|
END
|
||||||
WHERE ShowID = new.ID;
|
WHERE ShowID = new.ID;
|
||||||
|
@ -114,6 +114,9 @@ namespace Kyoo.Controllers
|
|||||||
obj.ExternalIDs.ForEach(x => _database.Entry(x).State = EntityState.Added);
|
obj.ExternalIDs.ForEach(x => _database.Entry(x).State = EntityState.Added);
|
||||||
await _database.SaveChangesAsync($"Trying to insert a duplicated episode (slug {obj.Slug} already exists).");
|
await _database.SaveChangesAsync($"Trying to insert a duplicated episode (slug {obj.Slug} already exists).");
|
||||||
return await ValidateTracks(obj);
|
return await ValidateTracks(obj);
|
||||||
|
// TODO check if this is needed
|
||||||
|
// obj.Slug = await _database.Entry(obj).Property(x => x.Slug).
|
||||||
|
// return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -148,6 +151,7 @@ namespace Kyoo.Controllers
|
|||||||
resource.Tracks = await TaskUtils.DefaultIfNull(resource.Tracks?.MapAsync((x, i) =>
|
resource.Tracks = await TaskUtils.DefaultIfNull(resource.Tracks?.MapAsync((x, i) =>
|
||||||
{
|
{
|
||||||
x.Episode = resource;
|
x.Episode = resource;
|
||||||
|
// TODO use a trigger for the next line.
|
||||||
x.TrackIndex = resource.Tracks.Take(i).Count(y => x.Language == y.Language
|
x.TrackIndex = resource.Tracks.Take(i).Count(y => x.Language == y.Language
|
||||||
&& x.IsForced == y.IsForced
|
&& x.IsForced == y.IsForced
|
||||||
&& x.Codec == y.Codec
|
&& x.Codec == y.Codec
|
||||||
|
@ -47,8 +47,8 @@ namespace Kyoo
|
|||||||
// TODO remove postgres from here and load it like a normal plugin.
|
// TODO remove postgres from here and load it like a normal plugin.
|
||||||
_plugins.LoadPlugins(new IPlugin[] {
|
_plugins.LoadPlugins(new IPlugin[] {
|
||||||
new CoreModule(configuration),
|
new CoreModule(configuration),
|
||||||
// new PostgresModule(configuration, host),
|
new PostgresModule(configuration, host),
|
||||||
new SqLiteModule(configuration, host),
|
// new SqLiteModule(configuration, host),
|
||||||
new AuthenticationModule(configuration, loggerFactory, host)
|
new AuthenticationModule(configuration, loggerFactory, host)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user