Refactoring, database structure changed

This commit is contained in:
2025-03-03 00:56:32 +01:00
Unverified
parent d3805ef3db
commit c603c41c0b
913 changed files with 21764 additions and 32775 deletions

View File

@@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Accounts;
namespace WatchIt.Database.Configuration.Accounts;
public class AccountBackgroundPictureConfiguration : IEntityTypeConfiguration<AccountBackgroundPicture>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<AccountBackgroundPicture> builder)
{
builder.ToTable("AccountBackgroundPictures", "accounts");
// Account
builder.HasKey(x => x.AccountId);
builder.HasIndex(x => x.AccountId)
.IsUnique();
builder.HasOne(x => x.Account)
.WithOne(x => x.BackgroundPicture)
.HasForeignKey<AccountBackgroundPicture>(x => x.AccountId)
.IsRequired();
builder.Property(x => x.AccountId)
.IsRequired();
// Background
builder.HasOne(x => x.Background)
.WithMany(x => x.BackgroundUsages)
.HasForeignKey(x => x.BackgroundId)
.IsRequired();
builder.Property(x => x.BackgroundId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -0,0 +1,98 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Accounts;
namespace WatchIt.Database.Configuration.Accounts;
public class AccountConfiguration : IEntityTypeConfiguration<Account>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<Account> builder)
{
builder.ToTable("Accounts", "accounts");
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired()
.UseIdentityAlwaysColumn();
// Username
builder.Property(x => x.Username)
.HasMaxLength(50)
.IsRequired();
// Email
builder.Property(x => x.Email)
.HasMaxLength(320)
.IsRequired();
// Password
builder.Property(x => x.Password)
.HasMaxLength(1000)
.IsRequired();
// Left salt
builder.Property(x => x.LeftSalt)
.HasMaxLength(20)
.IsRequired();
// Right salt
builder.Property(x => x.RightSalt)
.HasMaxLength(20)
.IsRequired();
// Is admin
builder.Property(x => x.IsAdmin)
.IsRequired()
.HasDefaultValue(false);
// Join date
builder.Property(x => x.JoinDate)
.IsRequired()
.HasDefaultValueSql("now()");
// Active date
builder.Property(x => x.ActiveDate)
.IsRequired()
.HasDefaultValueSql("now()");
// Description
builder.Property(x => x.Description)
.HasMaxLength(1000);
// Gender
builder.HasOne(x => x.Gender)
.WithMany(x => x.Accounts)
.HasForeignKey(x => x.GenderId);
builder.Property(x => x.GenderId);
// Version
builder.Property(b => b.Version)
.IsRowVersion();
#region Navigation
// AccountFollow
builder.HasMany(x => x.Follows)
.WithMany(x => x.Followers)
.UsingEntity<AccountFollow>(
x => x.HasOne<Account>(y => y.Followed)
.WithMany(y => y.FollowersRelationshipObjects)
.HasForeignKey(y => y.FollowedId)
.IsRequired(),
x => x.HasOne<Account>(y => y.Follower)
.WithMany(y => y.FollowsRelationshipObjects)
.HasForeignKey(y => y.FollowerId)
.IsRequired()
);
#endregion
}
#endregion
}

View File

@@ -0,0 +1,32 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Accounts;
namespace WatchIt.Database.Configuration.Accounts;
public class AccountFollowConfiguration : IEntityTypeConfiguration<AccountFollow>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<AccountFollow> builder)
{
builder.ToTable("AccountFollows", "accounts");
builder.HasKey(x => new { x.FollowerId, x.FollowedId });
// Follower
// FK configured in AccountConfiguration
builder.Property(x => x.FollowerId)
.IsRequired();
// Followed
// FK configured in AccountConfiguration
builder.Property(x => x.FollowedId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -0,0 +1,35 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Accounts;
namespace WatchIt.Database.Configuration.Accounts;
public class AccountProfilePictureConfiguration : ImageEntityConfiguration<AccountProfilePicture>
{
#region PUBLIC METHODS
public override void Configure(EntityTypeBuilder<AccountProfilePicture> builder)
{
builder.ToTable($"AccountProfilePictures", "accounts");
// Account
builder.HasKey(x => x.AccountId);
builder.HasIndex(x => x.AccountId)
.IsUnique();
builder.HasOne(x => x.Account)
.WithOne(x => x.ProfilePicture)
.HasForeignKey<AccountProfilePicture>(x => x.AccountId)
.IsRequired();
builder.Property(x => x.AccountId)
.IsRequired();
// Generic properties
base.Configure(builder);
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -1,30 +1,44 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Account;
using WatchIt.Database.Model.Accounts;
namespace WatchIt.Database.Model.Configuration.Account;
namespace WatchIt.Database.Configuration.Accounts;
public class AccountRefreshTokenConfiguration : IEntityTypeConfiguration<AccountRefreshToken>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<AccountRefreshToken> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
builder.ToTable("AccountRefreshTokens", "accounts");
// Id
builder.HasKey(x => x.Token);
builder.HasIndex(x => x.Token)
.IsUnique();
builder.Property(x => x.Id)
builder.Property(x => x.Token)
.IsRequired();
// Account
builder.HasOne(x => x.Account)
.WithMany(x => x.AccountRefreshTokens)
.WithMany(x => x.RefreshTokens)
.HasForeignKey(x => x.AccountId)
.IsRequired();
builder.Property(x => x.AccountId)
.IsRequired();
// Expiration date
builder.Property(x => x.ExpirationDate)
.IsRequired();
// Is extendable
builder.Property(x => x.IsExtendable)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Genders;
namespace WatchIt.Database.Configuration.Genders;
public class GenderConfiguration : IEntityTypeConfiguration<Gender>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<Gender> builder)
{
builder.ToTable("Genders", "genders");
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired()
.UseIdentityAlwaysColumn();
// Name
builder.Property(x => x.Name)
.HasMaxLength(100)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -1,31 +1,34 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Common;
using WatchIt.Database.Model.Media;
using WatchIt.Database.Model.Seeding;
using WatchIt.Database.Model.Genres;
namespace WatchIt.Database.Model.Configuration.Common;
namespace WatchIt.Database.Configuration.Genres;
public class GenreConfiguration : IEntityTypeConfiguration<Genre>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<Genre> builder)
{
builder.ToTable("Genres", "genres");
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
.IsRequired()
.UseIdentityAlwaysColumn();
// Name
builder.Property(x => x.Name)
.HasMaxLength(100)
.IsRequired();
// Navigation
builder.HasMany(x => x.Media)
.WithMany(x => x.Genres)
.UsingEntity<MediaGenre>();
// Data
builder.HasData(DataReader.Read<Genre>());
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
}
#endregion
}

View File

@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model;
namespace WatchIt.Database.Configuration;
public abstract class ImageEntityConfiguration<T> : IEntityTypeConfiguration<T> where T : class, IImageEntity
{
#region PUBLIC METHODS
public virtual void Configure(EntityTypeBuilder<T> builder)
{
// Image
builder.Property(x => x.Image)
.HasMaxLength(-1)
.IsRequired();
// MimeType
builder.Property(x => x.MimeType)
.HasMaxLength(50)
.IsRequired();
// UploadDate
builder.Property(x => x.UploadDate)
.IsRequired()
.HasDefaultValueSql("now()");
}
#endregion
}

View File

@@ -0,0 +1,90 @@
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Configuration.Media;
public class MediumConfiguration : IEntityTypeConfiguration<Medium>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<Medium> builder)
{
builder.ToTable("Media", "media");
builder.HasDiscriminator<MediumType>("Type")
.HasValue<MediumMovie>(MediumType.Movie)
.HasValue<MediumSeries>(MediumType.Series);
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired()
.UseIdentityAlwaysColumn();
// Type
builder.Property(x => x.Type)
.IsRequired();
// Title
builder.Property(x => x.Title)
.HasMaxLength(250)
.IsRequired();
// Original title
builder.Property(x => x.OriginalTitle)
.HasMaxLength(250);
// Description
builder.Property(x => x.Description)
.HasMaxLength(1000);
// Duration
builder.Property(x => x.Duration);
// Release date
builder.Property(x => x.ReleaseDate);
// Version
builder.Property(b => b.Version)
.IsRowVersion();
#region Navigation
// MediumGenre
builder.HasMany(x => x.Genres)
.WithMany(x => x.Media)
.UsingEntity<MediumGenre>(
x => x.HasOne(y => y.Genre)
.WithMany(y => y.MediaRelationObjects)
.HasForeignKey(y => y.GenreId)
.IsRequired(),
x => x.HasOne(y => y.Medium)
.WithMany(y => y.GenresRelationshipObjects)
.HasForeignKey(y => y.MediumId)
.IsRequired()
);
// MediumRating
builder.HasMany(x => x.RatedBy)
.WithMany(x => x.MediaRated)
.UsingEntity<MediumRating>(
x => x.HasOne(y => y.Account)
.WithMany(y => y.MediaRatings)
.HasForeignKey(y => y.AccountId)
.IsRequired(),
x => x.HasOne(y => y.Medium)
.WithMany(y => y.Ratings)
.HasForeignKey(y => y.MediumId)
.IsRequired()
);
#endregion
}
#endregion
}

View File

