Updating migrations to use the unique slug of shows

This commit is contained in:
Zoe Roux 2020-06-24 01:39:53 +02:00
parent d3a126bf03
commit 9d6efebcf2
4 changed files with 19 additions and 1 deletions

View File

@ -10,7 +10,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Models.DatabaseMigrations.Internal namespace Kyoo.Models.DatabaseMigrations.Internal
{ {
[DbContext(typeof(DatabaseContext))] [DbContext(typeof(DatabaseContext))]
[Migration("20200623000428_Initial")] [Migration("20200623233713_Initial")]
partial class Initial partial class Initial
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -432,6 +432,9 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.HasKey("ID"); b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("StudioID"); b.HasIndex("StudioID");
b.ToTable("Shows"); b.ToTable("Shows");

View File

@ -523,6 +523,12 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
columns: new[] { "ShowID", "SeasonNumber" }, columns: new[] { "ShowID", "SeasonNumber" },
unique: true); unique: true);
migrationBuilder.CreateIndex(
name: "IX_Shows_Slug",
table: "Shows",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Shows_StudioID", name: "IX_Shows_StudioID",
table: "Shows", table: "Shows",

View File

@ -430,6 +430,9 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.HasKey("ID"); b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("StudioID"); b.HasIndex("StudioID");
b.ToTable("Shows"); b.ToTable("Shows");

View File

@ -150,6 +150,12 @@ namespace Kyoo.Controllers
Regex regex = new Regex(patern, RegexOptions.IgnoreCase); Regex regex = new Regex(patern, RegexOptions.IgnoreCase);
Match match = regex.Match(relativePath); Match match = regex.Match(relativePath);
if (!match.Success)
{
await Console.Error.WriteLineAsync($"The episode at {path} does not match the episode's regex.");
return;
}
string showPath = Path.GetDirectoryName(path); string showPath = Path.GetDirectoryName(path);
string collectionName = match.Groups["Collection"]?.Value; string collectionName = match.Groups["Collection"]?.Value;
string showName = match.Groups["Show"].Value; string showName = match.Groups["Show"].Value;