From b753fdd2b009f872dfd5c8fcf8d8ced68e22ac1c Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 22 Jul 2023 16:34:47 +0900 Subject: [PATCH] Fix database migration issue --- .../Models/Resources/Collection.cs | 2 +- .../Models/Resources/Episode.cs | 4 +- .../Models/Resources/Library.cs | 2 +- .../Models/Resources/People.cs | 4 +- .../Models/Resources/Season.cs | 2 +- .../Models/Resources/Show.cs | 8 ++-- .../Models/Resources/Studio.cs | 2 +- .../20230621074246_RemoveTrigers.Designer.cs | 3 +- .../20230621074246_RemoveTrigers.cs | 38 +++++++++++-------- .../Database/RepositoryActivator.cs | 4 +- docker-compose.dev.yml | 2 +- docker-compose.prod.yml | 2 +- docker-compose.yml | 2 +- 13 files changed, 42 insertions(+), 33 deletions(-) diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Collection.cs b/back/src/Kyoo.Abstractions/Models/Resources/Collection.cs index 101781f4..079c5eef 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Collection.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Collection.cs @@ -57,6 +57,6 @@ namespace Kyoo.Abstractions.Models [LoadableRelation] public ICollection Libraries { get; set; } /// - [EditableRelation] [LoadableRelation] public ICollection ExternalIDs { get; set; } + [EditableRelation][LoadableRelation] public ICollection ExternalIDs { get; set; } } } diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs b/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs index ccf1f420..619b802e 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs @@ -146,12 +146,12 @@ namespace Kyoo.Abstractions.Models public DateTime? ReleaseDate { get; set; } /// - [EditableRelation] [LoadableRelation] public ICollection ExternalIDs { get; set; } + [EditableRelation][LoadableRelation] public ICollection ExternalIDs { get; set; } /// /// The list of tracks this episode has. This lists video, audio and subtitles available. /// - [EditableRelation] [LoadableRelation] public ICollection Tracks { get; set; } + [EditableRelation][LoadableRelation] public ICollection Tracks { get; set; } /// /// Get the slug of an episode. diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Library.cs b/back/src/Kyoo.Abstractions/Models/Resources/Library.cs index a615b0f4..e56bb352 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Library.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Library.cs @@ -45,7 +45,7 @@ namespace Kyoo.Abstractions.Models /// /// The list of used for items in this library. /// - [EditableRelation] [LoadableRelation] public ICollection Providers { get; set; } + [EditableRelation][LoadableRelation] public ICollection Providers { get; set; } /// /// The list of shows in this library. diff --git a/back/src/Kyoo.Abstractions/Models/Resources/People.cs b/back/src/Kyoo.Abstractions/Models/Resources/People.cs index 71f9012d..9ed2cea3 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/People.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/People.cs @@ -41,11 +41,11 @@ namespace Kyoo.Abstractions.Models public Dictionary Images { get; set; } /// - [EditableRelation] [LoadableRelation] public ICollection ExternalIDs { get; set; } + [EditableRelation][LoadableRelation] public ICollection ExternalIDs { get; set; } /// /// The list of roles this person has played in. See for more information. /// - [EditableRelation] [LoadableRelation] public ICollection Roles { get; set; } + [EditableRelation][LoadableRelation] public ICollection Roles { get; set; } } } diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Season.cs b/back/src/Kyoo.Abstractions/Models/Resources/Season.cs index f07055e8..91063b8b 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Season.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Season.cs @@ -102,7 +102,7 @@ namespace Kyoo.Abstractions.Models public Dictionary Images { get; set; } /// - [EditableRelation] [LoadableRelation] public ICollection ExternalIDs { get; set; } + [EditableRelation][LoadableRelation] public ICollection ExternalIDs { get; set; } /// /// The list of episodes that this season contains. diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Show.cs b/back/src/Kyoo.Abstractions/Models/Resources/Show.cs index 97061446..90600d0d 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Show.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Show.cs @@ -88,7 +88,7 @@ namespace Kyoo.Abstractions.Models public bool IsMovie { get; set; } /// - [EditableRelation] [LoadableRelation] public ICollection ExternalIDs { get; set; } + [EditableRelation][LoadableRelation] public ICollection ExternalIDs { get; set; } /// /// The ID of the Studio that made this show. @@ -99,17 +99,17 @@ namespace Kyoo.Abstractions.Models /// The Studio that made this show. /// This must be explicitly loaded via a call to . /// - [LoadableRelation(nameof(StudioID))] [EditableRelation] public Studio Studio { get; set; } + [LoadableRelation(nameof(StudioID))][EditableRelation] public Studio Studio { get; set; } /// /// The list of genres (themes) this show has. /// - [LoadableRelation] [EditableRelation] public ICollection Genres { get; set; } + [LoadableRelation][EditableRelation] public ICollection Genres { get; set; } /// /// The list of people that made this show. /// - [LoadableRelation] [EditableRelation] public ICollection People { get; set; } + [LoadableRelation][EditableRelation] public ICollection People { get; set; } /// /// The different seasons in this show. If this is a movie, this list is always null or empty. diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Studio.cs b/back/src/Kyoo.Abstractions/Models/Resources/Studio.cs index 4bfcf5d0..973404d2 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Studio.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Studio.cs @@ -44,7 +44,7 @@ namespace Kyoo.Abstractions.Models [LoadableRelation] public ICollection Shows { get; set; } /// - [EditableRelation] [LoadableRelation] public ICollection ExternalIDs { get; set; } + [EditableRelation][LoadableRelation] public ICollection ExternalIDs { get; set; } /// /// Create a new, empty, . diff --git a/back/src/Kyoo.Postgresql/Migrations/20230621074246_RemoveTrigers.Designer.cs b/back/src/Kyoo.Postgresql/Migrations/20230621074246_RemoveTrigers.Designer.cs index 58f1b145..84ac2c3f 100644 --- a/back/src/Kyoo.Postgresql/Migrations/20230621074246_RemoveTrigers.Designer.cs +++ b/back/src/Kyoo.Postgresql/Migrations/20230621074246_RemoveTrigers.Designer.cs @@ -15,7 +15,8 @@ namespace Kyoo.Postgresql.Migrations [Migration("20230621074246_RemoveTrigers")] partial class RemoveTrigers { - protected override void BuildTargetModel(ModelBuilder modelBuilder) + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder diff --git a/back/src/Kyoo.Postgresql/Migrations/20230621074246_RemoveTrigers.cs b/back/src/Kyoo.Postgresql/Migrations/20230621074246_RemoveTrigers.cs index 69275171..50a96086 100644 --- a/back/src/Kyoo.Postgresql/Migrations/20230621074246_RemoveTrigers.cs +++ b/back/src/Kyoo.Postgresql/Migrations/20230621074246_RemoveTrigers.cs @@ -1,19 +1,33 @@ +// Kyoo - A portable and vast media library solution. +// Copyright (c) Kyoo. +// +// See AUTHORS.md and LICENSE file in the project root for full license information. +// +// Kyoo is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// Kyoo is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kyoo. If not, see . + using Microsoft.EntityFrameworkCore.Migrations; namespace Kyoo.Postgresql.Migrations { + /// + /// Remove triggers + /// public partial class RemoveTrigers : Migration { + /// protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.AlterDatabase() - .Annotation("Npgsql:Enum:item_type", "show,movie,collection") - .Annotation("Npgsql:Enum:status", "unknown,finished,airing,planned") - .Annotation("Npgsql:Enum:stream_type", "unknown,video,audio,subtitle") - .OldAnnotation("Npgsql:Enum:item_type", "show,movie,collection") - .OldAnnotation("Npgsql:Enum:status", "unknown,finished,airing,planned") - .OldAnnotation("Npgsql:Enum:stream_type", "unknown,video,audio,subtitle,attachment"); - // language=PostgreSQL migrationBuilder.Sql("DROP TRIGGER show_slug_trigger ON shows;"); // language=PostgreSQL @@ -36,15 +50,9 @@ namespace Kyoo.Postgresql.Migrations migrationBuilder.Sql(@"DROP FUNCTION episode_update_tracks_slug;"); } + /// protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.AlterDatabase() - .Annotation("Npgsql:Enum:item_type", "show,movie,collection") - .Annotation("Npgsql:Enum:status", "unknown,finished,airing,planned") - .Annotation("Npgsql:Enum:stream_type", "unknown,video,audio,subtitle,attachment") - .OldAnnotation("Npgsql:Enum:item_type", "show,movie,collection") - .OldAnnotation("Npgsql:Enum:status", "unknown,finished,airing,planned") - .OldAnnotation("Npgsql:Enum:stream_type", "unknown,video,audio,subtitle"); } } } diff --git a/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs b/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs index dbe697f4..fe9adcbc 100644 --- a/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs +++ b/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs @@ -45,11 +45,11 @@ namespace Kyoo.Tests.Database PeopleRepository people = new(_NewContext(), provider, new Lazy(() => LibraryManager.ShowRepository)); ShowRepository show = new(_NewContext(), studio, people, genre, provider); - SeasonRepository season = new(_NewContext(), provider); + SeasonRepository season = new(_NewContext(), show, provider); LibraryItemRepository libraryItem = new(_NewContext(), new Lazy(() => LibraryManager.LibraryRepository)); TrackRepository track = new(_NewContext()); - EpisodeRepository episode = new(_NewContext(), provider, track); + EpisodeRepository episode = new(_NewContext(), show, provider, track); UserRepository user = new(_NewContext()); LibraryManager = new LibraryManager(new IBaseRepository[] { diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index b510fa5b..fdc036df 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -80,7 +80,7 @@ services: - "8901:8901" postgres: - image: "postgres" + image: postgres:15 restart: on-failure env_file: - ./.env diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 618a3454..57cea1d8 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -58,7 +58,7 @@ services: - "8901:8901" postgres: - image: postgres + image: postgres:15 restart: on-failure env_file: - ./.env diff --git a/docker-compose.yml b/docker-compose.yml index fc1b6db5..14bfe964 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -58,7 +58,7 @@ services: - "8901:8901" postgres: - image: postgres + image: postgres:15 restart: on-failure env_file: - ./.env