@@ -0,0 +1,32 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Configuration.Media;
public class MediumGenreConfiguration : IEntityTypeConfiguration<MediumGenre>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<MediumGenre> builder)
{
builder.ToTable("MediumGenres", "media");
builder.HasKey(x => new { x.GenreId, x.MediumId });
// Medium
// FK configured in MediumConfiguration
builder.Property(x => x.MediumId)
.IsRequired();
// Genre
// FK configured in MediumConfiguration
builder.Property(x => x.GenreId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Configuration.Media;
public class MediumMovieConfiguration : IEntityTypeConfiguration<MediumMovie>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<MediumMovie> builder)
{
// Budget
builder.Property(x => x.Budget)
.HasColumnType("money");
}
#endregion
}

View File

@@ -0,0 +1,35 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Configuration.Media;
public class MediumPictureConfiguration : ImageEntityConfiguration<MediumPicture>
{
#region PUBLIC METHODS
public override void Configure(EntityTypeBuilder<MediumPicture> builder)
{
builder.ToTable("MediumPictures", "media");
// Medium
builder.HasKey(x => x.MediumId);
builder.HasIndex(x => x.MediumId)
.IsUnique();
builder.HasOne(x => x.Medium)
.WithOne(x => x.Picture)
.HasForeignKey<MediumPicture>(x => x.MediumId)
.IsRequired();
builder.Property(x => x.MediumId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
// Generic properties
base.Configure(builder);
}
#endregion
}

View File

@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Accounts;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Configuration.Media;
public class MediumRatingConfiguration : RatingEntityConfiguration<MediumRating>
{
#region PUBLIC METHODS
public override void Configure(EntityTypeBuilder<MediumRating> builder)
{
builder.ToTable("MediumRatings", "media");
builder.HasKey(x => new { x.AccountId, x.MediumId });
// Medium
// FK configured in MediumConfiguration
builder.Property(x => x.MediumId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
// Generic properties
base.Configure(builder);
}
#endregion
}

View File

@@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Configuration.Media;
public class MediumSeriesConfiguration : IEntityTypeConfiguration<MediumSeries>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<MediumSeries> builder)
{
// Has ended
builder.Property(x => x.HasEnded)
.IsRequired()
.HasDefaultValue(false);
}
#endregion
}

View File

@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Configuration.Media;
public class MediumViewCountConfiguration : ViewCountEntityConfiguration<MediumViewCount>
{
#region PUBLIC METHODS
public override void Configure(EntityTypeBuilder<MediumViewCount> builder)
{
builder.ToTable("MediumViewCounts", "media");
builder.HasKey(x => new { x.MediumId, x.Date });
// Medium
builder.HasOne(x => x.Medium)
.WithMany(x => x.ViewCounts)
.HasForeignKey(x => x.MediumId)
.IsRequired();
builder.Property(x => x.MediumId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
// Generic properties
base.Configure(builder);
}
#endregion
}

View File

@@ -0,0 +1,54 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.People;
namespace WatchIt.Database.Configuration.People;
public class PersonConfiguration : IEntityTypeConfiguration<Person>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<Person> builder)
{
builder.ToTable("People", "people");
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired()
.UseIdentityAlwaysColumn();
// Name
builder.Property(x => x.Name)
.HasMaxLength(100)
.IsRequired();
// Full name
builder.Property(x => x.FullName)
.HasMaxLength(200);
// Description
builder.Property(x => x.Description)
.HasMaxLength(1000);
// Birth date
builder.Property(x => x.BirthDate);
// Death date
builder.Property(x => x.DeathDate);
// Gender
builder.HasOne(x => x.Gender)
.WithMany(x => x.People)
.HasForeignKey(x => x.GenderId);
builder.Property(x => x.GenderId);
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
using WatchIt.Database.Model.People;
namespace WatchIt.Database.Configuration.People;
public class PersonPictureConfiguration : ImageEntityConfiguration<PersonPicture>
{
#region PUBLIC METHODS
public override void Configure(EntityTypeBuilder<PersonPicture> builder)
{
builder.ToTable("PersonPictures", "people");
// Person
builder.HasKey(x => x.PersonId);
builder.HasIndex(x => x.PersonId)
.IsUnique();
builder.HasOne(x => x.Person)
.WithOne(x => x.Picture)
.HasForeignKey<PersonPicture>(x => x.PersonId)
.IsRequired();
builder.Property(x => x.PersonId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
// Generic properties
base.Configure(builder);
}
#endregion
}

View File

@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.People;
namespace WatchIt.Database.Configuration.People;
public class PersonViewCountConfiguration : ViewCountEntityConfiguration<PersonViewCount>
{
#region PUBLIC METHODS
public override void Configure(EntityTypeBuilder<PersonViewCount> builder)
{
builder.ToTable("PersonViewCounts", "people");
builder.HasKey(x => new { x.PersonId, x.Date });
// Medium
builder.HasOne(x => x.Person)
.WithMany(x => x.ViewCounts)
.HasForeignKey(x => x.PersonId)
.IsRequired();
builder.Property(x => x.PersonId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
// Generic properties
base.Configure(builder);
}
#endregion
}

View File

@@ -0,0 +1,54 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Converters;
using WatchIt.Database.Model.Photos;
namespace WatchIt.Database.Configuration.Photos;
public class PhotoBackgroundConfiguration : IEntityTypeConfiguration<PhotoBackground>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<PhotoBackground> builder)
{
builder.ToTable("PhotoBackground", "photos");
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
// Photo
builder.HasOne(x => x.Photo)
.WithOne(x => x.Background)
.HasForeignKey<PhotoBackground>(x => x.PhotoId)
.IsRequired();
builder.HasIndex(x => x.PhotoId)
.IsUnique();
builder.Property(x => x.PhotoId)
.IsRequired();
// Is universal
builder.Property(x => x.IsUniversal)
.IsRequired()
.HasDefaultValue(false);
// First gradient color
builder.Property(x => x.FirstGradientColor)
.HasConversion<ColorToByteArrayConverter>()
.IsRequired();
// Second gradient color
builder.Property(x => x.SecondGradientColor)
.HasConversion<ColorToByteArrayConverter>()
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Photos;
namespace WatchIt.Database.Configuration.Photos;
public class PhotoConfiguration : ImageEntityConfiguration<Photo>
{
#region PUBLIC METHODS
public override void Configure(EntityTypeBuilder<Photo> builder)
{
builder.ToTable("Photos", "photos");
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
// Medium
builder.HasOne(x => x.Medium)
.WithMany(x => x.Photos)
.HasForeignKey(x => x.MediumId)
.IsRequired();
builder.Property(x => x.MediumId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
// Generic properties
base.Configure(builder);
}
#endregion
}

View File

@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model;
using WatchIt.Database.Model.Accounts;
namespace WatchIt.Database.Configuration;
public abstract class RatingEntityConfiguration<T> : IEntityTypeConfiguration<T> where T : class, IRatingEntity
{
#region PUBLIC METHODS
public virtual void Configure(EntityTypeBuilder<T> builder)
{
// Account
// You have to configure FK and PK by yourself
builder.Property(x => x.AccountId)
.IsRequired();
// Rating
builder.Property(x => x.Rating)
.IsRequired();
// Date
builder.Property(x => x.Date)
.IsRequired()
.HasDefaultValueSql("now()");
}
#endregion
}

View File

@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleActorConfiguration : IEntityTypeConfiguration<RoleActor>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<RoleActor> builder)
{
// Actor type
builder.HasOne(x => x.ActorType)
.WithMany(x => x.Roles)
.HasForeignKey(x => x.ActorTypeId)
.IsRequired();
builder.Property(x => x.ActorTypeId)
.IsRequired();
// Name
builder.Property(x => x.Name)
.HasMaxLength(100)
.IsRequired();
}
#endregion
}

View File

@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleActorTypeConfiguration : IEntityTypeConfiguration<RoleActorType>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<RoleActorType> builder)
{
builder.ToTable("RoleActorTypes", "roles");
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired()
.UseIdentityAlwaysColumn();
// Name
builder.Property(x => x.Name)
.HasMaxLength(100)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -0,0 +1,70 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleConfiguration : IEntityTypeConfiguration<Role>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<Role> builder)
{
builder.ToTable("Roles", "roles");
builder.HasDiscriminator<RoleType>("Type")
.HasValue<RoleActor>(RoleType.Actor)
.HasValue<RoleCreator>(RoleType.Creator);
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
// Type
builder.Property(x => x.Type)
.IsRequired();
// Medium
builder.HasOne(x => x.Medium)
.WithMany(x => x.Roles)
.HasForeignKey(x => x.MediumId)
.IsRequired();
builder.Property(x => x.MediumId)
.IsRequired();
// Person
builder.HasOne(x => x.Person)
.WithMany(x => x.Roles)
.HasForeignKey(x => x.PersonId)
.IsRequired();
builder.Property(x => x.PersonId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
#region Navigation
// RoleRating
builder.HasMany(x => x.RatedBy)
.WithMany(x => x.RolesRated)
.UsingEntity<RoleRating>(
x => x.HasOne(y => y.Account)
.WithMany(y => y.RolesRatings)
.HasForeignKey(y => y.AccountId)
.IsRequired(),
x => x.HasOne(y => y.Role)
.WithMany(y => y.Ratings)
.HasForeignKey(y => y.RoleId)
.IsRequired()
);
#endregion
}
#endregion
}

View File

@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleCreatorConfiguration : IEntityTypeConfiguration<RoleCreator>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<RoleCreator> builder)
{
// Creator type
builder.HasOne(x => x.CreatorType)
.WithMany(x => x.Roles)
.HasForeignKey(x => x.CreatorTypeId)
.IsRequired();
builder.Property(x => x.CreatorTypeId)
.IsRequired();
}
#endregion
}

View File

