genre added
This commit is contained in:
@@ -13,7 +13,11 @@ namespace WatchIt.Database.Model
|
|||||||
#region PUBLIC METHODS
|
#region PUBLIC METHODS
|
||||||
|
|
||||||
public static void Build<T>(ModelBuilder builder) where T : class, IEntity<T> => Build<T>(builder.Entity<T>());
|
public static void Build<T>(ModelBuilder builder) where T : class, IEntity<T> => Build<T>(builder.Entity<T>());
|
||||||
public static void Build<T>(EntityTypeBuilder<T> builder) where T : class, IEntity<T> => T.Build(builder);
|
public static void Build<T>(EntityTypeBuilder<T> builder) where T : class, IEntity<T>
|
||||||
|
{
|
||||||
|
T.Build(builder);
|
||||||
|
builder.HasData(T.InsertData());
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
49
WatchIt.Database/WatchIt.Database.Model/Genre/Genre.cs
Normal file
49
WatchIt.Database/WatchIt.Database.Model/Genre/Genre.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WatchIt.Database.Model.Genre
|
||||||
|
{
|
||||||
|
public class Genre : IEntity<Genre>
|
||||||
|
{
|
||||||
|
#region PROPERTIES
|
||||||
|
|
||||||
|
public short Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region PUBLIC METHODS
|
||||||
|
|
||||||
|
static void IEntity<Genre>.Build(EntityTypeBuilder<Genre> builder)
|
||||||
|
{
|
||||||
|
builder.HasKey(x => x.Id);
|
||||||
|
builder.HasIndex(x => x.Id)
|
||||||
|
.IsUnique();
|
||||||
|
builder.Property(x => x.Id)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(x => x.Name)
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(x => x.Description)
|
||||||
|
.HasMaxLength(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
static IEnumerable<Genre> IEntity<Genre>.InsertData() => new List<Genre>
|
||||||
|
{
|
||||||
|
new Genre { Id = 1, Name = "Comedy" },
|
||||||
|
new Genre { Id = 2, Name = "Thriller" },
|
||||||
|
new Genre { Id = 3, Name = "Horror" },
|
||||||
|
};
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ namespace WatchIt.Database.Model
|
|||||||
#region METHODS
|
#region METHODS
|
||||||
|
|
||||||
static abstract void Build(EntityTypeBuilder<T> builder);
|
static abstract void Build(EntityTypeBuilder<T> builder);
|
||||||
|
static virtual IEnumerable<T> InsertData() => Array.Empty<T>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using WatchIt.Database.Model;
|
using WatchIt.Database.Model;
|
||||||
using WatchIt.Database.Model.Account;
|
using WatchIt.Database.Model.Account;
|
||||||
|
using WatchIt.Database.Model.Genre;
|
||||||
|
|
||||||
namespace WatchIt.Database
|
namespace WatchIt.Database
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,9 @@ namespace WatchIt.Database
|
|||||||
public virtual DbSet<Account> Accounts { get; set; }
|
public virtual DbSet<Account> Accounts { get; set; }
|
||||||
public virtual DbSet<AccountProfilePicture> AccountProfilePictures { get; set; }
|
public virtual DbSet<AccountProfilePicture> AccountProfilePictures { get; set; }
|
||||||
|
|
||||||
|
// Genre
|
||||||
|
public virtual DbSet<Genre> Genres { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -41,6 +45,9 @@ namespace WatchIt.Database
|
|||||||
// Account
|
// Account
|
||||||
EntityBuilder.Build<Account>(modelBuilder);
|
EntityBuilder.Build<Account>(modelBuilder);
|
||||||
EntityBuilder.Build<AccountProfilePicture>(modelBuilder);
|
EntityBuilder.Build<AccountProfilePicture>(modelBuilder);
|
||||||
|
|
||||||
|
// Genre
|
||||||
|
EntityBuilder.Build<Genre>(modelBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using WatchIt.Database;
|
|||||||
namespace WatchIt.Database.Migrations
|
namespace WatchIt.Database.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(DatabaseContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20240317125055_Migration1")]
|
[Migration("20240317131418_Migration1")]
|
||||||
partial class Migration1
|
partial class Migration1
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -119,6 +119,31 @@ namespace WatchIt.Database.Migrations
|
|||||||
b.ToTable("AccountProfilePictures");
|
b.ToTable("AccountProfilePictures");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WatchIt.Database.Model.Genre.Genre", b =>
|
||||||
|
{
|
||||||
|
b.Property<short>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<short>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasMaxLength(1000)
|
||||||
|
.HasColumnType("character varying(1000)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("character varying(100)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Id")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Genres");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b =>
|
modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("WatchIt.Database.Model.Account.AccountProfilePicture", "AccountProfilePicture")
|
b.HasOne("WatchIt.Database.Model.Account.AccountProfilePicture", "AccountProfilePicture")
|
||||||
@@ -26,6 +26,20 @@ namespace WatchIt.Database.Migrations
|
|||||||
table.PrimaryKey("PK_AccountProfilePictures", x => x.Id);
|
table.PrimaryKey("PK_AccountProfilePictures", x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Genres",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<short>(type: "smallint", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||||
|
Description = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Genres", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Accounts",
|
name: "Accounts",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
@@ -71,6 +85,12 @@ namespace WatchIt.Database.Migrations
|
|||||||
table: "Accounts",
|
table: "Accounts",
|
||||||
column: "Id",
|
column: "Id",
|
||||||
unique: true);
|
unique: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Genres_Id",
|
||||||
|
table: "Genres",
|
||||||
|
column: "Id",
|
||||||
|
unique: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -79,6 +99,9 @@ namespace WatchIt.Database.Migrations
|
|||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Accounts");
|
name: "Accounts");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Genres");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "AccountProfilePictures");
|
name: "AccountProfilePictures");
|
||||||
}
|
}
|
||||||
183
WatchIt.Database/WatchIt.Database/Migrations/20240317132500_Migration2.Designer.cs
generated
Normal file
183
WatchIt.Database/WatchIt.Database/Migrations/20240317132500_Migration2.Designer.cs
generated
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using WatchIt.Database;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace WatchIt.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DatabaseContext))]
|
||||||
|
[Migration("20240317132500_Migration2")]
|
||||||
|
partial class Migration2
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.3")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<Guid>("AccountProfilePictureId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("CreationDate")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("timestamp with time zone")
|
||||||
|
.HasDefaultValueSql("now()");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(1000)
|
||||||
|
.HasColumnType("character varying(1000)");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(320)
|
||||||
|
.HasColumnType("character varying(320)");
|
||||||
|
|
||||||
|
b.Property<bool>("IsAdmin")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("LastActive")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("timestamp with time zone")
|
||||||
|
.HasDefaultValueSql("now()");
|
||||||
|
|
||||||
|
b.Property<string>("LeftSalt")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.HasColumnType("character varying(20)");
|
||||||
|
|
||||||
|
b.Property<byte[]>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(1000)
|
||||||
|
.HasColumnType("bytea");
|
||||||
|
|
||||||
|
b.Property<string>("RightSalt")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.HasColumnType("character varying(20)");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("character varying(50)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("AccountProfilePictureId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("Id")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Accounts");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WatchIt.Database.Model.Account.AccountProfilePicture", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<byte[]>("Image")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(-1)
|
||||||
|
.HasColumnType("bytea");
|
||||||
|
|
||||||
|
b.Property<string>("MimeType")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("character varying(50)");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UploadDate")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("timestamp with time zone")
|
||||||
|
.HasDefaultValueSql("now()");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Id")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("AccountProfilePictures");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WatchIt.Database.Model.Genre.Genre", b =>
|
||||||
|
{
|
||||||
|
b.Property<short>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<short>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasMaxLength(1000)
|
||||||
|
.HasColumnType("character varying(1000)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("character varying(100)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Id")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Genres");
|
||||||
|
|
||||||
|
b.HasData(
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = (short)1,
|
||||||
|
Name = "Comedy"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = (short)2,
|
||||||
|
Name = "Thriller"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = (short)3,
|
||||||
|
Name = "Horror"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("WatchIt.Database.Model.Account.AccountProfilePicture", "AccountProfilePicture")
|
||||||
|
.WithOne("Account")
|
||||||
|
.HasForeignKey("WatchIt.Database.Model.Account.Account", "AccountProfilePictureId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("AccountProfilePicture");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WatchIt.Database.Model.Account.AccountProfilePicture", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Account")
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
|
||||||
|
|
||||||
|
namespace WatchIt.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Migration2 : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.InsertData(
|
||||||
|
table: "Genres",
|
||||||
|
columns: new[] { "Id", "Description", "Name" },
|
||||||
|
values: new object[,]
|
||||||
|
{
|
||||||
|
{ (short)1, null, "Comedy" },
|
||||||
|
{ (short)2, null, "Thriller" },
|
||||||
|
{ (short)3, null, "Horror" }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "Genres",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: (short)1);
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "Genres",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: (short)2);
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "Genres",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: (short)3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -116,6 +116,48 @@ namespace WatchIt.Database.Migrations
|
|||||||
b.ToTable("AccountProfilePictures");
|
b.ToTable("AccountProfilePictures");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WatchIt.Database.Model.Genre.Genre", b =>
|
||||||
|
{
|
||||||
|
b.Property<short>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<short>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasMaxLength(1000)
|
||||||
|
.HasColumnType("character varying(1000)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("character varying(100)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Id")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Genres");
|
||||||
|
|
||||||
|
b.HasData(
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = (short)1,
|
||||||
|
Name = "Comedy"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = (short)2,
|
||||||
|
Name = "Thriller"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = (short)3,
|
||||||
|
Name = "Horror"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b =>
|
modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("WatchIt.Database.Model.Account.AccountProfilePicture", "AccountProfilePicture")
|
b.HasOne("WatchIt.Database.Model.Account.AccountProfilePicture", "AccountProfilePicture")
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\WatchIt.Database\WatchIt.Database.csproj" />
|
|
||||||
<ProjectReference Include="..\WatchIt.Database\WatchIt.Database\WatchIt.Database.csproj" />
|
<ProjectReference Include="..\WatchIt.Database\WatchIt.Database\WatchIt.Database.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user