using System; using System.Collections.Generic; using Kyoo.Models; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace Kyoo.Postgresql.Migrations { public partial class Initial : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterDatabase() .Annotation("Npgsql:Enum:item_type", "show,movie,collection") .Annotation("Npgsql:Enum:status", "finished,airing,planned,unknown") .Annotation("Npgsql:Enum:stream_type", "unknown,video,audio,subtitle,attachment"); migrationBuilder.CreateTable( name: "Collections", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Slug = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: true), Poster = table.Column(type: "text", nullable: true), Overview = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Collections", x => x.ID); }); migrationBuilder.CreateTable( name: "Genres", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Slug = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Genres", x => x.ID); }); migrationBuilder.CreateTable( name: "Libraries", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Slug = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: true), Paths = table.Column(type: "text[]", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Libraries", x => x.ID); }); migrationBuilder.CreateTable( name: "People", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Slug = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: true), Poster = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_People", x => x.ID); }); migrationBuilder.CreateTable( name: "Providers", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Slug = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: true), Logo = table.Column(type: "text", nullable: true), LogoExtension = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Providers", x => x.ID); }); migrationBuilder.CreateTable( name: "Studios", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Slug = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Studios", x => x.ID); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Slug = table.Column(type: "text", nullable: false), Username = table.Column(type: "text", nullable: true), Email = table.Column(type: "text", nullable: true), Password = table.Column(type: "text", nullable: true), Permissions = table.Column(type: "text[]", nullable: true), ExtraData = table.Column>(type: "jsonb", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.ID); }); migrationBuilder.CreateTable( name: "Link", columns: table => new { FirstID = table.Column(type: "integer", nullable: false), SecondID = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Link", x => new { x.FirstID, x.SecondID }); table.ForeignKey( name: "FK_Link_Collections_SecondID", column: x => x.SecondID, principalTable: "Collections", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Link_Libraries_FirstID", column: x => x.FirstID, principalTable: "Libraries", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Link", columns: table => new { FirstID = table.Column(type: "integer", nullable: false), SecondID = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Link", x => new { x.FirstID, x.SecondID }); table.ForeignKey( name: "FK_Link_Libraries_FirstID", column: x => x.FirstID, principalTable: "Libraries", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Link_Providers_SecondID", column: x => x.SecondID, principalTable: "Providers", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "MetadataID", columns: table => new { FirstID = table.Column(type: "integer", nullable: false), SecondID = table.Column(type: "integer", nullable: false), DataID = table.Column(type: "text", nullable: true), Link = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_MetadataID", x => new { x.FirstID, x.SecondID }); table.ForeignKey( name: "FK_MetadataID_People_FirstID", column: x => x.FirstID, principalTable: "People", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_MetadataID_Providers_SecondID", column: x => x.SecondID, principalTable: "Providers", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Shows", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Slug = table.Column(type: "text", nullable: false), Title = table.Column(type: "text", nullable: true), Aliases = table.Column(type: "text[]", nullable: true), Path = table.Column(type: "text", nullable: true), Overview = table.Column(type: "text", nullable: true), Status = table.Column(type: "status", nullable: true), TrailerUrl = table.Column(type: "text", nullable: true), StartAir = table.Column(type: "timestamp without time zone", nullable: true), EndAir = table.Column(type: "timestamp without time zone", nullable: true), Poster = table.Column(type: "text", nullable: true), Logo = table.Column(type: "text", nullable: true), Backdrop = table.Column(type: "text", nullable: true), IsMovie = table.Column(type: "boolean", nullable: false), StudioID = table.Column(type: "integer", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Shows", x => x.ID); table.ForeignKey( name: "FK_Shows_Studios_StudioID", column: x => x.StudioID, principalTable: "Studios", principalColumn: "ID", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Link", columns: table => new { FirstID = table.Column(type: "integer", nullable: false), SecondID = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Link", x => new { x.FirstID, x.SecondID }); table.ForeignKey( name: "FK_Link_Collections_FirstID", column: x => x.FirstID, principalTable: "Collections", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Link_Shows_SecondID", column: x => x.SecondID, principalTable: "Shows", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Link", columns: table => new { FirstID = table.Column(type: "integer", nullable: false), SecondID = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Link", x => new { x.FirstID, x.SecondID }); table.ForeignKey( name: "FK_Link_Libraries_FirstID", column: x => x.FirstID, principalTable: "Libraries", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Link_Shows_SecondID", column: x => x.SecondID, principalTable: "Shows", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Link", columns: table => new { FirstID = table.Column(type: "integer", nullable: false), SecondID = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Link", x => new { x.FirstID, x.SecondID }); table.ForeignKey( name: "FK_Link_Genres_SecondID", column: x => x.SecondID, principalTable: "Genres", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Link_Shows_FirstID", column: x => x.FirstID, principalTable: "Shows", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Link", columns: table => new { FirstID = table.Column(type: "integer", nullable: false), SecondID = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Link", x => new { x.FirstID, x.SecondID }); table.ForeignKey( name: "FK_Link_Shows_SecondID", column: x => x.SecondID, principalTable: "Shows", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Link_Users_FirstID", column: x => x.FirstID, principalTable: "Users", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "MetadataID", columns: table => new { FirstID = table.Column(type: "integer", nullable: false), SecondID = table.Column(type: "integer", nullable: false), DataID = table.Column(type: "text", nullable: true), Link = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_MetadataID", x => new { x.FirstID, x.SecondID }); table.ForeignKey( name: "FK_MetadataID_Providers_SecondID", column: x => x.SecondID, principalTable: "Providers", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_MetadataID_Shows_FirstID", column: x => x.FirstID, principalTable: "Shows", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "PeopleRoles", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), ForPeople = table.Column(type: "boolean", nullable: false), PeopleID = table.Column(type: "integer", nullable: false), ShowID = table.Column(type: "integer", nullable: false), Type = table.Column(type: "text", nullable: true), Role = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_PeopleRoles", x => x.ID); table.ForeignKey( name: "FK_PeopleRoles_People_PeopleID", column: x => x.PeopleID, principalTable: "People", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_PeopleRoles_Shows_ShowID", column: x => x.ShowID, principalTable: "Shows", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Seasons", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Slug = table.Column(type: "text", nullable: true), ShowID = table.Column(type: "integer", nullable: false), SeasonNumber = table.Column(type: "integer", nullable: false), Title = table.Column(type: "text", nullable: true), Overview = table.Column(type: "text", nullable: true), StartDate = table.Column(type: "timestamp without time zone", nullable: true), EndDate = table.Column(type: "timestamp without time zone", nullable: true), Poster = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Seasons", x => x.ID); table.ForeignKey( name: "FK_Seasons_Shows_ShowID", column: x => x.ShowID, principalTable: "Shows", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Episodes", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Slug = table.Column(type: "text", nullable: true), ShowID = table.Column(type: "integer", nullable: false), SeasonID = table.Column(type: "integer", nullable: true), SeasonNumber = table.Column(type: "integer", nullable: false), EpisodeNumber = table.Column(type: "integer", nullable: false), AbsoluteNumber = table.Column(type: "integer", nullable: false), Path = table.Column(type: "text", nullable: true), Thumb = table.Column(type: "text", nullable: true), Title = table.Column(type: "text", nullable: true), Overview = table.Column(type: "text", nullable: true), ReleaseDate = table.Column(type: "timestamp without time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Episodes", x => x.ID); table.ForeignKey( name: "FK_Episodes_Seasons_SeasonID", column: x => x.SeasonID, principalTable: "Seasons", principalColumn: "ID", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Episodes_Shows_ShowID", column: x => x.ShowID, principalTable: "Shows", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "MetadataID", columns: table => new { FirstID = table.Column(type: "integer", nullable: false), SecondID = table.Column(type: "integer", nullable: false), DataID = table.Column(type: "text", nullable: true), Link = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_MetadataID", x => new { x.FirstID, x.SecondID }); table.ForeignKey( name: "FK_MetadataID_Providers_SecondID", column: x => x.SecondID, principalTable: "Providers", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_MetadataID_Seasons_FirstID", column: x => x.FirstID, principalTable: "Seasons", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "MetadataID", columns: table => new { FirstID = table.Column(type: "integer", nullable: false), SecondID = table.Column(type: "integer", nullable: false), DataID = table.Column(type: "text", nullable: true), Link = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_MetadataID", x => new { x.FirstID, x.SecondID }); table.ForeignKey( name: "FK_MetadataID_Episodes_FirstID", column: x => x.FirstID, principalTable: "Episodes", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_MetadataID_Providers_SecondID", column: x => x.SecondID, principalTable: "Providers", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Tracks", columns: table => new { ID = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Slug = table.Column(type: "text", nullable: true), Title = table.Column(type: "text", nullable: true), Language = table.Column(type: "text", nullable: true), Codec = table.Column(type: "text", nullable: true), IsDefault = table.Column(type: "boolean", nullable: false), IsForced = table.Column(type: "boolean", nullable: false), IsExternal = table.Column(type: "boolean", nullable: false), Path = table.Column(type: "text", nullable: true), Type = table.Column(type: "stream_type", nullable: false), EpisodeID = table.Column(type: "integer", nullable: false), TrackIndex = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tracks", x => x.ID); table.ForeignKey( name: "FK_Tracks_Episodes_EpisodeID", column: x => x.EpisodeID, principalTable: "Episodes", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "WatchedEpisodes", columns: table => new { FirstID = table.Column(type: "integer", nullable: false), SecondID = table.Column(type: "integer", nullable: false), WatchedPercentage = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_WatchedEpisodes", x => new { x.FirstID, x.SecondID }); table.ForeignKey( name: "FK_WatchedEpisodes_Episodes_SecondID", column: x => x.SecondID, principalTable: "Episodes", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_WatchedEpisodes_Users_FirstID", column: x => x.FirstID, principalTable: "Users", principalColumn: "ID", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Collections_Slug", table: "Collections", column: "Slug", unique: true); migrationBuilder.CreateIndex( name: "IX_Episodes_SeasonID", table: "Episodes", column: "SeasonID"); migrationBuilder.CreateIndex( name: "IX_Episodes_ShowID_SeasonNumber_EpisodeNumber_AbsoluteNumber", table: "Episodes", columns: new[] { "ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber" }, 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_SecondID", table: "Link", column: "SecondID"); migrationBuilder.CreateIndex( name: "IX_Link_SecondID", table: "Link", column: "SecondID"); migrationBuilder.CreateIndex( name: "IX_Link_SecondID", table: "Link", column: "SecondID"); migrationBuilder.CreateIndex( name: "IX_Link_SecondID", table: "Link", column: "SecondID"); migrationBuilder.CreateIndex( name: "IX_Link_SecondID", table: "Link", column: "SecondID"); migrationBuilder.CreateIndex( name: "IX_Link_SecondID", table: "Link", column: "SecondID"); migrationBuilder.CreateIndex( name: "IX_MetadataID_SecondID", table: "MetadataID", column: "SecondID"); migrationBuilder.CreateIndex( name: "IX_MetadataID_SecondID", table: "MetadataID", column: "SecondID"); migrationBuilder.CreateIndex( name: "IX_MetadataID_SecondID", table: "MetadataID", column: "SecondID"); migrationBuilder.CreateIndex( name: "IX_MetadataID_SecondID", table: "MetadataID", column: "SecondID"); migrationBuilder.CreateIndex( name: "IX_People_Slug", table: "People", column: "Slug", unique: true); migrationBuilder.CreateIndex( name: "IX_PeopleRoles_PeopleID", table: "PeopleRoles", column: "PeopleID"); migrationBuilder.CreateIndex( name: "IX_PeopleRoles_ShowID", table: "PeopleRoles", column: "ShowID"); migrationBuilder.CreateIndex( name: "IX_Providers_Slug", table: "Providers", column: "Slug", unique: true); migrationBuilder.CreateIndex( name: "IX_Seasons_ShowID_SeasonNumber", table: "Seasons", columns: new[] { "ShowID", "SeasonNumber" }, unique: true); migrationBuilder.CreateIndex( name: "IX_Shows_Slug", table: "Shows", column: "Slug", unique: true); migrationBuilder.CreateIndex( name: "IX_Shows_StudioID", table: "Shows", column: "StudioID"); migrationBuilder.CreateIndex( name: "IX_Studios_Slug", table: "Studios", column: "Slug", unique: true); migrationBuilder.CreateIndex( name: "IX_Tracks_EpisodeID_Type_Language_TrackIndex_IsForced", table: "Tracks", columns: new[] { "EpisodeID", "Type", "Language", "TrackIndex", "IsForced" }, unique: true); migrationBuilder.CreateIndex( name: "IX_Users_Slug", table: "Users", column: "Slug", unique: true); migrationBuilder.CreateIndex( name: "IX_WatchedEpisodes_SecondID", table: "WatchedEpisodes", column: "SecondID"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Link"); migrationBuilder.DropTable( name: "Link"); migrationBuilder.DropTable( name: "Link"); migrationBuilder.DropTable( name: "Link"); migrationBuilder.DropTable( name: "Link"); migrationBuilder.DropTable( name: "Link"); migrationBuilder.DropTable( name: "MetadataID"); migrationBuilder.DropTable( name: "MetadataID"); migrationBuilder.DropTable( name: "MetadataID"); migrationBuilder.DropTable( name: "MetadataID"); migrationBuilder.DropTable( name: "PeopleRoles"); migrationBuilder.DropTable( name: "Tracks"); migrationBuilder.DropTable( name: "WatchedEpisodes"); migrationBuilder.DropTable( name: "Collections"); migrationBuilder.DropTable( name: "Libraries"); migrationBuilder.DropTable( name: "Genres"); migrationBuilder.DropTable( name: "Providers"); migrationBuilder.DropTable( name: "People"); migrationBuilder.DropTable( name: "Episodes"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Seasons"); migrationBuilder.DropTable( name: "Shows"); migrationBuilder.DropTable( name: "Studios"); } } }