@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleCreatorTypeConfiguration : IEntityTypeConfiguration<RoleCreatorType>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<RoleCreatorType> builder)
{
builder.ToTable("RoleCreatorTypes", "roles");
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired()
.UseIdentityAlwaysColumn();
// Name
builder.Property(x => x.Name)
.HasMaxLength(100)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleRatingConfiguration : RatingEntityConfiguration<RoleRating>
{
#region PUBLIC METHODS
public override void Configure(EntityTypeBuilder<RoleRating> builder)
{
builder.ToTable("RoleRatings", "roles");
builder.HasKey(x => new { x.AccountId, x.RoleId });
// Role
// FK configured in RoleConfiguration
builder.Property(x => x.RoleId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
// Generic properties
base.Configure(builder);
}
#endregion
}

View File

@@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model;
namespace WatchIt.Database.Configuration;
public abstract class ViewCountEntityConfiguration<T> : IEntityTypeConfiguration<T> where T : class, IViewCountEntity
{
#region PUBLIC METHODS
public virtual void Configure(EntityTypeBuilder<T> builder)
{
// Date
// You have to configure PK by yourself
builder.Property(x => x.Date)
.IsRequired()
.HasDefaultValueSql("now()");
// View count
builder.Property(x => x.ViewCount)
.IsRequired();
}
#endregion
}

View File

@@ -0,0 +1,14 @@
using System.Drawing;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace WatchIt.Database.Converters;
public class ColorToByteArrayConverter : ValueConverter<Color, byte[]>
{
#region CONSTRUCTORS
public ColorToByteArrayConverter() : base(x => new byte[] { x.R, x.G, x.B, x.A }, x => Color.FromArgb(x.Length > 3 ? x[3] : 0x00, x[0], x[1], x[2])) {}
#endregion
}

View File

@@ -0,0 +1,83 @@
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using WatchIt.Database.Model.Accounts;
using WatchIt.Database.Model.Genders;
using WatchIt.Database.Model.Genres;
using WatchIt.Database.Model.Media;
using WatchIt.Database.Model.People;
using WatchIt.Database.Model.Photos;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database;
public class DatabaseContext : DbContext
{
#region CONSTRUCTORS
public DatabaseContext()
{
}
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options)
{
}
#endregion
#region PROPERTIES
// Media
public virtual DbSet<Medium> Media { get; set; }
public virtual DbSet<MediumGenre> MediumGenres { get; set; }
public virtual DbSet<MediumRating> MediumRatings { get; set; }
public virtual DbSet<MediumViewCount> MediumViewCounts { get; set; }
public virtual DbSet<MediumPicture> MediumPictures { get; set; }
// People
public virtual DbSet<Person> People { get; set; }
public virtual DbSet<PersonViewCount> PersonViewCounts { get; set; }
public virtual DbSet<PersonPicture> PersonPictures { get; set; }
// Roles
public virtual DbSet<Role> Roles { get; set; }
public virtual DbSet<RoleActorType> RoleActorTypes { get; set; }
public virtual DbSet<RoleCreatorType> RoleCreatorTypes { get; set; }
public virtual DbSet<RoleRating> RoleRatings { get; set; }
// Accounts
public virtual DbSet<Account> Accounts { get; set; }
public virtual DbSet<AccountFollow> AccountFollows { get; set; }
public virtual DbSet<AccountProfilePicture> AccountProfilePictures { get; set; }
public virtual DbSet<AccountBackgroundPicture> AccountBackgroundPictures { get; set; }
public virtual DbSet<AccountRefreshToken> AccountRefreshTokens { get; set; }
// Photos
public virtual DbSet<Photo> Photos { get; set; }
public virtual DbSet<PhotoBackground> PhotoBackgrounds { get; set; }
// Genders
public virtual DbSet<Gender> Genders { get; set; }
// Genres
public virtual DbSet<Genre> Genres { get; set; }
#endregion
#region PROTECTED METHODS
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("name=Database");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetAssembly(typeof(Account))!);
}
#endregion
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,828 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace WatchIt.Database.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "accounts");
migrationBuilder.EnsureSchema(
name: "genders");
migrationBuilder.EnsureSchema(
name: "genres");
migrationBuilder.EnsureSchema(
name: "media");
migrationBuilder.EnsureSchema(
name: "people");
migrationBuilder.EnsureSchema(
name: "photos");
migrationBuilder.EnsureSchema(
name: "roles");
migrationBuilder.CreateTable(
name: "Genders",
schema: "genders",
columns: table => new
{
Id = table.Column<short>(type: "smallint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Genders", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Genres",
schema: "genres",
columns: table => new
{
Id = table.Column<short>(type: "smallint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Genres", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Media",
schema: "media",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
Type = table.Column<byte>(type: "smallint", nullable: false),
Title = table.Column<string>(type: "character varying(250)", maxLength: 250, nullable: false),
OriginalTitle = table.Column<string>(type: "character varying(250)", maxLength: 250, nullable: true),
Description = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
Duration = table.Column<short>(type: "smallint", nullable: true),
ReleaseDate = table.Column<DateOnly>(type: "date", nullable: true),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false),
Budget = table.Column<decimal>(type: "money", nullable: true),
HasEnded = table.Column<bool>(type: "boolean", nullable: true, defaultValue: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Media", x => x.Id);
});
migrationBuilder.CreateTable(
name: "RoleActorTypes",
schema: "roles",
columns: table => new
{
Id = table.Column<short>(type: "smallint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RoleActorTypes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "RoleCreatorTypes",
schema: "roles",
columns: table => new
{
Id = table.Column<short>(type: "smallint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RoleCreatorTypes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Accounts",
schema: "accounts",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
Username = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
Email = table.Column<string>(type: "character varying(320)", maxLength: 320, nullable: false),
Password = table.Column<byte[]>(type: "bytea", maxLength: 1000, nullable: false),
LeftSalt = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
RightSalt = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
IsAdmin = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
JoinDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
ActiveDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
Description = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
GenderId = table.Column<short>(type: "smallint", nullable: true),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Accounts", x => x.Id);
table.ForeignKey(
name: "FK_Accounts_Genders_GenderId",
column: x => x.GenderId,
principalSchema: "genders",
principalTable: "Genders",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "People",
schema: "people",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
FullName = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
Description = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
BirthDate = table.Column<DateOnly>(type: "date", nullable: true),
DeathDate = table.Column<DateOnly>(type: "date", nullable: true),
GenderId = table.Column<short>(type: "smallint", nullable: true),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_People", x => x.Id);
table.ForeignKey(
name: "FK_People_Genders_GenderId",
column: x => x.GenderId,
principalSchema: "genders",
principalTable: "Genders",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "MediumGenres",
schema: "media",
columns: table => new
{
MediumId = table.Column<long>(type: "bigint", nullable: false),
GenreId = table.Column<short>(type: "smallint", nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MediumGenres", x => new { x.GenreId, x.MediumId });
table.ForeignKey(
name: "FK_MediumGenres_Genres_GenreId",
column: x => x.GenreId,
principalSchema: "genres",
principalTable: "Genres",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MediumGenres_Media_MediumId",
column: x => x.MediumId,
principalSchema: "media",
principalTable: "Media",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "MediumPictures",
schema: "media",
columns: table => new
{
MediumId = table.Column<long>(type: "bigint", nullable: false),
Image = table.Column<byte[]>(type: "bytea", maxLength: -1, nullable: false),
MimeType = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
UploadDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MediumPictures", x => x.MediumId);
table.ForeignKey(
name: "FK_MediumPictures_Media_MediumId",
column: x => x.MediumId,
principalSchema: "media",
principalTable: "Media",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "MediumViewCounts",
schema: "media",
columns: table => new
{
MediumId = table.Column<long>(type: "bigint", nullable: false),
Date = table.Column<DateOnly>(type: "date", nullable: false, defaultValueSql: "now()"),
ViewCount = table.Column<long>(type: "bigint", nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MediumViewCounts", x => new { x.MediumId, x.Date });
table.ForeignKey(
name: "FK_MediumViewCounts_Media_MediumId",
column: x => x.MediumId,
principalSchema: "media",
principalTable: "Media",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Photos",
schema: "photos",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
MediumId = table.Column<long>(type: "bigint", nullable: false),
Image = table.Column<byte[]>(type: "bytea", maxLength: -1, nullable: false),
MimeType = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
UploadDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Photos", x => x.Id);
table.ForeignKey(
name: "FK_Photos_Media_MediumId",
column: x => x.MediumId,
principalSchema: "media",
principalTable: "Media",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AccountFollows",
schema: "accounts",
columns: table => new
{
FollowerId = table.Column<long>(type: "bigint", nullable: false),
FollowedId = table.Column<long>(type: "bigint", nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AccountFollows", x => new { x.FollowerId, x.FollowedId });
table.ForeignKey(
name: "FK_AccountFollows_Accounts_FollowedId",
column: x => x.FollowedId,
principalSchema: "accounts",
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AccountFollows_Accounts_FollowerId",
column: x => x.FollowerId,
principalSchema: "accounts",
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AccountProfilePictures",
schema: "accounts",
columns: table => new
{
AccountId = table.Column<long>(type: "bigint", nullable: false),
Image = table.Column<byte[]>(type: "bytea", maxLength: -1, nullable: false),
MimeType = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
UploadDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AccountProfilePictures", x => x.AccountId);
table.ForeignKey(
name: "FK_AccountProfilePictures_Accounts_AccountId",
column: x => x.AccountId,
principalSchema: "accounts",
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AccountRefreshTokens",
schema: "accounts",
columns: table => new
{
Token = table.Column<Guid>(type: "uuid", nullable: false),
AccountId = table.Column<long>(type: "bigint", nullable: false),
ExpirationDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
IsExtendable = table.Column<bool>(type: "boolean", nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AccountRefreshTokens", x => x.Token);
table.ForeignKey(
name: "FK_AccountRefreshTokens_Accounts_AccountId",
column: x => x.AccountId,
principalSchema: "accounts",
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "MediumRatings",
schema: "media",
columns: table => new
{
AccountId = table.Column<long>(type: "bigint", nullable: false),
MediumId = table.Column<long>(type: "bigint", nullable: false),
Rating = table.Column<byte>(type: "smallint", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MediumRatings", x => new { x.AccountId, x.MediumId });
table.ForeignKey(
name: "FK_MediumRatings_Accounts_AccountId",
column: x => x.AccountId,
principalSchema: "accounts",
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MediumRatings_Media_MediumId",
column: x => x.MediumId,
principalSchema: "media",
principalTable: "Media",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PersonPictures",
schema: "people",
columns: table => new
{
PersonId = table.Column<long>(type: "bigint", nullable: false),
Image = table.Column<byte[]>(type: "bytea", maxLength: -1, nullable: false),
MimeType = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
UploadDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PersonPictures", x => x.PersonId);
table.ForeignKey(
name: "FK_PersonPictures_People_PersonId",
column: x => x.PersonId,
principalSchema: "people",
principalTable: "People",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PersonViewCounts",
schema: "people",
columns: table => new
{
PersonId = table.Column<long>(type: "bigint", nullable: false),
Date = table.Column<DateOnly>(type: "date", nullable: false, defaultValueSql: "now()"),
ViewCount = table.Column<long>(type: "bigint", nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PersonViewCounts", x => new { x.PersonId, x.Date });
table.ForeignKey(
name: "FK_PersonViewCounts_People_PersonId",
column: x => x.PersonId,
principalSchema: "people",
principalTable: "People",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Roles",
schema: "roles",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Type = table.Column<byte>(type: "smallint", nullable: false),
MediumId = table.Column<long>(type: "bigint", nullable: false),
PersonId = table.Column<long>(type: "bigint", nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false),
ActorTypeId = table.Column<short>(type: "smallint", nullable: true),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
CreatorTypeId = table.Column<short>(type: "smallint", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Roles", x => x.Id);
table.ForeignKey(
name: "FK_Roles_Media_MediumId",
column: x => x.MediumId,
principalSchema: "media",
principalTable: "Media",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Roles_People_PersonId",
column: x => x.PersonId,
principalSchema: "people",
principalTable: "People",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Roles_RoleActorTypes_ActorTypeId",
column: x => x.ActorTypeId,
principalSchema: "roles",
principalTable: "RoleActorTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Roles_RoleCreatorTypes_CreatorTypeId",
column: x => x.CreatorTypeId,
principalSchema: "roles",
principalTable: "RoleCreatorTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PhotoBackground",
schema: "photos",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
PhotoId = table.Column<Guid>(type: "uuid", nullable: false),
IsUniversal = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
FirstGradientColor = table.Column<byte[]>(type: "bytea", nullable: false),
SecondGradientColor = table.Column<byte[]>(type: "bytea", nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PhotoBackground", x => x.Id);
table.ForeignKey(
name: "FK_PhotoBackground_Photos_PhotoId",
column: x => x.PhotoId,
principalSchema: "photos",
principalTable: "Photos",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "RoleRatings",
schema: "roles",
columns: table => new
{
AccountId = table.Column<long>(type: "bigint", nullable: false),
RoleId = table.Column<Guid>(type: "uuid", nullable: false),
Rating = table.Column<byte>(type: "smallint", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RoleRatings", x => new { x.AccountId, x.RoleId });
table.ForeignKey(
name: "FK_RoleRatings_Accounts_AccountId",
column: x => x.AccountId,
principalSchema: "accounts",
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RoleRatings_Roles_RoleId",
column: x => x.RoleId,
principalSchema: "roles",
principalTable: "Roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AccountBackgroundPictures",
schema: "accounts",
columns: table => new
{
AccountId = table.Column<long>(type: "bigint", nullable: false),
BackgroundId = table.Column<Guid>(type: "uuid", nullable: false),
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AccountBackgroundPictures", x => x.AccountId);
table.ForeignKey(
name: "FK_AccountBackgroundPictures_Accounts_AccountId",
column: x => x.AccountId,
principalSchema: "accounts",
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AccountBackgroundPictures_PhotoBackground_BackgroundId",
column: x => x.BackgroundId,
principalSchema: "photos",
principalTable: "PhotoBackground",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_AccountBackgroundPictures_AccountId",
schema: "accounts",
table: "AccountBackgroundPictures",
column: "AccountId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_AccountBackgroundPictures_BackgroundId",
schema: "accounts",
table: "AccountBackgroundPictures",
column: "BackgroundId");
migrationBuilder.CreateIndex(
name: "IX_AccountFollows_FollowedId",
schema: "accounts",
table: "AccountFollows",
column: "FollowedId");
migrationBuilder.CreateIndex(
name: "IX_AccountProfilePictures_AccountId",
schema: "accounts",
table: "AccountProfilePictures",
column: "AccountId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_AccountRefreshTokens_AccountId",
schema: "accounts",
table: "AccountRefreshTokens",
column: "AccountId");
migrationBuilder.CreateIndex(
name: "IX_AccountRefreshTokens_Token",
schema: "accounts",
table: "AccountRefreshTokens",
column: "Token",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Accounts_GenderId",
schema: "accounts",
table: "Accounts",
column: "GenderId");
migrationBuilder.CreateIndex(
name: "IX_Accounts_Id",
schema: "accounts",
table: "Accounts",
column: "Id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Genders_Id",
schema: "genders",
table: "Genders",
column: "Id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Genres_Id",
schema: "genres",
table: "Genres",
column: "Id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Media_Id",
schema: "media",
table: "Media",
column: "Id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_MediumGenres_MediumId",
schema: "media",
table: "MediumGenres",
column: "MediumId");
migrationBuilder.CreateIndex(
name: "IX_MediumPictures_MediumId",
schema: "media",
table: "MediumPictures",
column: "MediumId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_MediumRatings_MediumId",
schema: "media",
table: "MediumRatings",
column: "MediumId");
migrationBuilder.CreateIndex(
name: "IX_People_GenderId",
schema: "people",
table: "People",
column: "GenderId");
migrationBuilder.CreateIndex(
name: "IX_People_Id",
schema: "people",
table: "People",
column: "Id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_PersonPictures_PersonId",
schema: "people",
table: "PersonPictures",
column: "PersonId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_PhotoBackground_Id",
schema: "photos",
table: "PhotoBackground",
column: "Id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_PhotoBackground_PhotoId",
schema: "photos",
table: "PhotoBackground",
column: "PhotoId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Photos_Id",
schema: "photos",
table: "Photos",
column: "Id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Photos_MediumId",
schema: "photos",
table: "Photos",
column: "MediumId");
migrationBuilder.CreateIndex(
name: "IX_RoleActorTypes_Id",
schema: "roles",
table: "RoleActorTypes",
column: "Id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_RoleCreatorTypes_Id",
schema: "roles",
table: "RoleCreatorTypes",
column: "Id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_RoleRatings_RoleId",
schema: "roles",
table: "RoleRatings",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_Roles_ActorTypeId",
schema: "roles",
table: "Roles",
column: "ActorTypeId");
migrationBuilder.CreateIndex(
name: "IX_Roles_CreatorTypeId",
schema: "roles",
table: "Roles",
column: "CreatorTypeId");
migrationBuilder.CreateIndex(
name: "IX_Roles_Id",
schema: "roles",
table: "Roles",
column: "Id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Roles_MediumId",
schema: "roles",
table: "Roles",
column: "MediumId");
migrationBuilder.CreateIndex(
name: "IX_Roles_PersonId",
schema: "roles",
table: "Roles",
column: "PersonId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AccountBackgroundPictures",
schema: "accounts");
migrationBuilder.DropTable(
name: "AccountFollows",
schema: "accounts");
migrationBuilder.DropTable(
name: "AccountProfilePictures",
schema: "accounts");
migrationBuilder.DropTable(
name: "AccountRefreshTokens",
schema: "accounts");
migrationBuilder.DropTable(
name: "MediumGenres",
schema: "media");
migrationBuilder.DropTable(
name: "MediumPictures",
schema: "media");
migrationBuilder.DropTable(
name: "MediumRatings",
schema: "media");
migrationBuilder.DropTable(
name: "MediumViewCounts",
schema: "media");
migrationBuilder.DropTable(
name: "PersonPictures",
schema: "people");
migrationBuilder.DropTable(
name: "PersonViewCounts",
schema: "people");
migrationBuilder.DropTable(
name: "RoleRatings",
schema: "roles");
migrationBuilder.DropTable(
name: "PhotoBackground",
schema: "photos");
migrationBuilder.DropTable(
name: "Genres",
schema: "genres");
migrationBuilder.DropTable(
name: "Accounts",
schema: "accounts");
migrationBuilder.DropTable(
name: "Roles",
schema: "roles");
migrationBuilder.DropTable(
name: "Photos",
schema: "photos");
migrationBuilder.DropTable(
name: "People",
schema: "people");
migrationBuilder.DropTable(
name: "RoleActorTypes",
schema: "roles");
migrationBuilder.DropTable(
name: "RoleCreatorTypes",
schema: "roles");
migrationBuilder.DropTable(
name: "Media",
schema: "media");
migrationBuilder.DropTable(
name: "Genders",
schema: "genders");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
using WatchIt.Database.Model.Genders;
using WatchIt.Database.Model.Media;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Model.Accounts;
public class Account
{
#region PROPERTIES
public long Id { get; set; }
public string Username { get; set; } = default!;
public string Email { get; set; } = default!;
public byte[] Password { get; set; } = default!;
public string LeftSalt { get; set; } = default!;
public string RightSalt { get; set; } = default!;
public bool IsAdmin { get; set; } = false;
public DateTimeOffset JoinDate { get; set; }
public DateTimeOffset ActiveDate { get; set; }
public string? Description { get; set; }
public short? GenderId { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Profile picture
public virtual AccountProfilePicture? ProfilePicture { get; set; }
// Background picture
public virtual AccountBackgroundPicture? BackgroundPicture { get; set; }
// Refresh tokens
public virtual IEnumerable<AccountRefreshToken> RefreshTokens { get; set; } = new List<AccountRefreshToken>();
// Follows
public virtual IEnumerable<AccountFollow> FollowsRelationshipObjects { get; set; } = new List<AccountFollow>();
public virtual IEnumerable<Account> Follows { get; set; } = new List<Account>();
// Followers
public virtual IEnumerable<AccountFollow> FollowersRelationshipObjects { get; set; } = new List<AccountFollow>();
public virtual IEnumerable<Account> Followers { get; set; } = new List<Account>();
// Gender
public virtual Gender? Gender { get; set; }
// Media ratings
public virtual IEnumerable<MediumRating> MediaRatings { get; set; } = new List<MediumRating>();
public virtual IEnumerable<Medium> MediaRated { get; set; } = new List<Medium>();
// Roles ratings
public virtual IEnumerable<RoleRating> RolesRatings { get; set; } = new List<RoleRating>();
public virtual IEnumerable<Role> RolesRated { get; set; } = new List<Role>();
#endregion
}

View File

@@ -0,0 +1,26 @@
using WatchIt.Database.Model.Photos;
namespace WatchIt.Database.Model.Accounts;
public class AccountBackgroundPicture
{
#region PROPERTIES
public long AccountId { get; set; }
public Guid BackgroundId { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Account
public virtual Account Account { get; set; } = default!;
// Background
public virtual PhotoBackground Background { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,24 @@
namespace WatchIt.Database.Model.Accounts;
public class AccountFollow
{
#region PROPERTIES
public long FollowerId { get; set; }
public long FollowedId { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Follower
public virtual Account Follower { get; set; } = default!;
// Followed
public virtual Account Followed { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,23 @@
namespace WatchIt.Database.Model.Accounts;
public class AccountProfilePicture : IImageEntity
{
#region PROPERTIES
public long AccountId { get; set; }
public byte[] Image { get; set; } = default!;
public string MimeType { get; set; } = default!;
public DateTimeOffset UploadDate { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Account
public virtual Account Account { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,23 @@
namespace WatchIt.Database.Model.Accounts;
public class AccountRefreshToken
{
#region PROPERTIES
public Guid Token { get; set; }
public long AccountId { get; set; }
public DateTimeOffset ExpirationDate { get; set; }
public bool IsExtendable { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Account
public virtual Account Account { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,26 @@
using WatchIt.Database.Model.Accounts;
namespace WatchIt.Database.Model.Genders;
public class Gender
{
#region PROPERTIES
public short Id { get; set; }
public string Name { get; set; } = default!;
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Accounts
public virtual IEnumerable<Account> Accounts { get; set; } = new List<Account>();
// People
public virtual IEnumerable<People.Person> People { get; set; } = new List<People.Person>();
#endregion
}

View File

@@ -0,0 +1,24 @@
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Genres;
public class Genre
{
#region PROPERTIES
public short Id { get; set; }
public string Name { get; set; } = default!;
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Media
public virtual IEnumerable<MediumGenre> MediaRelationObjects { get; set; } = new List<MediumGenre>();
public virtual IEnumerable<Medium> Media { get; set; } = new List<Medium>();
#endregion
}

View File

@@ -0,0 +1,12 @@
namespace WatchIt.Database.Model;
public interface IImageEntity
{
#region PROPERTIES
byte[] Image { get; set; }
string MimeType { get; set; }
DateTimeOffset UploadDate { get; set; }
#endregion
}

View File

@@ -0,0 +1,23 @@
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model;
public interface IRatingEntity
{
#region PROPERTIES
long AccountId { get; set; }
byte Rating { get; set; }
DateTime Date { get; set; }
#endregion
#region NAVIGATION
// Account
Accounts.Account Account { get; set; }
#endregion
}

View File

@@ -0,0 +1,11 @@
namespace WatchIt.Database.Model;
public interface IViewCountEntity
{
#region PROPERTIES
DateOnly Date { get; set; }
long ViewCount { get; set; }
#endregion
}

View File

@@ -0,0 +1,47 @@
using WatchIt.Database.Model.Genres;
using WatchIt.Database.Model.Photos;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Model.Media;
public abstract class Medium
{
#region PROPERTIES
public long Id { get; set; }
public MediumType Type { get; set; }
public string Title { get; set; } = default!;
public string? OriginalTitle { get; set; }
public string? Description { get; set; }
public short? Duration { get; set; }
public DateOnly? ReleaseDate { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Genres
public virtual IEnumerable<MediumGenre> GenresRelationshipObjects { get; set; } = new List<MediumGenre>();
public virtual IEnumerable<Genre> Genres { get; set; } = new List<Genre>();
// Picture
public virtual MediumPicture? Picture { get; set; }
// Photos
public virtual IEnumerable<Photo> Photos { get; set; } = new List<Photo>();
// View counts
public virtual IEnumerable<MediumViewCount> ViewCounts { get; set; } = new List<MediumViewCount>();
// Ratings
public virtual IEnumerable<MediumRating> Ratings { get; set; } = new List<MediumRating>();
public virtual IEnumerable<Accounts.Account> RatedBy { get; set; } = new List<Accounts.Account>();
// Roles
public virtual IEnumerable<Role> Roles { get; set; } = new List<Role>();
#endregion
}

View File

@@ -0,0 +1,26 @@
using WatchIt.Database.Model.Genres;
namespace WatchIt.Database.Model.Media;
public class MediumGenre
{
#region PROPERTIES
public long MediumId { get; set; }
public short GenreId { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Medium
public virtual Medium Medium { get; set; } = default!;
// Genre
public virtual Genre Genre { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,10 @@
namespace WatchIt.Database.Model.Media;
public class MediumMovie : Medium
{
#region PROPERTIES
public decimal? Budget { get; set; }
#endregion
}

View File

@@ -0,0 +1,22 @@
namespace WatchIt.Database.Model.Media;
public class MediumPicture : IImageEntity
{
#region PROPERTIES
public long MediumId { get; set; }
public byte[] Image { get; set; } = default!;
public string MimeType { get; set; } = default!;
public DateTimeOffset UploadDate { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
public virtual Medium Medium { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,26 @@
namespace WatchIt.Database.Model.Media;
public class MediumRating : IRatingEntity
{
#region PROPERTIES
public long AccountId { get; set; }
public long MediumId { get; set; }
public byte Rating { get; set; }
public DateTime Date { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Account
public virtual Accounts.Account Account { get; set; } = default!;
// Medium
public virtual Medium Medium { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,10 @@
namespace WatchIt.Database.Model.Media;
public class MediumSeries : Medium
{
#region PROPERTIES
public bool HasEnded { get; set; }
#endregion
}

View File

@@ -0,0 +1,7 @@
namespace WatchIt.Database.Model.Media;
public enum MediumType : byte
{
Movie = 0,
Series = 1,
}

View File

@@ -0,0 +1,23 @@
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Media;
public class MediumViewCount : IViewCountEntity
{
#region PROPERTIES
public long MediumId { get; set; }
public DateOnly Date { get; set; }
public long ViewCount { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
public virtual Medium Medium { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,38 @@
using WatchIt.Database.Model.Genders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Model.People;
public class Person
{
#region PROPERTIES
public long Id { get; set; }
public string Name { get; set; } = default!;
public string? FullName { get; set; }
public string? Description { get; set; }
public DateOnly? BirthDate { get; set; }
public DateOnly? DeathDate { get; set; }
public short? GenderId { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Gender
public virtual Gender? Gender { get; set; }
// Picture
public virtual PersonPicture? Picture { get; set; }
// View counts
public virtual IEnumerable<PersonViewCount> ViewCounts { get; set; } = new List<PersonViewCount>();
// Roles
public virtual IEnumerable<Role> Roles { get; set; } = new List<Role>();
#endregion
}

View File

@@ -0,0 +1,22 @@
namespace WatchIt.Database.Model.People;
public class PersonPicture : IImageEntity
{
#region PROPERTIES
public long PersonId { get; set; }
public byte[] Image { get; set; } = default!;
public string MimeType { get; set; } = default!;
public DateTimeOffset UploadDate { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
public virtual Person Person { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,21 @@
namespace WatchIt.Database.Model.People;
public class PersonViewCount : IViewCountEntity
{
#region PROPERTIES
public long PersonId { get; set; }
public DateOnly Date { get; set; }
public long ViewCount { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
public virtual Person Person { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,29 @@
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Photos;
public class Photo : IImageEntity
{
#region PROPERTIES
public Guid Id { get; set; }
public long MediumId { get; set; }
public byte[] Image { get; set; } = null!;
public string MimeType { get; set; } = null!;
public DateTimeOffset UploadDate { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Medium
public virtual Medium Medium { get; set; } = default!;
// Background settings
public virtual PhotoBackground? Background { get; set; }
#endregion
}

View File

@@ -0,0 +1,30 @@
using System.Drawing;
using WatchIt.Database.Model.Accounts;
namespace WatchIt.Database.Model.Photos;
public class PhotoBackground
{
#region PROPERTIES
public Guid Id { get; set; }
public Guid PhotoId { get; set; }
public bool IsUniversal { get; set; }
public Color FirstGradientColor { get; set; }
public Color SecondGradientColor { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Photo
public virtual Photo Photo { get; set; } = default!;
// Background usages
public virtual IEnumerable<AccountBackgroundPicture> BackgroundUsages { get; set; } = new List<AccountBackgroundPicture>();
#endregion
}

View File

@@ -0,0 +1,32 @@
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Roles;
public abstract class Role
{
#region PROPERTIES
public Guid Id { get; set; }
public RoleType Type { get; set; }
public long MediumId { get; set; }
public long PersonId { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Medium
public virtual Medium Medium { get; set; } = default!;
// Person
public virtual People.Person Person { get; set; } = default!;
// Ratings
public virtual IEnumerable<RoleRating> Ratings { get; set; } = default!;
public virtual IEnumerable<Accounts.Account> RatedBy { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,20 @@
namespace WatchIt.Database.Model.Roles;
public class RoleActor : Role
{
#region PROPERTIES
public short ActorTypeId { get; set; }
public string Name { get; set; } = default!;
#endregion
#region NAVIGATION
// Actor type
public virtual RoleActorType ActorType { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,20 @@
namespace WatchIt.Database.Model.Roles;
public class RoleActorType
{
#region PROPERTIES
public short Id { get; set; }
public string Name { get; set; } = default!;
public uint Version { get; set; }
#endregion
#region NAVIGATION
public virtual IEnumerable<RoleActor> Roles { get; set; } = new List<RoleActor>();
#endregion
}

View File

@@ -0,0 +1,19 @@
namespace WatchIt.Database.Model.Roles;
public class RoleCreator : Role
{
#region PROPERTIES
public short CreatorTypeId { get; set; }
#endregion
#region NAVIGATION
// Creator type
public virtual RoleCreatorType CreatorType { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,20 @@
namespace WatchIt.Database.Model.Roles;
public class RoleCreatorType
{
#region PROPERTIES
public short Id { get; set; }
public string Name { get; set; } = default!;
public uint Version { get; set; }
#endregion
#region NAVIGATION
public virtual IEnumerable<RoleCreator> Roles { get; set; } = new List<RoleCreator>();
#endregion
}

View File

@@ -0,0 +1,26 @@
namespace WatchIt.Database.Model.Roles;
public class RoleRating : IRatingEntity
{
#region PROPERTIES
public long AccountId { get; set; }
public Guid RoleId { get; set; }
public byte Rating { get; set; }
public DateTime Date { get; set; }
public uint Version { get; set; }
#endregion
#region NAVIGATION
// Account
public virtual Accounts.Account Account { get; set; } = default!;
// Role
public virtual Role Role { get; set; } = default!;
#endregion
}

View File

@@ -0,0 +1,7 @@
namespace WatchIt.Database.Model.Roles;
public enum RoleType : byte
{
Actor = 0,
Creator = 1,
}

View File

@@ -1,66 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace WatchIt.Database.Model.Configuration.Account;
public class AccountConfiguration : IEntityTypeConfiguration<Model.Account.Account>
{
public void Configure(EntityTypeBuilder<Model.Account.Account> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.Property(x => x.Username)
.HasMaxLength(50)
.IsRequired();
builder.Property(x => x.Email)
.HasMaxLength(320)
.IsRequired();
builder.Property(x => x.Description)
.HasMaxLength(1000);
builder.HasOne(x => x.Gender)
.WithMany()
.HasForeignKey(x => x.GenderId);
builder.Property(x => x.GenderId);
builder.HasOne(x => x.ProfilePicture)
.WithOne(x => x.Account)
.HasForeignKey<Model.Account.Account>(e => e.ProfilePictureId);
builder.Property(x => x.ProfilePictureId);
builder.HasOne(x => x.BackgroundPicture)
.WithMany()
.HasForeignKey(x => x.BackgroundPictureId);
builder.Property(x => x.BackgroundPictureId);
builder.Property(x => x.Password)
.HasMaxLength(1000)
.IsRequired();
builder.Property(x => x.LeftSalt)
.HasMaxLength(20)
.IsRequired();
builder.Property(x => x.RightSalt)
.HasMaxLength(20)
.IsRequired();
builder.Property(x => x.IsAdmin)
.IsRequired()
.HasDefaultValue(false);
builder.Property(x => x.CreationDate)
.IsRequired()
.HasDefaultValueSql("now()");
builder.Property(x => x.LastActive)
.IsRequired()
.HasDefaultValueSql("now()");
}
}

View File

@@ -1,31 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Account;
namespace WatchIt.Database.Model.Configuration.Account;
public class AccountFollowConfiguration : IEntityTypeConfiguration<AccountFollow>
{
public void Configure(EntityTypeBuilder<AccountFollow> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.AccountFollower)
.WithMany(x => x.AccountFollows)
.HasForeignKey(x => x.AccountFollowerId)
.IsRequired();
builder.Property(x => x.AccountFollowerId)
.IsRequired();
builder.HasOne(x => x.AccountFollowed)
.WithMany(x => x.AccountFollowers)
.HasForeignKey(x => x.AccountFollowedId)
.IsRequired();
builder.Property(x => x.AccountFollowedId)
.IsRequired();
}
}

View File

@@ -1,29 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Account;
namespace WatchIt.Database.Model.Configuration.Account;
public class AccountProfilePictureConfiguration : IEntityTypeConfiguration<AccountProfilePicture>
{
public void Configure(EntityTypeBuilder<AccountProfilePicture> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.Property(x => x.Image)
.HasMaxLength(-1)
.IsRequired();
builder.Property(x => x.MimeType)
.HasMaxLength(50)
.IsRequired();
builder.Property(x => x.UploadDate)
.IsRequired()
.HasDefaultValueSql("now()");
}
}

View File

@@ -1,35 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Common;
using WatchIt.Database.Model.Media;
using WatchIt.Database.Model.Seeding;
namespace WatchIt.Database.Model.Configuration.Common;
public class CountryConfiguration : IEntityTypeConfiguration<Country>
{
public void Configure(EntityTypeBuilder<Country> 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.IsHistorical)
.HasDefaultValue(false)
.IsRequired();
// Navigation
builder.HasMany(x => x.MediaProduction)
.WithMany(x => x.ProductionCountries)
.UsingEntity<MediaProductionCountry>();
// Data
builder.HasData(DataReader.Read<Country>());
}
}

View File

@@ -1,24 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Common;
using WatchIt.Database.Model.Seeding;
namespace WatchIt.Database.Model.Configuration.Common;
public class GenderConfiguration : IEntityTypeConfiguration<Gender>
{
public void Configure(EntityTypeBuilder<Gender> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.Property(x => x.Name)
.IsRequired();
// Data
builder.HasData(DataReader.Read<Gender>());
}
}

View File

@@ -1,44 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Configuration.Media;
public class MediaConfiguration : IEntityTypeConfiguration<Model.Media.Media>
{
public void Configure(EntityTypeBuilder<Model.Media.Media> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.Property(x => x.Title)
.HasMaxLength(250)
.IsRequired();
builder.Property(x => x.OriginalTitle)
.HasMaxLength(250);
builder.Property(x => x.Description)
.HasMaxLength(1000);
builder.Property(x => x.ReleaseDate);
builder.Property(x => x.Length);
builder.HasOne(x => x.MediaPosterImage)
.WithOne(x => x.Media)
.HasForeignKey<Model.Media.Media>(x => x.MediaPosterImageId);
builder.Property(x => x.MediaPosterImageId);
// Navigation
builder.HasMany(x => x.Genres)
.WithMany(x => x.Media)
.UsingEntity<MediaGenre>();
builder.HasMany(x => x.ProductionCountries)
.WithMany(x => x.MediaProduction)
.UsingEntity<MediaProductionCountry>();
}
}

View File

@@ -1,25 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Configuration.Media;
public class MediaGenreConfiguration : IEntityTypeConfiguration<MediaGenre>
{
public void Configure(EntityTypeBuilder<MediaGenre> builder)
{
builder.HasOne(x => x.Media)
.WithMany(x => x.MediaGenres)
.HasForeignKey(x => x.MediaId)
.IsRequired();
builder.Property(x => x.MediaId)
.IsRequired();
builder.HasOne(x => x.Genre)
.WithMany(x => x.MediaGenres)
.HasForeignKey(x => x.GenreId)
.IsRequired();
builder.Property(x => x.GenreId)
.IsRequired();
}
}

View File

@@ -1,24 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Configuration.Media;
public class MediaMovieConfiguration : IEntityTypeConfiguration<MediaMovie>
{
public void Configure(EntityTypeBuilder<MediaMovie> builder)
{
builder.HasKey(x => x.Id);
builder.HasOne(x => x.Media)
.WithOne()
.HasForeignKey<MediaMovie>(x => x.Id)
.IsRequired();
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.Property(x => x.Budget)
.HasColumnType("money");
}
}

View File

@@ -1,29 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Configuration.Media;
public class MediaPhotoImageBackgroundConfiguration : IEntityTypeConfiguration<MediaPhotoImageBackground>
{
public void Configure(EntityTypeBuilder<MediaPhotoImageBackground> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.Property(x => x.IsUniversalBackground)
.IsRequired()
.HasDefaultValue(false);
builder.Property(x => x.FirstGradientColor)
.IsRequired()
.HasMaxLength(3);
builder.Property(x => x.SecondGradientColor)
.IsRequired()
.HasMaxLength(3);
}
}

View File

@@ -1,40 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Configuration.Media;
public class MediaPhotoImageConfiguration : IEntityTypeConfiguration<MediaPhotoImage>
{
public void Configure(EntityTypeBuilder<MediaPhotoImage> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.Media)
.WithMany(x => x.MediaPhotoImages)
.HasForeignKey(x => x.MediaId)
.IsRequired();
builder.Property(x => x.MediaId)
.IsRequired();
builder.Property(x => x.Image)
.HasMaxLength(-1)
.IsRequired();
builder.Property(x => x.MimeType)
.HasMaxLength(50)
.IsRequired();
builder.Property(x => x.UploadDate)
.IsRequired()
.HasDefaultValueSql("now()");
builder.HasOne(x => x.MediaPhotoImageBackground)
.WithOne(x => x.MediaPhotoImage)
.HasForeignKey<MediaPhotoImageBackground>();
}
}

View File

@@ -1,29 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Configuration.Media;
public class MediaPosterImageConfiguration : IEntityTypeConfiguration<MediaPosterImage>
{
public void Configure(EntityTypeBuilder<MediaPosterImage> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.Property(x => x.Image)
.HasMaxLength(-1)
.IsRequired();
builder.Property(x => x.MimeType)
.HasMaxLength(50)
.IsRequired();
builder.Property(x => x.UploadDate)
.IsRequired()
.HasDefaultValueSql("now()");
}
}

View File

@@ -1,25 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Configuration.Media;
public class MediaProductionCountryConfiguration : IEntityTypeConfiguration<MediaProductionCountry>
{
public void Configure(EntityTypeBuilder<MediaProductionCountry> builder)
{
builder.HasOne(x => x.Media)
.WithMany(x => x.MediaProductionCountries)
.HasForeignKey(x => x.MediaId)
.IsRequired();
builder.Property(x => x.MediaId)
.IsRequired();
builder.HasOne(x => x.Country)
.WithMany(x => x.MediaProductionCountries)
.HasForeignKey(x => x.CountryId)
.IsRequired();
builder.Property(x => x.CountryId)
.IsRequired();
}
}

View File

@@ -1,25 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Configuration.Media;
public class MediaSeriesConfiguration : IEntityTypeConfiguration<MediaSeries>
{
public void Configure(EntityTypeBuilder<MediaSeries> builder)
{
builder.HasKey(x => x.Id);
builder.HasOne(x => x.Media)
.WithOne()
.HasForeignKey<MediaSeries>(x => x.Id)
.IsRequired();
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.Property(x => x.HasEnded)
.IsRequired()
.HasDefaultValue(false);
}
}

View File

@@ -1,33 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Configuration.Media;
public class MediaSeriesEpisodeConfiguration : IEntityTypeConfiguration<MediaSeriesEpisode>
{
public void Configure(EntityTypeBuilder<MediaSeriesEpisode> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.MediaSeriesSeason)
.WithMany(x => x.MediaSeriesEpisodes)
.HasForeignKey(x => x.MediaSeriesSeasonId)
.IsRequired();
builder.Property(x => x.MediaSeriesSeasonId)
.IsRequired();
builder.Property(x => x.Number)
.IsRequired();
builder.Property(x => x.Name);
builder.Property(x => x.IsSpecial)
.IsRequired()
.HasDefaultValue(false);
}
}

View File

@@ -1,29 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Media;
namespace WatchIt.Database.Model.Configuration.Media;
public class MediaSeriesSeasonConfiguration : IEntityTypeConfiguration<MediaSeriesSeason>
{
public void Configure(EntityTypeBuilder<MediaSeriesSeason> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.MediaSeries)
.WithMany(x => x.MediaSeriesSeasons)
.HasForeignKey(x => x.MediaSeriesId)
.IsRequired();
builder.Property(x => x.MediaSeriesId)
.IsRequired();
builder.Property(x => x.Number)
.IsRequired();
builder.Property(x => x.Name);
}
}

View File

@@ -1,42 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Person;
namespace WatchIt.Database.Model.Configuration.Person;
public class PersonActorRoleConfiguration : IEntityTypeConfiguration<PersonActorRole>
{
public void Configure(EntityTypeBuilder<PersonActorRole> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.Person)
.WithMany(x => x.PersonActorRoles)
.HasForeignKey(x => x.PersonId)
.IsRequired();
builder.Property(x => x.PersonId)
.IsRequired();
builder.HasOne(x => x.Media)
.WithMany(x => x.PersonActorRoles)
.HasForeignKey(x => x.MediaId)
.IsRequired();
builder.Property(x => x.MediaId)
.IsRequired();
builder.HasOne(x => x.PersonActorRoleType)
.WithMany()
.HasForeignKey(x => x.PersonActorRoleTypeId)
.IsRequired();
builder.Property(x => x.PersonActorRoleTypeId)
.IsRequired();
builder.Property(x => x.RoleName)
.HasMaxLength(100)
.IsRequired();
}
}

View File

@@ -1,25 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Person;
using WatchIt.Database.Model.Seeding;
namespace WatchIt.Database.Model.Configuration.Person;
public class PersonActorRoleTypeConfiguration : IEntityTypeConfiguration<PersonActorRoleType>
{
public void Configure(EntityTypeBuilder<PersonActorRoleType> 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();
// Data
builder.HasData(DataReader.Read<PersonActorRoleType>());
}
}

View File

@@ -1,40 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace WatchIt.Database.Model.Configuration.Person;
public class PersonConfiguration : IEntityTypeConfiguration<Model.Person.Person>
{
public void Configure(EntityTypeBuilder<Model.Person.Person> 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.FullName)
.HasMaxLength(200);
builder.Property(x => x.Description)
.HasMaxLength(1000);
builder.Property(x => x.BirthDate);
builder.Property(x => x.DeathDate);
builder.HasOne(x => x.Gender)
.WithMany()
.HasForeignKey(x => x.GenderId);
builder.Property(x => x.GenderId);
builder.HasOne(x => x.PersonPhoto)
.WithOne(x => x.Person)
.HasForeignKey<Model.Person.Person>(e => e.PersonPhotoId);
builder.Property(x => x.PersonPhotoId);
}
}

View File

@@ -1,38 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Person;
namespace WatchIt.Database.Model.Configuration.Person;
public class PersonCreatorRoleConfiguration : IEntityTypeConfiguration<PersonCreatorRole>
{
public void Configure(EntityTypeBuilder<PersonCreatorRole> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.Person)
.WithMany(x => x.PersonCreatorRoles)
.HasForeignKey(x => x.PersonId)
.IsRequired();
builder.Property(x => x.PersonId)
.IsRequired();
builder.HasOne(x => x.Media)
.WithMany(x => x.PersonCreatorRoles)
.HasForeignKey(x => x.MediaId)
.IsRequired();
builder.Property(x => x.MediaId)
.IsRequired();
builder.HasOne(x => x.PersonCreatorRoleType)
.WithMany()
.HasForeignKey(x => x.PersonCreatorRoleTypeId)
.IsRequired();
builder.Property(x => x.PersonCreatorRoleTypeId)
.IsRequired();
}
}

View File

@@ -1,25 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Person;
using WatchIt.Database.Model.Seeding;
namespace WatchIt.Database.Model.Configuration.Person;
public class PersonCreatorRoleTypeConfiguration : IEntityTypeConfiguration<PersonCreatorRoleType>
{
public void Configure(EntityTypeBuilder<PersonCreatorRoleType> 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();
// Data
builder.HasData(DataReader.Read<PersonCreatorRoleType>());
}
}

View File

@@ -1,29 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Person;
namespace WatchIt.Database.Model.Configuration.Person;
public class PersonPhotoImageConfiguration : IEntityTypeConfiguration<PersonPhotoImage>
{
public void Configure(EntityTypeBuilder<PersonPhotoImage> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.Property(x => x.Image)
.HasMaxLength(-1)
.IsRequired();
builder.Property(x => x.MimeType)
.HasMaxLength(50)
.IsRequired();
builder.Property(x => x.UploadDate)
.IsRequired()
.HasDefaultValueSql("now()");
}
}

View File

@@ -1,38 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Rating;
namespace WatchIt.Database.Model.Configuration.Rating;
public class RatingMediaConfiguration : IEntityTypeConfiguration<RatingMedia>
{
public void Configure(EntityTypeBuilder<RatingMedia> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.Media)
.WithMany(x => x.RatingMedia)
.HasForeignKey(x => x.MediaId)
.IsRequired();
builder.Property(x => x.MediaId)
.IsRequired();
builder.HasOne(x => x.Account)
.WithMany(x => x.RatingMedia)
.HasForeignKey(x => x.AccountId)
.IsRequired();
builder.Property(x => x.AccountId)
.IsRequired();
builder.Property(x => x.Rating)
.IsRequired();
builder.Property(x => x.Date)
.IsRequired()
.HasDefaultValueSql("now()");
}
}

View File

@@ -1,38 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Rating;
namespace WatchIt.Database.Model.Configuration.Rating;
public class RatingMediaSeriesEpisodeConfiguration : IEntityTypeConfiguration<RatingMediaSeriesEpisode>
{
public void Configure(EntityTypeBuilder<RatingMediaSeriesEpisode> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.MediaSeriesEpisode)
.WithMany(x => x.RatingMediaSeriesEpisode)
.HasForeignKey(x => x.MediaSeriesEpisodeId)
.IsRequired();
builder.Property(x => x.MediaSeriesEpisodeId)
.IsRequired();
builder.HasOne(x => x.Account)
.WithMany(x => x.RatingMediaSeriesEpisode)
.HasForeignKey(x => x.AccountId)
.IsRequired();
builder.Property(x => x.AccountId)
.IsRequired();
builder.Property(x => x.Rating)
.IsRequired();
builder.Property(x => x.Date)
.IsRequired()
.HasDefaultValueSql("now()");
}
}

View File

@@ -1,38 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Rating;
namespace WatchIt.Database.Model.Configuration.Rating;
public class RatingMediaSeriesSeasonConfiguration : IEntityTypeConfiguration<RatingMediaSeriesSeason>
{
public void Configure(EntityTypeBuilder<RatingMediaSeriesSeason> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.MediaSeriesSeason)
.WithMany(x => x.RatingMediaSeriesSeason)
.HasForeignKey(x => x.MediaSeriesSeasonId)
.IsRequired();
builder.Property(x => x.MediaSeriesSeasonId)
.IsRequired();
builder.HasOne(x => x.Account)
.WithMany(x => x.RatingMediaSeriesSeason)
.HasForeignKey(x => x.AccountId)
.IsRequired();
builder.Property(x => x.AccountId)
.IsRequired();
builder.Property(x => x.Rating)
.IsRequired();
builder.Property(x => x.Date)
.IsRequired()
.HasDefaultValueSql("now()");
}
}

View File

@@ -1,40 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Rating;
namespace WatchIt.Database.Model.Configuration.Rating;
public class RatingPersonActorRoleConfiguration : IEntityTypeConfiguration<RatingPersonActorRole>
{
public void Configure(EntityTypeBuilder<RatingPersonActorRole> builder)
{
builder.ToTable("RatingsPersonActorRole");
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.PersonActorRole)
.WithMany(x => x.RatingPersonActorRole)
.HasForeignKey(x => x.PersonActorRoleId)
.IsRequired();
builder.Property(x => x.PersonActorRoleId)
.IsRequired();
builder.HasOne(x => x.Account)
.WithMany(x => x.RatingPersonActorRole)
.HasForeignKey(x => x.AccountId)
.IsRequired();
builder.Property(x => x.AccountId)
.IsRequired();
builder.Property(x => x.Rating)
.IsRequired();
builder.Property(x => x.Date)
.IsRequired()
.HasDefaultValueSql("now()");
}
}

View File

@@ -1,40 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Rating;
namespace WatchIt.Database.Model.Configuration.Rating;
public class RatingPersonCreatorRoleConfiguration : IEntityTypeConfiguration<RatingPersonCreatorRole>
{
public void Configure(EntityTypeBuilder<RatingPersonCreatorRole> builder)
{
builder.ToTable("RatingsPersonCreatorRole");
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.PersonCreatorRole)
.WithMany(x => x.RatingPersonCreatorRole)
.HasForeignKey(x => x.PersonCreatorRoleId)
.IsRequired();
builder.Property(x => x.PersonCreatorRoleId)
.IsRequired();
builder.HasOne(x => x.Account)
.WithMany(x => x.RatingPersonCreatorRole)
.HasForeignKey(x => x.AccountId)
.IsRequired();
builder.Property(x => x.AccountId)
.IsRequired();
builder.Property(x => x.Rating)
.IsRequired();
builder.Property(x => x.Date)
.IsRequired()
.HasDefaultValueSql("now()");
}
}

View File

@@ -1,34 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.ViewCount;
namespace WatchIt.Database.Model.Configuration.ViewCount;
public class ViewCountMediaConfiguration : IEntityTypeConfiguration<ViewCountMedia>
{
public void Configure(EntityTypeBuilder<ViewCountMedia> builder)
{
builder.ToTable("ViewCountsMedia");
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.Media)
.WithMany(x => x.ViewCountsMedia)
.HasForeignKey(x => x.MediaId)
.IsRequired();
builder.Property(x => x.MediaId)
.IsRequired();
builder.Property(x => x.Date)
.IsRequired()
.HasDefaultValueSql("now()");
builder.Property(x => x.ViewCount)
.IsRequired()
.HasDefaultValue(0);
}
}

View File

@@ -1,34 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.ViewCount;
namespace WatchIt.Database.Model.Configuration.ViewCount;
public class ViewCountPersonConfiguration : IEntityTypeConfiguration<ViewCountPerson>
{
public void Configure(EntityTypeBuilder<ViewCountPerson> builder)
{
builder.ToTable("ViewCountsPerson");
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.Person)
.WithMany(x => x.ViewCountsPerson)
.HasForeignKey(x => x.PersonId)
.IsRequired();
builder.Property(x => x.PersonId)
.IsRequired();
builder.Property(x => x.Date)
.IsRequired()
.HasDefaultValueSql("now()");
builder.Property(x => x.ViewCount)
.IsRequired()
.HasDefaultValue(0);
}
}

View File

@@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\WatchIt.Database.Model.Seeding\WatchIt.Database.Model.Seeding.csproj" />
<ProjectReference Include="..\WatchIt.Database.Model\WatchIt.Database.Model.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.5" />
</ItemGroup>
</Project>

View File

@@ -1,12 +0,0 @@
[
{
"Id": 1,
"Name": "Afghanistan",
"IsHistorical": false
},
{
"Id": 2,
"Name": "Albania",
"IsHistorical": false
}
]

View File

@@ -1,10 +0,0 @@
[
{
"Id": 1,
"Name": "Male"
},
{
"Id": 2,
"Name": "Female"
}
]

View File

@@ -1,22 +0,0 @@
[
{
"Id": 1,
"Name": "Comedy"
},
{
"Id": 2,
"Name": "Thriller"
},
{
"Id": 3,
"Name": "Horror"
},
{
"Id": 4,
"Name": "Action"
},
{
"Id": 5,
"Name": "Drama"
}
]

View File

@@ -1,14 +0,0 @@
[
{
"Id": 1,
"Name": "Actor"
},
{
"Id": 2,
"Name": "Supporting actor"
},
{
"Id": 3,
"Name": "Voice actor"
}
]

View File

@@ -1,14 +0,0 @@
[
{
"Id": 1,
"Name": "Director"
},
{
"Id": 2,
"Name": "Producer"
},
{
"Id": 3,
"Name": "Screenwriter"
}
]

View File

@@ -1,24 +0,0 @@
using System.Diagnostics;
using System.Text.Json;
namespace WatchIt.Database.Model.Seeding;
public class DataReader
{
#region METHODS
public static IEnumerable<T> Read<T>() => Read<T>(typeof(T).Name);
public static IEnumerable<T> Read<T>(string filename)
{
string jsonFile = $@"{AppContext.BaseDirectory}/Data/{filename}.json";
string dataString = File.ReadAllText(jsonFile);
IEnumerable<T>? data = JsonSerializer.Deserialize<IEnumerable<T>>(dataString);
if (data is null)
{
throw new JsonException();
}
return data;
}
#endregion
}

View File

@@ -1,27 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Update="Data\Country.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\Gender.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\Genre.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\PersonActorRoleType.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\PersonCreatorRoleType.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -1,47 +0,0 @@
using WatchIt.Database.Model.Common;
using WatchIt.Database.Model.Media;
using WatchIt.Database.Model.Rating;
namespace WatchIt.Database.Model.Account;
public class Account
{
#region PROPERTIES
public long Id { get; set; }
public required string Username { get; set; }
public required string Email { get; set; }
public string? Description { get; set; }
public short? GenderId { get; set; }
public Guid? ProfilePictureId { get; set; }
public Guid? BackgroundPictureId { get; set; }
public byte[] Password { get; set; }
public string LeftSalt { get; set; }
public string RightSalt { get; set; }
public bool IsAdmin { get; set; } = false;
public DateTime CreationDate { get; set; }
public DateTime LastActive { get; set; }
#endregion
#region NAVIGATION
public virtual Gender? Gender { get; set; }
public virtual AccountProfilePicture? ProfilePicture { get; set; }
public virtual MediaPhotoImage? BackgroundPicture { get; set; }
public virtual IEnumerable<RatingMedia> RatingMedia { get; set; } = new List<RatingMedia>();
public virtual IEnumerable<RatingPersonActorRole> RatingPersonActorRole { get; set; } = new List<RatingPersonActorRole>();
public virtual IEnumerable<RatingPersonCreatorRole> RatingPersonCreatorRole { get; set; } = new List<RatingPersonCreatorRole>();
public virtual IEnumerable<RatingMediaSeriesSeason> RatingMediaSeriesSeason { get; set; } = new List<RatingMediaSeriesSeason>();
public virtual IEnumerable<RatingMediaSeriesEpisode> RatingMediaSeriesEpisode { get; set; } = new List<RatingMediaSeriesEpisode>();
public virtual IEnumerable<AccountRefreshToken> AccountRefreshTokens { get; set; } = new List<AccountRefreshToken>();
public virtual IEnumerable<AccountFollow> AccountFollows { get; set; } = new List<AccountFollow>();
public virtual IEnumerable<AccountFollow> AccountFollowers { get; set; } = new List<AccountFollow>();
#endregion
}

Some files were not shown because too many files have changed in this diff Show More