Split movies and shows, enable nullable handling (wip)

This commit is contained in:
Zoe Roux
2023-08-05 14:13:49 +09:00
parent 386c6bf268
commit 19ae15f53f
78 changed files with 1976 additions and 7118 deletions
+40 -47
View File
@@ -41,16 +41,16 @@ namespace Kyoo.Postgresql
/// </remarks>
public abstract class DatabaseContext : DbContext
{
/// <summary>
/// All libraries of Kyoo. See <see cref="Library"/>.
/// </summary>
public DbSet<Library> Libraries { get; set; }
/// <summary>
/// All collections of Kyoo. See <see cref="Collection"/>.
/// </summary>
public DbSet<Collection> Collections { get; set; }
/// <summary>
/// All movies of Kyoo. See <see cref="Movie"/>.
/// </summary>
public DbSet<Movie> Movies { get; set; }
/// <summary>
/// All shows of Kyoo. See <see cref="Show"/>.
/// </summary>
@@ -66,11 +66,6 @@ namespace Kyoo.Postgresql
/// </summary>
public DbSet<Episode> Episodes { get; set; }
/// <summary>
/// All genres of Kyoo. See <see cref="Genres"/>.
/// </summary>
public DbSet<Genre> Genres { get; set; }
/// <summary>
/// All people of Kyoo. See <see cref="People"/>.
/// </summary>
@@ -91,18 +86,38 @@ namespace Kyoo.Postgresql
/// </summary>
public DbSet<PeopleRole> PeopleRoles { get; set; }
/// <summary>
/// Episodes with a watch percentage. See <see cref="WatchedEpisode"/>.
/// </summary>
public DbSet<WatchedEpisode> WatchedEpisodes { get; set; }
/// <summary>
/// The list of library items (shows and collections that are part of a library - or the global one).
/// </summary>
/// <remarks>
/// This set is ready only, on most database this will be a view.
/// </remarks>
public DbSet<LibraryItem> LibraryItems { get; set; }
public IQueryable<BagItem> LibraryItems =>
Shows.Select(x => new BagItem
{
ID = x.ID,
Slug = x.Slug,
Name = x.Name,
AirDate = x.StartAir,
Poster = x.Poster,
Rest = x
}).Union(Movies.Select(x => new BagItem
{
ID = x.ID,
Slug = x.Slug,
Name = x.Name,
AirDate = x.AirDate,
Poster = x.Poster,
Rest = x
})).Union(Collections.Select(x => new BagItem
{
ID = x.ID,
Slug = x.Slug,
Name = x.Name,
AirDate = null,
Poster = x.Poster,
Rest = x
}));
/// <summary>
/// Add a many to many link between two resources.
@@ -138,14 +153,6 @@ namespace Kyoo.Postgresql
: base(options)
{ }
/// <summary>
/// Get the name of the metadata table of the given type.
/// </summary>
/// <typeparam name="T">The type related to the metadata</typeparam>
/// <returns>The name of the table containing the metadata.</returns>
protected abstract string MetadataName<T>()
where T : IMetadata;
/// <summary>
/// Get the name of the link table of the two given types.
/// </summary>
@@ -265,15 +272,16 @@ namespace Kyoo.Postgresql
.WithOne(x => x.Season)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Movie>()
.HasOne(x => x.Studio)
.WithMany(x => x.Movies)
.OnDelete(DeleteBehavior.SetNull);
modelBuilder.Entity<Show>()
.HasOne(x => x.Studio)
.WithMany(x => x.Shows)
.OnDelete(DeleteBehavior.SetNull);
_HasManyToMany<Library, Collection>(modelBuilder, x => x.Collections, x => x.Libraries);
_HasManyToMany<Library, Show>(modelBuilder, x => x.Shows, x => x.Libraries);
_HasManyToMany<Collection, Show>(modelBuilder, x => x.Shows, x => x.Collections);
_HasManyToMany<Show, Genre>(modelBuilder, x => x.Genres, x => x.Shows);
modelBuilder.Entity<User>()
.HasMany(x => x.Watched)
@@ -281,14 +289,15 @@ namespace Kyoo.Postgresql
.UsingEntity(x => x.ToTable(LinkName<User, Show>()));
_HasMetadata<Collection>(modelBuilder);
_HasMetadata<Movie>(modelBuilder);
_HasMetadata<Show>(modelBuilder);
_HasMetadata<Season>(modelBuilder);
_HasMetadata<Episode>(modelBuilder);
_HasMetadata<People>(modelBuilder);
_HasMetadata<Studio>(modelBuilder);
_HasImages<LibraryItem>(modelBuilder);
_HasImages<Collection>(modelBuilder);
_HasImages<Movie>(modelBuilder);
_HasImages<Show>(modelBuilder);
_HasImages<Season>(modelBuilder);
_HasImages<Episode>(modelBuilder);
@@ -299,28 +308,15 @@ namespace Kyoo.Postgresql
modelBuilder.Entity<WatchedEpisode>()
.HasKey(x => new { User = x.UserID, Episode = x.EpisodeID });
modelBuilder.Entity<Collection>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Genre>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Library>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<People>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Show>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Season>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Episode>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Studio>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<User>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Collection>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<Genre>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<Library>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<People>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<Movie>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<Show>()
.HasIndex(x => x.Slug)
.IsUnique();
@@ -342,9 +338,6 @@ namespace Kyoo.Postgresql
modelBuilder.Entity<User>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<LibraryItem>()
.ToView("library_items");
}
/// <summary>
@@ -18,4 +18,8 @@
<ProjectReference Include="../Kyoo.Abstractions/Kyoo.Abstractions.csproj" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>
@@ -1,872 +0,0 @@
// 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 <https://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using Kyoo.Abstractions.Models;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Postgresql.Migrations
{
/// <summary>
/// The initial migration that build most of the database.
/// </summary>
[DbContext(typeof(PostgresContext))]
[Migration("20210801171613_Initial")]
public partial class Initial : Migration
{
/// <inheritdoc/>
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,attachment");
migrationBuilder.CreateTable(
name: "collections",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "text", nullable: false),
name = table.Column<string>(type: "text", nullable: true),
images = table.Column<Dictionary<int, string>>(type: "jsonb", nullable: true),
overview = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_collections", x => x.id);
});
migrationBuilder.CreateTable(
name: "genres",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "text", nullable: false),
name = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_genres", x => x.id);
});
migrationBuilder.CreateTable(
name: "libraries",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "text", nullable: false),
name = table.Column<string>(type: "text", nullable: true),
paths = table.Column<string[]>(type: "text[]", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_libraries", x => x.id);
});
migrationBuilder.CreateTable(
name: "people",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "text", nullable: false),
name = table.Column<string>(type: "text", nullable: true),
images = table.Column<Dictionary<int, string>>(type: "jsonb", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_people", x => x.id);
});
migrationBuilder.CreateTable(
name: "providers",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "text", nullable: false),
name = table.Column<string>(type: "text", nullable: true),
images = table.Column<Dictionary<int, string>>(type: "jsonb", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_providers", x => x.id);
});
migrationBuilder.CreateTable(
name: "studios",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "text", nullable: false),
name = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_studios", x => x.id);
});
migrationBuilder.CreateTable(
name: "users",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "text", nullable: false),
username = table.Column<string>(type: "text", nullable: true),
email = table.Column<string>(type: "text", nullable: true),
password = table.Column<string>(type: "text", nullable: true),
permissions = table.Column<string[]>(type: "text[]", nullable: true),
extra_data = table.Column<Dictionary<string, string>>(type: "jsonb", nullable: true),
images = table.Column<Dictionary<int, string>>(type: "jsonb", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_users", x => x.id);
});
migrationBuilder.CreateTable(
name: "link_library_collection",
columns: table => new
{
collection_id = table.Column<int>(type: "integer", nullable: false),
library_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_link_library_collection", x => new { x.collection_id, x.library_id });
table.ForeignKey(
name: "fk_link_library_collection_collections_collection_id",
column: x => x.collection_id,
principalTable: "collections",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_link_library_collection_libraries_library_id",
column: x => x.library_id,
principalTable: "libraries",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "collection_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_collection_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_collection_metadata_id_collections_collection_id",
column: x => x.resource_id,
principalTable: "collections",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_collection_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "link_library_provider",
columns: table => new
{
library_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_link_library_provider", x => new { x.library_id, x.provider_id });
table.ForeignKey(
name: "fk_link_library_provider_libraries_library_id",
column: x => x.library_id,
principalTable: "libraries",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_link_library_provider_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "people_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_people_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_people_metadata_id_people_people_id",
column: x => x.resource_id,
principalTable: "people",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_people_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "shows",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "text", nullable: false),
title = table.Column<string>(type: "text", nullable: true),
aliases = table.Column<string[]>(type: "text[]", nullable: true),
path = table.Column<string>(type: "text", nullable: true),
overview = table.Column<string>(type: "text", nullable: true),
status = table.Column<Status>(type: "status", nullable: false),
start_air = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
end_air = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
images = table.Column<Dictionary<int, string>>(type: "jsonb", nullable: true),
is_movie = table.Column<bool>(type: "boolean", nullable: false),
studio_id = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_shows", x => x.id);
table.ForeignKey(
name: "fk_shows_studios_studio_id",
column: x => x.studio_id,
principalTable: "studios",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "studio_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_studio_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_studio_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_studio_metadata_id_studios_studio_id",
column: x => x.resource_id,
principalTable: "studios",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "link_collection_show",
columns: table => new
{
collection_id = table.Column<int>(type: "integer", nullable: false),
show_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_link_collection_show", x => new { x.collection_id, x.show_id });
table.ForeignKey(
name: "fk_link_collection_show_collections_collection_id",
column: x => x.collection_id,
principalTable: "collections",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_link_collection_show_shows_show_id",
column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "link_library_show",
columns: table => new
{
library_id = table.Column<int>(type: "integer", nullable: false),
show_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_link_library_show", x => new { x.library_id, x.show_id });
table.ForeignKey(
name: "fk_link_library_show_libraries_library_id",
column: x => x.library_id,
principalTable: "libraries",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_link_library_show_shows_show_id",
column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "link_show_genre",
columns: table => new
{
genre_id = table.Column<int>(type: "integer", nullable: false),
show_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_link_show_genre", x => new { x.genre_id, x.show_id });
table.ForeignKey(
name: "fk_link_show_genre_genres_genre_id",
column: x => x.genre_id,
principalTable: "genres",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_link_show_genre_shows_show_id",
column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "link_user_show",
columns: table => new
{
users_id = table.Column<int>(type: "integer", nullable: false),
watched_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_link_user_show", x => new { x.users_id, x.watched_id });
table.ForeignKey(
name: "fk_link_user_show_shows_watched_id",
column: x => x.watched_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_link_user_show_users_users_id",
column: x => x.users_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "people_roles",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
people_id = table.Column<int>(type: "integer", nullable: false),
show_id = table.Column<int>(type: "integer", nullable: false),
type = table.Column<string>(type: "text", nullable: true),
role = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_people_roles", x => x.id);
table.ForeignKey(
name: "fk_people_roles_people_people_id",
column: x => x.people_id,
principalTable: "people",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_people_roles_shows_show_id",
column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "seasons",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "text", nullable: true),
show_id = table.Column<int>(type: "integer", nullable: false),
season_number = table.Column<int>(type: "integer", nullable: false),
title = table.Column<string>(type: "text", nullable: true),
overview = table.Column<string>(type: "text", nullable: true),
start_date = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
end_date = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
images = table.Column<Dictionary<int, string>>(type: "jsonb", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_seasons", x => x.id);
table.ForeignKey(
name: "fk_seasons_shows_show_id",
column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "show_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_show_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_show_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_show_metadata_id_shows_show_id",
column: x => x.resource_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "episodes",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "text", nullable: true),
show_id = table.Column<int>(type: "integer", nullable: false),
season_id = table.Column<int>(type: "integer", nullable: true),
season_number = table.Column<int>(type: "integer", nullable: true),
episode_number = table.Column<int>(type: "integer", nullable: true),
absolute_number = table.Column<int>(type: "integer", nullable: true),
path = table.Column<string>(type: "text", nullable: true),
images = table.Column<Dictionary<int, string>>(type: "jsonb", nullable: true),
title = table.Column<string>(type: "text", nullable: true),
overview = table.Column<string>(type: "text", nullable: true),
release_date = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_episodes", x => x.id);
table.ForeignKey(
name: "fk_episodes_seasons_season_id",
column: x => x.season_id,
principalTable: "seasons",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_episodes_shows_show_id",
column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "season_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_season_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_season_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_season_metadata_id_seasons_season_id",
column: x => x.resource_id,
principalTable: "seasons",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "episode_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_episode_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_episode_metadata_id_episodes_episode_id",
column: x => x.resource_id,
principalTable: "episodes",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_episode_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "tracks",
columns: table => new
{
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),
is_default = table.Column<bool>(type: "boolean", nullable: false),
is_forced = table.Column<bool>(type: "boolean", nullable: false),
is_external = table.Column<bool>(type: "boolean", nullable: false),
path = table.Column<string>(type: "text", nullable: true),
type = table.Column<object>(type: "stream_type", nullable: false),
episode_id = table.Column<int>(type: "integer", nullable: false),
track_index = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_tracks", x => x.id);
table.ForeignKey(
name: "fk_tracks_episodes_episode_id",
column: x => x.episode_id,
principalTable: "episodes",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "watched_episodes",
columns: table => new
{
user_id = table.Column<int>(type: "integer", nullable: false),
episode_id = table.Column<int>(type: "integer", nullable: false),
watched_percentage = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_watched_episodes", x => new { x.user_id, x.episode_id });
table.ForeignKey(
name: "fk_watched_episodes_episodes_episode_id",
column: x => x.episode_id,
principalTable: "episodes",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_watched_episodes_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_collection_metadata_id_provider_id",
table: "collection_metadata_id",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_collections_slug",
table: "collections",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_episode_metadata_id_provider_id",
table: "episode_metadata_id",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_episodes_season_id",
table: "episodes",
column: "season_id");
migrationBuilder.CreateIndex(
name: "ix_episodes_show_id_season_number_episode_number_absolute_numb",
table: "episodes",
columns: new[] { "show_id", "season_number", "episode_number", "absolute_number" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_episodes_slug",
table: "episodes",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_genres_slug",
table: "genres",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_libraries_slug",
table: "libraries",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_link_collection_show_show_id",
table: "link_collection_show",
column: "show_id");
migrationBuilder.CreateIndex(
name: "ix_link_library_collection_library_id",
table: "link_library_collection",
column: "library_id");
migrationBuilder.CreateIndex(
name: "ix_link_library_provider_provider_id",
table: "link_library_provider",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_link_library_show_show_id",
table: "link_library_show",
column: "show_id");
migrationBuilder.CreateIndex(
name: "ix_link_show_genre_show_id",
table: "link_show_genre",
column: "show_id");
migrationBuilder.CreateIndex(
name: "ix_link_user_show_watched_id",
table: "link_user_show",
column: "watched_id");
migrationBuilder.CreateIndex(
name: "ix_people_slug",
table: "people",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_people_metadata_id_provider_id",
table: "people_metadata_id",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_people_roles_people_id",
table: "people_roles",
column: "people_id");
migrationBuilder.CreateIndex(
name: "ix_people_roles_show_id",
table: "people_roles",
column: "show_id");
migrationBuilder.CreateIndex(
name: "ix_providers_slug",
table: "providers",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_season_metadata_id_provider_id",
table: "season_metadata_id",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_seasons_show_id_season_number",
table: "seasons",
columns: new[] { "show_id", "season_number" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_seasons_slug",
table: "seasons",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_show_metadata_id_provider_id",
table: "show_metadata_id",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_shows_slug",
table: "shows",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_shows_studio_id",
table: "shows",
column: "studio_id");
migrationBuilder.CreateIndex(
name: "ix_studio_metadata_id_provider_id",
table: "studio_metadata_id",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_studios_slug",
table: "studios",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_tracks_episode_id_type_language_track_index_is_forced",
table: "tracks",
columns: new[] { "episode_id", "type", "language", "track_index", "is_forced" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_tracks_slug",
table: "tracks",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_users_slug",
table: "users",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_watched_episodes_episode_id",
table: "watched_episodes",
column: "episode_id");
}
/// <inheritdoc/>
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "collection_metadata_id");
migrationBuilder.DropTable(
name: "episode_metadata_id");
migrationBuilder.DropTable(
name: "link_collection_show");
migrationBuilder.DropTable(
name: "link_library_collection");
migrationBuilder.DropTable(
name: "link_library_provider");
migrationBuilder.DropTable(
name: "link_library_show");
migrationBuilder.DropTable(
name: "link_show_genre");
migrationBuilder.DropTable(
name: "link_user_show");
migrationBuilder.DropTable(
name: "people_metadata_id");
migrationBuilder.DropTable(
name: "people_roles");
migrationBuilder.DropTable(
name: "season_metadata_id");
migrationBuilder.DropTable(
name: "show_metadata_id");
migrationBuilder.DropTable(
name: "studio_metadata_id");
migrationBuilder.DropTable(
name: "tracks");
migrationBuilder.DropTable(
name: "watched_episodes");
migrationBuilder.DropTable(
name: "collections");
migrationBuilder.DropTable(
name: "libraries");
migrationBuilder.DropTable(
name: "genres");
migrationBuilder.DropTable(
name: "people");
migrationBuilder.DropTable(
name: "providers");
migrationBuilder.DropTable(
name: "episodes");
migrationBuilder.DropTable(
name: "users");
migrationBuilder.DropTable(
name: "seasons");
migrationBuilder.DropTable(
name: "shows");
migrationBuilder.DropTable(
name: "studios");
}
}
}
@@ -1,192 +0,0 @@
// 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 <https://www.gnu.org/licenses/>.
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Kyoo.Postgresql.Migrations
{
/// <summary>
/// A migration that adds postgres triggers to update slugs.
/// </summary>
[DbContext(typeof(PostgresContext))]
[Migration("20210801171641_Triggers")]
public partial class Triggers : Migration
{
/// <inheritdoc/>
protected override void Up(MigrationBuilder migrationBuilder)
{
// language=PostgreSQL
migrationBuilder.Sql(@"
CREATE FUNCTION season_slug_update()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS $$
BEGIN
NEW.slug := CONCAT(
(SELECT slug FROM shows WHERE id = NEW.show_id),
'-s',
NEW.season_number
);
RETURN NEW;
END
$$;");
// language=PostgreSQL
migrationBuilder.Sql(@"
CREATE TRIGGER season_slug_trigger BEFORE INSERT OR UPDATE OF season_number, show_id ON seasons
FOR EACH ROW EXECUTE PROCEDURE season_slug_update();");
// language=PostgreSQL
migrationBuilder.Sql(@"
CREATE FUNCTION episode_slug_update()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS $$
BEGIN
NEW.slug := CONCAT(
(SELECT slug FROM shows WHERE id = NEW.show_id),
CASE
WHEN NEW.season_number IS NULL AND NEW.episode_number IS NULL THEN NULL
WHEN NEW.season_number IS NULL THEN CONCAT('-', NEW.absolute_number)
ELSE CONCAT('-s', NEW.season_number, 'e', NEW.episode_number)
END
);
RETURN NEW;
END
$$;");
// language=PostgreSQL
migrationBuilder.Sql(@"
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();");
// language=PostgreSQL
migrationBuilder.Sql(@"
CREATE FUNCTION show_slug_update()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS $$
BEGIN
UPDATE seasons SET slug = CONCAT(NEW.slug, '-s', season_number) WHERE show_id = NEW.id;
UPDATE episodes SET slug = CASE
WHEN season_number IS NULL AND episode_number IS NULL THEN NEW.slug
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;
END
$$;");
// language=PostgreSQL
migrationBuilder.Sql(@"
CREATE TRIGGER show_slug_trigger AFTER UPDATE OF slug ON shows
FOR EACH ROW EXECUTE PROCEDURE show_slug_update();");
// language=PostgreSQL
migrationBuilder.Sql(@"
CREATE FUNCTION episode_update_tracks_slug()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS $$
BEGIN
UPDATE tracks SET slug = CONCAT(
NEW.slug,
'.', language,
CASE (track_index)
WHEN 0 THEN ''
ELSE CONCAT('-', track_index)
END,
CASE (is_forced)
WHEN false THEN ''
ELSE '.forced'
END,
'.', type
) WHERE episode_id = NEW.id;
RETURN NEW;
END;
$$;");
// language=PostgreSQL
migrationBuilder.Sql(@"
CREATE TRIGGER episode_track_slug_trigger AFTER UPDATE OF slug ON episodes
FOR EACH ROW EXECUTE PROCEDURE episode_update_tracks_slug();");
// language=PostgreSQL
migrationBuilder.Sql(@"
CREATE FUNCTION track_slug_update()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS $$
BEGIN
IF NEW.track_index = 0 THEN
NEW.track_index := (SELECT COUNT(*) FROM tracks
WHERE episode_id = NEW.episode_id AND type = NEW.type
AND language = NEW.language AND is_forced = NEW.is_forced);
END IF;
NEW.slug := CONCAT(
(SELECT slug FROM episodes WHERE id = NEW.episode_id),
'.', COALESCE(NEW.language, 'und'),
CASE (NEW.track_index)
WHEN 0 THEN ''
ELSE CONCAT('-', NEW.track_index)
END,
CASE (NEW.is_forced)
WHEN false THEN ''
ELSE '.forced'
END,
'.', NEW.type
);
RETURN NEW;
END
$$;");
// language=PostgreSQL
migrationBuilder.Sql(@"
CREATE TRIGGER track_slug_trigger
BEFORE INSERT OR UPDATE OF episode_id, is_forced, language, track_index, type ON tracks
FOR EACH ROW EXECUTE PROCEDURE track_slug_update();");
MigrationHelper.CreateLibraryItemsView(migrationBuilder);
}
/// <inheritdoc/>
protected override void Down(MigrationBuilder migrationBuilder)
{
// language=PostgreSQL
migrationBuilder.Sql("DROP TRIGGER show_slug_trigger ON shows;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP FUNCTION show_slug_update;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP TRIGGER season_slug_trigger ON seasons;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP FUNCTION season_slug_update;");
// language=PostgreSQL
migrationBuilder.Sql("DROP TRIGGER episode_slug_trigger ON episodes;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP FUNCTION episode_slug_update;");
// language=PostgreSQL
migrationBuilder.Sql("DROP TRIGGER track_slug_trigger ON tracks;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP FUNCTION track_slug_update;");
// language=PostgreSQL
migrationBuilder.Sql("DROP TRIGGER episode_track_slug_trigger ON episodes;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP FUNCTION episode_update_tracks_slug;");
MigrationHelper.DropLibraryItemsView(migrationBuilder);
}
}
}
@@ -1,114 +0,0 @@
// 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 <https://www.gnu.org/licenses/>.
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Kyoo.Postgresql.Migrations
{
/// <summary>
/// Remove triggers
/// </summary>
[DbContext(typeof(PostgresContext))]
[Migration("20230724144449_RemoveTriggers")]
public partial class RemoveTriggers : Migration
{
/// <inheritdoc/>
protected override void Up(MigrationBuilder migrationBuilder)
{
// language=PostgreSQL
migrationBuilder.Sql("DROP TRIGGER show_slug_trigger ON shows;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP FUNCTION show_slug_update;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP TRIGGER season_slug_trigger ON seasons;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP FUNCTION season_slug_update;");
// language=PostgreSQL
migrationBuilder.Sql("DROP TRIGGER episode_slug_trigger ON episodes;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP FUNCTION episode_slug_update;");
// language=PostgreSQL
migrationBuilder.Sql("DROP TRIGGER track_slug_trigger ON tracks;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP FUNCTION track_slug_update;");
// language=PostgreSQL
migrationBuilder.Sql("DROP TRIGGER episode_track_slug_trigger ON episodes;");
// language=PostgreSQL
migrationBuilder.Sql(@"DROP FUNCTION episode_update_tracks_slug;");
migrationBuilder.AlterColumn<string>(
name: "slug",
table: "tracks",
type: "text",
nullable: false,
defaultValue: string.Empty,
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "slug",
table: "seasons",
type: "text",
nullable: false,
defaultValue: string.Empty,
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "slug",
table: "episodes",
type: "text",
nullable: false,
defaultValue: string.Empty,
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
}
/// <inheritdoc/>
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "slug",
table: "tracks",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "slug",
table: "seasons",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "slug",
table: "episodes",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
}
}
}
File diff suppressed because it is too large Load Diff
@@ -1,138 +0,0 @@
// 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 <https://www.gnu.org/licenses/>.
using System;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
/// <inheritdoc />
[DbContext(typeof(PostgresContext))]
[Migration("20230726100747_Timestamp")]
public partial class Timestamp : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
MigrationHelper.DropLibraryItemsView(migrationBuilder);
migrationBuilder.AlterColumn<DateTime>(
name: "start_air",
table: "shows",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "end_air",
table: "shows",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "start_date",
table: "seasons",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "end_date",
table: "seasons",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "release_date",
table: "episodes",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone",
oldNullable: true);
MigrationHelper.CreateLibraryItemsView(migrationBuilder);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
MigrationHelper.DropLibraryItemsView(migrationBuilder);
migrationBuilder.AlterColumn<DateTime>(
name: "start_air",
table: "shows",
type: "timestamp without time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "end_air",
table: "shows",
type: "timestamp without time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "start_date",
table: "seasons",
type: "timestamp without time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "end_date",
table: "seasons",
type: "timestamp without time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "release_date",
table: "episodes",
type: "timestamp without time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true);
MigrationHelper.CreateLibraryItemsView(migrationBuilder);
}
}
}
File diff suppressed because it is too large Load Diff
@@ -1,95 +0,0 @@
// 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 <https://www.gnu.org/licenses/>.
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
/// <inheritdoc />
public partial class RemoveTracks : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "tracks");
migrationBuilder.AlterDatabase()
.Annotation("Npgsql:Enum:item_type", "show,movie,collection")
.Annotation("Npgsql:Enum:status", "unknown,finished,airing,planned")
.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");
}
/// <inheritdoc />
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")
.OldAnnotation("Npgsql:Enum:item_type", "show,movie,collection")
.OldAnnotation("Npgsql:Enum:status", "unknown,finished,airing,planned");
migrationBuilder.CreateTable(
name: "tracks",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
episode_id = table.Column<int>(type: "integer", nullable: false),
codec = table.Column<string>(type: "text", nullable: true),
is_default = table.Column<bool>(type: "boolean", nullable: false),
is_external = table.Column<bool>(type: "boolean", nullable: false),
is_forced = table.Column<bool>(type: "boolean", nullable: false),
language = table.Column<string>(type: "text", nullable: true),
path = table.Column<string>(type: "text", nullable: true),
slug = table.Column<string>(type: "text", nullable: false),
title = table.Column<string>(type: "text", nullable: true),
track_index = table.Column<int>(type: "integer", nullable: false),
type = table.Column<string>(type: "stream_type", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_tracks", x => x.id);
table.ForeignKey(
name: "fk_tracks_episodes_episode_id",
column: x => x.episode_id,
principalTable: "episodes",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_tracks_episode_id_type_language_track_index_is_forced",
table: "tracks",
columns: new[] { "episode_id", "type", "language", "track_index", "is_forced" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_tracks_slug",
table: "tracks",
column: "slug",
unique: true);
}
}
}
@@ -1,772 +0,0 @@
// 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 <https://www.gnu.org/licenses/>.
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
/// <inheritdoc />
public partial class AddBlurhash : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
MigrationHelper.DropLibraryItemsView(migrationBuilder);
migrationBuilder.DropTable(
name: "collection_metadata_id");
migrationBuilder.DropTable(
name: "episode_metadata_id");
migrationBuilder.DropTable(
name: "link_library_provider");
migrationBuilder.DropTable(
name: "people_metadata_id");
migrationBuilder.DropTable(
name: "season_metadata_id");
migrationBuilder.DropTable(
name: "show_metadata_id");
migrationBuilder.DropTable(
name: "studio_metadata_id");
migrationBuilder.DropTable(
name: "providers");
migrationBuilder.DropColumn(
name: "images",
table: "users");
migrationBuilder.DropColumn(
name: "images",
table: "shows");
migrationBuilder.DropColumn(
name: "images",
table: "seasons");
migrationBuilder.DropColumn(
name: "images",
table: "people");
migrationBuilder.DropColumn(
name: "images",
table: "episodes");
migrationBuilder.DropColumn(
name: "images",
table: "collections");
migrationBuilder.AddColumn<string>(
name: "logo_blurhash",
table: "users",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "logo_source",
table: "users",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "external_id",
table: "studios",
type: "json",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "external_id",
table: "shows",
type: "json",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "logo_blurhash",
table: "shows",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "logo_source",
table: "shows",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "poster_blurhash",
table: "shows",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "poster_source",
table: "shows",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "thumbnail_blurhash",
table: "shows",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "thumbnail_source",
table: "shows",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "trailer",
table: "shows",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "external_id",
table: "seasons",
type: "json",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "logo_blurhash",
table: "seasons",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "logo_source",
table: "seasons",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "poster_blurhash",
table: "seasons",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "poster_source",
table: "seasons",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "thumbnail_blurhash",
table: "seasons",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "thumbnail_source",
table: "seasons",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "external_id",
table: "people",
type: "json",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "logo_blurhash",
table: "people",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "logo_source",
table: "people",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "poster_blurhash",
table: "people",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "poster_source",
table: "people",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "thumbnail_blurhash",
table: "people",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "thumbnail_source",
table: "people",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "external_id",
table: "episodes",
type: "json",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "logo_blurhash",
table: "episodes",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "logo_source",
table: "episodes",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "poster_blurhash",
table: "episodes",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "poster_source",
table: "episodes",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "thumbnail_blurhash",
table: "episodes",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "thumbnail_source",
table: "episodes",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "external_id",
table: "collections",
type: "json",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "logo_blurhash",
table: "collections",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "logo_source",
table: "collections",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "poster_blurhash",
table: "collections",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "poster_source",
table: "collections",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "thumbnail_blurhash",
table: "collections",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "thumbnail_source",
table: "collections",
type: "text",
nullable: true);
MigrationHelper.CreateLibraryItemsView(migrationBuilder);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
MigrationHelper.DropLibraryItemsView(migrationBuilder);
migrationBuilder.DropColumn(
name: "logo_blurhash",
table: "users");
migrationBuilder.DropColumn(
name: "logo_source",
table: "users");
migrationBuilder.DropColumn(
name: "external_id",
table: "studios");
migrationBuilder.DropColumn(
name: "external_id",
table: "shows");
migrationBuilder.DropColumn(
name: "logo_blurhash",
table: "shows");
migrationBuilder.DropColumn(
name: "logo_source",
table: "shows");
migrationBuilder.DropColumn(
name: "poster_blurhash",
table: "shows");
migrationBuilder.DropColumn(
name: "poster_source",
table: "shows");
migrationBuilder.DropColumn(
name: "thumbnail_blurhash",
table: "shows");
migrationBuilder.DropColumn(
name: "thumbnail_source",
table: "shows");
migrationBuilder.DropColumn(
name: "trailer",
table: "shows");
migrationBuilder.DropColumn(
name: "external_id",
table: "seasons");
migrationBuilder.DropColumn(
name: "logo_blurhash",
table: "seasons");
migrationBuilder.DropColumn(
name: "logo_source",
table: "seasons");
migrationBuilder.DropColumn(
name: "poster_blurhash",
table: "seasons");
migrationBuilder.DropColumn(
name: "poster_source",
table: "seasons");
migrationBuilder.DropColumn(
name: "thumbnail_blurhash",
table: "seasons");
migrationBuilder.DropColumn(
name: "thumbnail_source",
table: "seasons");
migrationBuilder.DropColumn(
name: "external_id",
table: "people");
migrationBuilder.DropColumn(
name: "logo_blurhash",
table: "people");
migrationBuilder.DropColumn(
name: "logo_source",
table: "people");
migrationBuilder.DropColumn(
name: "poster_blurhash",
table: "people");
migrationBuilder.DropColumn(
name: "poster_source",
table: "people");
migrationBuilder.DropColumn(
name: "thumbnail_blurhash",
table: "people");
migrationBuilder.DropColumn(
name: "thumbnail_source",
table: "people");
migrationBuilder.DropColumn(
name: "external_id",
table: "episodes");
migrationBuilder.DropColumn(
name: "logo_blurhash",
table: "episodes");
migrationBuilder.DropColumn(
name: "logo_source",
table: "episodes");
migrationBuilder.DropColumn(
name: "poster_blurhash",
table: "episodes");
migrationBuilder.DropColumn(
name: "poster_source",
table: "episodes");
migrationBuilder.DropColumn(
name: "thumbnail_blurhash",
table: "episodes");
migrationBuilder.DropColumn(
name: "thumbnail_source",
table: "episodes");
migrationBuilder.DropColumn(
name: "external_id",
table: "collections");
migrationBuilder.DropColumn(
name: "logo_blurhash",
table: "collections");
migrationBuilder.DropColumn(
name: "logo_source",
table: "collections");
migrationBuilder.DropColumn(
name: "poster_blurhash",
table: "collections");
migrationBuilder.DropColumn(
name: "poster_source",
table: "collections");
migrationBuilder.DropColumn(
name: "thumbnail_blurhash",
table: "collections");
migrationBuilder.DropColumn(
name: "thumbnail_source",
table: "collections");
migrationBuilder.AddColumn<Dictionary<int, string>>(
name: "images",
table: "users",
type: "jsonb",
nullable: true);
migrationBuilder.AddColumn<Dictionary<int, string>>(
name: "images",
table: "shows",
type: "jsonb",
nullable: true);
migrationBuilder.AddColumn<Dictionary<int, string>>(
name: "images",
table: "seasons",
type: "jsonb",
nullable: true);
migrationBuilder.AddColumn<Dictionary<int, string>>(
name: "images",
table: "people",
type: "jsonb",
nullable: true);
migrationBuilder.AddColumn<Dictionary<int, string>>(
name: "images",
table: "episodes",
type: "jsonb",
nullable: true);
migrationBuilder.AddColumn<Dictionary<int, string>>(
name: "images",
table: "collections",
type: "jsonb",
nullable: true);
migrationBuilder.CreateTable(
name: "providers",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
images = table.Column<Dictionary<int, string>>(type: "jsonb", nullable: true),
name = table.Column<string>(type: "text", nullable: true),
slug = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_providers", x => x.id);
});
migrationBuilder.CreateTable(
name: "collection_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_collection_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_collection_metadata_id_collections_collection_id",
column: x => x.resource_id,
principalTable: "collections",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_collection_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "episode_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_episode_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_episode_metadata_id_episodes_episode_id",
column: x => x.resource_id,
principalTable: "episodes",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_episode_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "link_library_provider",
columns: table => new
{
library_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_link_library_provider", x => new { x.library_id, x.provider_id });
table.ForeignKey(
name: "fk_link_library_provider_libraries_library_id",
column: x => x.library_id,
principalTable: "libraries",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_link_library_provider_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "people_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_people_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_people_metadata_id_people_people_id",
column: x => x.resource_id,
principalTable: "people",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_people_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "season_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_season_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_season_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_season_metadata_id_seasons_season_id",
column: x => x.resource_id,
principalTable: "seasons",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "show_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_show_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_show_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_show_metadata_id_shows_show_id",
column: x => x.resource_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "studio_metadata_id",
columns: table => new
{
resource_id = table.Column<int>(type: "integer", nullable: false),
provider_id = table.Column<int>(type: "integer", nullable: false),
data_id = table.Column<string>(type: "text", nullable: true),
link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_studio_metadata_id", x => new { x.resource_id, x.provider_id });
table.ForeignKey(
name: "fk_studio_metadata_id_providers_provider_id",
column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_studio_metadata_id_studios_studio_id",
column: x => x.resource_id,
principalTable: "studios",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_collection_metadata_id_provider_id",
table: "collection_metadata_id",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_episode_metadata_id_provider_id",
table: "episode_metadata_id",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_link_library_provider_provider_id",
table: "link_library_provider",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_people_metadata_id_provider_id",
table: "people_metadata_id",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_providers_slug",
table: "providers",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_season_metadata_id_provider_id",
table: "season_metadata_id",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_show_metadata_id_provider_id",
table: "show_metadata_id",
column: "provider_id");
migrationBuilder.CreateIndex(
name: "ix_studio_metadata_id_provider_id",
table: "studio_metadata_id",
column: "provider_id");
MigrationHelper.CreateLibraryItemsView(migrationBuilder);
}
}
}
@@ -0,0 +1,528 @@
using System;
using Kyoo.Abstractions.Models;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
/// <inheritdoc />
public partial class initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("Npgsql:Enum:genre", "action,adventure,animation,comedy,crime,documentary,drama,family,fantasy,history,horror,music,mystery,romance,science_fiction,thriller,war,western")
.Annotation("Npgsql:Enum:status", "unknown,finished,airing,planned");
migrationBuilder.CreateTable(
name: "collections",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
name = table.Column<string>(type: "text", nullable: false),
poster_source = table.Column<string>(type: "text", nullable: true),
poster_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
thumbnail_source = table.Column<string>(type: "text", nullable: true),
thumbnail_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
logo_source = table.Column<string>(type: "text", nullable: true),
logo_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
overview = table.Column<string>(type: "text", nullable: true),
external_id = table.Column<string>(type: "json", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_collections", x => x.id);
});
migrationBuilder.CreateTable(
name: "people",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
name = table.Column<string>(type: "text", nullable: false),
poster_source = table.Column<string>(type: "text", nullable: true),
poster_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
thumbnail_source = table.Column<string>(type: "text", nullable: true),
thumbnail_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
logo_source = table.Column<string>(type: "text", nullable: true),
logo_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
external_id = table.Column<string>(type: "json", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_people", x => x.id);
});
migrationBuilder.CreateTable(
name: "studios",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
name = table.Column<string>(type: "text", nullable: false),
external_id = table.Column<string>(type: "json", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_studios", x => x.id);
});
migrationBuilder.CreateTable(
name: "users",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
username = table.Column<string>(type: "text", nullable: false),
email = table.Column<string>(type: "text", nullable: false),
password = table.Column<string>(type: "text", nullable: false),
permissions = table.Column<string[]>(type: "text[]", nullable: false),
logo_source = table.Column<string>(type: "text", nullable: true),
logo_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_users", x => x.id);
});
migrationBuilder.CreateTable(
name: "movies",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
name = table.Column<string>(type: "text", nullable: false),
tagline = table.Column<string>(type: "text", nullable: true),
aliases = table.Column<string[]>(type: "text[]", nullable: false),
path = table.Column<string>(type: "text", nullable: false),
overview = table.Column<string>(type: "text", nullable: true),
tags = table.Column<string[]>(type: "text[]", nullable: false),
genres = table.Column<Genre[]>(type: "genre[]", nullable: false),
status = table.Column<Status>(type: "status", nullable: false),
air_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
poster_source = table.Column<string>(type: "text", nullable: true),
poster_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
thumbnail_source = table.Column<string>(type: "text", nullable: true),
thumbnail_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
logo_source = table.Column<string>(type: "text", nullable: true),
logo_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
trailer = table.Column<string>(type: "text", nullable: true),
external_id = table.Column<string>(type: "json", nullable: false),
studio_id = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_movies", x => x.id);
table.ForeignKey(
name: "fk_movies_studios_studio_id",
column: x => x.studio_id,
principalTable: "studios",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "shows",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
name = table.Column<string>(type: "text", nullable: false),
tagline = table.Column<string>(type: "text", nullable: true),
aliases = table.Column<string[]>(type: "text[]", nullable: false),
overview = table.Column<string>(type: "text", nullable: true),
tags = table.Column<string[]>(type: "text[]", nullable: false),
genres = table.Column<Genre[]>(type: "genre[]", nullable: false),
status = table.Column<Status>(type: "status", nullable: false),
start_air = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
end_air = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
poster_source = table.Column<string>(type: "text", nullable: true),
poster_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
thumbnail_source = table.Column<string>(type: "text", nullable: true),
thumbnail_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
logo_source = table.Column<string>(type: "text", nullable: true),
logo_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
trailer = table.Column<string>(type: "text", nullable: true),
external_id = table.Column<string>(type: "json", nullable: false),
studio_id = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_shows", x => x.id);
table.ForeignKey(
name: "fk_shows_studios_studio_id",
column: x => x.studio_id,
principalTable: "studios",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "collection_movie",
columns: table => new
{
collections_id = table.Column<int>(type: "integer", nullable: false),
movies_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_collection_movie", x => new { x.collections_id, x.movies_id });
table.ForeignKey(
name: "fk_collection_movie_collections_collections_id",
column: x => x.collections_id,
principalTable: "collections",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_collection_movie_movies_movies_id",
column: x => x.movies_id,
principalTable: "movies",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "link_collection_show",
columns: table => new
{
collection_id = table.Column<int>(type: "integer", nullable: false),
show_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_link_collection_show", x => new { x.collection_id, x.show_id });
table.ForeignKey(
name: "fk_link_collection_show_collections_collection_id",
column: x => x.collection_id,
principalTable: "collections",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_link_collection_show_shows_show_id",
column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "link_user_show",
columns: table => new
{
users_id = table.Column<int>(type: "integer", nullable: false),
watched_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_link_user_show", x => new { x.users_id, x.watched_id });
table.ForeignKey(
name: "fk_link_user_show_shows_watched_id",
column: x => x.watched_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_link_user_show_users_users_id",
column: x => x.users_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "people_roles",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
people_id = table.Column<int>(type: "integer", nullable: false),
show_id = table.Column<int>(type: "integer", nullable: true),
movie_id = table.Column<int>(type: "integer", nullable: true),
type = table.Column<string>(type: "text", nullable: false),
role = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_people_roles", x => x.id);
table.ForeignKey(
name: "fk_people_roles_movies_movie_id",
column: x => x.movie_id,
principalTable: "movies",
principalColumn: "id");
table.ForeignKey(
name: "fk_people_roles_people_people_id",
column: x => x.people_id,
principalTable: "people",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_people_roles_shows_show_id",
column: x => x.show_id,
principalTable: "shows",
principalColumn: "id");
});
migrationBuilder.CreateTable(
name: "seasons",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
show_id = table.Column<int>(type: "integer", nullable: false),
season_number = table.Column<int>(type: "integer", nullable: false),
name = table.Column<string>(type: "text", nullable: true),
overview = table.Column<string>(type: "text", nullable: true),
start_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
end_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
poster_source = table.Column<string>(type: "text", nullable: true),
poster_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
thumbnail_source = table.Column<string>(type: "text", nullable: true),
thumbnail_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
logo_source = table.Column<string>(type: "text", nullable: true),
logo_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
external_id = table.Column<string>(type: "json", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_seasons", x => x.id);
table.ForeignKey(
name: "fk_seasons_shows_show_id",
column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "episodes",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
show_id = table.Column<int>(type: "integer", nullable: false),
season_id = table.Column<int>(type: "integer", nullable: true),
season_number = table.Column<int>(type: "integer", nullable: true),
episode_number = table.Column<int>(type: "integer", nullable: true),
absolute_number = table.Column<int>(type: "integer", nullable: true),
path = table.Column<string>(type: "text", nullable: false),
name = table.Column<string>(type: "text", nullable: true),
overview = table.Column<string>(type: "text", nullable: true),
release_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
poster_source = table.Column<string>(type: "text", nullable: true),
poster_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
thumbnail_source = table.Column<string>(type: "text", nullable: true),
thumbnail_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
logo_source = table.Column<string>(type: "text", nullable: true),
logo_blurhash = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
external_id = table.Column<string>(type: "json", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_episodes", x => x.id);
table.ForeignKey(
name: "fk_episodes_seasons_season_id",
column: x => x.season_id,
principalTable: "seasons",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_episodes_shows_show_id",
column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "watched_episode",
columns: table => new
{
user_id = table.Column<int>(type: "integer", nullable: false),
episode_id = table.Column<int>(type: "integer", nullable: false),
watched_percentage = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_watched_episode", x => new { x.user_id, x.episode_id });
table.ForeignKey(
name: "fk_watched_episode_episodes_episode_id",
column: x => x.episode_id,
principalTable: "episodes",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_watched_episode_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_collection_movie_movies_id",
table: "collection_movie",
column: "movies_id");
migrationBuilder.CreateIndex(
name: "ix_collections_slug",
table: "collections",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_episodes_season_id",
table: "episodes",
column: "season_id");
migrationBuilder.CreateIndex(
name: "ix_episodes_show_id_season_number_episode_number_absolute_numb",
table: "episodes",
columns: new[] { "show_id", "season_number", "episode_number", "absolute_number" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_episodes_slug",
table: "episodes",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_link_collection_show_show_id",
table: "link_collection_show",
column: "show_id");
migrationBuilder.CreateIndex(
name: "ix_link_user_show_watched_id",
table: "link_user_show",
column: "watched_id");
migrationBuilder.CreateIndex(
name: "ix_movies_slug",
table: "movies",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_movies_studio_id",
table: "movies",
column: "studio_id");
migrationBuilder.CreateIndex(
name: "ix_people_slug",
table: "people",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_people_roles_movie_id",
table: "people_roles",
column: "movie_id");
migrationBuilder.CreateIndex(
name: "ix_people_roles_people_id",
table: "people_roles",
column: "people_id");
migrationBuilder.CreateIndex(
name: "ix_people_roles_show_id",
table: "people_roles",
column: "show_id");
migrationBuilder.CreateIndex(
name: "ix_seasons_show_id_season_number",
table: "seasons",
columns: new[] { "show_id", "season_number" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_seasons_slug",
table: "seasons",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_shows_slug",
table: "shows",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_shows_studio_id",
table: "shows",
column: "studio_id");
migrationBuilder.CreateIndex(
name: "ix_studios_slug",
table: "studios",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_users_slug",
table: "users",
column: "slug",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_watched_episode_episode_id",
table: "watched_episode",
column: "episode_id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "collection_movie");
migrationBuilder.DropTable(
name: "link_collection_show");
migrationBuilder.DropTable(
name: "link_user_show");
migrationBuilder.DropTable(
name: "people_roles");
migrationBuilder.DropTable(
name: "watched_episode");
migrationBuilder.DropTable(
name: "collections");
migrationBuilder.DropTable(
name: "movies");
migrationBuilder.DropTable(
name: "people");
migrationBuilder.DropTable(
name: "episodes");
migrationBuilder.DropTable(
name: "users");
migrationBuilder.DropTable(
name: "seasons");
migrationBuilder.DropTable(
name: "shows");
migrationBuilder.DropTable(
name: "studios");
}
}
}
@@ -1,6 +1,5 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using Kyoo.Abstractions.Models;
using Kyoo.Postgresql;
using Microsoft.EntityFrameworkCore;
@@ -22,10 +21,29 @@ namespace Kyoo.Postgresql.Migrations
.HasAnnotation("ProductVersion", "7.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "item_type", new[] { "show", "movie", "collection" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "genre", new[] { "action", "adventure", "animation", "comedy", "crime", "documentary", "drama", "family", "fantasy", "history", "horror", "music", "mystery", "romance", "science_fiction", "thriller", "war", "western" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "status", new[] { "unknown", "finished", "airing", "planned" });
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("CollectionMovie", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("integer")
.HasColumnName("collections_id");
b.Property<int>("MoviesID")
.HasColumnType("integer")
.HasColumnName("movies_id");
b.HasKey("CollectionsID", "MoviesID")
.HasName("pk_collection_movie");
b.HasIndex("MoviesID")
.HasDatabaseName("ix_collection_movie_movies_id");
b.ToTable("collection_movie", (string)null);
});
modelBuilder.Entity("Kyoo.Abstractions.Models.Collection", b =>
{
b.Property<int>("ID")
@@ -35,11 +53,13 @@ namespace Kyoo.Postgresql.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<string>("ExternalIDs")
b.Property<string>("ExternalId")
.IsRequired()
.HasColumnType("json")
.HasColumnName("external_i_ds");
.HasColumnName("external_id");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text")
.HasColumnName("name");
@@ -49,7 +69,8 @@ namespace Kyoo.Postgresql.Migrations
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("slug");
b.HasKey("ID")
@@ -79,15 +100,21 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("integer")
.HasColumnName("episode_number");
b.Property<string>("ExternalIDs")
b.Property<string>("ExternalId")
.IsRequired()
.HasColumnType("json")
.HasColumnName("external_i_ds");
.HasColumnName("external_id");
b.Property<string>("Name")
.HasColumnType("text")
.HasColumnName("name");
b.Property<string>("Overview")
.HasColumnType("text")
.HasColumnName("overview");
b.Property<string>("Path")
.IsRequired()
.HasColumnType("text")
.HasColumnName("path");
@@ -109,13 +136,10 @@ namespace Kyoo.Postgresql.Migrations
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("slug");
b.Property<string>("Title")
.HasColumnType("text")
.HasColumnName("title");
b.HasKey("ID")
.HasName("pk_episodes");
@@ -133,7 +157,7 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("episodes", (string)null);
});
modelBuilder.Entity("Kyoo.Abstractions.Models.Genre", b =>
modelBuilder.Entity("Kyoo.Abstractions.Models.Movie", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
@@ -142,97 +166,77 @@ namespace Kyoo.Postgresql.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<string>("Name")
.HasColumnType("text")
.HasColumnName("name");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasColumnName("slug");
b.HasKey("ID")
.HasName("pk_genres");
b.HasIndex("Slug")
.IsUnique()
.HasDatabaseName("ix_genres_slug");
b.ToTable("genres", (string)null);
});
modelBuilder.Entity("Kyoo.Abstractions.Models.Library", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<string>("Name")
.HasColumnType("text")
.HasColumnName("name");
b.Property<string[]>("Paths")
.HasColumnType("text[]")
.HasColumnName("paths");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasColumnName("slug");
b.HasKey("ID")
.HasName("pk_libraries");
b.HasIndex("Slug")
.IsUnique()
.HasDatabaseName("ix_libraries_slug");
b.ToTable("libraries", (string)null);
});
modelBuilder.Entity("Kyoo.Abstractions.Models.LibraryItem", b =>
{
b.Property<int>("ID")
.HasColumnType("integer")
.HasColumnName("id");
b.Property<DateTime?>("EndAir")
b.Property<DateTime?>("AirDate")
.HasColumnType("timestamp with time zone")
.HasColumnName("end_air");
.HasColumnName("air_date");
b.Property<string[]>("Aliases")
.IsRequired()
.HasColumnType("text[]")
.HasColumnName("aliases");
b.Property<string>("ExternalId")
.IsRequired()
.HasColumnType("json")
.HasColumnName("external_id");
b.Property<Genre[]>("Genres")
.IsRequired()
.HasColumnType("genre[]")
.HasColumnName("genres");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text")
.HasColumnName("name");
b.Property<string>("Overview")
.HasColumnType("text")
.HasColumnName("overview");
b.Property<string>("Slug")
b.Property<string>("Path")
.IsRequired()
.HasColumnType("text")
.HasColumnName("path");
b.Property<string>("Slug")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("slug");
b.Property<DateTime?>("StartAir")
.HasColumnType("timestamp with time zone")
.HasColumnName("start_air");
b.Property<Status?>("Status")
b.Property<Status>("Status")
.HasColumnType("status")
.HasColumnName("status");
b.Property<string>("Title")
.HasColumnType("text")
.HasColumnName("title");
b.Property<int?>("StudioID")
.HasColumnType("integer")
.HasColumnName("studio_id");
b.Property<ItemType>("Type")
.HasColumnType("item_type")
.HasColumnName("type");
b.Property<string>("Tagline")
.HasColumnType("text")
.HasColumnName("tagline");
b.Property<string[]>("Tags")
.IsRequired()
.HasColumnType("text[]")
.HasColumnName("tags");
b.Property<string>("Trailer")
.HasColumnType("text")
.HasColumnName("trailer");
b.HasKey("ID")
.HasName("pk_library_items");
.HasName("pk_movies");
b.ToTable((string)null);
b.HasIndex("Slug")
.IsUnique()
.HasDatabaseName("ix_movies_slug");
b.ToView("library_items", (string)null);
b.HasIndex("StudioID")
.HasDatabaseName("ix_movies_studio_id");
b.ToTable("movies", (string)null);
});
modelBuilder.Entity("Kyoo.Abstractions.Models.People", b =>
@@ -244,17 +248,20 @@ namespace Kyoo.Postgresql.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<string>("ExternalIDs")
b.Property<string>("ExternalId")
.IsRequired()
.HasColumnType("json")
.HasColumnName("external_i_ds");
.HasColumnName("external_id");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text")
.HasColumnName("name");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("slug");
b.HasKey("ID")
@@ -276,25 +283,34 @@ namespace Kyoo.Postgresql.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<int?>("MovieID")
.HasColumnType("integer")
.HasColumnName("movie_id");
b.Property<int>("PeopleID")
.HasColumnType("integer")
.HasColumnName("people_id");
b.Property<string>("Role")
.IsRequired()
.HasColumnType("text")
.HasColumnName("role");
b.Property<int>("ShowID")
b.Property<int?>("ShowID")
.HasColumnType("integer")
.HasColumnName("show_id");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text")
.HasColumnName("type");
b.HasKey("ID")
.HasName("pk_people_roles");
b.HasIndex("MovieID")
.HasDatabaseName("ix_people_roles_movie_id");
b.HasIndex("PeopleID")
.HasDatabaseName("ix_people_roles_people_id");
@@ -317,9 +333,14 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("timestamp with time zone")
.HasColumnName("end_date");
b.Property<string>("ExternalIDs")
b.Property<string>("ExternalId")
.IsRequired()
.HasColumnType("json")
.HasColumnName("external_i_ds");
.HasColumnName("external_id");
b.Property<string>("Name")
.HasColumnType("text")
.HasColumnName("name");
b.Property<string>("Overview")
.HasColumnType("text")
@@ -335,17 +356,14 @@ namespace Kyoo.Postgresql.Migrations
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("slug");
b.Property<DateTime?>("StartDate")
.HasColumnType("timestamp with time zone")
.HasColumnName("start_date");
b.Property<string>("Title")
.HasColumnType("text")
.HasColumnName("title");
b.HasKey("ID")
.HasName("pk_seasons");
@@ -370,6 +388,7 @@ namespace Kyoo.Postgresql.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<string[]>("Aliases")
.IsRequired()
.HasColumnType("text[]")
.HasColumnName("aliases");
@@ -377,25 +396,29 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("timestamp with time zone")
.HasColumnName("end_air");
b.Property<string>("ExternalIDs")
b.Property<string>("ExternalId")
.IsRequired()
.HasColumnType("json")
.HasColumnName("external_i_ds");
.HasColumnName("external_id");
b.Property<bool>("IsMovie")
.HasColumnType("boolean")
.HasColumnName("is_movie");
b.Property<Genre[]>("Genres")
.IsRequired()
.HasColumnType("genre[]")
.HasColumnName("genres");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text")
.HasColumnName("name");
b.Property<string>("Overview")
.HasColumnType("text")
.HasColumnName("overview");
b.Property<string>("Path")
.HasColumnType("text")
.HasColumnName("path");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("slug");
b.Property<DateTime?>("StartAir")
@@ -410,9 +433,14 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("integer")
.HasColumnName("studio_id");
b.Property<string>("Title")
b.Property<string>("Tagline")
.HasColumnType("text")
.HasColumnName("title");
.HasColumnName("tagline");
b.Property<string[]>("Tags")
.IsRequired()
.HasColumnType("text[]")
.HasColumnName("tags");
b.Property<string>("Trailer")
.HasColumnType("text")
@@ -440,17 +468,20 @@ namespace Kyoo.Postgresql.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<string>("ExternalIDs")
b.Property<string>("ExternalId")
.IsRequired()
.HasColumnType("json")
.HasColumnName("external_i_ds");
.HasColumnName("external_id");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text")
.HasColumnName("name");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("slug");
b.HasKey("ID")
@@ -473,27 +504,28 @@ namespace Kyoo.Postgresql.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text")
.HasColumnName("email");
b.Property<Dictionary<string, string>>("ExtraData")
.HasColumnType("jsonb")
.HasColumnName("extra_data");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text")
.HasColumnName("password");
b.Property<string[]>("Permissions")
.IsRequired()
.HasColumnType("text[]")
.HasColumnName("permissions");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("slug");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text")
.HasColumnName("username");
@@ -522,12 +554,12 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("watched_percentage");
b.HasKey("UserID", "EpisodeID")
.HasName("pk_watched_episodes");
.HasName("pk_watched_episode");
b.HasIndex("EpisodeID")
.HasDatabaseName("ix_watched_episodes_episode_id");
.HasDatabaseName("ix_watched_episode_episode_id");
b.ToTable("watched_episodes", (string)null);
b.ToTable("watched_episode", (string)null);
});
modelBuilder.Entity("ShowUser", b =>
@@ -568,61 +600,21 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("link_collection_show", (string)null);
});
modelBuilder.Entity("link_library_collection", b =>
modelBuilder.Entity("CollectionMovie", b =>
{
b.Property<int>("collection_id")
.HasColumnType("integer")
.HasColumnName("collection_id");
b.HasOne("Kyoo.Abstractions.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_collection_movie_collections_collections_id");
b.Property<int>("library_id")
.HasColumnType("integer")
.HasColumnName("library_id");
b.HasKey("collection_id", "library_id")
.HasName("pk_link_library_collection");
b.HasIndex("library_id")
.HasDatabaseName("ix_link_library_collection_library_id");
b.ToTable("link_library_collection", (string)null);
});
modelBuilder.Entity("link_library_show", b =>
{
b.Property<int>("library_id")
.HasColumnType("integer")
.HasColumnName("library_id");
b.Property<int>("show_id")
.HasColumnType("integer")
.HasColumnName("show_id");
b.HasKey("library_id", "show_id")
.HasName("pk_link_library_show");
b.HasIndex("show_id")
.HasDatabaseName("ix_link_library_show_show_id");
b.ToTable("link_library_show", (string)null);
});
modelBuilder.Entity("link_show_genre", b =>
{
b.Property<int>("genre_id")
.HasColumnType("integer")
.HasColumnName("genre_id");
b.Property<int>("show_id")
.HasColumnType("integer")
.HasColumnName("show_id");
b.HasKey("genre_id", "show_id")
.HasName("pk_link_show_genre");
b.HasIndex("show_id")
.HasDatabaseName("ix_link_show_genre_show_id");
b.ToTable("link_show_genre", (string)null);
b.HasOne("Kyoo.Abstractions.Models.Movie", null)
.WithMany()
.HasForeignKey("MoviesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_collection_movie_movies_movies_id");
});
modelBuilder.Entity("Kyoo.Abstractions.Models.Collection", b =>
@@ -634,11 +626,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("logo_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("logo_source");
@@ -658,11 +652,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("poster_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("poster_source");
@@ -682,11 +678,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("thumbnail_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("thumbnail_source");
@@ -728,11 +726,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("logo_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("logo_source");
@@ -752,11 +752,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("poster_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("poster_source");
@@ -776,11 +778,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("thumbnail_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("thumbnail_source");
@@ -804,87 +808,98 @@ namespace Kyoo.Postgresql.Migrations
b.Navigation("Thumbnail");
});
modelBuilder.Entity("Kyoo.Abstractions.Models.LibraryItem", b =>
modelBuilder.Entity("Kyoo.Abstractions.Models.Movie", b =>
{
b.HasOne("Kyoo.Abstractions.Models.Studio", "Studio")
.WithMany("Movies")
.HasForeignKey("StudioID")
.OnDelete(DeleteBehavior.SetNull)
.HasConstraintName("fk_movies_studios_studio_id");
b.OwnsOne("Kyoo.Abstractions.Models.Image", "Logo", b1 =>
{
b1.Property<int>("LibraryItemID")
b1.Property<int>("MovieID")
.HasColumnType("integer")
.HasColumnName("library_item_id");
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("blurhash");
.HasColumnName("logo_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("source");
.HasColumnName("logo_source");
b1.HasKey("LibraryItemID");
b1.HasKey("MovieID");
b1.ToTable((string)null);
b1.ToView("library_items");
b1.ToTable("movies");
b1.WithOwner()
.HasForeignKey("LibraryItemID");
.HasForeignKey("MovieID")
.HasConstraintName("fk_movies_movies_id");
});
b.OwnsOne("Kyoo.Abstractions.Models.Image", "Poster", b1 =>
{
b1.Property<int>("LibraryItemID")
b1.Property<int>("MovieID")
.HasColumnType("integer")
.HasColumnName("library_item_id");
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("blurhash");
.HasColumnName("poster_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("source");
.HasColumnName("poster_source");
b1.HasKey("LibraryItemID");
b1.HasKey("MovieID");
b1.ToTable((string)null);
b1.ToView("library_items");
b1.ToTable("movies");
b1.WithOwner()
.HasForeignKey("LibraryItemID");
.HasForeignKey("MovieID")
.HasConstraintName("fk_movies_movies_id");
});
b.OwnsOne("Kyoo.Abstractions.Models.Image", "Thumbnail", b1 =>
{
b1.Property<int>("LibraryItemID")
b1.Property<int>("MovieID")
.HasColumnType("integer")
.HasColumnName("library_item_id");
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("blurhash");
.HasColumnName("thumbnail_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("source");
.HasColumnName("thumbnail_source");
b1.HasKey("LibraryItemID");
b1.HasKey("MovieID");
b1.ToTable((string)null);
b1.ToView("library_items");
b1.ToTable("movies");
b1.WithOwner()
.HasForeignKey("LibraryItemID");
.HasForeignKey("MovieID")
.HasConstraintName("fk_movies_movies_id");
});
b.Navigation("Logo");
b.Navigation("Poster");
b.Navigation("Studio");
b.Navigation("Thumbnail");
});
@@ -897,11 +912,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("logo_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("logo_source");
@@ -921,11 +938,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("poster_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("poster_source");
@@ -945,11 +964,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("thumbnail_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("thumbnail_source");
@@ -971,6 +992,11 @@ namespace Kyoo.Postgresql.Migrations
modelBuilder.Entity("Kyoo.Abstractions.Models.PeopleRole", b =>
{
b.HasOne("Kyoo.Abstractions.Models.Movie", "Movie")
.WithMany("People")
.HasForeignKey("MovieID")
.HasConstraintName("fk_people_roles_movies_movie_id");
b.HasOne("Kyoo.Abstractions.Models.People", "People")
.WithMany("Roles")
.HasForeignKey("PeopleID")
@@ -981,10 +1007,10 @@ namespace Kyoo.Postgresql.Migrations
b.HasOne("Kyoo.Abstractions.Models.Show", "Show")
.WithMany("People")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_people_roles_shows_show_id");
b.Navigation("Movie");
b.Navigation("People");
b.Navigation("Show");
@@ -1006,11 +1032,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("logo_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("logo_source");
@@ -1030,11 +1058,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("poster_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("poster_source");
@@ -1054,11 +1084,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("thumbnail_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("thumbnail_source");
@@ -1095,11 +1127,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("logo_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("logo_source");
@@ -1119,11 +1153,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("poster_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("poster_source");
@@ -1143,11 +1179,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("thumbnail_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("thumbnail_source");
@@ -1178,11 +1216,13 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("id");
b1.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("logo_blurhash");
b1.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("logo_source");
@@ -1205,14 +1245,14 @@ namespace Kyoo.Postgresql.Migrations
.HasForeignKey("EpisodeID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_watched_episodes_episodes_episode_id");
.HasConstraintName("fk_watched_episode_episodes_episode_id");
b.HasOne("Kyoo.Abstractions.Models.User", null)
.WithMany("CurrentlyWatching")
.HasForeignKey("UserID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_watched_episodes_users_user_id");
.HasConstraintName("fk_watched_episode_users_user_id");
b.Navigation("Episode");
});
@@ -1251,55 +1291,9 @@ namespace Kyoo.Postgresql.Migrations
.HasConstraintName("fk_link_collection_show_shows_show_id");
});
modelBuilder.Entity("link_library_collection", b =>
modelBuilder.Entity("Kyoo.Abstractions.Models.Movie", b =>
{
b.HasOne("Kyoo.Abstractions.Models.Collection", null)
.WithMany()
.HasForeignKey("collection_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_link_library_collection_collections_collection_id");
b.HasOne("Kyoo.Abstractions.Models.Library", null)
.WithMany()
.HasForeignKey("library_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_link_library_collection_libraries_library_id");
});
modelBuilder.Entity("link_library_show", b =>
{
b.HasOne("Kyoo.Abstractions.Models.Library", null)
.WithMany()
.HasForeignKey("library_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_link_library_show_libraries_library_id");
b.HasOne("Kyoo.Abstractions.Models.Show", null)
.WithMany()
.HasForeignKey("show_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_link_library_show_shows_show_id");
});
modelBuilder.Entity("link_show_genre", b =>
{
b.HasOne("Kyoo.Abstractions.Models.Genre", null)
.WithMany()
.HasForeignKey("genre_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_link_show_genre_genres_genre_id");
b.HasOne("Kyoo.Abstractions.Models.Show", null)
.WithMany()
.HasForeignKey("show_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_link_show_genre_shows_show_id");
b.Navigation("People");
});
modelBuilder.Entity("Kyoo.Abstractions.Models.People", b =>
@@ -1323,6 +1317,8 @@ namespace Kyoo.Postgresql.Migrations
modelBuilder.Entity("Kyoo.Abstractions.Models.Studio", b =>
{
b.Navigation("Movies");
b.Navigation("Shows");
});
+3 -18
View File
@@ -43,12 +43,12 @@ namespace Kyoo.Postgresql
/// </summary>
private readonly bool _skipConfigure;
// TOOD: This needs ot be updated but ef-core still does not offer a way to use this.
// TODO: This needs ot be updated but ef-core still does not offer a way to use this.
[Obsolete]
static PostgresContext()
{
NpgsqlConnection.GlobalTypeMapper.MapEnum<Status>();
NpgsqlConnection.GlobalTypeMapper.MapEnum<ItemType>();
NpgsqlConnection.GlobalTypeMapper.MapEnum<Genre>();
}
/// <summary>
@@ -100,26 +100,11 @@ namespace Kyoo.Postgresql
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasPostgresEnum<Status>();
modelBuilder.HasPostgresEnum<ItemType>();
modelBuilder.Entity<LibraryItem>()
.ToView("library_items")
.HasKey(x => x.ID);
modelBuilder.Entity<User>()
.Property(x => x.ExtraData)
.HasColumnType("jsonb");
modelBuilder.HasPostgresEnum<Genre>();
base.OnModelCreating(modelBuilder);
}
/// <inheritdoc />
protected override string MetadataName<T>()
{
SnakeCaseNameRewriter rewriter = new(CultureInfo.InvariantCulture);
return rewriter.RewriteName(typeof(T).Name + nameof(MetadataID));
}
/// <inheritdoc />
protected override string LinkName<T, T2>()
{